优化机器人/无人机逻辑

This commit is contained in:
weitang 2025-04-25 10:15:46 +08:00
parent 7b0eda3fb8
commit d8002fae52
7 changed files with 23 additions and 21 deletions

View File

@ -446,8 +446,8 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
SubstationPatroldevice substationPatroldevice = list.get(0); SubstationPatroldevice substationPatroldevice = list.get(0);
// 发送任务到机器人 // 发送任务到机器人
JSONArray jsonArray = JSONUtil.parseArray(items); JSONArray jsonArray = JSONUtil.parseArray(items);
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(),
httpServerConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), Type, Command, httpServerConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(), Type, Command,
Code, jsonArray.toString()); Code, jsonArray.toString());
} }
} }
@ -846,7 +846,7 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
// 机器人系统编码 // 机器人系统编码
String internationalId = substationPatroldevice.getInternationalId(); String internationalId = substationPatroldevice.getInternationalId();
// 机器人任务 // 机器人任务
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(),
httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null); httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null);
// 创建事件并注册 // 创建事件并注册
Event event = new Event(taskTodo.getTaskTodoId(), response -> { Event event = new Event(taskTodo.getTaskTodoId(), response -> {
@ -914,7 +914,7 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
// 机器人系统编码 // 机器人系统编码
String internationalId = substationPatroldevice.getInternationalId(); String internationalId = substationPatroldevice.getInternationalId();
// 机器人任务 // 机器人任务
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(),
httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null); httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null);
// 创建事件并注册 // 创建事件并注册
Event event = new Event(taskTodo.getTaskTodoId(), response -> { Event event = new Event(taskTodo.getTaskTodoId(), response -> {
@ -991,7 +991,7 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
// 机器人系统编码 // 机器人系统编码
String internationalId = substationPatroldevice.getInternationalId(); String internationalId = substationPatroldevice.getInternationalId();
// 机器人任务 // 机器人任务
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(),
httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null); httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null);
// 创建事件并注册 // 创建事件并注册
Event event = new Event(task.getTaskCode(), response -> { Event event = new Event(task.getTaskCode(), response -> {
@ -1063,7 +1063,7 @@ public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandler
// 机器人系统编码 // 机器人系统编码
String internationalId = substationPatroldevice.getInternationalId(); String internationalId = substationPatroldevice.getInternationalId();
// 机器人任务 // 机器人任务
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(),
httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null); httpServerConfig.getPatrolServerid(), internationalId, Type, Command, Code, null);
// 创建事件并注册 // 创建事件并注册
Event event = new Event(taskTodo.getTaskTodoId(), response -> { Event event = new Event(taskTodo.getTaskTodoId(), response -> {

View File

@ -187,7 +187,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<MyMessagePro
jsonArray.add(jsonObject); jsonArray.add(jsonObject);
WebSocketServer.sendInfo("robot_status_data", jsonArray.toString()); WebSocketServer.sendInfo("robot_status_data", jsonArray.toString());
} }
ChannelMap.getChannelMap().put(stationNodeIP, ctx.channel()); // ChannelMap.getChannelMap().put(stationNodeIP, ctx.channel());
} }
/** /**
@ -224,6 +224,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<MyMessagePro
Map<String, Object> map = MyXmlUtil.xmlToMap(xml); Map<String, Object> map = MyXmlUtil.xmlToMap(xml);
String Type = map.get("Type").toString(); String Type = map.get("Type").toString();
String Command = map.get("Command").toString(); String Command = map.get("Command").toString();
String SendCode = map.get("SendCode").toString();
String Code = ""; String Code = "";
if (ObjectUtil.isNotEmpty(map.get("Code"))) { if (ObjectUtil.isNotEmpty(map.get("Code"))) {
Code = map.get("Code").toString(); Code = map.get("Code").toString();
@ -250,6 +251,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<MyMessagePro
SystemCode.SUCCESS_STATUS_CODE.getCode(), jsonObject.toString()); SystemCode.SUCCESS_STATUS_CODE.getCode(), jsonObject.toString());
log.info("响应信息" + reponsexml); log.info("响应信息" + reponsexml);
sendResponseData(ctx, msg, reponsexml); sendResponseData(ctx, msg, reponsexml);
ChannelMap.getChannelMap().put(SendCode, ctx.channel());
log.info("机器人/无人机注册成功!{}", map.get("SendCode").toString()); log.info("机器人/无人机注册成功!{}", map.get("SendCode").toString());
} }
if (SystemCode.TYPE_SYSTEM_MESSAGE_CODE.getCode().equals(Type) && SystemCode.COMMAND_HEARTBEAT_CODE.getCode().equals(Command)) { if (SystemCode.TYPE_SYSTEM_MESSAGE_CODE.getCode().equals(Type) && SystemCode.COMMAND_HEARTBEAT_CODE.getCode().equals(Command)) {

View File

@ -357,7 +357,7 @@ public class LinkageSignalController {
List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, robotCode)); List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, robotCode));
if (list.size() > 0) { if (list.size() > 0) {
SubstationPatroldevice substationPatroldevice = list.get(0); SubstationPatroldevice substationPatroldevice = list.get(0);
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(),
SystemCode.TYPE_LINKAGE_TASK_ISSUED_CODE.getCode(), SystemCode.COMMAND_TASK_CONFIG_CODE.getCode(), code, jsonObject.toString()); SystemCode.TYPE_LINKAGE_TASK_ISSUED_CODE.getCode(), SystemCode.COMMAND_TASK_CONFIG_CODE.getCode(), code, jsonObject.toString());
} }
} }

View File

@ -183,7 +183,7 @@ public class ExaminePlanController {
List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, robotCode)); List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, robotCode));
if (list.size() > 0) { if (list.size() > 0) {
SubstationPatroldevice substationPatroldevice = list.get(0); SubstationPatroldevice substationPatroldevice = list.get(0);
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(),
SystemCode.TYPE_EXAMINE_ISSUED_CODE.getCode(), SystemCode.COMMAND_EXAMINE_CONFIG_CODE.getCode(), examinePlan.getStationCode(), jsonObject.toString()); SystemCode.TYPE_EXAMINE_ISSUED_CODE.getCode(), SystemCode.COMMAND_EXAMINE_CONFIG_CODE.getCode(), examinePlan.getStationCode(), jsonObject.toString());
} }
} }

View File

@ -224,7 +224,7 @@ public class TaskController {
taskService.createTodoTaskList(task); taskService.createTodoTaskList(task);
} }
} else { } else {
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), SystemCode.TYPE_TASK_CONTROL_CODE.getCode(), SystemCode.COMMAND_TASK_START_CODE.getCode(), task.getTaskCode(), null); stationRobotService.sendCommand(substationPatroldevice.getInternationalId(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(), SystemCode.TYPE_TASK_CONTROL_CODE.getCode(), SystemCode.COMMAND_TASK_START_CODE.getCode(), task.getTaskCode(), null);
} }
} }
@ -346,7 +346,7 @@ public class TaskController {
List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, task.getRobotCode())); List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, task.getRobotCode()));
if (list.size() > 0) { if (list.size() > 0) {
SubstationPatroldevice substationPatroldevice = list.get(0); SubstationPatroldevice substationPatroldevice = list.get(0);
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(),
SystemCode.TYPE_TASK_ISSUED_CODE.getCode(), SystemCode.COMMAND_TASK_CONFIG_CODE.getCode(), task.getStationCode(), jsonObject.toString()); SystemCode.TYPE_TASK_ISSUED_CODE.getCode(), SystemCode.COMMAND_TASK_CONFIG_CODE.getCode(), task.getStationCode(), jsonObject.toString());
} }
if ("1".equals(task.getTaskTodoType())) { if ("1".equals(task.getTaskTodoType())) {

View File

@ -186,7 +186,7 @@ public class TaskTodoController {
List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, robotCode)); List<SubstationPatroldevice> list = substationPatroldeviceService.list(new LambdaQueryWrapper<SubstationPatroldevice>().eq(SubstationPatroldevice::getPatroldeviceCode, robotCode));
if (list.size() > 0) { if (list.size() > 0) {
SubstationPatroldevice substationPatroldevice = list.get(0); SubstationPatroldevice substationPatroldevice = list.get(0);
stationRobotService.sendCommand(substationPatroldevice.getIpaddr(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), SystemCode.TYPE_TASK_CONTROL_CODE.getCode(), stationRobotService.sendCommand(substationPatroldevice.getInternationalId(), httpServerConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(), SystemCode.TYPE_TASK_CONTROL_CODE.getCode(),
Command, Code, null); Command, Code, null);
} }
LambdaUpdateWrapper<TaskTodo> updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper<TaskTodo> updateWrapper = new LambdaUpdateWrapper<>();

View File

@ -115,10 +115,10 @@ public class StationRobotServiceImpl extends ServiceImpl<SubstationMapper, Subst
} }
@Override @Override
public void sendCommand(String targetIp, String sendcode, String receivecode, String type, String command, public void sendCommand(String targetId, String sendcode, String receivecode, String type, String command,
String code, String items) { String code, String items) {
log.info("进入sendCommand方法"); log.info("进入sendCommand方法");
if (StrUtil.isBlank(targetIp)) { if (StrUtil.isBlank(targetId)) {
log.info("判断机器人"); log.info("判断机器人");
// 机器人编码 // 机器人编码
List<SubstationPatroldevice> list = List<SubstationPatroldevice> list =
@ -126,10 +126,10 @@ public class StationRobotServiceImpl extends ServiceImpl<SubstationMapper, Subst
// 发送机器人控制指令 // 发送机器人控制指令
if (list.size() > 0) { if (list.size() > 0) {
SubstationPatroldevice substationPatroldevice = list.get(0); SubstationPatroldevice substationPatroldevice = list.get(0);
sendMsgtoRobot(substationPatroldevice.getIpaddr(), sendcode, substationPatroldevice.getCustom3(), type, command, code, items); sendMsgtoRobot(substationPatroldevice.getInternationalId(), sendcode, substationPatroldevice.getInternationalId(), type, command, code, items);
} }
} else { } else {
sendMsgtoRobot(targetIp, sendcode, receivecode, type, command, code, items); sendMsgtoRobot(targetId, sendcode, receivecode, type, command, code, items);
} }
@ -209,7 +209,7 @@ public class StationRobotServiceImpl extends ServiceImpl<SubstationMapper, Subst
/** /**
* 机器人发送消息 * 机器人发送消息
* *
* @param targetip 变电站IP * @param targetIp 目标id
* sendcode 发送方GBId * sendcode 发送方GBId
* receivecode 接收方BGId * receivecode 接收方BGId
* type 巡视系统规范中定义 * type 巡视系统规范中定义
@ -217,9 +217,9 @@ public class StationRobotServiceImpl extends ServiceImpl<SubstationMapper, Subst
* code 发送的编码 * code 发送的编码
* items 发送的内容数据信息封装成jsonstr * items 发送的内容数据信息封装成jsonstr
*/ */
private void sendMsgtoRobot(String targetip, String sendcode, String receivecode, String type, String command, private void sendMsgtoRobot(String targetIp, String sendcode, String receivecode, String type, String command,
String code, String items) { String code, String items) {
log.info("接收控制值targetip" + targetip + "接收控制值sendcode" + sendcode + "接收控制值receivecode" + receivecode + "接收控制值items" + items); log.info("接收控制值targetip" + targetIp + "接收控制值sendcode" + sendcode + "接收控制值receivecode" + receivecode + "接收控制值items" + items);
String reponsexml = MyXmlUtil.getXml(sendcode, receivecode, type, command, code, items); String reponsexml = MyXmlUtil.getXml(sendcode, receivecode, type, command, code, items);
log.info("主动发送控制命令" + reponsexml); log.info("主动发送控制命令" + reponsexml);
MyMessageProtocol messageProtocol = new MyMessageProtocol(); MyMessageProtocol messageProtocol = new MyMessageProtocol();
@ -231,7 +231,7 @@ public class StationRobotServiceImpl extends ServiceImpl<SubstationMapper, Subst
messageProtocol.setSessionflag(0); messageProtocol.setSessionflag(0);
messageProtocol.setXmllen(reponsexml.getBytes(CharsetUtil.UTF_8).length); messageProtocol.setXmllen(reponsexml.getBytes(CharsetUtil.UTF_8).length);
messageProtocol.setXmlcontent(reponsexml.getBytes(CharsetUtil.UTF_8)); messageProtocol.setXmlcontent(reponsexml.getBytes(CharsetUtil.UTF_8));
Channel channel = ChannelMap.getChannel(targetip); Channel channel = ChannelMap.getChannel(targetIp);
if (null == channel) { if (null == channel) {
throw new RuntimeException("客户端已离线"); throw new RuntimeException("客户端已离线");
} }
@ -643,7 +643,7 @@ public class StationRobotServiceImpl extends ServiceImpl<SubstationMapper, Subst
public void sendRobotModel(String robotId) { public void sendRobotModel(String robotId) {
SubstationPatroldevice substationPatroldevice = substationPatroldeviceMapper.selectById(robotId); SubstationPatroldevice substationPatroldevice = substationPatroldeviceMapper.selectById(robotId);
if (substationPatroldevice != null) { if (substationPatroldevice != null) {
sendMsgtoRobot(substationPatroldevice.getIpaddr(), serverConfig.getPatrolServerid(), substationPatroldevice.getCustom3(), SystemCode.TYPE_MODEL_SYNC_CODE.getCode(), SystemCode.COMMAND_MODEL_HOST_CODE.getCode(), substationPatroldevice.getStationCode(), ""); sendMsgtoRobot(substationPatroldevice.getInternationalId(), serverConfig.getPatrolServerid(), substationPatroldevice.getInternationalId(), SystemCode.TYPE_MODEL_SYNC_CODE.getCode(), SystemCode.COMMAND_MODEL_HOST_CODE.getCode(), substationPatroldevice.getStationCode(), "");
} }
} }