dockStatus字段逻辑修正
This commit is contained in:
parent
582a3d0e0c
commit
841f53cb4e
|
|
@ -80,10 +80,8 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
dto.setBindTime(device.getCreateTime().getTime());
|
||||
dto.setDockManufacturer(device.getDeviceManufacturer());
|
||||
|
||||
// 获取ThingsBoard数据并填充到DTO
|
||||
fillTuohengDockDetail(dto, device.getIotDeviceId());
|
||||
|
||||
// 查询关联的无人机
|
||||
// 查询关联的无人机,获取无人机的 iotDeviceId
|
||||
String aircraftIotDeviceId = null;
|
||||
List<DockAircraft> aircrafts = dockAircraftDomain.selectDockAircraftByDockId(dockId);
|
||||
if (!CollectionUtils.isEmpty(aircrafts)) {
|
||||
DockAircraft dockAircraft = aircrafts.get(0);
|
||||
|
|
@ -94,14 +92,15 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
|
||||
Device airDevice = deviceDomain.selectDeviceByDeviceId(aircraft.getDeviceId());
|
||||
if (airDevice != null) {
|
||||
dto.setAircraftIotId(airDevice.getIotDeviceId());
|
||||
|
||||
// 填充无人机状态信息
|
||||
fillTuohengAircraftStatus(dto, airDevice.getIotDeviceId());
|
||||
aircraftIotDeviceId = airDevice.getIotDeviceId();
|
||||
dto.setAircraftIotId(aircraftIotDeviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取ThingsBoard数据并填充到DTO(传入无人机的 iotDeviceId 用于判断工作状态)
|
||||
fillTuohengDockDetail(dto, device.getIotDeviceId(), aircraftIotDeviceId);
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
|
@ -191,9 +190,10 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
* 填充拓恒机场详情数据
|
||||
*
|
||||
* @param dto 机场详情DTO
|
||||
* @param iotDeviceId ThingsBoard设备ID
|
||||
* @param iotDeviceId ThingsBoard设备ID(机场)
|
||||
* @param aircraftIotDeviceId 无人机ThingsBoard设备ID(用于判断工作状态)
|
||||
*/
|
||||
private void fillTuohengDockDetail(DockDetailDTO dto, String iotDeviceId) {
|
||||
private void fillTuohengDockDetail(DockDetailDTO dto, String iotDeviceId, String aircraftIotDeviceId) {
|
||||
try {
|
||||
log.info("========== 开始填充拓恒机场详情 ==========");
|
||||
log.info("iotDeviceId: {}", iotDeviceId);
|
||||
|
|
@ -206,7 +206,7 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
TelemetryMap telemetry = thingsBoardDomain.getPredefinedTuohengDeviceTelemetry(iotDeviceId);
|
||||
log.info("拓恒设备遥测数据: {}", telemetry);
|
||||
|
||||
// 设置在线状态 - 基于心跳时间戳判断
|
||||
// 设置在线状态 - 基于心跳时间戳判断离线,基于无人机mode判断工作状态
|
||||
telemetry.get(TuohengDeviceTelemetry.STATUS).ifPresentOrElse(statusValue -> {
|
||||
long lastHeartbeatTime = statusValue.getTimestamp();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
|
@ -220,9 +220,34 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService {
|
|||
dto.setDockStatus("OFFLINE");
|
||||
log.info("心跳超时(>5分钟),设置机场状态为 OFFLINE");
|
||||
} else {
|
||||
String status = statusValue.getValue();
|
||||
log.info("STATUS 遥测值: {}", status);
|
||||
String dockStatus = "online".equals(status) ? "IDLE" : "OFFLINE";
|
||||
// 心跳正常,机场在线,通过无人机mode判断是IDLE还是WORKING
|
||||
String dockStatus = "IDLE"; // 默认空闲
|
||||
|
||||
if (aircraftIotDeviceId != null) {
|
||||
try {
|
||||
// 获取无人机遥测数据
|
||||
TelemetryMap aircraftTelemetry = thingsBoardDomain.getPredefinedTuohengDeviceTelemetry(aircraftIotDeviceId);
|
||||
|
||||
// 通过mode字段判断工作状态
|
||||
String mode = aircraftTelemetry.get(TuohengDeviceTelemetry.MODE)
|
||||
.map(TelemetryValue::getValue)
|
||||
.orElse("");
|
||||
|
||||
log.info("无人机MODE值: {}", mode);
|
||||
|
||||
if ("auto".equalsIgnoreCase(mode)) {
|
||||
dockStatus = "WORKING"; // auto模式表示正在执行任务
|
||||
log.info("无人机处于auto模式,设置机场状态为 WORKING");
|
||||
} else {
|
||||
log.info("无人机处于{}模式,设置机场状态为 IDLE", mode);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取无人机mode失败,默认设置为IDLE: {}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
log.info("机场未绑定无人机,设置机场状态为 IDLE");
|
||||
}
|
||||
|
||||
dto.setDockStatus(dockStatus);
|
||||
log.info("心跳正常,设置机场状态: {}", dockStatus);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue