From 4e8a1c02b45f72f6377603778e8c8746ed82f374 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Tue, 06 Jan 2026 10:04:33 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java |  583 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 449 insertions(+), 134 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
index 810d866..ed5d4bb 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
@@ -1,66 +1,72 @@
 package com.ard.work.service.impl;
 
-import com.ard.common.utils.ByteUtils;
-import com.ard.work.aspect.annotation.CheckTakeoffAltitude;
+import com.ard.common.exception.ControlException;
 import com.ard.work.aspect.annotation.CheckControlRight;
+import com.ard.work.aspect.annotation.CheckDroneStatus;
+import com.ard.work.aspect.annotation.CheckNoFlyZone;
+import com.ard.work.aspect.annotation.CheckTakeoffAltitude;
+import com.ard.work.component.forest.TyClient;
+import com.ard.work.component.netty.TcpClientUtil;
 import com.ard.work.component.netty.command.BaseCmd;
 import com.ard.work.component.netty.command.camera.*;
+import com.ard.work.component.netty.command.control.AbsAngleControlCmd;
+import com.ard.work.component.netty.command.control.AngleControlCmd;
+import com.ard.work.component.netty.command.control.SpeedControlCmd;
 import com.ard.work.component.netty.command.manual.*;
+import com.ard.work.component.netty.command.notice.BoxPowerStatusReplyCmd;
+import com.ard.work.component.netty.command.notice.WayLineFinishedReplyCmd;
+import com.ard.work.component.netty.command.notice.UavReadyReplyCmd;
+import com.ard.work.component.netty.command.real.SignalInfoCmd;
+import com.ard.work.component.netty.command.real.UavStateCmd;
+import com.ard.work.component.netty.command.real.UavTelemetryDataCmd;
 import com.ard.work.component.netty.command.register.*;
 import com.ard.work.component.netty.command.settings.*;
 import com.ard.work.component.netty.command.speaker.*;
 import com.ard.work.component.netty.command.wayline.*;
-import com.ard.work.domain.dto.camera.*;
-import com.ard.work.domain.dto.manual.*;
-import com.ard.work.domain.dto.speaker.*;
-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.receiver.*;
-import com.ard.work.component.forest.TyClient;
+import com.ard.work.component.netty.handler.ErrorCodeEnum;
+import com.ard.work.component.netty.protobuf.TelemetryDataPB;
+import com.ard.work.component.websocket.utils.WebSocketUtil;
+import com.ard.work.config.RouteStateMachineService;
 import com.ard.work.domain.cache.UavSignalInfoCache;
 import com.ard.work.domain.cache.UavStateCache;
 import com.ard.work.domain.cache.UavTelemetryDataCache;
 import com.ard.work.domain.dto.BoxHistoryDTO;
 import com.ard.work.domain.dto.BoxPhotosDTO;
 import com.ard.work.domain.dto.BoxSettingsDTO;
+import com.ard.work.domain.dto.BoxVideosDTO;
+import com.ard.work.domain.dto.camera.*;
 import com.ard.work.domain.dto.control.AbsAngleControlDTO;
 import com.ard.work.domain.dto.control.AngleControlDTO;
 import com.ard.work.domain.dto.control.SpeedControlDTO;
 import com.ard.work.domain.dto.converter.wayline.PlanLineDataConverter;
+import com.ard.work.domain.dto.manual.*;
 import com.ard.work.domain.dto.settings.ReturnHeightSettingDTO;
 import com.ard.work.domain.dto.settings.ReturnPointSettingDTO;
 import com.ard.work.domain.dto.settings.VideoStreamSettingDTO;
 import com.ard.work.domain.dto.signal.SignalInfo;
+import com.ard.work.domain.dto.speaker.*;
 import com.ard.work.domain.dto.state.UavState;
 import com.ard.work.domain.dto.telemetry.TelemetryData;
