From b612510f2479cc7fc04fbf9c4982742bee9e2ceb Mon Sep 17 00:00:00 2001
From: wang <3597712270@qq.com>
Date: 星期四, 18 四月 2024 16:55:46 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/HangZhouMes

---
 hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java |  141 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 141 insertions(+), 0 deletions(-)

diff --git a/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java
new file mode 100644
index 0000000..4bd20de
--- /dev/null
+++ b/hangzhoumesParent/moduleService/CacheGlassModule/src/main/java/com/mes/common/PlcBitObject.java
@@ -0,0 +1,141 @@
+package com.mes.common;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class PlcBitObject {
+
+    // 璇ユā鍧楁暟鎹被鍨嬶紝鏁版嵁璧峰浣嶇疆
+    private String plcAddressBegin;
+    // 鏁版嵁鍦板潃闀垮害锛氱涓�鍙傛暟鍒版渶鍚庝竴涓弬鏁扮殑闀垮害
+    private int plcAddressLength;
+    private ArrayList<PlcBitInfo> plcBitList;
+
+    /**
+     * @return 鏁版嵁鍖哄紑濮嬪湴鍧�
+     */
+    public String getPlcAddressBegin() {
+        return plcAddressBegin;
+    }
+
+    /**
+     * @param plcAddressBegin 璁剧疆鏁版嵁鍖哄紑濮嬪湴鍧�
+     */
+    public void setPlcAddressBegin(String plcAddressBegin) {
+        this.plcAddressBegin = plcAddressBegin;
+    }
+
+    /**
+     * @return 鏁版嵁鍖� 璇诲彇鎵�鏈夋暟鎹墍闇�鐨勯暱搴︼紙浠yte绫诲瀷涓哄熀鍑嗭級
+     */
+    public int getPlcAddressLength() {
+        return plcAddressLength;
+    }
+
+    /**
+     * @return 璁剧疆锛氭暟鎹尯 璇诲彇鎵�鏈夋暟鎹墍闇�鐨勯暱搴︼紙浠yte绫诲瀷涓哄熀鍑嗭級
+     */
+    public void setPlcAddressLength(int plcAddressLength) {
+        this.plcAddressLength = plcAddressLength;
+    }
+
+    /**
+     * @return 鑾峰彇鍙傛暟瀹炰緥闆嗗悎
+     */
+    public ArrayList<PlcBitInfo> getBitList() {
+        return plcBitList;
+    }
+
+    /**
+     * 鏍规嵁鍙傛暟鏍囪瘑 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
+     *
+     * @param codeid 鍙傛暟鏍囪瘑
+     * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
+     */
+    public PlcBitInfo getPlcBit(String codeid) {
+        if (plcBitList != null) {
+            for (PlcBitInfo plcbitInfo : plcBitList) {
+                if (plcbitInfo.getCodeId().equals(codeid))
+                    return plcbitInfo;
+            }
+            return null;
+        } else
+            return null;
+    }
+
+    /**
+     * 鏍规嵁鍙傛暟鏍囪瘑 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
+     *
+     * @param codeid 鍙傛暟鏍囪瘑
+     * @return 鑾峰彇鏌愪釜鍙傛暟瀹炰緥
+     */
+    public List<Boolean> getPlcBitValues(List<String> codeids) {
+        List<Boolean> arrayList = new ArrayList<>();
+        if (plcBitList != null) {
+            Map<String, Boolean> resultMap = new LinkedHashMap<>(); // 浣跨敤 LinkedHashMap 淇濈暀鎻掑叆椤哄簭
+            for (PlcBitInfo plcBitInfo : plcBitList) {
+                if (codeids.contains(plcBitInfo.getCodeId().toString())) {
+                    resultMap.put(plcBitInfo.getCodeId().toString(), plcBitInfo.getValue());
+                }
+            }
+            for (String codeId : codeids) { // 鎸夌収浼犲叆鍙傛暟鐨勯『搴忛亶鍘�
+                Boolean value = resultMap.get(codeId);
+                if (value != null) {
+                    arrayList.add(value);
+                } else {
+                    arrayList.add(null); // 濡傛灉鎵句笉鍒板搴旂殑鍊硷紝娣诲姞 null
+                }
+            }
+        }
+        return arrayList;
+    }
+
+
+    public List<String> getAddressListByCodeId(List<String> codeIdList) {
+        List<String> addressList = new ArrayList<>();
+        for (String codeId : codeIdList) {
+            for (PlcBitInfo plcBitInfo : plcBitList) {
+                if (plcBitInfo.getCodeId().equals(codeId)) {
+                    int index = plcBitInfo.getAddressIndex();
+                    String address = plcBitInfo.getAddress(index);
+                    if (address != null) {
+                        addressList.add(address);
+                    }
+                }
+            }
+        }
+        return addressList;
+    }
+
+
+    /**
+     * 娣诲姞鍙傛暟瀹炰緥
+     *
+     * @param param 鍙傛暟瀹炰緥
+     */
+    public void addPlcBit(PlcBitInfo param) {
+        if (plcBitList != null)
+            plcBitList.add(param);
+        else {
+            plcBitList = new ArrayList<PlcBitInfo>();
+            plcBitList.add(param);
+        }
+    }
+
+    /**
+     * 鏍规嵁PLC杩斿洖鐨勬暟鎹� 缁欏弬鏁板疄渚嬭祴鍊�
+     *
+     * @param plcValueArray PLC璇诲彇鍥炴潵鐨刡yte绫诲瀷鏁版嵁闆嗗悎
+     */
+    public void setPlcBitList(List<Boolean> plcValueArray) {
+        if (plcBitList != null) {
+            for (PlcBitInfo plcbitInfo : plcBitList) {
+                plcbitInfo.setValue(plcValueArray.get(plcbitInfo.getAddressIndex()));
+            }
+        }
+    }
+
+
+}
\ No newline at end of file

--
Gitblit v1.8.0