diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllUserAction.java new file mode 100755 index 000000000..eb7574040 --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllUserAction.java @@ -0,0 +1,59 @@ +/* + * This file is part of the Wildfire Chat package. + * (c) Heavyrain2012 + * + * 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 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; + } +} diff --git a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java index d175ec92e..433285a50 100644 --- a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java +++ b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java @@ -2640,6 +2640,103 @@ String getUserIdByMobile(String mobile) { return null; } + List getAllUsers(int count, int offset) { + Connection connection = null; + PreparedStatement statement = null; + ResultSet rs = null; + List 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 getAllEnds() { Connection connection = null; PreparedStatement statement = null; diff --git a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java index 4c3e4cee6..029def629 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -2764,6 +2764,12 @@ public WFCMessage.User getUserInfoByMobile(String mobile) { String userId = databaseStore.getUserIdByMobile(mobile); return getUserInfo(userId); } + + @Override + public List getUserInfoList(int count, int offset) { + return databaseStore.getAllUsers(count, offset); + } + @Override public List searchUser(String keyword, int searchType, int page) { if (mDisableSearch) { diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 16080a327..ea2d8adad 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -158,6 +158,8 @@ public String toString() { WFCMessage.User getUserInfoByMobile(String mobile); List searchUser(String keyword, int searchType, int page); + List getUserInfoList(int count, int offset); + boolean updateSystemSetting(int id, String value, String desc); SystemSettingPojo getSystemSetting(int id); void createChatroom(String chatroomId, WFCMessage.ChatroomInfo chatroomInfo); diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index 973793d4d..b941f8a60 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -26,6 +26,7 @@ public interface APIPath { String User_Get_Token = "/admin/user/get_token"; String User_Update_Block_Status = "/admin/user/update_block_status"; 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_Blocked_List = "/admin/user/get_blocked_list"; String User_Check_Block_Status = "/admin/user/check_block_status"; diff --git a/common/src/main/java/cn/wildfirechat/pojos/InputGetUserList.java b/common/src/main/java/cn/wildfirechat/pojos/InputGetUserList.java new file mode 100644 index 000000000..d67bfa048 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/InputGetUserList.java @@ -0,0 +1,6 @@ +package cn.wildfirechat.pojos; + +public class InputGetUserList { + public int count; + public int offset; +} diff --git a/common/src/main/java/cn/wildfirechat/pojos/OutputGetUserList.java b/common/src/main/java/cn/wildfirechat/pojos/OutputGetUserList.java new file mode 100644 index 000000000..e2597b6f5 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputGetUserList.java @@ -0,0 +1,7 @@ +package cn.wildfirechat.pojos; + +import java.util.List; + +public class OutputGetUserList { + public List userInfoList; +} diff --git a/sdk/sdk_readme.txt b/sdk/sdk_readme.txt index bdf6ebac7..e9e69055c 100644 --- a/sdk/sdk_readme.txt +++ b/sdk/sdk_readme.txt @@ -27,7 +27,7 @@ commons-codec commons-codec - 1.11 + 1.15 diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 272c2c2e1..2ecd2098b 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -300,6 +300,20 @@ static void testUser() throws Exception { System.exit(-1); } + int limit = 5; + for (int i = 0; i < 100; i++) { + IMResult 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) { IMResult getOnlineUserCountResultIMResult = UserAdmin.getOnlineUserCount(); if (getOnlineUserCountResultIMResult != null && getOnlineUserCountResultIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java index bba3c5b4f..cac4470e1 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java @@ -24,6 +24,14 @@ public static IMResult getUserByMobile(String mobile) throw return AdminHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class); } + public static IMResult 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 createUser(InputOutputUserInfo user) throws Exception { String path = APIPath.Create_User; return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);