From dd7a033e4591b8004ecd570ef4ff2ef925df65bc Mon Sep 17 00:00:00 2001
From: jiazx0107@163.com <jiazx0107@163.com>
Date: 星期五, 19 一月 2024 23:28:50 +0800
Subject: [PATCH] 增加油罐仓的解析
---
src/main/java/com/fzzy/gateway/GatewayUtils.java | 105 +++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 82 insertions(+), 23 deletions(-)
diff --git a/src/main/java/com/fzzy/gateway/GatewayUtils.java b/src/main/java/com/fzzy/gateway/GatewayUtils.java
index 7704a2f..7e4df85 100644
--- a/src/main/java/com/fzzy/gateway/GatewayUtils.java
+++ b/src/main/java/com/fzzy/gateway/GatewayUtils.java
@@ -1,12 +1,12 @@
package com.fzzy.gateway;
+import com.fzzy.api.Constant;
+import com.fzzy.api.data.ApiCommonDevice;
+import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.gateway.entity.GatewayDevice;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* 甯搁噺
@@ -14,36 +14,78 @@
@Component
public class GatewayUtils {
-
- /**
- * 璁惧鍦ㄧ嚎鏍囪锛岄拡瀵筗EBSocket璇锋眰锛屾帶鍒惰澶囨槸鍚﹀湪绾匡紝key = deviceId锛孷alue=Y/N
- */
- public static Map<String, String> contextOnlineMap = new HashMap<>();
-
-
/**
* 璁惧缂撳瓨
*/
public static Map<String, GatewayDevice> cacheMapDeviceId = new HashMap<>();
/**
- * 璁惧缂撳瓨
+ * 璁惧缂撳瓨-鍙拡瀵�
*/
- public static Map<String, GatewayDevice> cacheMapDeviceSn = new HashMap<>();
+ public static Map<String, GatewayDevice> cacheMapDeviceWeight = new HashMap<>();
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<>();
@@ -63,20 +105,37 @@
public static void removeCache(GatewayDevice data) {
cacheMapDeviceId.remove(data.getDeviceId());
- cacheMapDeviceSn.remove(data.getDeviceSn());
+ //cacheMapDeviceSn.remove(data.getDeviceSn());
}
- public static void updateOnline(String deviceId) {
- contextOnlineMap.put(deviceId, "Y");
+ public static String getStatus(String sn) {
+ ApiCommonDevice device = Constant.getCommonDeviceCache(sn);
+ if (null == device) return Constant.YN_N;
+ return device.getStatus();
}
- public static void updateOffOnline(String deviceId) {
- contextOnlineMap.put(deviceId, "N");
- }
public static boolean isOnline(String deviceId) {
- String value = contextOnlineMap.get(deviceId);
- if (null == value || "N".equals(value)) return false;
+ GatewayDevice device = getCacheByDeviceId(deviceId);
+ if (null == device.getStatus() || Constant.YN_N.equals(device.getStatus())) return false;
return true;
}
+
+
+ public static Collection<GatewayDevice> listDeviceWeight() {
+ return cacheMapDeviceWeight.values();
+ }
+
+ public static GatewayDevice getCacheByDepotSysId(String depotSysId) {
+
+ if (null == depotSysId) return null;
+ Collection<GatewayDevice> list = allCacheDevice();
+ if (null == list || list.isEmpty()) return null;
+
+ for (GatewayDevice device : list) {
+ if (null == device.getDepotIdSys()) continue;
+ if (depotSysId.equals(device.getDepotIdSys())) return device;
+ }
+ return null;
+ }
}
--
Gitblit v1.9.3