添加获取所有机器人的接口

This commit is contained in:
heavyrian2012
2026-04-05 11:28:46 +08:00
parent 33f2124352
commit 576fcf3e77
8 changed files with 163 additions and 0 deletions
@@ -0,0 +1,62 @@
/*
* 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.*;
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<WFCMessage.Robot> 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;
}
}
@@ -3188,6 +3188,69 @@ public class DatabaseStore {
return outList; return outList;
} }
List<WFCMessage.Robot> getAllRobots(int count, int offset) {
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
List<WFCMessage.Robot> 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<String> getUserRobotIds(String userId) { List<String> getUserRobotIds(String userId) {
Connection connection = null; Connection connection = null;
PreparedStatement statement = null; PreparedStatement statement = null;
@@ -3277,6 +3277,11 @@ public class MemoryMessagesStore implements IMessagesStore {
return databaseStore.getAllUsers(count, offset); return databaseStore.getAllUsers(count, offset);
} }
@Override
public List<WFCMessage.Robot> getRobotInfoList(int count, int offset) {
return databaseStore.getAllRobots(count, offset);
}
@Override @Override
public List<String> getUserRobotIds(String userId) { public List<String> getUserRobotIds(String userId) {
return databaseStore.getUserRobotIds(userId); return databaseStore.getUserRobotIds(userId);
@@ -157,6 +157,7 @@ public interface IMessagesStore {
ErrorCode searchUser(String userId, String keyword, int searchType, int userType, int page, List<WFCMessage.User> users); ErrorCode searchUser(String userId, String keyword, int searchType, int userType, int page, List<WFCMessage.User> users);
List<WFCMessage.User> getUserInfoList(int count, int offset); List<WFCMessage.User> getUserInfoList(int count, int offset);
List<WFCMessage.Robot> getRobotInfoList(int count, int offset);
List<String> getUserRobotIds(String userId); List<String> getUserRobotIds(String userId);
boolean updateSystemSetting(int id, String value, String desc); boolean updateSystemSetting(int id, String value, String desc);
@@ -45,6 +45,7 @@ public interface APIPath {
String User_Get_Email_Info = "/admin/user/get_info_by_email"; String User_Get_Email_Info = "/admin/user/get_info_by_email";
String User_Get_All = "/admin/user/all"; 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_All_Robots = "/admin/user/get_all_robots";
String User_Get_User_Robots = "/admin/user/get_user_robots"; String User_Get_User_Robots = "/admin/user/get_user_robots";
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,7 @@
package cn.wildfirechat.pojos;
import java.util.List;
public class OutputGetRobotList {
public List<OutputRobot> robotInfoList;
}
@@ -465,6 +465,15 @@ public class Main {
System.exit(-1); System.exit(-1);
} }
// 获取所有机器人列表(分页:每页100条,第0页)
IMResult<OutputGetRobotList> 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) { if (commercialServer) {
// 获取在线用户总数 // 获取在线用户总数
@@ -117,6 +117,21 @@ public class UserAdmin {
return AdminHttpUtils.httpJsonPost(path, input, OutputGetUserList.class); return AdminHttpUtils.httpJsonPost(path, input, OutputGetUserList.class);
} }
/**
* 获取所有机器人列表(分页)
* @param count 每页数量
* @param offset 偏移量
* @return 机器人列表
* @throws Exception 请求失败时抛出异常
*/
public static IMResult<OutputGetRobotList> 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列表 * @param userIds 用户ID列表