From f7178996ca77a1bccc941c0e7a73b36803e508cb Mon Sep 17 00:00:00 2001
From: vince <757871790@qq.com>
Date: 星期五, 01 三月 2024 16:13:11 +0800
Subject: [PATCH] 优化协议

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

diff --git a/src/main/java/com/fzzy/gateway/GatewayUtils.java b/src/main/java/com/fzzy/gateway/GatewayUtils.java
index e7da33c..00fc7f8 100644
--- a/src/main/java/com/fzzy/gateway/GatewayUtils.java
+++ b/src/main/java/com/fzzy/gateway/GatewayUtils.java
@@ -2,7 +2,9 @@
 
 import com.fzzy.api.Constant;
 import com.fzzy.api.data.ApiCommonDevice;
+import com.fzzy.api.data.DepotType;
 import com.fzzy.api.data.GatewayDeviceType;
+import com.fzzy.gateway.data.GrainCableData;
 import com.fzzy.gateway.entity.GatewayDevice;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
@@ -42,6 +44,13 @@
         return cacheMapDeviceId.get(deviceId);
     }
 
+
+    /**
+     * 閽堝涓�涓垎鏈哄寤掗棿鐨勬儏鍐�
+     *
+     * @param deviceSn
+     * @return
+     */
     public static GatewayDevice getCacheByDeviceSn(String deviceSn) {
         Collection<GatewayDevice> list = allCacheDevice();
         if (null == list || list.isEmpty()) return null;
@@ -50,6 +59,16 @@
             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;
     }
 
@@ -109,4 +128,54 @@
     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;
+    }
+
+
+    public static GrainCableData getCableData(GatewayDevice gatewayDevice) {
+        String cableRule = gatewayDevice.getCableRule();
+        String cableCir = gatewayDevice.getCableCir();
+
+        GrainCableData result = new GrainCableData();
+        result.setCableRule(cableRule);
+        result.setCableCir(cableCir);
+
+        int cableY, cableX;
+        String[] attCable = cableRule.split("-");
+        int cableZ = Integer.valueOf(attCable[0]);
+
+        if (StringUtils.isEmpty(cableCir)) {
+            cableY = Integer.valueOf(attCable[1]);
+            cableX = Integer.valueOf(attCable[2]);
+        } else {
+            String[] attCir = cableCir.split("-");
+            cableZ = Integer.valueOf(attCir[0]);
+            cableY = 1;
+            cableX = 0;
+            //閽堝澶氬湀璁$畻鎬昏繃澶氬皯鏍圭數缂�
+            for (int i = 0; i < cableCir.length(); i++) {
+                cableX += Integer.valueOf(attCable[i]);
+            }
+        }
+
+        result.setCableY(cableY);
+        result.setCableZ(cableZ);
+        result.setCableX(cableX);
+        result.setSumNum(cableZ * cableY * cableX);
+
+        result.setTotalCircle(attCable.length);
+
+        return result;
+    }
 }

--
Gitblit v1.9.3