-import com.ard.work.component.netty.command.control.AbsAngleControlCmd;
-import com.ard.work.component.netty.command.control.AngleControlCmd;
-import com.ard.work.component.netty.command.control.SpeedControlCmd;
-import com.ard.work.component.netty.command.notice.BoxPowerStatusReplyCmd;
-import com.ard.work.component.netty.command.notice.FlyWayEndReplyCmd;
-import com.ard.work.component.netty.command.notice.UavReadyReplyCmd;
-import com.ard.work.component.netty.command.real.SignalInfoCmd;
-import com.ard.work.component.netty.command.real.UavStateCmd;
-import com.ard.work.component.netty.command.real.UavTelemetryDataCmd;
-import com.ard.work.component.netty.handler.ErrorCodeEnum;
-import com.ard.work.component.netty.protobuf.TelemetryDataPB;
+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.enums.RouteEvent;
+import com.ard.work.domain.message.ServerReplyMessage;
+import com.ard.work.domain.message.UavControlType;
+import com.ard.work.domain.receiver.*;
 import com.ard.work.service.IArdDroneInfoService;
+import com.ard.work.service.IArdFlightTaskPartService;
 import com.ard.work.service.IArdServerInfoService;
 import com.ard.work.service.ITyService;
-import com.ard.work.domain.message.UavControlType;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.net.InetSocketAddress;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-
-import static com.ard.work.component.netty.TyTcpClientManager.channels;
 
 /**
  * TyServiceImpl
@@ -77,9 +83,13 @@
     private IArdDroneInfoService ardDroneService;
     @Resource
     private TyClient tyClient;
+    @Autowired
+    private RouteStateMachineService stateMachineService;
+    @Autowired
+    private IArdFlightTaskPartService ardFlightTaskPartService;
 
     /**
-     * 获取六合token信息
+     * 获取边缘服务器token信息
      *
      * @return AccessTokenReceiver
      */
@@ -89,14 +99,27 @@
     }
 
     /**
-     * 获取云盒列表
+     * 获取全部云盒列表
      *
      * @return List<BoxInfoReceiver>
      */
     @Override
     public List<BoxInfoReceiver> getBoxList() {
-        List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo());
+        List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo() {{
+            setUseDataScope(false);
+        }});
         return getBoxList(ardServerInfos);
+    }
+
+    /**
+     * 获取指定服务器云盒列表
+     *
+     * @return List<BoxInfoReceiver>
+     */
+    @Override
+    public List<BoxInfoReceiver> getBoxList(String serverId) {
+        TyHttpCommonReceiver<List<BoxInfoReceiver>> boxList = tyClient.getBoxList(serverId);
+        return boxList == null ? null : boxList.getContent();
     }
 
     /**
@@ -107,8 +130,14 @@
     @Override
     public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) {
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
-        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),boxSn);
-        return boxLiveUrl.getContent();
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+
+
+        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
+                boxSn);
+        return boxLiveUrl == null ? null : boxLiveUrl.getContent();
     }
 
     /**
@@ -118,32 +147,60 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerId(),
                 boxHistoryDTO);
-        return boxHistory.getContent();
+        return boxHistory == null ? null : boxHistory.getContent();
     }
 
     /**
-     * 获取盒子图片
+     * 获取任务图片
      *
      * @return List<BoxPhotosReceiver>
      */
     @Override
     public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
-        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn());
-        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),boxPhotosDTO);
-        return boxPhotos.getContent();
+        String boxSn = boxPhotosDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),
+                boxPhotosDTO);
+        return boxPhotos == null ? null : boxPhotos.getContent();
     }
-
+    /**
+     * 获取任务视频
+     *
+     * @return List<BoxVideosReceiver>
+     */
+    @Override
+    public List<BoxVideosReceiver> getBoxVideos(BoxVideosDTO boxVideosDTO) {
+        String boxSn = boxVideosDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        TyHttpCommonReceiver<List<BoxVideosReceiver>> boxVideos = tyClient.getBoxVideos(ardDroneInfo.getServerId(),
+                boxVideosDTO);
+        return boxVideos == null ? null : boxVideos.getContent();
+    }
     /**
      * 修改云盒设置
      */
     @Override
     public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) {
-        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn());
-        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(),boxSettingsDTO);
-        return result.getState() == 1;
+        String boxSn = boxSettingsDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO);
+        return result.getState() == 0;
     }
 
     /**
@@ -151,7 +208,11 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnHeightSettingCmd);
         return true;
@@ -162,7 +223,11 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnPointSettingCmd);
         return true;
@@ -173,14 +238,18 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), videoStreamSettingCmd);
         return true;
     }
 
     /**
-     * 注册六合平台
+     * 注册边缘服务器平台
      */
     @Override
     public Boolean registerMessage(String serverId) {
@@ -188,10 +257,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());
+            log.error("注册边缘服务器平台失败:{}", e.getMessage());
+            return false;
         }
