#消息推送相关
This commit is contained in:
@@ -26,6 +26,9 @@ public class DevicePlanTask extends OrgBaseDO {
|
||||
|
||||
private String deviceId;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String deviceAlias; // 别名
|
||||
|
||||
private DeviceTaskStaus taskStaus; // 任务状态
|
||||
|
||||
@TableField(exist = false)
|
||||
|
||||
@@ -163,8 +163,9 @@ public class NettyDevice extends Connector {
|
||||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean canceledTask() {
|
||||
public synchronized Long canceledTask() {
|
||||
if (task != null) {
|
||||
Long taskId = task.getId();
|
||||
task.setTaskStaus(DeviceTaskStaus.CANCELED);
|
||||
task.setUpdateTime(LocalDateTime.now());
|
||||
devicePlanTaskMapper.saveOrUpdate(task);
|
||||
@@ -177,12 +178,14 @@ public class NettyDevice extends Connector {
|
||||
currentPoint = null;
|
||||
locationQueue.clear();
|
||||
executingTask = false;
|
||||
return taskId;
|
||||
}
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized boolean failedTask() {
|
||||
public synchronized Long failedTask() {
|
||||
if (task != null) {
|
||||
Long taskId = task.getId();
|
||||
task.setTaskStaus(DeviceTaskStaus.FAILED);
|
||||
task.setUpdateTime(LocalDateTime.now());
|
||||
devicePlanTaskMapper.saveOrUpdate(task);
|
||||
@@ -195,8 +198,9 @@ public class NettyDevice extends Connector {
|
||||
currentPoint = null;
|
||||
locationQueue.clear();
|
||||
executingTask = false;
|
||||
return taskId;
|
||||
}
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendPathCommand(byte commandType, short pointCounts, double lat, double lng, short speed) {
|
||||
@@ -366,7 +370,7 @@ public class NettyDevice extends Connector {
|
||||
dto.setProtocol_version(Constant.protocol_version);
|
||||
|
||||
PointEntity point = new PointEntity();
|
||||
//TODO 增加其他系统任务类型 写死的code
|
||||
// TODO 增加其他系统任务类型 写死的code
|
||||
if (RouteType.BACK_TO_REST_POINT.equals(task.getRouteType())) {
|
||||
point.setLongitude(task.getBackTaskPoint().getPosition().getLng());
|
||||
point.setLatitude(task.getBackTaskPoint().getPosition().getLat());
|
||||
|
||||
@@ -40,11 +40,7 @@ public class IotAutoRuleRecord extends OrgNoUserDO {
|
||||
*/
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 触发时的指标快照
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private Object triggerValue;
|
||||
private String triggerValue;
|
||||
|
||||
/**
|
||||
* 触发时间
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package com.maibu.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.maibu.core.business.DevicePlanTask;
|
||||
import com.maibu.mybatis.mapper.BaseMapperX;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 设备历史状态
|
||||
@@ -10,4 +17,11 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface DevicePlanTaskMapper extends BaseMapperX<DevicePlanTask> {
|
||||
|
||||
@Select("SELECT t.*, d.device_alias " +
|
||||
"FROM iot_device_task t " +
|
||||
"LEFT JOIN iot_device d ON d.device_id = t.device_id " +
|
||||
"${ew.customSqlSegment}")
|
||||
List<DevicePlanTask> selectTaskHistoryWithDeviceAlias(
|
||||
@Param(Constants.WRAPPER) Wrapper<DevicePlanTask> wrapper);
|
||||
|
||||
}
|
||||
|
||||
@@ -465,6 +465,16 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
||||
if (device != null && device.getDevice() != null) {
|
||||
Long siteId = device.getDevice().getSiteId();
|
||||
websocketMesDispather.mapMessageDispather(siteId,
|
||||
JsonUtils.toJsonString(dto));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("实时地图数据websocket推送失败: siteId={}, error={}", e);
|
||||
}
|
||||
// todo 推送实时位置和状态消息到外部
|
||||
try {
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
@@ -512,44 +522,22 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
if ("completed".equals(dto.getStatus())) {
|
||||
Long taskId = nettyDevice.finishTask();
|
||||
|
||||
WebDeviceTaskStatusMessageDTO sendDto = new WebDeviceTaskStatusMessageDTO();
|
||||
sendDto.setDeviceId(deviceId);
|
||||
sendDto.setTaskId(taskId);
|
||||
sendDto.setStatus(DeviceTaskStaus.FINISH.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, taskId),
|
||||
JsonUtils.toJsonString(sendDto));
|
||||
} catch (MqttException e) {
|
||||
log.error("实时数据websocket任务状态推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
|
||||
}
|
||||
pushTaskChangeMessage(deviceId, taskId, DeviceTaskStaus.FINISH.toString());
|
||||
|
||||
}
|
||||
if ("cancelled".equals(dto.getStatus())) {
|
||||
nettyDevice.canceledTask();
|
||||
Long taskId = nettyDevice.canceledTask();
|
||||
pushTaskChangeMessage(deviceId, taskId, DeviceTaskStaus.CANCELED.toString());
|
||||
|
||||
}
|
||||
// if("paused".equals(dto.getStatus())){
|
||||
// NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
// nettyDevice.finishTask();
|
||||
// }
|
||||
if ("failed".equals(dto.getStatus())) {
|
||||
nettyDevice.failedTask();
|
||||
Long taskId = nettyDevice.failedTask();
|
||||
pushTaskChangeMessage(deviceId, taskId, DeviceTaskStaus.FAILED.toString());
|
||||
|
||||
}
|
||||
// if ("accepted".equals(dto.getStatus())) {
|
||||
// NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
@@ -563,6 +551,45 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
|
||||
}
|
||||
|
||||
public void pushTaskChangeMessage(String deviceId, Long taskId, String status) {
|
||||
WebDeviceTaskStatusMessageDTO sendDto = new WebDeviceTaskStatusMessageDTO();
|
||||
sendDto.setDeviceId(deviceId);
|
||||
sendDto.setTaskId(taskId);
|
||||
sendDto.setStatus(status);
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
||||
// if (device != null && device.getDevice() != null) {
|
||||
// Long siteId = device.getDevice().getSiteId();
|
||||
// websocketMesDispather.mapMessageDispather(siteId,
|
||||
// JsonUtils.toJsonString(sendDto));
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("实时地图数据websocket推送失败: siteId={}, error={}", e);
|
||||
// }
|
||||
// todo 推送实时位置和状态消息到外部
|
||||
try {
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
String.format(MqttTopic.DEVICE_TASK_STATUS_TOPIC, taskId),
|
||||
JsonUtils.toJsonString(sendDto));
|
||||
} catch (MqttException e) {
|
||||
log.error("实时数据websocket任务状态推送失败: deviceId={}, error={}", deviceId, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理配置响应
|
||||
*/
|
||||
@@ -609,6 +636,15 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (device != null && device.getDevice() != null) {
|
||||
Long siteId = device.getDevice().getSiteId();
|
||||
websocketMesDispather.mapMessageDispather(siteId,
|
||||
JsonUtils.toJsonString(sendDto));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("实时地图数据websocket推送失败: siteId={}, error={}", e);
|
||||
}
|
||||
// todo 推送实时位置和状态消息到外部
|
||||
try {
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
@@ -671,7 +707,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
JsonUtils.toJsonString(data));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("实时地图数据websocket推送失败: siteId={}, error={}", e);
|
||||
log.error("实时地图数据websocket推送失败: siteId={}, error={}", e);
|
||||
}
|
||||
try {
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
|
||||
Reference in New Issue
Block a user