From 1a09dd79bd0b156ceb13470c312e44e522238780 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Wed, 22 Oct 2025 16:52:33 +0800
Subject: [PATCH] 增加回复指令通过websocket返回给前端

---
 ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java |   54 +++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 19 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 922fe9a..74a0c0c 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
@@ -23,6 +23,7 @@
 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.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;
@@ -52,6 +53,7 @@
 import com.ard.work.service.ITyService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+
 import javax.annotation.Resource;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -93,6 +95,7 @@
         List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo());
         return getBoxList(ardServerInfos);
     }
+
     /**
      * 获取指定服务器云盒列表
      *
@@ -101,8 +104,9 @@
     @Override
     public List<BoxInfoReceiver> getBoxList(String serverId) {
         TyHttpCommonReceiver<List<BoxInfoReceiver>> boxList = tyClient.getBoxList(serverId);
-        return boxList.getContent();
+        return boxList == null ? null : boxList.getContent();
     }
+
     /**
      * 获取直播地址
      *
@@ -111,8 +115,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();
     }
 
     /**
@@ -125,7 +134,7 @@
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxHistoryDTO.getBoxSn());
         TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerId(),
                 boxHistoryDTO);
-        return boxHistory.getContent();
+        return boxHistory == null ? null : boxHistory.getContent();
     }
 
     /**
@@ -136,8 +145,9 @@
     @Override
     public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) {
         ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn());
-        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),boxPhotosDTO);
-        return boxPhotos.getContent();
+        TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(),
+                boxPhotosDTO);
+        return boxPhotos == null ? null : boxPhotos.getContent();
     }
 
     /**
@@ -146,7 +156,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;
     }
 
@@ -472,7 +482,7 @@
      */
     @Override
     public UavState getUavState(String boxSn) {
-        return UavStateCache.getUavState(boxSn);
+        return UavStateCache.get(boxSn);
     }
 
     /**
@@ -480,7 +490,7 @@
      */
     @Override
     public TelemetryData getUavTelemetryData(String boxSn) {
-        return UavTelemetryDataCache.getUavTelemetryData(boxSn);
+        return UavTelemetryDataCache.get(boxSn);
     }
 
     /**
@@ -488,7 +498,7 @@
      */
     @Override
     public SignalInfo getSignalInfo(String boxSn) {
-        return UavSignalInfoCache.getUavSignalInfo(boxSn);
+        return UavSignalInfoCache.get(boxSn);
     }
 
     /**
@@ -669,8 +679,8 @@
                 break;
             case 0x02:
                 // 处理注册消息
-                 HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
-                 logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
+                HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
+                logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
                 break;
             case 0x03:
                 // 处理订阅消息
@@ -691,14 +701,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;
@@ -706,7 +716,7 @@
             case (byte) 0x0C:
                 // 处理无人机信道质量数据
                 SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand;
-                UavSignalInfoCache.putUavSignalInfoCache(signalInfoCmd.getSignalInfo());
+                UavSignalInfoCache.put(signalInfoCmd.getSignalInfo());
                 //logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn());
                 break;
             case (byte) 0xD1:
@@ -892,21 +902,27 @@
 
     //公共日志打印
     private void logPrint(String message, Object obj) {
-        log.debug("收到{}回复{}", message, obj);
+        String text = String.format("收到%s回复%s", message, obj);
+        WebSocketUtil.sendMessageAll(text);
+        log.info(text);
     }
 
     //公共日志打印
     private void logPrint(String message, byte result, Integer errorCode) {
-        log.info("收到{}回复:{} 错误码:{}【{}】",
+        String text = String.format(
+                "收到%s回复:%s 错误码:%d【%s】",
                 message,
                 ByteUtils.byteToHex(result),
                 errorCode,
-                ErrorCodeEnum.getDescByCode(errorCode));
+                ErrorCodeEnum.getDescByCode(errorCode)
+        );
+        WebSocketUtil.sendMessageAll(text);
+        log.info(text);
     }
 
 
     /**
-     * 发送消息
+     * 发送tcp消息
      */
     private void sendMessage(String key, BaseCmd msg) {
         TcpClientUtil.sendMessage(key, msg);

--
Gitblit v1.9.3