#任务下发状态推送
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.maibu.core.business.dto;
|
||||
|
||||
import com.maibu.core.enums.MesType;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WebOlineStatusMessageDTO {
|
||||
private String deviceId;
|
||||
private Integer onlineStatus;
|
||||
private Integer hasError;
|
||||
private String errorCode;
|
||||
private String description;
|
||||
private MesType type;
|
||||
|
||||
private Long time;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import java.util.List;
|
||||
*/
|
||||
@Slf4j
|
||||
public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
|
||||
|
||||
private final DeviceSessionManager deviceSessionManager = SpringUtils.getBean(DeviceSessionManager.class);
|
||||
|
||||
private final WebsocketMesDispather websocketMesDispather = SpringUtils.getBean(WebsocketMesDispather.class);
|
||||
@@ -155,7 +155,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
|
||||
public WebStatusMessageDTO createWebDeviceLocationMessage(HostLocationRelTimeDTO locationRelTimeDTO,
|
||||
String deviceId) {
|
||||
String deviceId) {
|
||||
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
||||
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
||||
|
||||
@@ -397,7 +397,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
if ("failed".equals(dto.getStatus())) {
|
||||
nettyDevice.failedTask();
|
||||
}
|
||||
// if("accepted".equals(dto.getStatus())){
|
||||
// if ("accepted".equals(dto.getStatus())) {
|
||||
// NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
// nettyDevice.finishTask();
|
||||
// }
|
||||
@@ -436,6 +436,35 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
if (device != null && device.getTask() != null
|
||||
&& String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) {
|
||||
device.getTask().setTaskAccepted(true);
|
||||
|
||||
WebDeviceTaskStatusMessageDTO sendDto = new WebDeviceTaskStatusMessageDTO();
|
||||
sendDto.setDeviceId(deviceId);
|
||||
sendDto.setTaskId(device.getTask().getId());
|
||||
sendDto.setStatus(DeviceTaskStaus.EXECUTING.toString());
|
||||
sendDto.setType(MesType.device_task_change);
|
||||
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
for (NettyDevice x : controlMasters) {
|
||||
try {
|
||||
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(sendDto));
|
||||
} catch (Exception e) {
|
||||
log.error("实时数据websocket推送失败: connectorId={}, error={}", x.getConnectorId(),
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
// todo 推送实时位置和状态消息到外部
|
||||
try {
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
String.format(MqttTopic.DEVICE_TASK_STATUS_TOPIC, device.getTask().getId()),
|
||||
JsonUtils.toJsonString(sendDto));
|
||||
} catch (MqttException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -444,17 +473,18 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
* 处理控制指令响应
|
||||
*/
|
||||
private void handleUpgradeReply(String deviceId, String topic, String payload) {
|
||||
// log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload);
|
||||
//
|
||||
// // todo 更新任务接收状态
|
||||
// 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())) {
|
||||
// device.getTask().setTaskAccepted(true);
|
||||
// }
|
||||
// }
|
||||
// log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload);
|
||||
//
|
||||
// // todo 更新任务接收状态
|
||||
// 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())) {
|
||||
// device.getTask().setTaskAccepted(true);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -510,7 +540,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
if (remaining.equals("/ota/result/post"))
|
||||
return "upgrade_reply";
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ public class MqttTopic {
|
||||
public static final String DEVICE_ERROR_PUSH_TOPIC = "device/%s/error";
|
||||
public static final String DEVICE_ROUTE_PUSH_TOPIC = "device/%s/route/post";
|
||||
|
||||
public static final String DEVICE_STATUS_PUSH_TOPIC = "device/%s/status/change";
|
||||
|
||||
/** 产品标识:割草机 */
|
||||
public static final String MOWER_PRODUCT = "mower";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user