diff --git a/src/main/java/com/ruoyi/device/domain/model/thingsboard/tuoheng/constants/TuohengDeviceAttributes.java b/src/main/java/com/ruoyi/device/domain/model/thingsboard/tuoheng/constants/TuohengDeviceAttributes.java index c9c2d03..ebbc792 100644 --- a/src/main/java/com/ruoyi/device/domain/model/thingsboard/tuoheng/constants/TuohengDeviceAttributes.java +++ b/src/main/java/com/ruoyi/device/domain/model/thingsboard/tuoheng/constants/TuohengDeviceAttributes.java @@ -195,6 +195,36 @@ public class TuohengDeviceAttributes { } ); + /** + * 机场运行数据属性(手动维护) + */ + + // 运行时长(小时) - Integer + public static final AttributeKey RUNNING_DURATION = AttributeKey.of( + "runningDuration", + Integer.class, + value -> { + if (value == null) return null; + if (value instanceof Number) { + return ((Number) value).intValue(); + } + return Integer.parseInt(value.toString()); + } + ); + + // 作业架次 - Integer + public static final AttributeKey MISSION_COUNT = AttributeKey.of( + "missionCount", + Integer.class, + value -> { + if (value == null) return null; + if (value instanceof Number) { + return ((Number) value).intValue(); + } + return Integer.parseInt(value.toString()); + } + ); + private TuohengDeviceAttributes() { // 工具类,禁止实例化 } @@ -221,7 +251,9 @@ public class TuohengDeviceAttributes { HOME_LONGITUDE, HOME_LATITUDE, BACKUP_LONGITUDE, - BACKUP_LATITUDE + BACKUP_LATITUDE, + RUNNING_DURATION, + MISSION_COUNT ); } diff --git a/src/main/java/com/ruoyi/device/service/impl/TuohengBufferDeviceImpl.java b/src/main/java/com/ruoyi/device/service/impl/TuohengBufferDeviceImpl.java index 8794c79..c8b159d 100644 --- a/src/main/java/com/ruoyi/device/service/impl/TuohengBufferDeviceImpl.java +++ b/src/main/java/com/ruoyi/device/service/impl/TuohengBufferDeviceImpl.java @@ -266,6 +266,18 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService { dto.setBackupLatitude(DEFAULT_LATITUDE); } + // 设置运行数据(从属性中获取 runningDuration 和 missionCount,取不到则默认为 0) + log.info("---------- 解析运行数据 ----------"); + Integer runningDuration = attributes.get(TuohengDeviceAttributes.RUNNING_DURATION) + .orElse(0); + log.info("RUNNING_DURATION 运行时长: {} 小时", runningDuration); + dto.setRunningDuration(runningDuration); + + Integer missionCount = attributes.get(TuohengDeviceAttributes.MISSION_COUNT) + .orElse(0); + log.info("MISSION_COUNT 作业架次: {}", missionCount); + dto.setMissionCount(missionCount); + // 设置在线状态 - 基于心跳时间戳判断离线,基于无人机mode判断工作状态 telemetry.get(TuohengDeviceTelemetry.STATUS).ifPresentOrElse(statusValue -> { long lastHeartbeatTime = statusValue.getTimestamp(); @@ -476,10 +488,6 @@ public class TuohengBufferDeviceImpl implements IBufferDeviceService { dto.setAircraftStatus(aircraftStatus); - // 设置作业架次 - 暂时设置为0,拓恒设备可能没有这个数据 - dto.setMissionCount(0); - log.info("设置作业架次: 0 (拓恒设备暂无此数据)"); - log.info("拓恒无人机状态填充完成: aircraftIotDeviceId={}, aircraftStatus={}", aircraftIotDeviceId, dto.getAircraftStatus()); log.info("========== 拓恒无人机状态填充结束 ==========");