From f0ed143646e3c280416ca05f64c1b59604289928 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Mon, 20 Oct 2025 10:52:48 +0800
Subject: [PATCH] websocket无人机控制者和视频流数据增加boxSn

---
 ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java |  127 +++++++++++++++++++++---------------------
 1 files changed, 64 insertions(+), 63 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 af0f6ca..f872a47 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,62 @@
 package com.ard.work.service.impl;
 
 import com.ard.common.utils.ByteUtils;
-import com.ard.work.aspect.annotation.CheckTakeoffAltitude;
 import com.ard.work.aspect.annotation.CheckControlRight;
+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.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.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.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.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.UavControlType;
+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 com.ard.work.domain.message.UavControlType;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.net.InetSocketAddress;
 import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-
-import static com.ard.work.component.netty.TyTcpClientManager.channels;
 
 /**
  * TyServiceImpl
@@ -79,7 +75,7 @@
     private TyClient tyClient;
 
     /**
-     * 获取六合token信息
+     * 获取边缘服务器token信息
      *
      * @return AccessTokenReceiver
      */
@@ -89,7 +85,7 @@
     }
 
     /**
-     * 获取云盒列表
+     * 获取全部云盒列表
      *
      * @return List<BoxInfoReceiver>
      */
@@ -100,6 +96,17 @@
     }
 
     /**
+     * 获取指定服务器云盒列表
+     *
+     * @return List<BoxInfoReceiver>
+     */
+    @Override
+    public List<BoxInfoReceiver> getBoxList(String serverId) {
+        TyHttpCommonReceiver<List<BoxInfoReceiver>> boxList = tyClient.getBoxList(serverId);
+        return boxList.getContent();
+    }
+
+    /**
      * 获取直播地址
      *
      * @return BoxStreamUrlReceiver
@@ -107,8 +114,13 @@
     @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) {
+            log.warn("未找到对应的飞行器信息,boxSn:{}", boxSn);
+            return null;
+        }
+        TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
+                boxSn);
+        return boxLiveUrl == null ? null : boxLiveUrl.getContent();
     }
 
     /**
@@ -132,7 +144,8 @@
     @Override
     public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn());
-        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),boxPhotosDTO);
+        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),
+                boxPhotosDTO);
         return boxPhotos.getContent();
     }
 
@@ -142,7 +155,7 @@
     @Override
     public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) {
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn());
-        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(),boxSettingsDTO);
+        TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO);
         return result.getState() == 1;
     }
 
@@ -180,7 +193,7 @@
     }
 
     /**
-     * 注册六合平台
+     * 注册边缘服务器平台
      */
     @Override
     public Boolean registerMessage(String serverId) {
@@ -189,7 +202,7 @@
             RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes());
             this.sendMessage(serverId, registerMessage);
         } catch (Exception e) {
-            log.error("注册六合平台失败:{}", e.getMessage());
+            log.error("注册边缘服务器平台失败:{}", e.getMessage());
         }
         return true;
     }
@@ -647,7 +660,7 @@
     }
 
     /**
-     * 处理六合服务器返回的消息
+     * 处理边缘服务器返回的消息
      */
     @Override
     public void processReplyMessage(String key, BaseCmd tyCommand) {
@@ -665,8 +678,8 @@
                 break;
             case 0x02:
                 // 处理注册消息
-                 HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
-                 logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
+                HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
+                logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
                 break;
             case 0x03:
                 // 处理订阅消息
@@ -831,7 +844,7 @@
     }
 
     /**
-     * 根据[服务器id]获取六合盒子列表
+     * 根据[服务器id]获取边缘服务器盒子列表
      */
     @Override
     public List<BoxInfoReceiver> getBoxSnToList(String id) {
@@ -873,6 +886,7 @@
 
     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();
@@ -899,25 +913,12 @@
                 ErrorCodeEnum.getDescByCode(errorCode));
     }
 
+
     /**
      * 发送消息
      */
     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