From 2a729cd545ddbbab1eae6cbcf819783ef11da4ab Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Mon, 24 Nov 2025 09:56:07 +0800
Subject: [PATCH] 增加格式化存储卡接口

---
 ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java |  628 ++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 463 insertions(+), 165 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 f6c4f27..6543a15 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,63 +1,66 @@
 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.manual.*;
-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.config.TyConfiguration;
-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.receiver.*;
-import com.ard.work.component.forest.TyClient;
-import com.ard.work.domain.cache.TyTcpServerCache;
-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.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.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.state.UavState;
-import com.ard.work.domain.dto.telemetry.TelemetryData;
-import com.ard.work.component.netty.NettyTcpClient;
 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.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.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.component.netty.handler.ErrorCodeEnum;
 import com.ard.work.component.netty.protobuf.TelemetryDataPB;
-import com.ard.work.service.ITyService;
+import com.ard.work.component.websocket.utils.WebSocketUtil;
+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.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.domain.dto.wayline.*;
+import com.ard.work.domain.entity.ArdDroneInfo;
+import com.ard.work.domain.entity.ArdServerInfo;
+import com.ard.work.domain.message.ServerReplyMessage;
 import com.ard.work.domain.message.UavControlType;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
+import com.ard.work.domain.receiver.*;
+import com.ard.work.service.IArdDroneInfoService;
+import com.ard.work.service.IArdServerInfoService;
+import com.ard.work.service.ITyService;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * TyServiceImpl
@@ -68,39 +71,45 @@
 @Slf4j
 @Service
 public class TyServiceImpl implements ITyService {
-
+    @Resource
+    private IArdServerInfoService ardServerService;
+    @Resource
+    private IArdDroneInfoService ardDroneService;
     @Resource
     private TyClient tyClient;
 
-    @Resource
-    private TyConfiguration tyConfiguration;
-
-
     /**
-     * 获取天宇token信息
+     * 获取边缘服务器token信息
      *
      * @return AccessTokenReceiver
      */
     @Override
-    public AccessTokenReceiver getAccessToken() {
-        return tyConfiguration.getAccessToken();
+    public AccessTokenReceiver getAccessToken(String serverId) {
+        return ardServerService.getAccessToken(serverId);
     }
 
     /**
-     * 获取云盒列表
+     * 获取全部云盒列表
      *
      * @return List<BoxInfoReceiver>
      */
     @Override
     public List<BoxInfoReceiver> getBoxList() {
-        //请求云盒列表
-        try {
-            TyHttpCommonReceiver<List<BoxInfoReceiver>> boxListReceiver = tyClient.getBoxList();
-            return boxListReceiver.getContent();
-        } catch (Exception e) {
-            log.error("获取云盒列表失败:{}", e.getMessage());
-            return new ArrayList<>();
-        }
+        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();
     }
 
     /**
@@ -110,9 +119,15 @@
      */
     @Override
     public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) {
-
-        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(boxSn);
-        return boxLiveUrl.getContent();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        
+        
+        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
+                boxSn);
+        return boxLiveUrl == null ? null : boxLiveUrl.getContent();
     }
 
     /**
@@ -122,8 +137,14 @@
      */
     @Override
     public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO boxHistoryDTO) {
-        TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(boxHistoryDTO);
-        return boxHistory.getContent();
+        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 == null ? null : boxHistory.getContent();
     }
 
     /**
@@ -133,8 +154,14 @@
      */
     @Override
     public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
-        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(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();
     }
 
     /**
@@ -142,7 +169,12 @@
      */
     @Override
     public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) {
-        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(boxSettingsDTO);
+        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() == 1;
     }
 
@@ -151,8 +183,13 @@
      */
     @Override
     public Boolean updateReturnHeight(ReturnHeightSettingDTO returnHeightSettingDTO) {
+        String boxSn = returnHeightSettingDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), returnHeightSettingCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), returnHeightSettingCmd);
         return true;
     }
 
@@ -161,8 +198,13 @@
      */
     @Override
     public Boolean updateReturnPoint(ReturnPointSettingDTO returnPointSettingDTO) {
+        String boxSn = returnPointSettingDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), returnPointSettingCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), returnPointSettingCmd);
         return true;
     }
 
