From 6eb6558c6e3f092a4585c39eae2b4a295400c5f6 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期二, 05 五月 2026 08:12:43 +0800
Subject: [PATCH] 更新标准输送线程序代码;generateBusAndTask补充校验任务是否存校验逻辑

---
 zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java |   63 ++++++++++++++++---------------
 1 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java b/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
index 838d394..71894ea 100644
--- a/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
+++ b/zy-asc-conveyor/src/main/java/com/zy/acs/conveyor/core/thread/SiemensDevpThread.java
@@ -39,7 +39,7 @@
 
     private SiemensS7Net siemensS7Net;
 
-    private Map<Integer, StaProtocol> station;
+    private StationService stationService;
 
     private final RedisSupport redis = RedisSupport.defaultRedisSupport;
 
@@ -55,10 +55,10 @@
     private long lastDbUpdateTime = 0;
 
 
-    public SiemensDevpThread(DevpSlave slave, SiemensS7Net siemensS7Net, Map<Integer, StaProtocol> station) {
+    public SiemensDevpThread(DevpSlave slave, SiemensS7Net siemensS7Net, StationService stationService) {
         this.slave = slave;
         this.siemensS7Net = siemensS7Net;
-        this.station = station;
+        this.stationService = stationService;
     }
 
 
@@ -92,13 +92,12 @@
             log.warn("PLC鏈繛鎺ワ紝璺宠繃璇诲彇 [id:{}]", slave.getId());
             return;
         }
-        if (station == null) {
-            StationService stationService = SpringContextUtil.getBean(StationService.class);
-            if (stationService != null) {
-                station = stationService.getStationMap(slave.getId());
-            }
-            log.warn("绔欑偣鏈繛鎺ワ紝璺宠繃璇诲彇 [id:{}]", slave.getId());
-            return;
+        Map<Integer, StaProtocol> stationMap = null;
+        if (stationService == null) {
+            stationService = SpringContextUtil.getBean(StationService.class);
+            stationMap = stationService.getStationMap(slave.getId());
+        } else {
+            stationMap = stationService.getStationMap(slave.getId());
         }
 
         List<Integer> staNos = slave.getStaNos();
@@ -116,28 +115,30 @@
 
         byte[] content = result.Content;
         for (int i = 0; i < staNoSize; i++) {
-            StaProtocol staProtocol = station.get(staNos.get(i));
+            StaProtocol staProtocol = stationMap.get(staNos.get(i));
             parseStationStatus(content, i, staProtocol);
         }
 
         // 璇诲彇鏉$爜
-        readBarcodes();
+        readBarcodes(stationMap);
 
         // 绉伴噸
-        readWeight();
+        readWeight(stationMap);
 
         // 璇诲彇澶栧舰妫�娴嬮敊璇�
-        readDimensionErrors();
+        readDimensionErrors(stationMap);
 
         // 璇诲彇PLC鏁呴殰
-        readPlcAlarms(staNos, staNoSize);
+        readPlcAlarms(stationMap, staNos, staNoSize);
 
         // 璇诲彇瀹夊叏浜や簰淇″彿
-        readSaleSingle(slave.getPutSta(), slave.getTakeSta());
+        readSaleSingle(stationMap, slave.getPutSta(), slave.getTakeSta());
 
 
         // 瀹氭湡鏇存柊鏁版嵁搴擄紙闄嶄綆棰戠巼锛�
-        updateDatabaseIfNeeded();
+        updateDatabaseIfNeeded(stationMap);
+
+
     }
 
     /**
@@ -187,7 +188,7 @@
     /**
      * 璇诲彇鏉$爜淇℃伅
      */
