zhaowenyu
2025-12-08 4ccb6e629d3c39521435046e94d5bec927861247
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
67
package com.ard.sample.component.mqtt.handler;
 
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 DockWebSocketHandler _dockWebSocketHandler;
    @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());
            String deviceSn= stateReceiver.getGateway();
            DeviceQueryParam param = DeviceQueryParam.builder().deviceSn(deviceSn).build();
            List<DeviceDTO> deviceDTOS = _deviceService.getDevicesByParams(param);
            if(deviceDTOS!=null && deviceDTOS.size()>0)
            {
                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;
                    }
                }
                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);
    }
}