From de026326a9df6f4a2192e99cf0e53e7e7b6d445d Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Fri, 24 Oct 2025 17:29:33 +0800
Subject: [PATCH] 1.整理文件管理文件路径。 2.新增航线信息接口业务。 3.优化KMZ文件接口业务逻辑。 4.pom文件修改。 5.增加业务工具类。 6.增加部分业务注解。 7.增加修改无人机状态方法。

---
 ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java b/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
index 9514f09..a58e7a6 100644
--- a/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
+++ b/ard-work/src/main/java/com/ard/work/component/netty/TyTcpClientManager.java
@@ -6,6 +6,7 @@
 import com.ard.work.component.netty.handler.MessageProtocolEncoder;
 import com.ard.work.component.netty.cache.TyTcpServerCache;
 import com.ard.work.domain.entity.ArdServerInfo;
+import com.ard.work.service.IArdDroneInfoService;
 import com.ard.work.service.IArdServerInfoService;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.*;
@@ -34,6 +35,9 @@
     private IArdServerInfoService ardServerService; // ← 从数据库读取边缘服务器配置
 
     @Resource
+    private IArdDroneInfoService ardDroneService;
+
+    @Resource
     private ClientHandler clientHandler;
 
     /**
@@ -49,7 +53,7 @@
                     @Override
                     protected void initChannel(SocketChannel socketChannel) {
                         ChannelPipeline pipeline = socketChannel.pipeline();
-                        pipeline.addLast("heart", new IdleStateHandler(0, 3, 0, TimeUnit.SECONDS));
+                        pipeline.addLast("heart", new IdleStateHandler(0, 5, 0, TimeUnit.SECONDS));
                         pipeline.addLast("encoder", new MessageProtocolEncoder());
                         pipeline.addLast("decoder", new MessageProtocolDecoder());
                         pipeline.addLast("handler", clientHandler);
@@ -76,8 +80,8 @@
                 Channel channel = f.channel();
                 channel.attr(AttributeKey.valueOf("serverId")).set(serverId);
                 TyTcpServerCache.putTcpServerCache(serverId, true);
-                // 断开服务器,修改状态为: 0 - 在线
-                ardServerService.updateServerStatus(serverId, "1");
+                // 修改状态为: 1 - 在线
+                updateServerAndDroneStatus(serverId, "1");
 
                 // 成功后再加入 channels
                 TyTcpServerCache.putChannel(serverId, channel);
@@ -86,7 +90,7 @@
                 log.warn("❌ 服务器 [{}] 连接失败", serverId);
                 TyTcpServerCache.putTcpServerCache(serverId, false);
                 // 断开服务器,修改状态为: 0 - 离线
-                ardServerService.updateServerStatus(serverId, "0");
+                updateServerAndDroneStatus(serverId, "0");
             }
         });
     }
@@ -100,12 +104,19 @@
             channel.close();
             log.info("断开服务器 [{}] 连接", serverId);
             // 断开服务器,修改状态为: 0 - 离线
-            ardServerService.updateServerStatus(serverId, "0");
+            updateServerAndDroneStatus(serverId, "0");
             TyTcpServerCache.removeChannel(serverId);
         }
         TyTcpServerCache.removeTcpServerCache(serverId);
     }
 
+    /**
+     * 同步修改服务和无人机状态
+     */
+    private void updateServerAndDroneStatus(String serverId, String status) {
+        ardServerService.updateServerStatus(serverId, status);
+        ardDroneService.updateDroneStatus(serverId, status);
+    }
 
     /**
      * 启动时从数据库加载所有边缘服务器并建立 TCP 连接
@@ -143,9 +154,9 @@
     }
 
     /**
-     * 定时向所有已连接的边缘服务器服务器发送心跳
+     * 定时向所有已连接的边缘服务器服务器发送心跳(写空闲已经发心跳了,这里暂时取消)
      */
-    @Scheduled(fixedRate = 5000) // 每5秒执行一次
+   // @Scheduled(fixedRate = 5000) // 每5秒执行一次
     public void sendHeartBeat() {
         long timestamp = System.currentTimeMillis();
         TyTcpServerCache.getChannels().stream()

--
Gitblit v1.9.3