From 9ff685e0c1a76a92a74be956e3091b0a2c3c7ac3 Mon Sep 17 00:00:00 2001 From: rqian <1206436827@qq.com> Date: Tue, 25 Aug 2026 08:36:45 +0000 Subject: [PATCH] =?UTF-8?q?#=20=E6=B5=8B=E8=AF=95=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E8=A7=84=E5=88=92=E6=B6=88=E6=81=AF=E4=B8=8B?= =?UTF-8?q?=E5=8F=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/business/device/NettyDevice.java | 117 +++++++++--------- .../core/host/HostNavigationReplyDTO.java | 3 +- .../com/maibu/mqtt/HostMessageHandler.java | 4 +- .../service/DevicePlanTaskMonitorService.java | 4 +- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java b/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java index 3b7b08a..09f7793 100644 --- a/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java +++ b/maibu-common/src/main/java/com/maibu/core/business/device/NettyDevice.java @@ -62,7 +62,7 @@ public class NettyDevice extends Connector { // todo 注册的时候更新 siteId private Device device; - //todo 当前登录的账号的token 以token为控制的权限 + // todo 当前登录的账号的token 以token为控制的权限 private String token; @JsonIgnore @@ -86,7 +86,6 @@ public class NettyDevice extends Connector { this.deviceType = deviceType; } - public void status(Integer onlineStatus) { this.onlineStatus = onlineStatus; } @@ -123,7 +122,7 @@ public class NettyDevice extends Connector { } public synchronized Long finishTask() { -// sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0); + // sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0); long finishId = task.getId(); task.setTaskStaus(DeviceTaskStaus.FINISH); task.setFinishTime(LocalDateTime.now()); @@ -139,23 +138,24 @@ public class NettyDevice extends Connector { return finishId; } - // public synchronized boolean cancelTask() { -// if (task != null) { -// sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0); -// task.setTaskStaus(DeviceTaskStaus.CANCELED); -// task.setUpdateTime(LocalDateTime.now()); -// devicePlanTaskMapper.saveOrUpdate(task); -// SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), task.getSiteId()); -// siteMemory.removeDevicePlanPrepare(task); -// siteMemory.removeDevicePlanExecute(task.getDeviceId()); -// task = null; -// currentTaskId = null; -// currentPoint = null; -// locationQueue.clear(); -// executingTask = false; -// } -// return true; -// } + // public synchronized boolean cancelTask() { + // if (task != null) { + // sendPathCommand((byte) 0x01, (short) 0, 0.00d, 0.00d, (short) 0); + // task.setTaskStaus(DeviceTaskStaus.CANCELED); + // task.setUpdateTime(LocalDateTime.now()); + // devicePlanTaskMapper.saveOrUpdate(task); + // SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), + // task.getSiteId()); + // siteMemory.removeDevicePlanPrepare(task); + // siteMemory.removeDevicePlanExecute(task.getDeviceId()); + // task = null; + // currentTaskId = null; + // currentPoint = null; + // locationQueue.clear(); + // executingTask = false; + // } + // return true; + // } public synchronized boolean cancelingTask() throws MqttException { if (task != null) { @@ -171,7 +171,8 @@ public class NettyDevice extends Connector { dto.setMessage_id(task.getId() + "_" + System.currentTimeMillis()); dto.setProtocol_version("1.4"); - GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()), + GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, + String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()), JsonUtils.toJsonString(dto)); task.setTaskStaus(DeviceTaskStaus.CANCELING); task.setUpdateTime(LocalDateTime.now()); @@ -181,7 +182,6 @@ public class NettyDevice extends Connector { return true; } - public synchronized boolean canceledTask() { if (task != null) { task.setTaskStaus(DeviceTaskStaus.CANCELED); @@ -214,8 +214,9 @@ public class NettyDevice extends Connector { } } - //配置左右轮增益系数 - public void sendWheelGainCoefficientsCommand(double leftForwardGain, double leftBackwardGain, double rightForwardGain, double rightBackwardGain) { + // 配置左右轮增益系数 + public void sendWheelGainCoefficientsCommand(double leftForwardGain, double leftBackwardGain, + double rightForwardGain, double rightBackwardGain) { ByteBuffer buffer = ByteBuffer.allocate(39); buffer.order(ByteOrder.LITTLE_ENDIAN); @@ -247,7 +248,6 @@ public class NettyDevice extends Connector { } } - public void readConfigCommand() { byte[] bytes = DeviceRunParam.toReadBytes(); log.debug("下发读取配置的报文:{}", toHexString(bytes)); @@ -296,34 +296,35 @@ public class NettyDevice extends Connector { } } -// public void startTask() { -// try { -// if (executingTask) -// return; -// if (task != null) { -// Long routeId = task.getRouteId(); -// WorkRecord workRecord = workRecordMapper.selectById(routeId); -// if (workRecord != null) { -// PlanPath planPath = workRecord.getJsonData(); -// if (planPath != null && !CollectionUtils.isEmpty(planPath.getPath())) { -// planPath.getPath().forEach(x -> { -// locationQueue.offer(x); -// }); -// } -// } -// task.setStartTime(LocalDateTime.now()); -// } -// executingTask = true; -// sendNextPoint(); -// } catch (Exception e) { -// throw new RuntimeException(e); -// } -// } + // public void startTask() { + // try { + // if (executingTask) + // return; + // if (task != null) { + // Long routeId = task.getRouteId(); + // WorkRecord workRecord = workRecordMapper.selectById(routeId); + // if (workRecord != null) { + // PlanPath planPath = workRecord.getJsonData(); + // if (planPath != null && !CollectionUtils.isEmpty(planPath.getPath())) { + // planPath.getPath().forEach(x -> { + // locationQueue.offer(x); + // }); + // } + // } + // task.setStartTime(LocalDateTime.now()); + // } + // executingTask = true; + // sendNextPoint(); + // } catch (Exception e) { + // throw new RuntimeException(e); + // } + // } public void startTask() { try { if (executingTask) return; + executingTask = true; if (task != null) { // startTime 在启动前记录 task.setStartTime(LocalDateTime.now()); @@ -333,7 +334,6 @@ public class NettyDevice extends Connector { futureHolder[0] = executor.scheduleWithFixedDelay(() -> { int current = count.incrementAndGet(); try { - executingTask = true; if (task.isTaskAccepted()) { // 成功,停止后续执行 futureHolder[0].cancel(false); @@ -364,7 +364,7 @@ public class NettyDevice extends Connector { task = null; } - }, 0, 3, TimeUnit.SECONDS); + }, 0, 5, TimeUnit.SECONDS); } } catch (Exception e) { throw new RuntimeException(e); @@ -398,13 +398,13 @@ public class NettyDevice extends Connector { } if (workRecord.getMode().equals("coverage")) { List boundary_points = new ArrayList<>(); -// workRecord.getJsonData().getPath().forEach(x -> { -// MutiPointEntity mutiPoint = new MutiPointEntity(); -// mutiPoint.setLongitude(x.getLng()); -// mutiPoint.setLatitude(x.getLat()); -// mutiPoint.setIndex(); -// boundary_points.add(mutiPoint); -// }); + // workRecord.getJsonData().getPath().forEach(x -> { + // MutiPointEntity mutiPoint = new MutiPointEntity(); + // mutiPoint.setLongitude(x.getLng()); + // mutiPoint.setLatitude(x.getLat()); + // mutiPoint.setIndex(); + // boundary_points.add(mutiPoint); + // }); List path = workRecord.getJsonData().getPath(); for (int i = 0; i < path.size(); i++) { @@ -420,7 +420,8 @@ public class NettyDevice extends Connector { } } dto.setData(point); - GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()), + GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, + String.format(MqttTopic.MOWER_TASK_ROUTE_SET, task.getDeviceId()), JsonUtils.toJsonString(dto)); } } diff --git a/maibu-common/src/main/java/com/maibu/core/host/HostNavigationReplyDTO.java b/maibu-common/src/main/java/com/maibu/core/host/HostNavigationReplyDTO.java index e459414..69ecaa5 100644 --- a/maibu-common/src/main/java/com/maibu/core/host/HostNavigationReplyDTO.java +++ b/maibu-common/src/main/java/com/maibu/core/host/HostNavigationReplyDTO.java @@ -14,6 +14,5 @@ public class HostNavigationReplyDTO extends HostBase { private String code;//任务动作 OK|INVALID|BUSY|ERROR private String message; - - + } diff --git a/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java b/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java index ce148d7..8c6ff29 100644 --- a/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java +++ b/maibu-common/src/main/java/com/maibu/mqtt/HostMessageHandler.java @@ -314,7 +314,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler { log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload); //todo 更新任务接收状态 - HostNavigationReplyDTO replyDTO = SpringUtils.getBean(HostNavigationReplyDTO.class); + HostNavigationReplyDTO replyDTO = JsonUtils.parseObject(payload, HostNavigationReplyDTO.class); NettyDevice device = deviceSessionManager.getDevice(deviceId); if (replyDTO.isAccepted()) { if (device != null && device.getTask() != null && String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) { @@ -366,7 +366,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler { if (remaining.equals("task/finish/post")) return "task_finish_post"; if (remaining.equals("action/config/reply")) return "config_reply"; if (remaining.equals("action/control/reply")) return "control_reply"; - if (remaining.equals("/task/target/reply")) return "route_reply"; + if (remaining.equals("task/target/reply")) return "route_reply"; return null; } diff --git a/maibu-netty-server/src/main/java/com/maibu/service/DevicePlanTaskMonitorService.java b/maibu-netty-server/src/main/java/com/maibu/service/DevicePlanTaskMonitorService.java index d635f71..d4a9ed9 100644 --- a/maibu-netty-server/src/main/java/com/maibu/service/DevicePlanTaskMonitorService.java +++ b/maibu-netty-server/src/main/java/com/maibu/service/DevicePlanTaskMonitorService.java @@ -214,11 +214,11 @@ public class DevicePlanTaskMonitorService { planMap.keySet().forEach(key -> { NettyDevice device = deviceSessionManager.getDevice(key); //判断是否能进execute - if (device != null && device.getCurrentTaskId() == null && device.getOnlineStatus() != null && device.getOnlineStatus() == 1) { + if (device != null && device.getTask() == null && device.getOnlineStatus() != null && device.getOnlineStatus() == 1) { List tasks = planMap.get(key); if (!CollectionUtils.isEmpty(tasks)) { tasks.removeIf(Objects::isNull); - tasks.sort( + tasks.sort( Comparator.comparing( DevicePlanTask::getStartTime, Comparator.nullsLast(Comparator.naturalOrder())