#任务下发状态推送
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package com.maibu.dto;
|
package com.maibu.core.business.dto;
|
||||||
|
|
||||||
import com.maibu.core.enums.MesType;
|
import com.maibu.core.enums.MesType;
|
||||||
|
|
||||||
@@ -12,4 +12,6 @@ public class WebOlineStatusMessageDTO {
|
|||||||
private String errorCode;
|
private String errorCode;
|
||||||
private String description;
|
private String description;
|
||||||
private MesType type;
|
private MesType type;
|
||||||
|
|
||||||
|
private Long time;
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class HostMessageHandler implements CustomMqttMessageHandler {
|
public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||||
|
|
||||||
private final DeviceSessionManager deviceSessionManager = SpringUtils.getBean(DeviceSessionManager.class);
|
private final DeviceSessionManager deviceSessionManager = SpringUtils.getBean(DeviceSessionManager.class);
|
||||||
|
|
||||||
private final WebsocketMesDispather websocketMesDispather = SpringUtils.getBean(WebsocketMesDispather.class);
|
private final WebsocketMesDispather websocketMesDispather = SpringUtils.getBean(WebsocketMesDispather.class);
|
||||||
@@ -155,7 +155,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public WebStatusMessageDTO createWebDeviceLocationMessage(HostLocationRelTimeDTO locationRelTimeDTO,
|
public WebStatusMessageDTO createWebDeviceLocationMessage(HostLocationRelTimeDTO locationRelTimeDTO,
|
||||||
String deviceId) {
|
String deviceId) {
|
||||||
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
||||||
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
||||||
|
|
||||||
@@ -397,7 +397,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
|||||||
if ("failed".equals(dto.getStatus())) {
|
if ("failed".equals(dto.getStatus())) {
|
||||||
nettyDevice.failedTask();
|
nettyDevice.failedTask();
|
||||||
}
|
}
|
||||||
// if("accepted".equals(dto.getStatus())){
|
// if ("accepted".equals(dto.getStatus())) {
|
||||||
// NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
// NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||||
// nettyDevice.finishTask();
|
// nettyDevice.finishTask();
|
||||||
// }
|
// }
|
||||||
@@ -436,6 +436,35 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
|||||||
if (device != null && device.getTask() != null
|
if (device != null && device.getTask() != null
|
||||||
&& String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) {
|
&& String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) {
|
||||||
device.getTask().setTaskAccepted(true);
|
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) {
|
private void handleUpgradeReply(String deviceId, String topic, String payload) {
|
||||||
// log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload);
|
// log.debug("【路径任务下发响应】deviceId={}, payload={}", deviceId, payload);
|
||||||
//
|
//
|
||||||
// // todo 更新任务接收状态
|
// // todo 更新任务接收状态
|
||||||
// HostNavigationReplyDTO replyDTO = JsonUtils.parseObject(payload, HostNavigationReplyDTO.class);
|
// HostNavigationReplyDTO replyDTO = JsonUtils.parseObject(payload,
|
||||||
// NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
// HostNavigationReplyDTO.class);
|
||||||
// if (replyDTO.isAccepted()) {
|
// NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
||||||
// if (device != null && device.getTask() != null
|
// if (replyDTO.isAccepted()) {
|
||||||
// && String.valueOf(device.getTask().getId()).equals(replyDTO.getTask_id())) {
|
// if (device != null && device.getTask() != null
|
||||||
// device.getTask().setTaskAccepted(true);
|
// && 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"))
|
if (remaining.equals("/ota/result/post"))
|
||||||
return "upgrade_reply";
|
return "upgrade_reply";
|
||||||
|
|
||||||
|
|
||||||
return null;
|
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_ERROR_PUSH_TOPIC = "device/%s/error";
|
||||||
public static final String DEVICE_ROUTE_PUSH_TOPIC = "device/%s/route/post";
|
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";
|
public static final String MOWER_PRODUCT = "mower";
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import com.maibu.core.business.dto.DeviceMapPushDTO;
|
import com.maibu.core.business.dto.DeviceMapPushDTO;
|
||||||
import com.maibu.core.business.dto.WebMapMessageDTO;
|
import com.maibu.core.business.dto.WebMapMessageDTO;
|
||||||
|
import com.maibu.core.business.dto.WebOlineStatusMessageDTO;
|
||||||
import com.maibu.core.enums.*;
|
import com.maibu.core.enums.*;
|
||||||
import com.maibu.utils.json.JsonUtils;
|
import com.maibu.utils.json.JsonUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -43,6 +44,7 @@ import com.maibu.core.host.HeartBeatDTO;
|
|||||||
import com.maibu.core.host.LocationMessage;
|
import com.maibu.core.host.LocationMessage;
|
||||||
import com.maibu.core.redis.RedisCache;
|
import com.maibu.core.redis.RedisCache;
|
||||||
import com.maibu.dto.DeviceErrorPushDTO;
|
import com.maibu.dto.DeviceErrorPushDTO;
|
||||||
|
import com.maibu.dto.DeviceTaskStatusMessageDTO;
|
||||||
import com.maibu.mapper.DeviceRunStatisticsMapper;
|
import com.maibu.mapper.DeviceRunStatisticsMapper;
|
||||||
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
||||||
import com.maibu.mapper.HostLocationMapper;
|
import com.maibu.mapper.HostLocationMapper;
|
||||||
@@ -297,7 +299,7 @@ public class DeviceThreadService {
|
|||||||
}
|
}
|
||||||
if (nowTime - lastActiveTime >= Constant.hostOfflineInterval) {
|
if (nowTime - lastActiveTime >= Constant.hostOfflineInterval) {
|
||||||
// 超时了判断离线
|
// 超时了判断离线
|
||||||
if (nettyDevice != null) {
|
if (nettyDevice != null && nettyDevice.getOnlineStatus() == 1) {
|
||||||
nettyDevice.status(DeviceStatus.offline.getType());
|
nettyDevice.status(DeviceStatus.offline.getType());
|
||||||
// todo 推送设备离线
|
// todo 推送设备离线
|
||||||
String key = NettyCacheKey.latestPositonKey + deviceId;
|
String key = NettyCacheKey.latestPositonKey + deviceId;
|
||||||
@@ -309,7 +311,10 @@ public class DeviceThreadService {
|
|||||||
LocationMessage existing = hostLocationMapper.selectOne(queryWrapper);
|
LocationMessage existing = hostLocationMapper.selectOne(queryWrapper);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
locationMessage.setId(existing.getId());
|
locationMessage.setId(existing.getId());
|
||||||
|
} else {
|
||||||
|
locationMessage.setCreateTime(LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
locationMessage.setUpdateTime(LocalDateTime.now());
|
||||||
hostLocationMapper.saveOrUpdate(locationMessage);
|
hostLocationMapper.saveOrUpdate(locationMessage);
|
||||||
}
|
}
|
||||||
Device device = deviceService.selectDeviceBySerialNumber(deviceId);
|
Device device = deviceService.selectDeviceBySerialNumber(deviceId);
|
||||||
@@ -347,6 +352,7 @@ public class DeviceThreadService {
|
|||||||
siteMemory.removeMapPushDTO(deviceId);
|
siteMemory.removeMapPushDTO(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statusChangePush(deviceId, siteId, 0);
|
||||||
sessionManager.removeDevice(deviceId);
|
sessionManager.removeDevice(deviceId);
|
||||||
// TODO 统计总里程、总作业面积
|
// TODO 统计总里程、总作业面积
|
||||||
|
|
||||||
@@ -385,6 +391,7 @@ public class DeviceThreadService {
|
|||||||
// todo 推送设备上线
|
// todo 推送设备上线
|
||||||
nettyDevice.status(1);
|
nettyDevice.status(1);
|
||||||
nettyDevice.setDevice(device);
|
nettyDevice.setDevice(device);
|
||||||
|
statusChangePush(deviceId, nettyDevice.getDevice().getSiteId(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -395,8 +402,30 @@ public class DeviceThreadService {
|
|||||||
}, 0, 500, TimeUnit.MILLISECONDS);
|
}, 0, 500, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void statusChangePush(String deviceId, Long siteId, Integer status) {
|
||||||
|
// todo 推送设备离线
|
||||||
|
WebOlineStatusMessageDTO dto = new WebOlineStatusMessageDTO();
|
||||||
|
dto.setDeviceId(deviceId);
|
||||||
|
dto.setType(MesType.device_status_changed);
|
||||||
|
dto.setOnlineStatus(status);
|
||||||
|
try {
|
||||||
|
// 当前控制的web端
|
||||||
|
websocketMesDispather.dispather(deviceId, JsonUtils.toJsonString(dto));
|
||||||
|
// 地图监控页面推送
|
||||||
|
websocketMesDispather.mapMessageDispather(siteId,
|
||||||
|
JsonUtils.toJsonString(dto));
|
||||||
|
// 推送到mqtt服务器
|
||||||
|
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||||
|
String.format(MqttTopic.DEVICE_STATUS_PUSH_TOPIC, deviceId), JsonUtils.toJsonString(dto));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("机器状态变化推送失败: siteId={}, error={}", siteId,
|
||||||
|
e.getMessage(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监控心跳
|
* 地图监控
|
||||||
*/
|
*/
|
||||||
public void mapMessagePush() {
|
public void mapMessagePush() {
|
||||||
executor.scheduleWithFixedDelay(() -> {
|
executor.scheduleWithFixedDelay(() -> {
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ public class DeviceRunParamService {
|
|||||||
saveList.add(x);
|
saveList.add(x);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//todo 增加 解析sn码的功能
|
||||||
return deviceRunParamMapper.saveOrUpdateBatch(saveList);
|
return deviceRunParamMapper.saveOrUpdateBatch(saveList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.Objects;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import com.maibu.core.business.dto.WebDeviceTaskStatusMessageDTO;
|
import com.maibu.core.business.dto.WebDeviceTaskStatusMessageDTO;
|
||||||
|
import com.maibu.core.business.dto.WebOlineStatusMessageDTO;
|
||||||
import com.maibu.core.business.dto.WebStatusMessageDTO;
|
import com.maibu.core.business.dto.WebStatusMessageDTO;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
@@ -24,7 +25,6 @@ import com.maibu.dto.DeviceRespondDTO;
|
|||||||
import com.maibu.dto.NettySwitchDeviceDTO;
|
import com.maibu.dto.NettySwitchDeviceDTO;
|
||||||
import com.maibu.dto.ResultDTO;
|
import com.maibu.dto.ResultDTO;
|
||||||
import com.maibu.dto.WebAuthResponseDTO;
|
import com.maibu.dto.WebAuthResponseDTO;
|
||||||
import com.maibu.dto.WebOlineStatusMessageDTO;
|
|
||||||
import com.maibu.dto.WebSwitchControlResponseDTO;
|
import com.maibu.dto.WebSwitchControlResponseDTO;
|
||||||
import com.maibu.memory.MiddleGlobalMemory;
|
import com.maibu.memory.MiddleGlobalMemory;
|
||||||
import com.maibu.netty.NettyClient;
|
import com.maibu.netty.NettyClient;
|
||||||
|
|||||||
Reference in New Issue
Block a user