zhaowenyu
2025-11-06 1616262d6d534d2c31ab3aea9496420bf5ce5853
ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
@@ -1,6 +1,9 @@
package com.ard.work.service.impl;
import com.ard.common.utils.ByteUtils;
import com.ard.common.constant.CacheConstants;
import com.ard.common.core.redis.RedisCache;
import com.ard.common.exception.ServiceException;
import com.ard.common.utils.StringUtils;
import com.ard.work.aspect.annotation.CheckControlRight;
import com.ard.work.aspect.annotation.CheckTakeoffAltitude;
import com.ard.work.component.forest.TyClient;
@@ -46,7 +49,6 @@
import com.ard.work.domain.dto.wayline.*;
import com.ard.work.domain.entity.ArdDroneInfo;
import com.ard.work.domain.entity.ArdServerInfo;
import com.ard.work.domain.message.BaseMessage;
import com.ard.work.domain.message.ServerReplyMessage;
import com.ard.work.domain.message.UavControlType;
import com.ard.work.domain.receiver.*;
@@ -54,6 +56,7 @@
import com.ard.work.service.IArdServerInfoService;
import com.ard.work.service.ITyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -76,6 +79,8 @@
    private IArdDroneInfoService ardDroneService;
    @Resource
    private TyClient tyClient;
    @Autowired
    private RedisCache redisCache;
    /**
     * 获取边缘服务器token信息
@@ -94,7 +99,9 @@
     */
    @Override
    public List<BoxInfoReceiver> getBoxList() {
        List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo() {{ setUseDataScope(false); }});
        List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo() {{
            setUseDataScope(false);
        }});
        return getBoxList(ardServerInfos);
    }
@@ -118,8 +125,11 @@
    public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            log.warn("未找到对应的飞行器信息,boxSn:{}", boxSn);
            return null;
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
                boxSn);
@@ -133,7 +143,15 @@
     */
    @Override
    public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO boxHistoryDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxHistoryDTO.getBoxSn());
        String boxSn = boxHistoryDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行起飞指令, boxSn: " + boxSn);
        }
        TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerId(),
                boxHistoryDTO);
        return boxHistory == null ? null : boxHistory.getContent();
@@ -146,7 +164,15 @@
     */
    @Override
    public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn());
        String boxSn = boxPhotosDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行起飞指令, boxSn: " + boxSn);
        }
        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),
                boxPhotosDTO);
        return boxPhotos == null ? null : boxPhotos.getContent();
@@ -157,7 +183,15 @@
     */
    @Override
    public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn());
        String boxSn = boxSettingsDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO);
        return result.getState() == 1;
    }
@@ -167,7 +201,15 @@
     */
    @Override
    public Boolean updateReturnHeight(ReturnHeightSettingDTO returnHeightSettingDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHeightSettingDTO.getBoxSn());
        String boxSn = returnHeightSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnHeightSettingCmd);
        return true;
@@ -178,7 +220,15 @@
     */
    @Override
    public Boolean updateReturnPoint(ReturnPointSettingDTO returnPointSettingDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnPointSettingDTO.getBoxSn());
        String boxSn = returnPointSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnPointSettingCmd);
        return true;
@@ -189,7 +239,15 @@
     */
    @Override
    public Boolean updateVideoStream(VideoStreamSettingDTO videoStreamSettingDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(videoStreamSettingDTO.getBoxSn());
        String boxSn = videoStreamSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), videoStreamSettingCmd);
        return true;
