From 48afd71b25a91320c1855aace0303bb490ded161 Mon Sep 17 00:00:00 2001
From: Junjie <540245094@qq.com>
Date: 星期四, 22 五月 2025 15:27:38 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/service/WatchService.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/zy/common/service/WatchService.java b/src/main/java/com/zy/common/service/WatchService.java
new file mode 100644
index 0000000..f6b30fd
--- /dev/null
+++ b/src/main/java/com/zy/common/service/WatchService.java
@@ -0,0 +1,43 @@
+package com.zy.common.service;
+
+import com.zy.common.model.WatchModel;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class WatchService {
+
+    private HashMap<String, WatchModel> map = new HashMap<>();
+
+    public boolean push(String key, String msg) {
+        map.put(key, new WatchModel(key, msg));
+        return true;
+    }
+
+    public HashMap<String, WatchModel> getMap() {
+        return map;
+    }
+
+    public List<WatchModel> getList() {
+        return new ArrayList<>(map.values());
+    }
+
+    public synchronized void clearTimeOutData() {
+        ArrayList<String> removeKey = new ArrayList<>();
+        for (Map.Entry<String, WatchModel> entry : this.map.entrySet()) {
+            WatchModel watchModel = entry.getValue();
+            if (System.currentTimeMillis() - watchModel.getTime() > 1000 * 10) {
+                removeKey.add(entry.getKey());
+            }
+        }
+
+        for (String key : removeKey) {
+            map.remove(key);
+        }
+    }
+
+}

--
Gitblit v1.9.1