添加获取所有用户的Server API
This commit is contained in:
+59
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the Wildfire Chat package.
|
||||||
|
* (c) Heavyrain2012 <[email protected]>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.xiaoleilu.loServer.action.admin;
|
||||||
|
|
||||||
|
import cn.wildfirechat.common.APIPath;
|
||||||
|
import cn.wildfirechat.common.ErrorCode;
|
||||||
|
import cn.wildfirechat.pojos.InputGetUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.InputGetUserList;
|
||||||
|
import cn.wildfirechat.pojos.InputOutputUserInfo;
|
||||||
|
import cn.wildfirechat.pojos.OutputGetUserList;
|
||||||
|
import cn.wildfirechat.proto.WFCMessage;
|
||||||
|
import com.xiaoleilu.loServer.RestResult;
|
||||||
|
import com.xiaoleilu.loServer.annotation.HttpMethod;
|
||||||
|
import com.xiaoleilu.loServer.annotation.Route;
|
||||||
|
import com.xiaoleilu.loServer.handler.Request;
|
||||||
|
import com.xiaoleilu.loServer.handler.Response;
|
||||||
|
import io.netty.handler.codec.http.FullHttpRequest;
|
||||||
|
import io.netty.util.internal.StringUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Route(APIPath.User_Get_All)
|
||||||
|
@HttpMethod("POST")
|
||||||
|
public class GetAllUserAction extends AdminAction {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isTransactionAction() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean action(Request request, Response response) {
|
||||||
|
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||||
|
InputGetUserList input = getRequestBody(request.getNettyRequest(), InputGetUserList.class);
|
||||||
|
if (input != null && input.count > 0 && input.offset >= 0) {
|
||||||
|
List<WFCMessage.User> users = messagesStore.getUserInfoList(input.count, input.offset);
|
||||||
|
OutputGetUserList outputGetUserList = new OutputGetUserList();
|
||||||
|
outputGetUserList.userInfoList = new ArrayList<>();
|
||||||
|
for (WFCMessage.User user : users) {
|
||||||
|
outputGetUserList.userInfoList.add(InputOutputUserInfo.fromPbUser(user));
|
||||||
|
}
|
||||||
|
|
||||||
|
RestResult result = RestResult.ok(outputGetUserList);
|
||||||
|
setResponseContent(result, response);
|
||||||
|
} else {
|
||||||
|
setResponseContent(RestResult.resultOf(ErrorCode.INVALID_PARAMETER), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2640,6 +2640,103 @@ public class DatabaseStore {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<WFCMessage.User> getAllUsers(int count, int offset) {
|
||||||
|
Connection connection = null;
|
||||||
|
PreparedStatement statement = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<WFCMessage.User> outList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
connection = DBUtil.getConnection();
|
||||||
|
String sql = "select `_uid`, `_name`" +
|
||||||
|
", `_display_name`" +
|
||||||
|
", `_portrait`" +
|
||||||
|
", `_mobile`" +
|
||||||
|
", `_gender`" +
|
||||||
|
", `_email`" +
|
||||||
|
", `_address`" +
|
||||||
|
", `_company`" +
|
||||||
|
", `_social`" +
|
||||||
|
", `_extra`" +
|
||||||
|
", `_type`" +
|
||||||
|
", `_deleted`" +
|
||||||
|
", `_dt` from t_user where `_deleted` = 0 order by _createTime limit ? offset ?";
|
||||||
|
statement = connection.prepareStatement(sql);
|
||||||
|
|
||||||
|
int index = 1;
|
||||||
|
statement.setInt(1, count);
|
||||||
|
statement.setInt(2, offset);
|
||||||
|
|
||||||
|
|
||||||
|
rs = statement.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
WFCMessage.User.Builder builder = WFCMessage.User.newBuilder();
|
||||||
|
index = 1;
|
||||||
|
String value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setUid(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setName(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setDisplayName(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setPortrait(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setMobile(value);
|
||||||
|
|
||||||
|
int gender = rs.getInt(index++);
|
||||||
|
builder.setGender(gender);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setEmail(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setAddress(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setCompany(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setSocial(value);
|
||||||
|
|
||||||
|
value = rs.getString(index++);
|
||||||
|
value = (value == null ? "" : value);
|
||||||
|
builder.setExtra(value);
|
||||||
|
|
||||||
|
int type = rs.getInt(index++);
|
||||||
|
builder.setType(type);
|
||||||
|
|
||||||
|
int deleted = rs.getInt(index++);
|
||||||
|
builder.setDeleted(deleted);
|
||||||
|
|
||||||
|
long longValue = rs.getLong(index++);
|
||||||
|
if(longValue <= 0)
|
||||||
|
longValue = 1;
|
||||||
|
builder.setUpdateDt(longValue);
|
||||||
|
|
||||||
|
outList.add(builder.build());
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
Utility.printExecption(LOG, e, RDBS_Exception);
|
||||||
|
} finally {
|
||||||
|
DBUtil.closeDB(connection, statement, rs);
|
||||||
|
}
|
||||||
|
return outList;
|
||||||
|
}
|
||||||
|
|
||||||
Set<String> getAllEnds() {
|
Set<String> getAllEnds() {
|
||||||
Connection connection = null;
|
Connection connection = null;
|
||||||
PreparedStatement statement = null;
|
PreparedStatement statement = null;
|
||||||
|
|||||||
@@ -2764,6 +2764,12 @@ public class MemoryMessagesStore implements IMessagesStore {
|
|||||||
String userId = databaseStore.getUserIdByMobile(mobile);
|
String userId = databaseStore.getUserIdByMobile(mobile);
|
||||||
return getUserInfo(userId);
|
return getUserInfo(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<WFCMessage.User> getUserInfoList(int count, int offset) {
|
||||||
|
return databaseStore.getAllUsers(count, offset);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WFCMessage.User> searchUser(String keyword, int searchType, int page) {
|
public List<WFCMessage.User> searchUser(String keyword, int searchType, int page) {
|
||||||
if (mDisableSearch) {
|
if (mDisableSearch) {
|
||||||
|
|||||||
@@ -158,6 +158,8 @@ public interface IMessagesStore {
|
|||||||
WFCMessage.User getUserInfoByMobile(String mobile);
|
WFCMessage.User getUserInfoByMobile(String mobile);
|
||||||
List<WFCMessage.User> searchUser(String keyword, int searchType, int page);
|
List<WFCMessage.User> searchUser(String keyword, int searchType, int page);
|
||||||
|
|
||||||
|
List<WFCMessage.User> getUserInfoList(int count, int offset);
|
||||||
|
|
||||||
boolean updateSystemSetting(int id, String value, String desc);
|
boolean updateSystemSetting(int id, String value, String desc);
|
||||||
SystemSettingPojo getSystemSetting(int id);
|
SystemSettingPojo getSystemSetting(int id);
|
||||||
void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo);
|
void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public interface APIPath {
|
|||||||
String User_Get_Token = "/admin/user/get_token";
|
String User_Get_Token = "/admin/user/get_token";
|
||||||
String User_Update_Block_Status = "/admin/user/update_block_status";
|
String User_Update_Block_Status = "/admin/user/update_block_status";
|
||||||
String User_Get_Info = "/admin/user/get_info";
|
String User_Get_Info = "/admin/user/get_info";
|
||||||
|
String User_Get_All = "/admin/user/all";
|
||||||
String User_Get_Robot_Info = "/admin/user/get_robot_info";
|
String User_Get_Robot_Info = "/admin/user/get_robot_info";
|
||||||
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
|
String User_Get_Blocked_List = "/admin/user/get_blocked_list";
|
||||||
String User_Check_Block_Status = "/admin/user/check_block_status";
|
String User_Check_Block_Status = "/admin/user/check_block_status";
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
public class InputGetUserList {
|
||||||
|
public int count;
|
||||||
|
public int offset;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package cn.wildfirechat.pojos;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OutputGetUserList {
|
||||||
|
public List<InputOutputUserInfo> userInfoList;
|
||||||
|
}
|
||||||
+1
-1
@@ -27,7 +27,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-codec</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
<version>1.11</version>
|
<version>1.15</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -300,6 +300,20 @@ public class Main {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int limit = 5;
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
IMResult<OutputGetUserList> getUserListIMResult = UserAdmin.getAllUsers(limit, i*limit);
|
||||||
|
if (getUserListIMResult != null && getUserListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
System.out.println("getUserListIMResult success");
|
||||||
|
if(getUserListIMResult.getResult().userInfoList.size() < limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println("getUserListIMResult failure");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (commercialServer) {
|
if (commercialServer) {
|
||||||
IMResult<GetOnlineUserCountResult> getOnlineUserCountResultIMResult = UserAdmin.getOnlineUserCount();
|
IMResult<GetOnlineUserCountResult> getOnlineUserCountResultIMResult = UserAdmin.getOnlineUserCount();
|
||||||
if (getOnlineUserCountResultIMResult != null && getOnlineUserCountResultIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
if (getOnlineUserCountResultIMResult != null && getOnlineUserCountResultIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ public class UserAdmin {
|
|||||||
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IMResult<OutputGetUserList> getAllUsers(int count, int offset) throws Exception {
|
||||||
|
String path = APIPath.User_Get_All;
|
||||||
|
InputGetUserList input = new InputGetUserList();
|
||||||
|
input.count = count;
|
||||||
|
input.offset = offset;
|
||||||
|
return AdminHttpUtils.httpJsonPost(path, input, OutputGetUserList.class);
|
||||||
|
}
|
||||||
|
|
||||||
public static IMResult<OutputCreateUser> createUser(InputOutputUserInfo user) throws Exception {
|
public static IMResult<OutputCreateUser> createUser(InputOutputUserInfo user) throws Exception {
|
||||||
String path = APIPath.Create_User;
|
String path = APIPath.Create_User;
|
||||||
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user