| | |
| | | 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 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; |
| | |
| | | @Slf4j |
| | | public class StateLiveStatusHandler extends AbstractStateTopicHandler{ |
| | | |
| | | @Autowired |
| | | private DockWebSocketHandler _dockWebSocketHandler; |
| | | @Autowired |
| | | private IDeviceService _deviceService; |
| | | |
| | |
| | | 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); |