zhaowenyu
2025-11-06 3eb98b88c32d8c50d096d59c1b71e6bcfe8f074a
ard-sample/src/main/java/com/ard/sample/manage/service/impl/ControlServiceImpl.java
@@ -6,6 +6,8 @@
import com.ard.sample.component.mqtt.service.IMessageSenderService;
import com.ard.common.core.redis.RedisConst;
import com.ard.common.core.redis.RedisOpsUtils;
import com.ard.sample.component.websocket.enums.MessageType;
import com.ard.sample.component.websocket.handler.DockWebSocketHandler;
import com.ard.sample.component.websocket.service.ISendMessageService;
import com.ard.sample.manage.model.dto.BasicDeviceProperty;
import com.ard.sample.manage.model.dto.DeviceDTO;
@@ -37,7 +39,13 @@
    private IMessageSenderService messageSenderService;
    @Autowired
    private DockWebSocketHandler _dockWebSocketHandler;
    @Autowired
    private ISendMessageService webSocketMessageService;
    @Autowired
    private IDeviceService _deviceService;
//    @Autowired
//    private IWebSocketManageService webSocketManageService;
@@ -61,7 +69,14 @@
            if (Objects.isNull(param)) {
                return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
            }
            BasicDeviceProperty basicDeviceProperty = mapper.convertValue(param.getAction(), controlMethodEnum.getClazz());
            BasicDeviceProperty basicDeviceProperty = null;
            if(serviceIdentifier.equals("sdr_workmode_switch")){
                basicDeviceProperty= mapper.convertValue(param.getLink_workmode(), controlMethodEnum.getClazz());
            }
            else
            {
                basicDeviceProperty = mapper.convertValue(param.getAction(), controlMethodEnum.getClazz());
            }
            if (!basicDeviceProperty.valid()) {
                return ResponseResult.error(CommonErrorEnum.ILLEGAL_ARGUMENT);
            }
@@ -105,12 +120,21 @@
        if (RedisOpsUtils.getExpire(key) <= 0) {
            return;
        }
        // 更新设备列表状态--关闭舱盖中...
        String method = receiver.getMethod();
        String deviceSn = receiver.getGateway();
        if(method.equals("cover_close")){
            _deviceService.updateWorkType(deviceSn, 2L);
            RedisOpsUtils.setWithExpire(RedisConst.OSD_STATUS_PREFIX + deviceSn, 2, RedisConst.DEVICE_ALIVE_SECOND);
        }
        String sn = RedisOpsUtils.get(key).toString();
        receiver.setType(MessageType.PROGRESS.getType());
        EventsReceiver<EventsOutputReceiver> eventsReceiver = mapper.convertValue(receiver.getData(),
                new TypeReference<EventsReceiver<EventsOutputReceiver>>(){});
        eventsReceiver.setBid(receiver.getBid());
        eventsReceiver.setSn(sn);
        eventsReceiver.setGateway(sn);
        eventsReceiver.setType(MessageType.PROGRESS.getType());
        eventsReceiver.setMethod(receiver.getMethod());
        log.info("SN: {}, {} ===> Control progress: {}",
                sn, receiver.getMethod(), eventsReceiver.getOutput().getProgress().toString());
@@ -133,6 +157,21 @@
//                        .timestamp(System.currentTimeMillis())
//                        .bizCode(receiver.getMethod())
//                        .build());
        // 更新设备列表状态--飞行器开机中...
        if(method.equals("drone_open")){
            _deviceService.updateWorkType(device.getChildDeviceSn(), 7L);
            RedisOpsUtils.setWithExpire(RedisConst.OSD_STATUS_PREFIX + device.getChildDeviceSn(), 7, RedisConst.DEVICE_ALIVE_SECOND);
        }
        String dockProgress ="";
        try {
            dockProgress = mapper.writeValueAsString(eventsReceiver);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        // 设备控制进度消息websocket发给前端
        _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.PROGRESS.getType(), dockProgress);
        if (receiver.getNeedReply() != null && receiver.getNeedReply() == 1) {
            String topic = headers.get(MqttHeaders.RECEIVED_TOPIC) + TopicConst._REPLY_SUF;