@@ -204,10 +262,11 @@
            AccessTokenReceiver tyToken = ardServerService.getAccessToken(serverId);
            RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes());
            this.sendMessage(serverId, registerMessage);
            return true;
        } catch (Exception e) {
            log.error("注册边缘服务器平台失败:{}", e.getMessage());
            return false;
        }
        return true;
    }
    /**
@@ -216,7 +275,15 @@
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean angleControl(AngleControlDTO angleControlDto) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(angleControlDto.getBoxSn());
        String boxSn = angleControlDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto);
        this.sendMessage(ardDroneInfo.getServerId(), controlAngleCommand);
        return true;
@@ -228,7 +295,15 @@
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean absAngleControl(AbsAngleControlDTO absAngleControlDto) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(absAngleControlDto.getBoxSn());
        String boxSn = absAngleControlDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto);
        this.sendMessage(ardDroneInfo.getServerId(), absAngleControlCommand);
        return true;
@@ -240,7 +315,15 @@
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean speedControl(SpeedControlDTO speedControlDto) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(speedControlDto.getBoxSn());
        String boxSn = speedControlDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto);
        this.sendMessage(ardDroneInfo.getServerId(), speedControlCommand);
        return true;
@@ -251,7 +334,15 @@
     */
    @Override
    public Boolean updateCameraMode(CameraModeDTO cameraModeDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(cameraModeDTO.getBoxSn());
        String boxSn = cameraModeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), cameraModeCommand);
        return true;
@@ -262,11 +353,20 @@
     */
    @Override
    public Boolean capturePic(CapturePicDTO capturePicDto) {
        String boxSn = capturePicDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        //设置相机模式为拍照模式
        updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
        //设置拍照回传
        photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(capturePicDto.getBoxSn());
        CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
        this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand);
        return true;
@@ -277,6 +377,15 @@
     */
    @Override
    public Boolean record(RecordDTO recordDto) {
        String boxSn = recordDto.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        BaseCmd baseCmd;
        if (recordDto.getIsRecord()) {
            updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
@@ -284,7 +393,6 @@
        } else {
            baseCmd = new RecordStopCmd(recordDto);
        }
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordDto.getBoxSn());
        this.sendMessage(ardDroneInfo.getServerId(), baseCmd);
        return true;
    }
@@ -295,7 +403,15 @@
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean zoom(ZoomDTO zoomDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(zoomDTO.getBoxSn());
        String boxSn = zoomDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        ZoomCmd zoomCommand = new ZoomCmd(zoomDTO);
        this.sendMessage(ardDroneInfo.getServerId(), zoomCommand);
        return true;
@@ -307,7 +423,15 @@
    @CheckControlRight(UavControlType.PAYLOAD)
    @Override
    public Boolean zoomToLevel(ZoomToLevelDTO zoomToLevelDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(zoomToLevelDTO.getBoxSn());
        String boxSn = zoomToLevelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), zoomToLevelCommand);
        return true;
@@ -318,7 +442,15 @@
     */
    @Override
    public Boolean switchCamera(SwitchCameraDTO switchCameraDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchCameraDTO.getBoxSn());
        String boxSn = switchCameraDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO);
        this.sendMessage(ardDroneInfo.getServerId(), switchCameraCmd);
        return true;
@@ -329,7 +461,15 @@
     */
    @Override
    public Boolean switchSource(SwitchSourceDTO switchSourceDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchSourceDTO.getBoxSn());
        String boxSn = switchSourceDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO);
        this.sendMessage(ardDroneInfo.getServerId(), switchSourceCmd);
        return true;
@@ -340,7 +480,15 @@
     */
    @Override
    public Boolean photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(photoReturnToggleDTO.getBoxSn());
        String boxSn = photoReturnToggleDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO);
        this.sendMessage(ardDroneInfo.getServerId(), photoReturnToggleCmd);
        return true;
@@ -351,7 +499,15 @@
     */
    @Override
    public Boolean switchUavControl(SwitchUavControlDTO switchUavControlDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchUavControlDTO.getBoxSn());
        String boxSn = switchUavControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), switchUavControlCmd);
        return true;
@@ -363,7 +519,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean takeOff(TakeOffDTO takeOffDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(takeOffDTO.getBoxSn());
        String boxSn = takeOffDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO);
        this.sendMessage(ardDroneInfo.getServerId(), takeOffCmd);
        return true;
@@ -375,7 +539,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean returnHome(ReturnHomeDTO returnHomeDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHomeDTO.getBoxSn());
        String boxSn = returnHomeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnHomeCmd);
        return true;
