From 3f43e40ed1a1e9f66b3ad2862da9dbc4b710c712 Mon Sep 17 00:00:00 2001
From: nishiwei <13126973358@163.com>
Date: Fri, 23 Oct 2026 14:09:47 +0800
Subject: [PATCH] 智云3.0机场1适配内容提交
---
ard-sample/src/main/java/com/ard/sample/component/mqtt/handler/StateLiveStatusHandler.java | 51 +++++++++++++++++++++++++++++----------------------
1 files changed, 29 insertions(+), 22 deletions(-)
diff --git a/ard-sample/src/main/java/com/ard/sample/component/mqtt/handler/StateLiveStatusHandler.java b/ard-sample/src/main/java/com/ard/sample/component/mqtt/handler/StateLiveStatusHandler.java
index 2227171..1b22057 100644
--- a/ard-sample/src/main/java/com/ard/sample/component/mqtt/handler/StateLiveStatusHandler.java
+++ b/ard-sample/src/main/java/com/ard/sample/component/mqtt/handler/StateLiveStatusHandler.java
@@ -1,5 +1,7 @@
package com.ard.sample.component.mqtt.handler;
+import com.ard.common.core.redis.RedisConst;
+import com.ard.common.core.redis.RedisOpsUtils;
import com.ard.sample.component.mqtt.model.CommonTopicReceiver;
import com.ard.sample.component.mqtt.model.StateDataEnum;
import com.ard.sample.component.websocket.enums.MessageType;
@@ -15,6 +17,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
import java.util.List;
import java.util.Map;
@@ -23,8 +26,6 @@
@Slf4j
public class StateLiveStatusHandler extends AbstractStateTopicHandler{
- @Autowired
- private DockWebSocketHandler _dockWebSocketHandler;
@Autowired
private IDeviceService _deviceService;
@@ -36,28 +37,34 @@
public CommonTopicReceiver handleState(Map<String, Object> dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException {
if (dataNode.containsKey(StateDataEnum.LIVESTATUS.getDesc())) {
stateReceiver.setType(MessageType.LIVESTATUS.getType());
- String deviceSn= stateReceiver.getGateway();
- DeviceQueryParam param = DeviceQueryParam.builder().deviceSn(deviceSn).build();
- List<DeviceDTO> deviceDTOS = _deviceService.getDevicesByParams(param);
- // List<DeviceDTO> gatewaysList = _deviceService.getDevicesByParams(DeviceQueryParam.builder().childSn(deviceSn).build());
- String childSn = deviceDTOS.get(0).getChildDeviceSn();
- List<LiveStatusTwoReceiver> list = mapper.convertValue(dataNode.get(StateDataEnum.LIVESTATUS.getDesc()), new TypeReference<List<LiveStatusTwoReceiver>>() {});
- for (LiveStatusTwoReceiver receiver : list) {
- if(receiver.getVideoId().contains(childSn)){
- stateReceiver.setData(receiver);
- continue;
+ DeviceDTO device = (DeviceDTO) RedisOpsUtils.get(RedisConst.DEVICE_ONLINE_PREFIX + sn);
+ if(device != null)
+ {
+ String childSn = device.getChildDeviceSn();
+ List<LiveStatusTwoReceiver> list = mapper.convertValue(dataNode.get(StateDataEnum.LIVESTATUS.getDesc()),
+ new TypeReference<List<LiveStatusTwoReceiver>>() {});
+ for (LiveStatusTwoReceiver receiver : list) {
+ // 机场1(Dock1)未连接飞行器时 childDeviceSn 为空,跳过匹配,避免 String.contains(null) 抛 NPE
+ if (StringUtils.hasText(childSn) && receiver.getVideoId() != null
+ && receiver.getVideoId().contains(childSn)) {
+ stateReceiver.setData(receiver);
+ continue;
+ }
+ }
+ stateReceiver.setGateway(childSn);
+ String liveStatus = "";
+ try{
+ liveStatus=mapper.writeValueAsString(stateReceiver);
+ }
+ catch (Exception e){
+ log.error("接收state直播设备状态反馈转换异常:{}",e);
+ }
+ // 无子设备 SN 时不写缓存,避免产生 COVER_STATE_PREFIX + null 的非法 Redis key
+ if (StringUtils.hasText(childSn)) {
+ _deviceService.setChildRedisCamera(childSn, liveStatus);
}
}
- stateReceiver.setGateway(childSn);
- String liveStatus = "";
- try{
- liveStatus=mapper.writeValueAsString(stateReceiver);
- }
- catch (Exception e){
- log.error("接收state直播设备状态反馈转换异常:{}",e);
- }
- _deviceService.setChildRedisCamera(childSn, liveStatus);
- log.info("接收state直播设备状态反馈:{}",liveStatus);
+
return stateReceiver;
}
return handler.handleState(dataNode, stateReceiver, sn);
--
Gitblit v1.9.3