From 8efb5a8cd2c8a6b40e58f4f3fb851d54cf415af9 Mon Sep 17 00:00:00 2001 From: jiazx0107@163.com <jiazx0107@163.com> Date: 星期日, 24 十二月 2023 01:23:55 +0800 Subject: [PATCH] 游仙协议解析-1 --- src/main/java/com/fzzy/gateway/GatewayUtils.java | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fzzy/gateway/GatewayUtils.java b/src/main/java/com/fzzy/gateway/GatewayUtils.java index b87a207..e1e132f 100644 --- a/src/main/java/com/fzzy/gateway/GatewayUtils.java +++ b/src/main/java/com/fzzy/gateway/GatewayUtils.java @@ -4,7 +4,6 @@ import com.fzzy.api.data.ApiCommonDevice; import com.fzzy.api.data.GatewayDeviceType; import com.fzzy.gateway.entity.GatewayDevice; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import java.util.*; @@ -21,11 +20,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 +27,55 @@ 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; } + + /** + * 閽堝涓�涓�氳鍒嗘満瀵瑰涓粨鎯呭喌 + * + * @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 +95,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