#地图相关推送修改
This commit is contained in:
@@ -8,7 +8,7 @@ public class DeviceMapPushDTO {
|
||||
private double lat;
|
||||
private double lng;
|
||||
private double y; //yaw
|
||||
private double f; //fix_status
|
||||
private String f; //fix_status
|
||||
private double a; //altitude
|
||||
private String s;//status 运行状态
|
||||
private Long t; //taskId 任务id
|
||||
|
||||
@@ -11,12 +11,12 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeviceStatusEnum {
|
||||
|
||||
offline("0", "离线"),
|
||||
idle("1", "空闲中"),
|
||||
working("2", "工作中"),
|
||||
charging("3", "充电中"),
|
||||
error("4", "故障");
|
||||
|
||||
working("1", "工作中"),
|
||||
idle("2", "空闲中"),
|
||||
offline("3", "离线"),
|
||||
charging("4", "充电中"),
|
||||
error("5", "故障");
|
||||
|
||||
String code;
|
||||
String message;
|
||||
|
||||
@@ -229,7 +229,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
dto.setId(deviceId);
|
||||
// dto.setB();
|
||||
// dto.setHa();
|
||||
dto.setF(Double.parseDouble(fix_status.getValue()));
|
||||
dto.setF(fix_status.getValue());
|
||||
dto.setS(status.getValue());
|
||||
dto.setLat(Double.parseDouble(lat.getValue()));
|
||||
dto.setLng(Double.parseDouble(lng.getValue()));
|
||||
|
||||
@@ -284,9 +284,17 @@ public class DeviceThreadService {
|
||||
List<HeartBeatDTO> heartBeatDTOS = GlobalMemory.customMqttDeviceMonitor.getAllHeartBeat();
|
||||
if (!CollectionUtils.isEmpty(heartBeatDTOS)) {
|
||||
heartBeatDTOS.forEach(x -> {
|
||||
if (x == null) {
|
||||
return;
|
||||
}
|
||||
String deviceId = x.getSn();
|
||||
Long lastActiveTime = x.getSysTimestamp();
|
||||
NettyDevice nettyDevice = sessionManager.getDevice(x.getSn());
|
||||
|
||||
if (lastActiveTime == null) {
|
||||
log.error("设备心跳时间为空,deviceId={}", deviceId);
|
||||
return;
|
||||
}
|
||||
if (nowTime - lastActiveTime >= Constant.hostOfflineInterval) {
|
||||
// 超时了判断离线
|
||||
if (nettyDevice != null) {
|
||||
@@ -342,56 +350,45 @@ public class DeviceThreadService {
|
||||
|
||||
}
|
||||
} else {
|
||||
Device device = deviceService.selectDeviceBySerialNumber(deviceId);
|
||||
if (device == null) {
|
||||
device = new Device();
|
||||
device.setStatus(3);
|
||||
device.setOnlineStatus(DeviceStatus.online.getType());
|
||||
device.setSerialNumber(deviceId);
|
||||
device.setDeviceName(deviceId);
|
||||
device.setProductId(-1L);
|
||||
device.setTenantId(-1L);
|
||||
device.setFirmwareVersion(BigDecimal.valueOf(1.0));
|
||||
device.setProductName("割草机产品MC700");
|
||||
device.setCreateTime(LocalDateTime.now());
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
device.setHasHost(true);
|
||||
deviceService.insertDeviceBySelf(device);
|
||||
} else {
|
||||
device.setStatus(3);
|
||||
device.setOnlineStatus(DeviceStatus.online.getType());
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
device.setHasHost(true);
|
||||
deviceService.updateDeviceBySelf(device);
|
||||
}
|
||||
if (nettyDevice == null) {
|
||||
sessionManager.registerSlaveDevice(deviceId, ConnectorStatus.ACTIVE, null);
|
||||
Device device = deviceService.selectDeviceBySerialNumber(deviceId);
|
||||
if (device == null) {
|
||||
device = new Device();
|
||||
device.setStatus(3);
|
||||
device.setOnlineStatus(DeviceStatus.online.getType());
|
||||
device.setSerialNumber(deviceId);
|
||||
device.setDeviceName(deviceId);
|
||||
device.setProductId(-1L);
|
||||
device.setTenantId(-1L);
|
||||
device.setFirmwareVersion(BigDecimal.valueOf(1.0));
|
||||
device.setProductName("割草机产品MC700");
|
||||
device.setCreateTime(LocalDateTime.now());
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
device.setHasHost(true);
|
||||
deviceService.insertDeviceBySelf(device);
|
||||
} else {
|
||||
device.setStatus(3);
|
||||
device.setOnlineStatus(DeviceStatus.online.getType());
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
device.setHasHost(true);
|
||||
deviceService.updateDeviceBySelf(device);
|
||||
NettyDevice slaveDevice = sessionManager.getDevice(deviceId);
|
||||
if (slaveDevice != null) {
|
||||
slaveDevice.setOnlineStatus(1);
|
||||
slaveDevice.setDevice(device);
|
||||
}
|
||||
// 推送json 找到设备绑定的主机进行推送
|
||||
// List<NettyDevice> controlMasters =
|
||||
// sessionManager.getAllSlaveControl(device.getSerialNumber());
|
||||
// if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
// controlMasters.forEach(x -> {
|
||||
// DeviceStatusChangeDTO changeDTO = new DeviceStatusChangeDTO();
|
||||
// changeDTO.setDeviceId(data);
|
||||
// changeDTO.setStatus(DeviceStatus.online.getCode());
|
||||
// changeDTO.setEvent(RespondCode.device_status_changed);
|
||||
// ByteBuf buf = ctx.alloc().buffer();
|
||||
// CommandUtils.buildCommand(buf, changeDTO, CommandConstant.interaction);
|
||||
// String content = buf.toString(CharsetUtil.UTF_8);
|
||||
// logger.info("推送下位机登录状态消息:{}", content);
|
||||
// if (x.getChannel() != null && x.getChannel().isActive()) {
|
||||
// x.getChannel().writeAndFlush(buf);
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
// todo 推送设备上线
|
||||
nettyDevice.status(1);
|
||||
nettyDevice.setDevice(device);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("执行监测心跳线程错误:{}", e.getMessage());
|
||||
log.error("执行监测心跳线程错误", e);
|
||||
}
|
||||
}, 0, 500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user