@@ -387,7 +559,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean returnHomeCancel(ReturnHomeCancelDTO returnHomeCancelDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHomeCancelDTO.getBoxSn());
        String boxSn = returnHomeCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), returnHomeCancelCmd);
        return true;
@@ -399,7 +579,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean land(LandDTO landDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landDTO.getBoxSn());
        String boxSn = landDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        LandCmd landCmd = new LandCmd(landDTO);
        this.sendMessage(ardDroneInfo.getServerId(), landCmd);
        return true;
@@ -411,7 +599,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean landCancel(LandCancelDTO landCancelDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landCancelDTO.getBoxSn());
        String boxSn = landCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), landCancelCmd);
        return true;
@@ -423,7 +619,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean landForced(LandForcedDTO landForcedDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landForcedDTO.getBoxSn());
        String boxSn = landForcedDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO);
        this.sendMessage(ardDroneInfo.getServerId(), landForcedCmd);
        return true;
@@ -436,7 +640,15 @@
    @CheckTakeoffAltitude(minAltitude = 30.0)
    @Override
    public Boolean flyControl(FlyControlDTO flyControlDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyControlDTO.getBoxSn());
        String boxSn = flyControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyControlCmd);
        return true;
@@ -449,7 +661,15 @@
    @CheckTakeoffAltitude(minAltitude = 30.0)
    @Override
    public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyPointControlDTO.getBoxSn());
        String boxSn = flyPointControlDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCmd);
        return true;
@@ -461,7 +681,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean flyPointControlCancel(FlyPointControlCancelDTO flyPointControlCancelDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyPointControlCancelDTO.getBoxSn());
        String boxSn = flyPointControlCancelDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO);
        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
        return true;
@@ -473,7 +701,15 @@
    @CheckControlRight(UavControlType.FLY)
    @Override
    public Boolean emeragencyBrake(EmeragencyBrakeDTO emeragencyBrakeDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(emeragencyBrakeDTO.getBoxSn());
        String boxSn = emeragencyBrakeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd);
        return true;