-        return true;
     }
 
     /**
@@ -200,7 +270,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto);
         this.sendMessage(ardDroneInfo.getServerId(), controlAngleCommand);
         return true;
@@ -212,7 +286,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto);
         this.sendMessage(ardDroneInfo.getServerId(), absAngleControlCommand);
         return true;
@@ -224,18 +302,39 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto);
         this.sendMessage(ardDroneInfo.getServerId(), speedControlCommand);
+        return true;
+    }
+
+    @Override
+    public Boolean formatSdCard(FormatSdCardDTO formatSdCardDTO) {
+        String boxSn = formatSdCardDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        FormatSdCardCmd formatSdCardCmd = new FormatSdCardCmd(formatSdCardDTO);
+        this.sendMessage(ardDroneInfo.getServerId(), formatSdCardCmd);
         return true;
     }
 
     /**
      * 设置相机模式
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), cameraModeCommand);
         return true;
@@ -244,13 +343,20 @@
     /**
      * 拍照
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean capturePic(CapturePicDTO capturePicDto) {
+        String boxSn = capturePicDto.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         //设置相机模式为拍照模式
-        updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
+        //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());
+        //photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01)
+        // .build());
+
         CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
         this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand);
         return true;
@@ -259,16 +365,21 @@
     /**
      * 录像
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean record(RecordDTO recordDto) {
+        String boxSn = recordDto.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         BaseCmd baseCmd;
         if (recordDto.getIsRecord()) {
-            updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
+            //updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
             baseCmd = new RecordStartCmd(recordDto);
         } else {
             baseCmd = new RecordStopCmd(recordDto);
         }
-        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordDto.getBoxSn());
         this.sendMessage(ardDroneInfo.getServerId(), baseCmd);
         return true;
     }
@@ -279,7 +390,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ZoomCmd zoomCommand = new ZoomCmd(zoomDTO);
         this.sendMessage(ardDroneInfo.getServerId(), zoomCommand);
         return true;
@@ -291,7 +406,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), zoomToLevelCommand);
         return true;
@@ -300,9 +419,14 @@
     /**
      * 切换摄像头
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO);
         this.sendMessage(ardDroneInfo.getServerId(), switchCameraCmd);
         return true;
@@ -311,9 +435,14 @@
     /**
      * 切换视频源
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO);
         this.sendMessage(ardDroneInfo.getServerId(), switchSourceCmd);
         return true;
@@ -322,9 +451,14 @@
     /**
      * 打开或关闭照片回传
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO);
         this.sendMessage(ardDroneInfo.getServerId(), photoReturnToggleCmd);
         return true;
@@ -333,9 +467,14 @@
     /**
      * 切换无人机控制权
      */
+    @CheckDroneStatus
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO);
         this.sendMessage(ardDroneInfo.getServerId(), switchUavControlCmd);
         return true;
@@ -347,7 +486,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO);
         this.sendMessage(ardDroneInfo.getServerId(), takeOffCmd);
         return true;
@@ -359,7 +502,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnHomeCmd);
         return true;
@@ -371,7 +518,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnHomeCancelCmd);
         return true;
@@ -383,7 +534,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         LandCmd landCmd = new LandCmd(landDTO);
         this.sendMessage(ardDroneInfo.getServerId(), landCmd);
         return true;
@@ -395,7 +550,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), landCancelCmd);
         return true;
@@ -407,7 +566,11 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO);
         this.sendMessage(ardDroneInfo.getServerId(), landForcedCmd);
         return true;
@@ -417,10 +580,14 @@
      * 方向控制
      */
     @CheckControlRight(UavControlType.FLY)
-    @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckTakeoffAltitude
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyControlCmd);
         return true;
@@ -430,10 +597,19 @@
      * 指点飞行控制
      */
     @CheckControlRight(UavControlType.FLY)
