From c8a4f3f8327b4a2290d719503211adb8845e6fd8 Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期二, 19 十二月 2023 14:37:08 +0800
Subject: [PATCH] 优化代码,增加仓温仓湿度

---
 src/main/java/com/fzzy/gateway/GatewayUtils.java |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 47 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..8abd2bf 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,21 +28,64 @@
 
     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) {
         return cacheMapDeviceId.get(deviceId);
     }
 
+
+    /**
+     * 閽堝涓�涓垎鏈哄寤掗棿鐨勬儏鍐�
+     *
+     * @param deviceSn
+     * @return
+     */
     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;
     }
+    public static GatewayDevice getCacheByDeviceSIp(String ip) {
+        Collection<GatewayDevice> list = allCacheDevice();
+        if (null == list || list.isEmpty()) return null;
+
+        for (GatewayDevice device : list) {
+            if (ip.equals(device.getIp())) 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 +105,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