@@ -171,24 +213,30 @@
      */
     @Override
     public Boolean updateVideoStream(VideoStreamSettingDTO videoStreamSettingDTO) {
+        String boxSn = videoStreamSettingDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), videoStreamSettingCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), videoStreamSettingCmd);
         return true;
     }
 
     /**
-     * 注册天宇平台
+     * 注册边缘服务器平台
      */
     @Override
-    public Boolean registerMessage() {
+    public Boolean registerMessage(String serverId) {
         try {
-            AccessTokenReceiver tyToken = tyConfiguration.getAccessToken();
+            AccessTokenReceiver tyToken = ardServerService.getAccessToken(serverId);
             RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes());
-            this.sendMessage(tyConfiguration.getIpPort(), registerMessage);
+            this.sendMessage(serverId, registerMessage);
+            return true;
         } catch (Exception e) {
-            log.error("注册天宇平台失败:{}", e.getMessage());
+            log.error("注册边缘服务器平台失败:{}", e.getMessage());
+            return false;
         }
-        return true;
     }
 
     /**
@@ -197,8 +245,13 @@
     @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean angleControl(AngleControlDTO angleControlDto) {
+        String boxSn = angleControlDto.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto);
-        this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand);
+        this.sendMessage(ardDroneInfo.getServerId(), controlAngleCommand);
         return true;
     }
 
@@ -208,8 +261,13 @@
     @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean absAngleControl(AbsAngleControlDTO absAngleControlDto) {
+        String boxSn = absAngleControlDto.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto);
-        this.sendMessage(tyConfiguration.getIpPort(), absAngleControlCommand);
+        this.sendMessage(ardDroneInfo.getServerId(), absAngleControlCommand);
         return true;
     }
 
@@ -219,41 +277,76 @@
     @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean speedControl(SpeedControlDTO speedControlDto) {
+        String boxSn = speedControlDto.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto);
-        this.sendMessage(tyConfiguration.getIpPort(), speedControlCommand);
+        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 ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), cameraModeCommand);
+        this.sendMessage(ardDroneInfo.getServerId(), cameraModeCommand);
         return true;
     }
 
     /**
      * 拍照
      */
+    @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());
         //设置拍照回传
         photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
 
         CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
-        this.sendMessage(tyConfiguration.getIpPort(), capturePicCommand);
+        this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand);
         return true;
     }
 
     /**
      * 录像
      */
+    @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());
@@ -261,7 +354,7 @@
         } else {
             baseCmd = new RecordStopCmd(recordDto);
         }
-        this.sendMessage(tyConfiguration.getIpPort(), baseCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), baseCmd);
         return true;
     }
 
@@ -271,8 +364,13 @@
     @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean zoom(ZoomDTO zoomDTO) {
+        String boxSn = zoomDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ZoomCmd zoomCommand = new ZoomCmd(zoomDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), zoomCommand);
+        this.sendMessage(ardDroneInfo.getServerId(), zoomCommand);
         return true;
     }
 
@@ -282,48 +380,77 @@
     @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean zoomToLevel(ZoomToLevelDTO zoomToLevelDTO) {
+        String boxSn = zoomToLevelDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), zoomToLevelCommand);
+        this.sendMessage(ardDroneInfo.getServerId(), zoomToLevelCommand);
         return true;
     }
 
     /**
      * 切换摄像头
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean switchCamera(SwitchCameraDTO switchCameraDTO) {
+        String boxSn = switchCameraDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), switchCameraCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), switchCameraCmd);
         return true;
     }
 
     /**
      * 切换视频源
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean switchSource(SwitchSourceDTO switchSourceDTO) {
+        String boxSn = switchSourceDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), switchSourceCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), switchSourceCmd);
         return true;
     }
 
     /**
      * 打开或关闭照片回传
      */
+    @CheckControlRight(UavControlType.PAYLOAD)
     @Override
     public Boolean photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) {
+        String boxSn = photoReturnToggleDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), photoReturnToggleCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), photoReturnToggleCmd);
         return true;
     }
 
     /**
      * 切换无人机控制权
      */
+    @CheckDroneStatus
     @Override
     public Boolean switchUavControl(SwitchUavControlDTO switchUavControlDTO) {
+        String boxSn = switchUavControlDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), switchUavControlCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), switchUavControlCmd);
         return true;
     }
 
@@ -333,8 +460,13 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean takeOff(TakeOffDTO takeOffDTO) {
+        String boxSn = takeOffDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), takeOffCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), takeOffCmd);
         return true;
     }
 
@@ -344,8 +476,13 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean returnHome(ReturnHomeDTO returnHomeDTO) {
+        String boxSn = returnHomeDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), returnHomeCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), returnHomeCmd);
         return true;
     }
 
@@ -355,8 +492,13 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean returnHomeCancel(ReturnHomeCancelDTO returnHomeCancelDTO) {
+        String boxSn = returnHomeCancelDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), returnHomeCancelCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), returnHomeCancelCmd);
         return true;
     }
 
@@ -366,8 +508,13 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean land(LandDTO landDTO) {
+        String boxSn = landDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         LandCmd landCmd = new LandCmd(landDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), landCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), landCmd);
         return true;
     }
 
@@ -377,8 +524,13 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean landCancel(LandCancelDTO landCancelDTO) {
+        String boxSn = landCancelDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), landCancelCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), landCancelCmd);
         return true;
     }
 
@@ -388,8 +540,13 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean landForced(LandForcedDTO landForcedDTO) {
+        String boxSn = landForcedDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), landForcedCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), landForcedCmd);
         return true;
     }
 
@@ -400,8 +557,13 @@
     @CheckTakeoffAltitude(minAltitude = 30.0)
     @Override
     public Boolean flyControl(FlyControlDTO flyControlDTO) {
+        String boxSn = flyControlDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), flyControlCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), flyControlCmd);
         return true;
     }
 
@@ -410,10 +572,16 @@
      */
     @CheckControlRight(UavControlType.FLY)
     @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckNoFlyZone
     @Override
     public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) {
+        String boxSn = flyPointControlDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
         FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), flyPointControlCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCmd);
         return true;
     }
 
@@ -423,8 +591,15 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean flyPointControlCancel(FlyPointControlCancelDTO flyPointControlCancelDTO) {
+        String boxSn = flyPointControlCancelDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        
+        
         FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), flyPointControlCancelCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
         return true;
     }
 
@@ -434,8 +609,15 @@
     @CheckControlRight(UavControlType.FLY)
     @Override
     public Boolean emeragencyBrake(EmeragencyBrakeDTO emeragencyBrakeDTO) {
+        String boxSn = emeragencyBrakeDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        
+        
         EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), emergencyBrakeCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd);
         return true;
     }
 
@@ -444,7 +626,7 @@
      */
     @Override
     public UavState getUavState(String boxSn) {
-        return UavStateCache.getUavState(boxSn);
+        return UavStateCache.get(boxSn);
     }
 
     /**
@@ -452,7 +634,7 @@
      */
     @Override
     public TelemetryData getUavTelemetryData(String boxSn) {
-        return UavTelemetryDataCache.getUavTelemetryData(boxSn);
+        return UavTelemetryDataCache.get(boxSn);
     }
 
     /**
@@ -460,80 +642,131 @@
      */
     @Override
     public SignalInfo getSignalInfo(String boxSn) {
-        return UavSignalInfoCache.getUavSignalInfo(boxSn);
+        return UavSignalInfoCache.get(boxSn);
     }
 
     /**
      * 喊话模式切换
      */
     @Override
-    public void speakModeSwitch(SpeakModeSwitchDTO speakModeSwitchDTO) {
+    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(tyConfiguration.getIpPort(), speakModeSwitchCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), speakModeSwitchCmd);
+        return true;
     }
 
     /**
      * 文字喊话
      */
     @Override
-    public void textSpeak(TextSpeakDTO textSpeakDTO) {
+    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(tyConfiguration.getIpPort(), textSpeakCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), textSpeakCmd);
+        return true;
     }
 
     /**
      * 实时喊话
      */
     @Override
