From 46203ee88249d9a4046f3d453deb41edc562cf6c Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期二, 12 十二月 2023 12:36:53 +0800
Subject: [PATCH] 提交网关心跳和设备状态

---
 src/main/java/com/fzzy/gateway/GatewayUtils.java |   40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/fzzy/gateway/GatewayUtils.java b/src/main/java/com/fzzy/gateway/GatewayUtils.java
index b87a207..e7da33c 100644
--- a/src/main/java/com/fzzy/gateway/GatewayUtils.java
+++ b/src/main/java/com/fzzy/gateway/GatewayUtils.java
@@ -21,11 +21,6 @@
     public static Map<String, GatewayDevice> cacheMapDeviceId = new HashMap<>();
 
     /**
-     * 璁惧缂撳瓨
-     */
-    public static Map<String, GatewayDevice> cacheMapDeviceSn = new HashMap<>();
-
-    /**
      * 璁惧缂撳瓨-鍙拡瀵�
      */
     public static Map<String, GatewayDevice> cacheMapDeviceWeight = new HashMap<>();
@@ -33,12 +28,14 @@
 
     public static void add2Cache(GatewayDevice device) {
         cacheMapDeviceId.put(device.getDeviceId(), device);
-        cacheMapDeviceSn.put(device.getDeviceSn(), device);
-
         //淇濆瓨鍦扮
         if (GatewayDeviceType.TYPE_01.getCode().equals(device.getType())) {
             cacheMapDeviceWeight.put(device.getDeviceId(), device);
         }
+    }
+
+    public static Collection<GatewayDevice> allCacheDevice() {
+        return cacheMapDeviceId.values();
     }
 
     public static GatewayDevice getCacheByDeviceId(String deviceId) {
@@ -46,8 +43,33 @@
     }
 
     public static GatewayDevice getCacheByDeviceSn(String deviceSn) {
-        return cacheMapDeviceSn.get(deviceSn);
+        Collection<GatewayDevice> list = allCacheDevice();
+        if (null == list || list.isEmpty()) return null;
+
+        for (GatewayDevice device : list) {
+            if (deviceSn.equals(device.getDeviceSn())) return device;
+        }
+
+        return null;
     }
+
+    /**
+     * 閽堝涓�涓�氳鍒嗘満瀵瑰涓粨鎯呭喌
+     *
+     * @param deviceSn
+     * @return
+     */
+    public static List<GatewayDevice> getCacheByDeviceSn2(String deviceSn) {
+        Collection<GatewayDevice> list = allCacheDevice();
+        if (null == list || list.isEmpty()) return null;
+
+        List<GatewayDevice> result = new ArrayList<>();
+        for (GatewayDevice device : list) {
+            if (deviceSn.equals(device.getDeviceSn())) result.add(device);
+        }
+        return result;
+    }
+
 
     public static List<GatewayDevice> getCacheByDeviceType(String deviceType) {
         List<GatewayDevice> result = new ArrayList<>();
@@ -67,7 +89,7 @@
 
     public static void removeCache(GatewayDevice data) {
         cacheMapDeviceId.remove(data.getDeviceId());
-        cacheMapDeviceSn.remove(data.getDeviceSn());
+        //cacheMapDeviceSn.remove(data.getDeviceSn());
     }
 
     public static String getStatus(String sn) {

--
Gitblit v1.9.3