zhaowenyu
2026-04-01 342236a5694a22c544a217c9f1503e5ac790b609
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
import com.ard.sample.component.websocket.handler.DockWebSocketHandler;
import com.ard.sample.manage.model.dto.DeviceDTO;
import com.ard.sample.manage.model.param.DeviceQueryParam;
import com.ard.sample.manage.model.receiver.LiveCapacityReceiver;
import com.ard.sample.manage.model.receiver.LiveStatusTwoReceiver;
import com.ard.sample.manage.service.IDeviceService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Map;
 
@Service
@Slf4j
public class StateLiveStatusHandler extends AbstractStateTopicHandler{
 
    @Autowired
    private IDeviceService _deviceService;
 
    protected StateLiveStatusHandler(@Autowired @Qualifier("stateFirmwareVersionHandler")AbstractStateTopicHandler handler) {
        super(handler);
    }
 
    @Override
    public CommonTopicReceiver handleState(Map<String, Object> dataNode, CommonTopicReceiver stateReceiver, String sn) throws JsonProcessingException {
        if (dataNode.containsKey(StateDataEnum.LIVESTATUS.getDesc())) {
            stateReceiver.setType(MessageType.LIVESTATUS.getType());
            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) {
                    if(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);
                }
                _deviceService.setChildRedisCamera(childSn, liveStatus);
            }
 
            return stateReceiver;
        }
        return handler.handleState(dataNode, stateReceiver, sn);
    }
}