@@ -507,81 +743,153 @@
     * 喊话模式切换
     */
    @Override
    public void speakModeSwitch(SpeakModeSwitchDTO speakModeSwitchDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(speakModeSwitchDTO.getBoxSn());
    public Boolean speakModeSwitch(SpeakModeSwitchDTO speakModeSwitchDTO) {
        String boxSn = speakModeSwitchDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        SpeakModeSwitchCmd speakModeSwitchCmd = new SpeakModeSwitchCmd(speakModeSwitchDTO);
        this.sendMessage(ardDroneInfo.getServerId(), speakModeSwitchCmd);
        return true;
    }
    /**
     * 文字喊话
     */
    @Override
    public void textSpeak(TextSpeakDTO textSpeakDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(textSpeakDTO.getBoxSn());
    public Boolean textSpeak(TextSpeakDTO textSpeakDTO) {
        String boxSn = textSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        TextSpeakCmd textSpeakCmd = new TextSpeakCmd(textSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), textSpeakCmd);
        return true;
    }
    /**
     * 实时喊话
     */
    @Override
    public void realSpeak(RealSpeakDTO realSpeakDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(realSpeakDTO.getBoxSn());
    public Boolean realSpeak(RealSpeakDTO realSpeakDTO) {
        String boxSn = realSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        RealSpeakCmd realSpeakCmd = new RealSpeakCmd(realSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), realSpeakCmd);
        return true;
    }
    /**
     * 录音喊话
     */
    @Override
    public void recordSpeak(RecordSpeakDTO recordSpeakDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordSpeakDTO.getBoxSn());
    public Boolean recordSpeak(RecordSpeakDTO recordSpeakDTO) {
        String boxSn = recordSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        RecordSpeakCmd recordSpeakCmd = new RecordSpeakCmd(recordSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), recordSpeakCmd);
        return true;
    }
    /**
     * 设置音量
     */
    @Override
    public void volumeSetting(VolumeSettingDTO volumeSettingDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(volumeSettingDTO.getBoxSn());
    public Boolean volumeSetting(VolumeSettingDTO volumeSettingDTO) {
        String boxSn = volumeSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        VolumeSettingCmd volumeSettingCmd = new VolumeSettingCmd(volumeSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), volumeSettingCmd);
        return true;
    }
    /**
     * 设置循环播放
     */
    @Override
    public void loopSetting(LoopSettingDTO loopSettingDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(loopSettingDTO.getBoxSn());
    public Boolean loopSetting(LoopSettingDTO loopSettingDTO) {
        String boxSn = loopSettingDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        LoopSettingCmd loopSettingCmd = new LoopSettingCmd(loopSettingDTO);
        this.sendMessage(ardDroneInfo.getServerId(), loopSettingCmd);
        return true;
    }
    /**
     * 停止喊话
     */
    @Override
    public void stopSpeak(StopSpeakDTO stopSpeakDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(stopSpeakDTO.getBoxSn());
    public Boolean stopSpeak(StopSpeakDTO stopSpeakDTO) {
        String boxSn = stopSpeakDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        StopSpeakCmd stopSpeakCmd = new StopSpeakCmd(stopSpeakDTO);
        this.sendMessage(ardDroneInfo.getServerId(), stopSpeakCmd);
        return true;
    }
    /**
     * 航线上传
     */
    @Override
    public void wayLineUpload(WayLineUploadDTO wayLineUploadDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineUploadDTO.getBoxSn());
        wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据
    public Boolean wayLineUpload(WayLineUploadDTO wayLineUploadDTO) {
        String boxSn = wayLineUploadDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        //wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据
        WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd);
        return true;
    }
    //创建航线
@@ -623,10 +931,19 @@
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public void wayLineBegin(WayLineBeginDTO wayLineBeginDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineBeginDTO.getBoxSn());
    public Boolean wayLineBegin(WayLineBeginDTO wayLineBeginDTO) {
        String boxSn = wayLineBeginDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        WayLineBeginCmd wayLineBeginCmd = new WayLineBeginCmd(wayLineBeginDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineBeginCmd);
        return true;
    }
    /**
@@ -634,10 +951,19 @@
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public void wayLinePause(WayLinePauseDTO wayLinePauseDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLinePauseDTO.getBoxSn());
    public Boolean wayLinePause(WayLinePauseDTO wayLinePauseDTO) {
        String boxSn = wayLinePauseDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        WayLinePauseCmd wayLinePauseCmd = new WayLinePauseCmd(wayLinePauseDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLinePauseCmd);
        return true;
    }
    /**
@@ -645,10 +971,19 @@
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public void wayLineResume(WayLineResumeDTO wayLineResumeDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineResumeDTO.getBoxSn());
    public Boolean wayLineResume(WayLineResumeDTO wayLineResumeDTO) {
        String boxSn = wayLineResumeDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        WayLineResumeCmd wayLineResumeCmd = new WayLineResumeCmd(wayLineResumeDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineResumeCmd);
        return true;
    }
    /**
@@ -656,10 +991,19 @@
     */
    @CheckControlRight(UavControlType.FLY)
    @Override
    public void wayLineEnd(WayLineEndDTO wayLineEndDTO) {
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineEndDTO.getBoxSn());
    public Boolean wayLineEnd(WayLineEndDTO wayLineEndDTO) {
        String boxSn = wayLineEndDTO.getBoxSn();
        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
        if (ardDroneInfo == null) {
            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
        }
        // ✅ 判断无人机是否在线
        if (!isDroneOnline(boxSn)) {
            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
        }
        WayLineEndCmd wayLineEndCmd = new WayLineEndCmd(wayLineEndDTO);
        this.sendMessage(ardDroneInfo.getServerId(), wayLineEndCmd);
        return true;
    }
    /**
@@ -932,4 +1276,13 @@
        TcpClientUtil.sendMessage(key, msg);
    }
    // 判断无人机是否在线
    private boolean isDroneOnline(String boxSn) {
        if (StringUtils.isBlank(boxSn)) {
            return false;
        }
        Object obj = redisCache.getCacheObject(CacheConstants.UAV_ONLINE_KEY + boxSn);
        return obj != null;
    }
}