-    public void realSpeak(RealSpeakDTO realSpeakDTO) {
+    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(tyConfiguration.getIpPort(), realSpeakCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), realSpeakCmd);
+        return true;
     }
 
     /**
      * 录音喊话
      */
     @Override
-    public void recordSpeak(RecordSpeakDTO recordSpeakDTO) {
+    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(tyConfiguration.getIpPort(), recordSpeakCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), recordSpeakCmd);
+        return true;
     }
 
     /**
      * 设置音量
      */
     @Override
-    public void volumeSetting(VolumeSettingDTO volumeSettingDTO) {
+    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(tyConfiguration.getIpPort(), volumeSettingCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), volumeSettingCmd);
+        return true;
     }
 
     /**
      * 设置循环播放
      */
     @Override
-    public void loopSetting(LoopSettingDTO loopSettingDTO) {
+    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(tyConfiguration.getIpPort(), loopSettingCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), loopSettingCmd);
+        return true;
     }
 
     /**
      * 停止喊话
      */
     @Override
-    public void stopSpeak(StopSpeakDTO stopSpeakDTO) {
+    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(tyConfiguration.getIpPort(), stopSpeakCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), stopSpeakCmd);
+        return true;
     }
 
     /**
      * 航线上传
      */
+    @CheckControlRight(UavControlType.FLY)
     @Override
-    public void wayLineUpload(WayLineUploadDTO wayLineUploadDTO) {
-        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);
         WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO);
-        this.sendMessage(tyConfiguration.getIpPort(), wayLineUploadCmd);
+        System.out.println("wayLineUploadCmd:-----------------" + wayLineUploadCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd);
+        return true;
     }
 
     //创建航线
@@ -575,9 +808,15 @@
      */
     @CheckControlRight(UavControlType.FLY)
     @Override
-    public void wayLineBegin(WayLineBeginDTO wayLineBeginDTO) {
+    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(tyConfiguration.getIpPort(), wayLineBeginCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), wayLineBeginCmd);
+        return true;
     }
 
     /**
@@ -585,9 +824,15 @@
      */
     @CheckControlRight(UavControlType.FLY)
     @Override
-    public void wayLinePause(WayLinePauseDTO wayLinePauseDTO) {
+    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(tyConfiguration.getIpPort(), wayLinePauseCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), wayLinePauseCmd);
+        return true;
     }
 
     /**
@@ -595,9 +840,15 @@
      */
     @CheckControlRight(UavControlType.FLY)
     @Override
-    public void wayLineResume(WayLineResumeDTO wayLineResumeDTO) {
+    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(tyConfiguration.getIpPort(), wayLineResumeCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), wayLineResumeCmd);
+        return true;
     }
 
     /**
@@ -605,13 +856,19 @@
      */
     @CheckControlRight(UavControlType.FLY)
     @Override
-    public void wayLineEnd(WayLineEndDTO wayLineEndDTO) {
+    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(tyConfiguration.getIpPort(), wayLineEndCmd);
+        this.sendMessage(ardDroneInfo.getServerId(), wayLineEndCmd);
+        return true;
     }
 
     /**
-     * 处理天宇服务器返回的消息
+     * 处理边缘服务器返回的消息
      */
     @Override
     public void processReplyMessage(String key, BaseCmd tyCommand) {
@@ -624,13 +881,13 @@
                 if (registerReplyCommand.getSuccess() != 1) {
                     // 注册失败,重新注册
                     log.info("注册失败,重新注册");
-                    registerMessage();
+                    registerMessage(key);
                 }
                 break;
             case 0x02:
                 // 处理注册消息
-                 HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
-                 logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
+                HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
+                //logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
                 break;
             case 0x03:
                 // 处理订阅消息
@@ -651,14 +908,14 @@
             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());
+                UavTelemetryDataCache.put(uavTelemetryDataCmd.getTelemetryData());
                 //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
                 //WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData());
                 break;
@@ -666,7 +923,7 @@
             case (byte) 0x0C:
                 // 处理无人机信道质量数据
                 SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand;
