#任务下发状态推送

This commit is contained in:
2026-10-13 12:57:29 +08:00
parent bde6b89965
commit 11e209bcb3
6 changed files with 82 additions and 19 deletions

View File

@@ -16,6 +16,7 @@ import java.util.stream.Collectors;
import com.maibu.core.business.dto.DeviceMapPushDTO;
import com.maibu.core.business.dto.WebMapMessageDTO;
import com.maibu.core.business.dto.WebOlineStatusMessageDTO;
import com.maibu.core.enums.*;
import com.maibu.utils.json.JsonUtils;
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.redis.RedisCache;
import com.maibu.dto.DeviceErrorPushDTO;
import com.maibu.dto.DeviceTaskStatusMessageDTO;
import com.maibu.mapper.DeviceRunStatisticsMapper;
import com.maibu.mapper.ErrorIdentificationStandardMapper;
import com.maibu.mapper.HostLocationMapper;
@@ -297,7 +299,7 @@ public class DeviceThreadService {
}
if (nowTime - lastActiveTime >= Constant.hostOfflineInterval) {
// 超时了判断离线
if (nettyDevice != null) {
if (nettyDevice != null && nettyDevice.getOnlineStatus() == 1) {
nettyDevice.status(DeviceStatus.offline.getType());
// todo 推送设备离线
String key = NettyCacheKey.latestPositonKey + deviceId;
@@ -309,7 +311,10 @@ public class DeviceThreadService {
LocationMessage existing = hostLocationMapper.selectOne(queryWrapper);
if (existing != null) {
locationMessage.setId(existing.getId());
} else {
locationMessage.setCreateTime(LocalDateTime.now());
}
locationMessage.setUpdateTime(LocalDateTime.now());
hostLocationMapper.saveOrUpdate(locationMessage);
}
Device device = deviceService.selectDeviceBySerialNumber(deviceId);
@@ -347,6 +352,7 @@ public class DeviceThreadService {
siteMemory.removeMapPushDTO(deviceId);
}
statusChangePush(deviceId, siteId, 0);
sessionManager.removeDevice(deviceId);
// TODO 统计总里程、总作业面积
@@ -385,6 +391,7 @@ public class DeviceThreadService {
// todo 推送设备上线
nettyDevice.status(1);
nettyDevice.setDevice(device);
statusChangePush(deviceId, nettyDevice.getDevice().getSiteId(), 1);
}
}
});
@@ -395,8 +402,30 @@ public class DeviceThreadService {
}, 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() {
executor.scheduleWithFixedDelay(() -> {