-    @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckTakeoffAltitude
+    @CheckNoFlyZone
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        //打点之前先停止打点
+        FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(FlyPointControlCancelDTO.builder().boxSn(boxSn).build());
+        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
+
         FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCmd);
         return true;
@@ -445,9 +621,46 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+
+
         FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
+        return true;
+    }
+
+
+    /**
+     * 环绕飞行控制
+     */
+    @Override
+    public Boolean FlyRoundControl(FlyRoundControlDTO flyRoundControlDTO) {
+        String boxSn = flyRoundControlDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        FlyRoundControlCmd flyRoundControlCmd = new FlyRoundControlCmd(flyRoundControlDTO);
+        this.sendMessage(ardDroneInfo.getServerId(), flyRoundControlCmd);
+        return true;
+    }
+
+    /**
+     * 停止环绕飞行控制
+     */
+    @Override
+    public Boolean FlyRoundControlCancel(FlyRoundControlCancelDTO flyRoundControlCancelDTO) {
+        String boxSn = flyRoundControlCancelDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        FlyRoundControlCancelCmd flyRoundControlCancelCmd = new FlyRoundControlCancelCmd(flyRoundControlCancelDTO);
+        this.sendMessage(ardDroneInfo.getServerId(), flyRoundControlCancelCmd);
         return true;
     }
 
@@ -457,7 +670,13 @@
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+
+
         EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd);
         return true;
@@ -468,7 +687,7 @@
      */
     @Override
     public UavState getUavState(String boxSn) {
-        return UavStateCache.getUavState(boxSn);
+        return UavStateCache.get(boxSn);
     }
 
     /**
@@ -476,7 +695,7 @@
      */
     @Override
     public TelemetryData getUavTelemetryData(String boxSn) {
-        return UavTelemetryDataCache.getUavTelemetryData(boxSn);
+        return UavTelemetryDataCache.get(boxSn);
     }
 
     /**
@@ -484,88 +703,132 @@
      */
     @Override
     public SignalInfo getSignalInfo(String boxSn) {
-        return UavSignalInfoCache.getUavSignalInfo(boxSn);
+        return UavSignalInfoCache.get(boxSn);
     }
 
     /**
      * 喊话模式切换
      */
     @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 ControlException("未找到对应的飞行器信息,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 ControlException("未找到对应的飞行器信息,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 ControlException("未找到对应的飞行器信息,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 ControlException("未找到对应的飞行器信息,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 ControlException("未找到对应的飞行器信息,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 ControlException("未找到对应的飞行器信息,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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         StopSpeakCmd stopSpeakCmd = new StopSpeakCmd(stopSpeakDTO);
         this.sendMessage(ardDroneInfo.getServerId(), stopSpeakCmd);
+        return true;
     }
 
     /**
      * 航线上传
      */
+    @CheckControlRight(UavControlType.FLY)
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        //wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据
+        System.out.println("wayLineUploadDTO:-----------------" + wayLineUploadDTO);
+        log.info("打印数据 ++++ wayLineUploadDTO:-----------------" + wayLineUploadDTO);
         WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO);
+        System.out.println("wayLineUploadCmd:-----------------" + wayLineUploadCmd);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd);
+        return true;
     }
 
     //创建航线
@@ -607,10 +870,15 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         WayLineBeginCmd wayLineBeginCmd = new WayLineBeginCmd(wayLineBeginDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineBeginCmd);
+        return true;
     }
 
     /**
@@ -618,10 +886,15 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         WayLinePauseCmd wayLinePauseCmd = new WayLinePauseCmd(wayLinePauseDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLinePauseCmd);
+        return true;
     }
 
     /**
@@ -629,10 +902,15 @@
      */
     @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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         WayLineResumeCmd wayLineResumeCmd = new WayLineResumeCmd(wayLineResumeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineResumeCmd);
