Compare commits
3 Commits
dev_map
...
40c6edda36
| Author | SHA1 | Date | |
|---|---|---|---|
| 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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -376,6 +377,14 @@ 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())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user