Compare commits
4 Commits
dev_map
...
1d2636f641
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d2636f641 | |||
| 40c6edda36 | |||
| be27d2b56e | |||
| f690786847 |
@@ -5,8 +5,12 @@ import com.maibu.core.business.device.Connector;
|
|||||||
import com.maibu.core.business.device.NettyDevice;
|
import com.maibu.core.business.device.NettyDevice;
|
||||||
import com.maibu.core.enums.ConnectorStatus;
|
import com.maibu.core.enums.ConnectorStatus;
|
||||||
import com.maibu.core.enums.ConnectorType;
|
import com.maibu.core.enums.ConnectorType;
|
||||||
|
import com.maibu.utils.json.JsonUtils;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -23,6 +27,7 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Data
|
@Data
|
||||||
|
@Slf4j
|
||||||
public class DeviceSessionManager {
|
public class DeviceSessionManager {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DeviceSessionManager.class);
|
private static final Logger logger = LoggerFactory.getLogger(DeviceSessionManager.class);
|
||||||
@@ -187,7 +192,7 @@ public class DeviceSessionManager {
|
|||||||
public List<NettyDevice> getSlaveControl(String slaveId) {
|
public List<NettyDevice> getSlaveControl(String slaveId) {
|
||||||
// 获取所有连接的主机 且是active状态的
|
// 获取所有连接的主机 且是active状态的
|
||||||
return deviceMap.values().stream()
|
return deviceMap.values().stream()
|
||||||
.filter(device -> ObjectUtil.equals(device.getCurrentSlaveId(), slaveId)
|
.filter(device -> Objects.equals(device.getCurrentSlaveId(), slaveId)
|
||||||
&& ConnectorStatus.ACTIVE.equals(device.getConnectorStatus()))
|
&& ConnectorStatus.ACTIVE.equals(device.getConnectorStatus()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -195,14 +200,16 @@ public class DeviceSessionManager {
|
|||||||
public List<NettyDevice> getAllSlaveControl(String slaveId) {
|
public List<NettyDevice> getAllSlaveControl(String slaveId) {
|
||||||
// 获取所有连接的主机 不区分状态
|
// 获取所有连接的主机 不区分状态
|
||||||
return deviceMap.values().stream()
|
return deviceMap.values().stream()
|
||||||
.filter(device -> ObjectUtil.equals(device.getCurrentSlaveId(), slaveId))
|
.filter(device -> !StringUtils.isEmpty(device.getCurrentSlaveId())
|
||||||
|
&& Objects.equals(device.getCurrentSlaveId(), slaveId)
|
||||||
|
&& device.getDeviceType().equals(ConnectorType.MASTER))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public NettyDevice getCurrentControl(String slaveId) {
|
public NettyDevice getCurrentControl(String slaveId) {
|
||||||
// 获取所有连接的主机 不区分状态
|
// 获取所有连接的主机 不区分状态
|
||||||
return deviceMap.values().stream()
|
return deviceMap.values().stream()
|
||||||
.filter(device -> ObjectUtil.equals(device.getCurrentSlaveId(), slaveId)
|
.filter(device -> Objects.equals(device.getCurrentSlaveId(), slaveId)
|
||||||
&& ConnectorStatus.ACTIVE.equals(device.getConnectorStatus()))
|
&& ConnectorStatus.ACTIVE.equals(device.getConnectorStatus()))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
@@ -312,8 +319,11 @@ public class DeviceSessionManager {
|
|||||||
if (taskId == null) {
|
if (taskId == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
log.debug("sendMessage deviceMap:{},taskId={}", JsonUtils.toJsonString(deviceMap), taskId);
|
||||||
for (String key : deviceMap.keySet()) {
|
for (String key : deviceMap.keySet()) {
|
||||||
NettyDevice nettyDevice = deviceMap.get(key);
|
NettyDevice nettyDevice = deviceMap.get(key);
|
||||||
|
log.debug("sendMessage currentTaskId:{},equal {}", JsonUtils.toJsonString(nettyDevice.getCurrentTaskId()),
|
||||||
|
Objects.equals(nettyDevice.getCurrentTaskId(), taskId));
|
||||||
if (nettyDevice != null && Objects.equals(nettyDevice.getCurrentTaskId(), taskId)) {
|
if (nettyDevice != null && Objects.equals(nettyDevice.getCurrentTaskId(), taskId)) {
|
||||||
return nettyDevice.getConnectorId();
|
return nettyDevice.getConnectorId();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,10 +63,13 @@ public class SiteMemory {
|
|||||||
return deviceMapPushMap;
|
return deviceMapPushMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveMaPushDTO(String deviceId, DeviceMapPushDTO dto) {
|
public void saveMapPushDTO(String deviceId, DeviceMapPushDTO dto) {
|
||||||
deviceMapPushMap.put(deviceId, dto);
|
deviceMapPushMap.put(deviceId, dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeMapPushDTO(String deviceId) {
|
||||||
|
deviceMapPushMap.remove(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
public void saveRunStatistics(DeviceRunStatistics deviceRunStatistics) {
|
public void saveRunStatistics(DeviceRunStatistics deviceRunStatistics) {
|
||||||
if (deviceRunStatistics != null && !StringUtils.isEmpty(deviceRunStatistics.getDeviceId())) {
|
if (deviceRunStatistics != null && !StringUtils.isEmpty(deviceRunStatistics.getDeviceId())) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.maibu.mqtt;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||||
import com.maibu.core.business.dto.DeviceMapPushDTO;
|
import com.maibu.core.business.dto.DeviceMapPushDTO;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@@ -164,11 +165,17 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
|||||||
String deviceId) {
|
String deviceId) {
|
||||||
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
||||||
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
||||||
|
|
||||||
|
DeviceStatusDetail d = new DeviceStatusDetail();
|
||||||
|
d.setName("deviceId");
|
||||||
|
d.setValue(deviceId);
|
||||||
|
d.setUnit("");
|
||||||
|
transferData.add(d);
|
||||||
|
|
||||||
DeviceStatusDetail lat = new DeviceStatusDetail();
|
DeviceStatusDetail lat = new DeviceStatusDetail();
|
||||||
lat.setName("latitude");
|
lat.setName("latitude");
|
||||||
lat.setValue(String.valueOf(locationRelTimeDTO.getData().getLatitude()));
|
lat.setValue(String.valueOf(locationRelTimeDTO.getData().getLatitude()));
|
||||||
lat.setUnit("");
|
lat.setUnit("");
|
||||||
|
|
||||||
transferData.add(lat);
|
transferData.add(lat);
|
||||||
|
|
||||||
DeviceStatusDetail lng = new DeviceStatusDetail();
|
DeviceStatusDetail lng = new DeviceStatusDetail();
|
||||||
@@ -235,7 +242,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
|||||||
dto.setLng(Double.parseDouble(lng.getValue()));
|
dto.setLng(Double.parseDouble(lng.getValue()));
|
||||||
dto.setT(nettyDevice.getCurrentTaskId());
|
dto.setT(nettyDevice.getCurrentTaskId());
|
||||||
dto.setY(Double.parseDouble(yaw.getValue()));
|
dto.setY(Double.parseDouble(yaw.getValue()));
|
||||||
siteMemory.saveMaPushDTO(deviceId, dto);
|
siteMemory.saveMapPushDTO(deviceId, dto);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,6 +383,15 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// todo 推送实时位置和状态消息到外部
|
||||||
|
try {
|
||||||
|
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||||
|
String.format(MqttTopic.DEVICE_TASK_STATUS_TOPIC, taskId),
|
||||||
|
JsonUtils.toJsonString(sendDto));
|
||||||
|
} catch (MqttException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ("cancelled".equals(dto.getStatus())) {
|
if ("cancelled".equals(dto.getStatus())) {
|
||||||
|
|||||||
@@ -453,9 +453,9 @@ public class DeviceTaskService {
|
|||||||
x.setTaskStausTranslate(taskStaus.getDescription());
|
x.setTaskStausTranslate(taskStaus.getDescription());
|
||||||
});
|
});
|
||||||
list.sort(
|
list.sort(
|
||||||
Comparator.comparing(DevicePlanTask::getFinishTime,
|
Comparator.comparing(DevicePlanTask::getCreateTime,
|
||||||
Comparator.nullsLast(Comparator.reverseOrder()))
|
Comparator.nullsLast(Comparator.reverseOrder()))
|
||||||
.thenComparing(DevicePlanTask::getCreateTime,
|
.thenComparing(DevicePlanTask::getFinishTime,
|
||||||
Comparator.nullsLast(Comparator.reverseOrder())));
|
Comparator.nullsLast(Comparator.reverseOrder())));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -343,6 +343,8 @@ public class DeviceThreadService {
|
|||||||
}
|
}
|
||||||
deviceRunStatisticsMapper.saveOrUpdate(deviceRunStatistics);
|
deviceRunStatisticsMapper.saveOrUpdate(deviceRunStatistics);
|
||||||
}
|
}
|
||||||
|
// todo 删除实时消息推送里面的数据
|
||||||
|
siteMemory.removeMapPushDTO(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionManager.removeDevice(deviceId);
|
sessionManager.removeDevice(deviceId);
|
||||||
@@ -393,7 +395,6 @@ public class DeviceThreadService {
|
|||||||
}, 0, 500, TimeUnit.MILLISECONDS);
|
}, 0, 500, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 监控心跳
|
* 监控心跳
|
||||||
*/
|
*/
|
||||||
@@ -404,19 +405,17 @@ public class DeviceThreadService {
|
|||||||
if (!CollectionUtils.isEmpty(list)) {
|
if (!CollectionUtils.isEmpty(list)) {
|
||||||
list.forEach(x -> {
|
list.forEach(x -> {
|
||||||
Map<String, DeviceMapPushDTO> map = x.getAllDeviceMapPush();
|
Map<String, DeviceMapPushDTO> map = x.getAllDeviceMapPush();
|
||||||
if (!CollectionUtils.isEmpty(map)) {
|
|
||||||
List<DeviceMapPushDTO> pushList = new ArrayList<>(map.values());
|
List<DeviceMapPushDTO> pushList = new ArrayList<>(map.values());
|
||||||
WebMapMessageDTO dto = new WebMapMessageDTO();
|
WebMapMessageDTO dto = new WebMapMessageDTO();
|
||||||
dto.setData(pushList);
|
dto.setData(pushList);
|
||||||
dto.setType(MesType.mapPush);
|
dto.setType(MesType.mapPush);
|
||||||
try {
|
try {
|
||||||
websocketMesDispather.mapMessageDispather(x.getSiteId(), JsonUtils.toJsonString(pushList));
|
websocketMesDispather.mapMessageDispather(x.getSiteId(),
|
||||||
|
JsonUtils.toJsonString(dto));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("实时地图数据websocket推送失败: siteId={}, error={}", x.getSiteId(),
|
log.error("实时地图数据websocket推送失败: siteId={}, error={}", x.getSiteId(),
|
||||||
e.getMessage(), e);
|
e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user