From 04a270ff2b5919127524913ffc45c59c6c6d9201 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Wed, 22 Apr 2026 14:22:30 +0800
Subject: [PATCH] 增加部门区域管理业务和无人机实时位置所属区域推送

---
 ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java |  448 ++++++++++++++++++++++++-------------------------------
 1 files changed, 198 insertions(+), 250 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 311c6c8..2fc7464 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,14 +1,10 @@
 package com.ard.work.service.impl;
 
-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.data.noflyzone.domain.ArdNoFlyZone;
-import com.ard.data.noflyzone.domain.Vertex;
-import com.ard.data.noflyzone.service.IArdNoFlyZoneService;
-import com.ard.data.noflyzone.utils.NoFlyZoneUtils;
+import com.ard.common.exception.ControlException;
+import com.ard.vtdu.config.MediamtxConfig;
 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;
@@ -19,7 +15,7 @@
 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.FlyWayEndReplyCmd;
+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;
@@ -31,12 +27,14 @@
 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;
@@ -53,10 +51,12 @@
 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 lombok.extern.slf4j.Slf4j;
@@ -65,6 +65,7 @@
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -82,12 +83,13 @@
     @Resource
     private IArdDroneInfoService ardDroneService;
     @Resource
-    private IArdNoFlyZoneService ardNoFlyZoneService;
-    @Resource
     private TyClient tyClient;
+    @Autowired
+    private RouteStateMachineService stateMachineService;
     @Resource
-    private RedisCache redisCache;
-
+    private UavPositionChangeService uavPositionChangeService;
+    @Resource
+    private UavRegionDetectService uavRegionDetectService;
     /**
      * 获取边缘服务器token信息
      *
@@ -131,12 +133,10 @@
     public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) {
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
         if (ardDroneInfo == null) {
-            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        // ✅ 判断无人机是否在线
-        if (!isDroneOnline(boxSn)) {
-            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
-        }
+
+
         TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
                 boxSn);
         return boxLiveUrl == null ? null : boxLiveUrl.getContent();
@@ -152,11 +152,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerId(),
                 boxHistoryDTO);
@@ -164,7 +160,7 @@
     }
 
     /**
-     * 获取盒子图片
+     * 获取任务图片
      *
      * @return List<BoxPhotosReceiver>
      */
@@ -173,17 +169,28 @@
         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);
+            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();
+    }
     /**
      * 修改云盒设置
      */
@@ -192,14 +199,10 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO);
-        return result.getState() == 1;
+        return result.getState() == 0;
     }
 
     /**
@@ -210,11 +213,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnHeightSettingCmd);
@@ -229,11 +228,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnPointSettingCmd);
@@ -248,11 +243,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), videoStreamSettingCmd);
@@ -284,11 +275,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto);
         this.sendMessage(ardDroneInfo.getServerId(), controlAngleCommand);
@@ -304,11 +291,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto);
         this.sendMessage(ardDroneInfo.getServerId(), absAngleControlCommand);
@@ -324,30 +307,35 @@
         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);
+            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) {
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), cameraModeCommand);
@@ -357,21 +345,19 @@
     /**
      * 拍照
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @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);
+            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());
+        //photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01)
+        // .build());
 
         CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
         this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand);
@@ -381,20 +367,17 @@
     /**
      * 录像
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @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);
+            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);
@@ -412,11 +395,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         ZoomCmd zoomCommand = new ZoomCmd(zoomDTO);
         this.sendMessage(ardDroneInfo.getServerId(), zoomCommand);
@@ -432,11 +411,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), zoomToLevelCommand);
@@ -446,16 +421,13 @@
     /**
      * 切换摄像头
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean switchCamera(SwitchCameraDTO switchCameraDTO) {
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO);
         this.sendMessage(ardDroneInfo.getServerId(), switchCameraCmd);
@@ -465,16 +437,13 @@
     /**
      * 切换视频源
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean switchSource(SwitchSourceDTO switchSourceDTO) {
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO);
         this.sendMessage(ardDroneInfo.getServerId(), switchSourceCmd);
@@ -484,16 +453,13 @@
     /**
      * 打开或关闭照片回传
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) {
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO);
         this.sendMessage(ardDroneInfo.getServerId(), photoReturnToggleCmd);
@@ -503,16 +469,13 @@
     /**
      * 切换无人机控制权
      */
+    @CheckDroneStatus
     @Override
     public Boolean switchUavControl(SwitchUavControlDTO switchUavControlDTO) {
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO);
         this.sendMessage(ardDroneInfo.getServerId(), switchUavControlCmd);
@@ -528,11 +491,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO);
         this.sendMessage(ardDroneInfo.getServerId(), takeOffCmd);
@@ -548,11 +507,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnHomeCmd);
@@ -568,11 +523,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), returnHomeCancelCmd);
@@ -588,11 +539,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         LandCmd landCmd = new LandCmd(landDTO);
         this.sendMessage(ardDroneInfo.getServerId(), landCmd);
@@ -608,11 +555,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), landCancelCmd);
@@ -628,11 +571,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO);
         this.sendMessage(ardDroneInfo.getServerId(), landForcedCmd);
@@ -643,17 +582,13 @@
      * 方向控制
      */
     @CheckControlRight(UavControlType.FLY)
-    @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckTakeoffAltitude
     @Override
     public Boolean flyControl(FlyControlDTO flyControlDTO) {
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyControlCmd);
@@ -664,27 +599,18 @@
      * 指点飞行控制
      */
     @CheckControlRight(UavControlType.FLY)
