nishiwei
5 days ago 3f43e40ed1a1e9f66b3ad2862da9dbc4b710c712
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,15 +37,16 @@
    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);
            if(deviceDTOS!=null && deviceDTOS.size()>0)
            DeviceDTO device = (DeviceDTO) RedisOpsUtils.get(RedisConst.DEVICE_ONLINE_PREFIX + sn);
            if(device != null)
            {
                String childSn = deviceDTOS.get(0).getChildDeviceSn();
                List<LiveStatusTwoReceiver> list = mapper.convertValue(dataNode.get(StateDataEnum.LIVESTATUS.getDesc()), new TypeReference<List<LiveStatusTwoReceiver>>() {});
                String childSn = device.getChildDeviceSn();
                List<LiveStatusTwoReceiver> list = mapper.convertValue(dataNode.get(StateDataEnum.LIVESTATUS.getDesc()),
                        new TypeReference<List<LiveStatusTwoReceiver>>() {});
                for (LiveStatusTwoReceiver receiver : list) {
                    if(receiver.getVideoId().contains(childSn)){
                    // 机场1(Dock1)未连接飞行器时 childDeviceSn 为空,跳过匹配,避免 String.contains(null) 抛 NPE
                    if (StringUtils.hasText(childSn) && receiver.getVideoId() != null
                            && receiver.getVideoId().contains(childSn)) {
                        stateReceiver.setData(receiver);
                        continue;
                    }
@@ -57,7 +59,10 @@
                catch (Exception e){
                    log.error("接收state直播设备状态反馈转换异常:{}",e);
                }
                _deviceService.setChildRedisCamera(childSn, liveStatus);
                // 无子设备 SN 时不写缓存,避免产生 COVER_STATE_PREFIX + null 的非法 Redis key
                if (StringUtils.hasText(childSn)) {
                    _deviceService.setChildRedisCamera(childSn, liveStatus);
                }
            }
            return stateReceiver;