-    private void readBarcodes() {
+    private void readBarcodes(Map<Integer, StaProtocol> stationMap) {
         if (slave.getBarcode() == null || !slave.getBarcode()) {
             return;
         }
@@ -211,7 +212,7 @@
                     DeviceField.BARCODE.getByteLength() - seg[1], "UTF-8").trim();
 
             if (!Cools.isEmpty(barcode) && !barcode.contains("Default") && !barcode.contains("Error") && staNo != 0) {
-                StaProtocol staProtocol = station.get(staNo);
+                StaProtocol staProtocol = stationMap.get(staNo);
                 if (staProtocol == null) {
                     log.warn("鎵爜绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
                     continue;
@@ -225,7 +226,7 @@
     /**
      * 璇诲彇閲嶉噺淇℃伅
      */
-    private void readWeight() {
+    private void readWeight(Map<Integer, StaProtocol> stationMap) {
         if (slave.getWeight() == null || !slave.getWeight()) {
             return;
         }
@@ -246,7 +247,7 @@
             Double weight = (double) siemensS7Net.getByteTransform().TransSingle(
                     content, seg[1] + i * DeviceField.WEIGHT.getByteLength());
             if (!Cools.isEmpty(weight) && staNo != 0) {
-                StaProtocol staProtocol = station.get(staNo);
+                StaProtocol staProtocol = stationMap.get(staNo);
                 if (staProtocol == null) {
                     log.warn(" [id:{}] [staNo:{}]", slave.getId(), staNo);
                     continue;
@@ -259,7 +260,7 @@
     /**
      * 璇诲彇澶栧舰妫�娴嬮敊璇�
      */
-    private void readDimensionErrors() {
+    private void readDimensionErrors(Map<Integer, StaProtocol> stationMap) {
         if (slave.getStaNosError() == null || !slave.getStaNosError()) {
             return;
         }
@@ -277,9 +278,9 @@
         for (int i = 0; i < DeviceField.DIMENSION_WORD.getArrLength(); i++) {
             int[] seg = DeviceField.DIMENSION_WORD.getSeg();
             int staNo = siemensS7Net.getByteTransform().TransInt16(
-                    content, seg[0]);
+                    content, seg[0] + i * DeviceField.DIMENSION_WORD.getByteLength());
             if (staNo != 0) {
-                StaProtocol staProtocol = station.get(staNo);
+                StaProtocol staProtocol = stationMap.get(staNo);
                 if (staProtocol == null) {
                     log.warn("寮傚父绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), staNo);
                     continue;
@@ -309,7 +310,7 @@
     /**
      * 璇诲彇PLC鏁呴殰淇℃伅
      */
-    private void readPlcAlarms(List<Integer> staNos, int staNoSize) {
+    private void readPlcAlarms(Map<Integer, StaProtocol> stationMap, List<Integer> staNos, int staNoSize) {
         OperateResultExOne<byte[]> result = siemensS7Net.Read(
                 PlcAlarmDefinition.ALL.buildAddress(),
                 (short) (staNoSize * PlcAlarmDefinition.ALL.getByteLength()));
@@ -322,7 +323,7 @@
         byte[] content = result.Content;
         for (int i = 0; i < staNoSize; i++) {
             Integer siteId = staNos.get(i);
-            StaProtocol staProtocol = station.get(siteId);
+            StaProtocol staProtocol = stationMap.get(siteId);
             if (staProtocol == null) {
                 log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{}]", slave.getId(), siteId);
                 continue;
@@ -345,7 +346,7 @@
     /**
      * 璇诲彇瀹夊叏浜や簰淇″彿
      */
-    private void readSaleSingle(List<DevpSlave.Sta> putSta, List<DevpSlave.Sta> takeSta) {
+    private void readSaleSingle(Map<Integer, StaProtocol> stationMap, List<DevpSlave.Sta> putSta, List<DevpSlave.Sta> takeSta) {
         int staNoSize = putSta.size();
         OperateResultExOne<byte[]> result = siemensS7Net.Read(
                 SafeSignalField.SAFE_SIGNAL_FROM_CONVEYOR.buildAddress(),
@@ -361,8 +362,8 @@
         for (int i = 0; i < staNoSize; i++) {
             Integer put = putSta.get(i).getStaNo();
             Integer take = takeSta.get(i).getStaNo();
-            StaProtocol staProtocolPut = station.get(put);
-            StaProtocol staProtocolTake = station.get(take);
+            StaProtocol staProtocolPut = stationMap.get(put);
+            StaProtocol staProtocolTake = stationMap.get(take);
             if (staProtocolPut == null || staProtocolTake == null) {
                 log.warn("绔欑偣涓嶅瓨鍦� [id:{}] [staNo:{},{}]", slave.getId(), put, take);
                 continue;
@@ -403,7 +404,7 @@
     /**
      * 鎸夐渶鏇存柊鏁版嵁搴擄紙闄嶄綆鏇存柊棰戠巼锛�
      */
-    private void updateDatabaseIfNeeded() {
+    private void updateDatabaseIfNeeded(Map<Integer, StaProtocol> stationMap) {
         long currentTime = System.currentTimeMillis();
         if (currentTime - lastDbUpdateTime < DB_UPDATE_INTERVAL_MS) {
             return;
@@ -413,7 +414,7 @@
             List<Integer> staNos = slave.getStaNos();
             List<Devp> devps = new ArrayList<>(staNos.size());
             for (Integer siteId : staNos) {
-                StaProtocol staProtocol = station.get(siteId);
+                StaProtocol staProtocol = stationMap.get(siteId);
                 if (staProtocol != null) {
                     devps.add(staProtocol.toSqlModel());
                 }

--
Gitblit v1.9.1