From 576fcf3e7783f6d3cb9ee95582627eb9a2d72afe Mon Sep 17 00:00:00 2001 From: heavyrian2012 Date: Sun, 5 Apr 2026 11:28:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=9C=BA=E5=99=A8=E4=BA=BA=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/admin/GetAllRobotAction.java | 62 ++++++++++++++++++ .../moquette/persistence/DatabaseStore.java | 63 +++++++++++++++++++ .../persistence/MemoryMessagesStore.java | 5 ++ .../java/io/moquette/spi/IMessagesStore.java | 1 + .../java/cn/wildfirechat/common/APIPath.java | 1 + .../pojos/OutputGetRobotList.java | 7 +++ .../main/java/cn/wildfirechat/sdk/Main.java | 9 +++ .../java/cn/wildfirechat/sdk/UserAdmin.java | 15 +++++ 8 files changed, 163 insertions(+) create mode 100755 broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllRobotAction.java create mode 100644 common/src/main/java/cn/wildfirechat/pojos/OutputGetRobotList.java diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllRobotAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllRobotAction.java new file mode 100755 index 00000000..7a9636be --- /dev/null +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/GetAllRobotAction.java @@ -0,0 +1,62 @@ +/* + * 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.*; +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.*; + +@Route(APIPath.User_Get_All_Robots) +@HttpMethod("POST") +public class GetAllRobotAction 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 robots = messagesStore.getRobotInfoList(input.count, input.offset); + + OutputGetRobotList outputGetUserList = new OutputGetRobotList(); + outputGetUserList.robotInfoList = new ArrayList<>(); + robots.forEach(robotData -> { + WFCMessage.User userInfoData = messagesStore.getUserInfo(robotData.getUid()); + if (userInfoData != null && !StringUtil.isNullOrEmpty(userInfoData.getName()) && userInfoData.getDeleted() ==0) { + OutputRobot outputRobot = new OutputRobot(); + outputRobot.fromUser(userInfoData); + outputRobot.fromRobot(robotData, true); + outputGetUserList.robotInfoList.add(outputRobot); + } + }); + + 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 af1dcea1..5c43767e 100644 --- a/broker/src/main/java/io/moquette/persistence/DatabaseStore.java +++ b/broker/src/main/java/io/moquette/persistence/DatabaseStore.java @@ -3188,6 +3188,69 @@ public class DatabaseStore { return outList; } + List getAllRobots(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`, `_owner`" + + ", `_secret`" + + ", `_callback`" + + ", `_state`" + + ", `_extra`" + + ", `_dt` from t_robot limit ? offset ?"; + statement = connection.prepareStatement(sql); + + int index = 1; + statement.setInt(1, count); + statement.setInt(2, offset); + + rs = statement.executeQuery(); + while (rs.next()) { + WFCMessage.Robot.Builder builder = WFCMessage.Robot.newBuilder(); + index = 1; + String value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setUid(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setOwner(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setSecret(value); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setCallback(value); + + + int state = rs.getInt(index++); + builder.setState(state); + + value = rs.getString(index++); + value = (value == null ? "" : value); + builder.setExtra(value); + + long longValue = rs.getLong(index++); + + 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; + } + List getUserRobotIds(String userId) { 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 b49246a5..8db21c3e 100755 --- a/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java +++ b/broker/src/main/java/io/moquette/persistence/MemoryMessagesStore.java @@ -3277,6 +3277,11 @@ public class MemoryMessagesStore implements IMessagesStore { return databaseStore.getAllUsers(count, offset); } + @Override + public List getRobotInfoList(int count, int offset) { + return databaseStore.getAllRobots(count, offset); + } + @Override public List getUserRobotIds(String userId) { return databaseStore.getUserRobotIds(userId); diff --git a/broker/src/main/java/io/moquette/spi/IMessagesStore.java b/broker/src/main/java/io/moquette/spi/IMessagesStore.java index 7e5b934e..5fc6ed36 100755 --- a/broker/src/main/java/io/moquette/spi/IMessagesStore.java +++ b/broker/src/main/java/io/moquette/spi/IMessagesStore.java @@ -157,6 +157,7 @@ public interface IMessagesStore { ErrorCode searchUser(String userId, String keyword, int searchType, int userType, int page, List users); List getUserInfoList(int count, int offset); + List getRobotInfoList(int count, int offset); List getUserRobotIds(String userId); boolean updateSystemSetting(int id, String value, String desc); diff --git a/common/src/main/java/cn/wildfirechat/common/APIPath.java b/common/src/main/java/cn/wildfirechat/common/APIPath.java index 51fd24ad..f4b5f108 100644 --- a/common/src/main/java/cn/wildfirechat/common/APIPath.java +++ b/common/src/main/java/cn/wildfirechat/common/APIPath.java @@ -45,6 +45,7 @@ public interface APIPath { String User_Get_Email_Info = "/admin/user/get_info_by_email"; String User_Get_All = "/admin/user/all"; String User_Get_Robot_Info = "/admin/user/get_robot_info"; + String User_Get_All_Robots = "/admin/user/get_all_robots"; String User_Get_User_Robots = "/admin/user/get_user_robots"; 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/OutputGetRobotList.java b/common/src/main/java/cn/wildfirechat/pojos/OutputGetRobotList.java new file mode 100644 index 00000000..8a3eceaf --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/pojos/OutputGetRobotList.java @@ -0,0 +1,7 @@ +package cn.wildfirechat.pojos; + +import java.util.List; + +public class OutputGetRobotList { + public List robotInfoList; +} diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java index 6eb2a0cc..1ed03bf8 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/Main.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/Main.java @@ -465,6 +465,15 @@ public class Main { System.exit(-1); } + // 获取所有机器人列表(分页:每页100条,第0页) + IMResult getRobotListIMResult = UserAdmin.getAllRobots(100, 0); + if (getRobotListIMResult != null && getRobotListIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) { + System.out.println("getRobotListIMResult success"); + } else { + System.out.println("getRobotListIMResult failure"); + System.exit(-1); + } + // 商业版专属功能 if (commercialServer) { // 获取在线用户总数 diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java index f24646d0..1cd94112 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/UserAdmin.java @@ -117,6 +117,21 @@ public class UserAdmin { return AdminHttpUtils.httpJsonPost(path, input, OutputGetUserList.class); } + /** + * 获取所有机器人列表(分页) + * @param count 每页数量 + * @param offset 偏移量 + * @return 机器人列表 + * @throws Exception 请求失败时抛出异常 + */ + public static IMResult getAllRobots(int count, int offset) throws Exception { + String path = APIPath.User_Get_All_Robots; + InputGetUserList input = new InputGetUserList(); + input.count = count; + input.offset = offset; + return AdminHttpUtils.httpJsonPost(path, input, OutputGetRobotList.class); + } + /** * 批量获取用户信息 * @param userIds 用户ID列表