+        return true;
     }
 
     /**
@@ -640,14 +918,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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         WayLineEndCmd wayLineEndCmd = new WayLineEndCmd(wayLineEndDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineEndCmd);
+        return true;
     }
 
     /**
-     * 处理六合服务器返回的消息
+     * 处理边缘服务器返回的消息
      */
     @Override
     public void processReplyMessage(String key, BaseCmd tyCommand) {
@@ -665,8 +948,8 @@
                 break;
             case 0x02:
                 // 处理注册消息
-                 HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
-                 logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
+                HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
+                //logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
                 break;
             case 0x03:
                 // 处理订阅消息
@@ -687,14 +970,15 @@
             case (byte) 0xA8:
                 // 处理无人机状态消息
                 UavStateCmd uavStateCmd = (UavStateCmd) tyCommand;
-                UavStateCache.putUavState(uavStateCmd.getUavState());
+                UavStateCache.put(uavStateCmd.getUavState());
                 //logPrint("无人机状态", uavStateCmd.getUavState().getBoxSn());
                 // WebSocketUtil.sendMessageAll(uavStateCmd.getUavState());
                 break;
             case (byte) 0xA9:
                 // 处理无人机遥测消息
                 UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand;
-                UavTelemetryDataCache.putUavTelemetryData(uavTelemetryDataCmd.getTelemetryData());
+                TelemetryData telemetryData = uavTelemetryDataCmd.getTelemetryData();
+                UavTelemetryDataCache.put(telemetryData);
                 //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
                 //WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData());
                 break;
@@ -702,7 +986,7 @@
             case (byte) 0x0C:
                 // 处理无人机信道质量数据
                 SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand;
-                UavSignalInfoCache.putUavSignalInfoCache(signalInfoCmd.getSignalInfo());
+                UavSignalInfoCache.put(signalInfoCmd.getSignalInfo());
                 //logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn());
                 break;
             case (byte) 0xD1:
@@ -721,9 +1005,10 @@
                     CameraModeReplyCmd cameraModeReplyCommand = (CameraModeReplyCmd) tyCommand;
                     logPrint("无人机设置相机模式", cameraModeReplyCommand.getResult(), cameraModeReplyCommand.getErrorCode());
                 }
-                if (tyCommand instanceof FlyWayEndReplyCmd) {
-                    FlyWayEndReplyCmd flyWayEndReplyCmd = (FlyWayEndReplyCmd) tyCommand;
-                    logPrint("无人机飞行结束", flyWayEndReplyCmd.getResult(), flyWayEndReplyCmd.getErrorCode());
+                //格式化存储卡
+                if (tyCommand instanceof FormatSdCardReplyCmd) {
+                    FormatSdCardReplyCmd formatSdCardReplyCmd = (FormatSdCardReplyCmd) tyCommand;
+                    logPrint("格式化存储卡", formatSdCardReplyCmd.getResult(), formatSdCardReplyCmd.getErrorCode());
                 }
                 if (tyCommand instanceof CapturePicReplyCmd) {
                     CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand;
@@ -785,23 +1070,53 @@
                 }
                 //开始航线回复
                 if (tyCommand instanceof WayLineBeginReplyCmd) {
+
                     WayLineBeginReplyCmd wayLineBeginReplyCmd = (WayLineBeginReplyCmd) tyCommand;
                     logPrint("开始航线", wayLineBeginReplyCmd.getResult(), wayLineBeginReplyCmd.getErrorCode());
+                    if (wayLineBeginReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.START_SUCCESS);
+                    }
                 }
                 //暂停航线回复
                 if (tyCommand instanceof WayLinePauseReplyCmd) {
                     WayLinePauseReplyCmd wayLinePauseReplyCmd = (WayLinePauseReplyCmd) tyCommand;
                     logPrint("暂停航线", wayLinePauseReplyCmd.getResult(), wayLinePauseReplyCmd.getErrorCode());
+                    if (wayLinePauseReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.PAUSE_SUCCESS);
+                    }
                 }
                 //恢复航线回复
                 if (tyCommand instanceof WayLineResumeReplyCmd) {
                     WayLineResumeReplyCmd wayLineResumeReplyCmd = (WayLineResumeReplyCmd) tyCommand;
                     logPrint("恢复航线", wayLineResumeReplyCmd.getResult(), wayLineResumeReplyCmd.getErrorCode());
+                    if (wayLineResumeReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.RESUME_SUCCESS);
+                    }
                 }
                 //结束航线回复
                 if (tyCommand instanceof WayLineEndReplyCmd) {
                     WayLineEndReplyCmd wayLineEndReplyCmd = (WayLineEndReplyCmd) tyCommand;
                     logPrint("结束航线", wayLineEndReplyCmd.getResult(), wayLineEndReplyCmd.getErrorCode());
+                    if (wayLineEndReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.STOP_SUCCESS);
+                    }
+                }
+                if (tyCommand instanceof WayLineFinishedReplyCmd) {
+                    WayLineFinishedReplyCmd wayLineFinishedReplyCmd = (WayLineFinishedReplyCmd) tyCommand;
+                    logPrint("航线执行完成", wayLineFinishedReplyCmd.getResult(), wayLineFinishedReplyCmd.getErrorCode());
+                    if (wayLineFinishedReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.RESET_ROUTE);
+                    }
                 }
                 //设置返航高度回复
                 if (tyCommand instanceof ReturnHeightSettingReplyCmd) {
@@ -814,6 +1129,12 @@
                     ReturnPointSettingReplyCmd returnPointSettingReplyCmd = (ReturnPointSettingReplyCmd) tyCommand;
                     logPrint("设置返航点", returnPointSettingReplyCmd.getResult(),
                             returnPointSettingReplyCmd.getErrorCode());
+                }
+                //到达环绕位置回复
+                if (tyCommand instanceof FlyRoundReplyCmd) {
+                    FlyRoundReplyCmd flyRoundReplyCmd = (FlyRoundReplyCmd) tyCommand;
+                    logPrint("到达环绕位置", flyRoundReplyCmd.getResult(),
+                            flyRoundReplyCmd.getErrorCode());
                 }
                 break;
             case (byte) 0xD2:
@@ -831,7 +1152,7 @@
     }
 
     /**
-     * 根据[服务器id]获取六合盒子列表
+     * 根据[服务器id]获取边缘服务器盒子列表
      */
     @Override
     public List<BoxInfoReceiver> getBoxSnToList(String id) {
@@ -888,37 +1209,31 @@
 
     //公共日志打印
     private void logPrint(String message, Object obj) {
-        log.debug("收到{}回复{}", message, obj);
+        String text = String.format("收到%s回复 %s", message, obj);
+        ServerReplyMessage serverReplyMessage = ServerReplyMessage.builder().message(text).build();
+        WebSocketUtil.sendMessage("reply", serverReplyMessage);
+        log.debug(text);
     }
 
     //公共日志打印
     private void logPrint(String message, byte result, Integer errorCode) {
-        log.info("收到{}回复:{} 错误码:{}【{}】",
+        String text = String.format(
+                "收到%s回复 状态码:%d【%s】",
                 message,
-                ByteUtils.byteToHex(result),
+                //ByteUtils.byteToHex(result),
                 errorCode,
-                ErrorCodeEnum.getDescByCode(errorCode));
+                ErrorCodeEnum.getDescByCode(errorCode)
+        );
+        ServerReplyMessage serverReplyMessage = ServerReplyMessage.builder().message(text).build();
+        WebSocketUtil.sendMessage("reply", serverReplyMessage);
+        log.debug(text);
     }
+
 
     /**
-     * 发送消息
+     * 发送tcp消息
      */
     private void sendMessage(String key, BaseCmd msg) {
-        try {
-            ChannelFuture future = channels.get(key).getChannelFuture();
-            Channel channel = future.channel();
-            if (channel.isActive()) {
-                InetSocketAddress ipSocket = (InetSocketAddress) channel.remoteAddress();
-                String host = ipSocket.getHostString();
-                int port = ipSocket.getPort();
-                channel.writeAndFlush(msg); // 发送编码后的数据
-                log.debug("向六合服务器【{}:{}】发送数据,命令码:{}", host, port, String.format("0x%02X", msg.getCmdCode() & 0xFF));
-            } else {
-                log.error("与六合服务器链接断开,无法发送数据!");
-            }
-        } catch (Exception e) {
-            log.error("发送消息异常:{}", e.getMessage());
-        }
+        TcpClientUtil.sendMessage(key, msg);
     }
-
 }
\ No newline at end of file

--
Gitblit v1.9.3