-                UavSignalInfoCache.putUavSignalInfoCache(signalInfoCmd.getSignalInfo());
+                UavSignalInfoCache.put(signalInfoCmd.getSignalInfo());
                 //logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn());
                 break;
             case (byte) 0xD1:
@@ -674,7 +931,7 @@
                 if (tyCommand instanceof UavInitReplyCmd) {
                     UavInitReplyCmd uavInitReplyCmd = (UavInitReplyCmd) tyCommand;
                     UavInitInfoCmd uavInitCommand = new UavInitInfoCmd(uavInitReplyCmd.getBoxSn());
-                    this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand);
+                    this.sendMessage(key, uavInitCommand);
                     logPrint("无人机初始化详情", uavInitCommand.getBoxSn());
                 }
                 if (tyCommand instanceof UavReadyReplyCmd) {
@@ -688,6 +945,11 @@
                 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;
@@ -794,53 +1056,89 @@
         }
     }
 
+    /**
+     * 根据[服务器id]获取边缘服务器盒子列表
+     */
+    @Override
+    public List<BoxInfoReceiver> getBoxSnToList(String id) {
+        try {
+            List<BoxInfoReceiver> remoteBoxList = tyClient.getBoxList(id).getContent();
+            List<ArdDroneInfo> existingDrones = getDroneLs(id);
+            return existingDrones.isEmpty() ? remoteBoxList : filterBoxInfoReceivers(remoteBoxList, existingDrones);
+        } catch (Exception e) {
+            log.error("获取云盒列表失败, 服务器id: {}", id, e);
+            return Collections.emptyList(); // 返回不可变空列表,更安全
+        }
+    }
+
+    /**
+     * 根据[服务器id]查询无人机盒子列表
+     */
+    private List<ArdDroneInfo> getDroneLs(String serverId) {
+        ArdDroneInfo query = new ArdDroneInfo();
+        query.setServerId(serverId);
+        return ardDroneService.selectArdDroneList(query);
+    }
+
+    /**
+     * 过滤掉在ardDroneInfos中已存在的boxSn
+     */
+    public List<BoxInfoReceiver> filterBoxInfoReceivers(
+            List<BoxInfoReceiver> boxInfoReceivers,
+            List<ArdDroneInfo> ardDroneInfos) {
+
+        Set<String> existingBoxSns = ardDroneInfos.stream()
+                .map(ArdDroneInfo::getBoxSn)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+
+        return boxInfoReceivers.stream()
+                .filter(box -> box.getBoxSn() != null && !existingBoxSns.contains(box.getBoxSn()))
+                .collect(Collectors.toList());
+    }
+
+    private List<BoxInfoReceiver> getBoxList(List<ArdServerInfo> ls) {
+        return ls.stream()
+                .filter(ardServerInfo -> ardServerInfo.getServerStatus().equals("1"))
+                .flatMap(ardServerInfo -> {
+                    try {
+                        List<BoxInfoReceiver> boxes = tyClient.getBoxList(ardServerInfo.getId()).getContent();
+                        return Optional.ofNullable(boxes).orElse(Collections.emptyList()).stream();
+                    } catch (Exception e) {
+                        log.error("获取云盒列表失败: {}", ardServerInfo.getId(), e);
+                        return Stream.empty();
+                    }
+                })
+                .collect(Collectors.toList());
+    }
+
     //公共日志打印
     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);
     }
 
-    /**
-     * 定时3秒发送心跳指令
-     */
-    @Scheduled(fixedRate = 3000)
-    public void sendHeartBeat() {
-        if (!TyTcpServerCache.getTcpServerCache(tyConfiguration.getTcpserver() + ":" + tyConfiguration.getTcpport())) {
-            return;
-        }
-        long timestamp = System.currentTimeMillis();
-        log.debug("定时向天宇发送⼼跳,时间戳{}", timestamp);
-        HeartbeatCmd heartbeatMessage = new HeartbeatCmd(timestamp);
-        this.sendMessage(tyConfiguration.getIpPort(), heartbeatMessage);
-    }
 
     /**
-     * 发送消息
+     * 发送tcp消息
      */
     private void sendMessage(String key, BaseCmd msg) {
-        try {
-            ChannelFuture future = NettyTcpClient.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