-    @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckTakeoffAltitude
+    @CheckNoFlyZone
     @Override
     public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) {
         String boxSn = flyPointControlDTO.getBoxSn();
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
         if (ardDroneInfo == null) {
-            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        // ✅ 判断无人机是否在线
-        if (!isDroneOnline(boxSn)) {
-            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
-        }
-        // 判断目标点是否经过禁飞区
-        List<ArdNoFlyZone> ardNoFlyZones = ardNoFlyZoneService.selectArdNoFlyZoneList(new ArdNoFlyZone());
-        if (!ardNoFlyZones.isEmpty()) {
-            Vertex vertex = new Vertex(flyPointControlDTO.getLongitude(), flyPointControlDTO.getLatitude());
-            boolean inNoFlyZones = NoFlyZoneUtils.isInNoFlyZones(vertex, ardNoFlyZones);
-            if (inNoFlyZones) {
-                throw new ServiceException("目标点在禁飞区内,无法执行指令, 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);
@@ -700,14 +626,46 @@
         String boxSn = flyPointControlCancelDTO.getBoxSn();
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
         if (ardDroneInfo == null) {
-            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        // ✅ 判断无人机是否在线
-        if (!isDroneOnline(boxSn)) {
-            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
-        }
+
+
         FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
+        return true;
+    }
+
+
+    /**
+     * 环绕飞行控制
+     */
+//    @CheckControlRight(UavControlType.FLY)
+//    @CheckTakeoffAltitude
+//    @CheckNoFlyZone
+    @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;
     }
 
@@ -720,12 +678,10 @@
         String boxSn = emeragencyBrakeDTO.getBoxSn();
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
         if (ardDroneInfo == null) {
-            throw new ServiceException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        // ✅ 判断无人机是否在线
-        if (!isDroneOnline(boxSn)) {
-            throw new ServiceException("无人机离线,无法执行指令, boxSn: " + boxSn);
-        }
+
+
         EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd);
         return true;
@@ -763,11 +719,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         SpeakModeSwitchCmd speakModeSwitchCmd = new SpeakModeSwitchCmd(speakModeSwitchDTO);
         this.sendMessage(ardDroneInfo.getServerId(), speakModeSwitchCmd);
@@ -782,11 +734,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         TextSpeakCmd textSpeakCmd = new TextSpeakCmd(textSpeakDTO);
         this.sendMessage(ardDroneInfo.getServerId(), textSpeakCmd);
@@ -801,11 +749,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         RealSpeakCmd realSpeakCmd = new RealSpeakCmd(realSpeakDTO);
         this.sendMessage(ardDroneInfo.getServerId(), realSpeakCmd);
@@ -820,11 +764,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         RecordSpeakCmd recordSpeakCmd = new RecordSpeakCmd(recordSpeakDTO);
         this.sendMessage(ardDroneInfo.getServerId(), recordSpeakCmd);
@@ -839,11 +779,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         VolumeSettingCmd volumeSettingCmd = new VolumeSettingCmd(volumeSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), volumeSettingCmd);
@@ -858,11 +794,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         LoopSettingCmd loopSettingCmd = new LoopSettingCmd(loopSettingDTO);
         this.sendMessage(ardDroneInfo.getServerId(), loopSettingCmd);
@@ -877,11 +809,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         StopSpeakCmd stopSpeakCmd = new StopSpeakCmd(stopSpeakDTO);
         this.sendMessage(ardDroneInfo.getServerId(), stopSpeakCmd);
@@ -891,18 +819,16 @@
     /**
      * 航线上传
      */
+    @CheckControlRight(UavControlType.FLY)
     @Override
     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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         //wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据
+        log.info("打印航线上传数据 ++++++++ wayLineUploadDTO:~~~~~~~~~~~~~~~" + wayLineUploadDTO);
         WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd);
         return true;
@@ -951,11 +877,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         WayLineBeginCmd wayLineBeginCmd = new WayLineBeginCmd(wayLineBeginDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineBeginCmd);
@@ -971,11 +893,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         WayLinePauseCmd wayLinePauseCmd = new WayLinePauseCmd(wayLinePauseDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLinePauseCmd);
@@ -991,11 +909,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         WayLineResumeCmd wayLineResumeCmd = new WayLineResumeCmd(wayLineResumeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineResumeCmd);
@@ -1011,11 +925,7 @@
         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);
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         WayLineEndCmd wayLineEndCmd = new WayLineEndCmd(wayLineEndDTO);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineEndCmd);
@@ -1042,7 +952,7 @@
             case 0x02:
                 // 处理注册消息
                 HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
-                logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
+                //logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
                 break;
             case 0x03:
                 // 处理订阅消息
@@ -1070,7 +980,18 @@
             case (byte) 0xA9:
                 // 处理无人机遥测消息
                 UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand;
-                UavTelemetryDataCache.put(uavTelemetryDataCmd.getTelemetryData());
+                TelemetryData telemetryData = uavTelemetryDataCmd.getTelemetryData();
+
+                // 判断是否需要触发区域检测
+                if (uavPositionChangeService.shouldTriggerRegionCheck(telemetryData)) {
+                    log.debug("无人机 {} 位置变化,触发区域检测", telemetryData.getBoxSn());
+                    // 异步触发区域检测(不阻塞)
+                    uavRegionDetectService.detectRegionAsync(telemetryData);
+                } else {
+                    log.debug("无人机 {} 位置未变化,跳过区域检测", telemetryData.getBoxSn());
+                }
+
+                UavTelemetryDataCache.put(telemetryData);
                 //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
                 //WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData());
                 break;
@@ -1097,9 +1018,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;
@@ -1161,23 +1083,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) {
@@ -1190,6 +1142,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:
@@ -1291,14 +1249,4 @@
     private void sendMessage(String key, BaseCmd msg) {
         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;
-    }
-
 }
\ No newline at end of file

--
Gitblit v1.9.3