From 24681c81c09022f584a57006f2534b5f74723414 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 30 六月 2026 09:27:31 +0800
Subject: [PATCH] 初始化项目

---
 yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerProtocol.java |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerProtocol.java b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerProtocol.java
index 80ce9ee..ea6e908 100644
--- a/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerProtocol.java
+++ b/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/modbus/tcpserver/IotModbusTcpServerProtocol.java
@@ -326,9 +326,27 @@
                     log.error("[refreshConfig][澶勭悊璁惧閰嶇疆澶辫触, deviceId={}]", config.getDeviceId(), e);
                 }
             }
+
+            // 3. 娓呯悊鏈疆涓嶅啀杩斿洖閰嶇疆鐨勫凡杩炴帴璁惧锛岄伩鍏嶇户缁疆璇㈠凡鍒犻櫎璁惧鐨勬棫鐐逛綅
+            Set<Long> missingDeviceIds = configCacheService.cleanupMissingConfigs(connectedDeviceIds, configs);
+            for (Long deviceId : missingDeviceIds) {
+                cleanupMissingDevice(deviceId);
+            }
         } catch (Exception e) {
             log.error("[refreshConfig][鍒锋柊閰嶇疆澶辫触]", e);
         }
     }
 
+    private void cleanupMissingDevice(Long deviceId) {
+        try {
+            pollScheduler.stopPolling(deviceId);
+            pendingRequestManager.removeDevice(deviceId);
+            configCacheService.removeConfig(deviceId);
+            connectionManager.closeConnection(deviceId);
+            log.info("[cleanupMissingDevice][璁惧 {} 閰嶇疆宸插け鏁堬紝宸插仠姝㈣疆璇㈠苟娓呯悊杩炴帴]", deviceId);
+        } catch (Exception e) {
+            log.error("[cleanupMissingDevice][娓呯悊璁惧澶辫触, deviceId={}]", deviceId, e);
+        }
+    }
+
 }

--
Gitblit v1.9.3