From 2bf7cdc2df8482b775c05e783e49f3bb7ec58da5 Mon Sep 17 00:00:00 2001
From: ljm <1271952916@qq.com>
Date: 星期四, 20 十月 2022 16:04:47 +0800
Subject: [PATCH] 【zlm心跳hook】重复查询redis了 变量也不需要多次定义 数据库有的话应该恢复zlm

---
 src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
index 3dfb167..195315a 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java
@@ -80,6 +80,7 @@
 
         // 鑾峰彇鎵�鏈夌殑zlm锛� 骞跺紑鍚富鍔ㄨ繛鎺�
         List<MediaServerItem> all = mediaServerService.getAllFromDatabase();
+        Map<String, MediaServerItem> allMap = new HashMap<>();
         mediaServerService.updateVmServer(all);
         if (all.size() == 0) {
             all.add(mediaConfig.getMediaSerItem());
@@ -90,6 +91,7 @@
             }
             startGetMedia.put(mediaServerItem.getId(), true);
             connectZlmServer(mediaServerItem);
+            allMap.put(mediaServerItem.getId(), mediaServerItem);
         }
         String taskKey = "zlm-connect-timeout";
         dynamicTask.startDelay(taskKey, ()->{
@@ -100,7 +102,13 @@
                 }
                 startGetMedia = null;
             }
-        //  TODO 娓呯悊鏁版嵁搴撲腑涓巖edis涓嶅尮閰嶇殑zlm
+            // 鑾峰彇redis涓墍鏈夌殑zlm
+            List<MediaServerItem> allInRedis = mediaServerService.getAll();
+            for (MediaServerItem mediaServerItem : allInRedis) {
+                if (!allMap.containsKey(mediaServerItem.getId())) {
+                    mediaServerService.delete(mediaServerItem.getId());
+                }
+            }
         }, 60 * 1000 );
     }
 

--
Gitblit v1.8.0