From e14a4372b6bd4a38e40a3a68bde32350d96071ab Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 15 一月 2026 13:11:56 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/plugin/NormalProcess.java |  166 +++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 112 insertions(+), 54 deletions(-)

diff --git a/src/main/java/com/zy/core/plugin/NormalProcess.java b/src/main/java/com/zy/core/plugin/NormalProcess.java
index 3792035..46d5934 100644
--- a/src/main/java/com/zy/core/plugin/NormalProcess.java
+++ b/src/main/java/com/zy/core/plugin/NormalProcess.java
@@ -32,6 +32,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -56,10 +57,10 @@
 
     @Override
     public void run() {
-        //璇锋眰鐢熸垚鍏ュ簱浠诲姟
-        generateStoreWrkFile();
         //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞跺惎鍔ㄥ叆搴�
         checkInStationHasTask();
+        //璇锋眰鐢熸垚鍏ュ簱浠诲姟
+        generateStoreWrkFile();
 
         //鎵ц鍫嗗灈鏈轰换鍔�
         crnOperateUtils.crnIoExecute();
@@ -71,6 +72,9 @@
         stationOperateProcessUtils.stationOutExecute();
         //妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
         stationOperateProcessUtils.stationOutExecuteFinish();
+
+        //妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
+        stationOperateProcessUtils.checkStationRunBlock();
     }
 
     /**
@@ -78,73 +82,126 @@
      * 鍏ュ簱绔欙紝鏍规嵁鏉$爜鎵弿鐢熸垚鍏ュ簱宸ヤ綔妗�
      */
     public synchronized void generateStoreWrkFile() {
-        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
-        for (BasDevp basDevp : basDevps) {
-            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
-                continue;
+        try {
+            Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+            if (systemConfigMapObj == null) {
+                return;
+            }
+            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+
+            int conveyorStationTaskLimit = 30;
+            String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
+            if (conveyorStationTaskLimitStr != null) {
+                conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
+            }
+            int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
+            if (currentStationTaskCount > conveyorStationTaskLimit) {
+                News.error("杈撻�佺珯鐐逛换鍔″凡杈惧埌涓婇檺锛屼笂闄愬�硷細{}锛岀珯鐐逛换鍔℃暟锛歿}", conveyorStationTaskLimit, currentStationTaskCount);
+                return;
             }
 
-            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
-
-            List<StationObjModel> list = basDevp.getBarcodeStationList$();
-            for (StationObjModel entity : list) {
-                Integer stationId = entity.getStationId();
-                if(!stationMap.containsKey(stationId)){
+            List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
+            for (BasDevp basDevp : basDevps) {
+                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
+                if (stationThread == null) {
                     continue;
                 }
 
-                StationProtocol stationProtocol = stationMap.get(stationId);
-                if (stationProtocol == null) {
-                    continue;
-                }
+                Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
 
-                //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
-                if (stationProtocol.isAutoing()
-                        && stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() > 0
-                ) {
-                    if (Cools.isEmpty(stationProtocol.getBarcode())) {
+                List<StationObjModel> list = basDevp.getBarcodeStationList$();
+                for (StationObjModel entity : list) {
+                    Integer stationId = entity.getStationId();
+                    if (!stationMap.containsKey(stationId)) {
                         continue;
                     }
 
-                    //妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
-                    if (!wrkMasts.isEmpty()) {
+                    StationProtocol stationProtocol = stationMap.get(stationId);
+                    if (stationProtocol == null) {
                         continue;
                     }
 
-                    Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
-                    if (lock != null) {
-                        continue;
-                    }
-                    redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
-
-                    String response = wmsOperateUtils.applyInTask(stationProtocol.getBarcode(), stationProtocol.getStationId(), stationProtocol.getPalletHeight());
-                    if (response == null) {
-                        News.error("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乺esponse锛歿}", response);
-                        continue;
-                    }
-                    JSONObject jsonObject = JSON.parseObject(response);
-                    if (jsonObject.getInteger("code").equals(200)) {
-                        StartupDto dto = jsonObject.getObject("data", StartupDto.class);
-
-                        CreateInTaskParam taskParam = new CreateInTaskParam();
-                        taskParam.setTaskNo(dto.getTaskNo());
-                        taskParam.setLocNo(dto.getLocNo());
-                        taskParam.setTaskPri(dto.getTaskPri());
-                        taskParam.setBarcode(stationProtocol.getBarcode());
-                        WrkMast wrkMast = commonService.createInTask(taskParam);
-
-                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0);
-                        if(command == null){
-                            News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                    // 婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
+                    if (stationProtocol.isAutoing()
+                            && stationProtocol.isLoading()
+                            && stationProtocol.getTaskNo() > 0) {
+                        if (Cools.isEmpty(stationProtocol.getBarcode())) {
                             continue;
                         }
-                        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+
+                        // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
+                        List<WrkMast> wrkMasts = wrkMastService
+                                .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+                        if (!wrkMasts.isEmpty()) {
+                            continue;
+                        }
+
+                        Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
+                        if (lock != null) {
+                            continue;
+                        }
+
+                        String barcode = stationProtocol.getBarcode();
+                        Integer stationIdVal = stationProtocol.getStationId();
+
+                        // 1. 棣栧厛鏌ヨ鏄惁鏈夊凡瀹屾垚鐨勫紓姝ュ搷搴�
+                        String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal);
+
+                        if (response != null) {
+                            // 2. 鏈夊搷搴旂粨鏋滐紝澶勭悊鍝嶅簲
+                            if (response.equals("FAILED") || response.startsWith("ERROR:")) {
+                                // 璇锋眰澶辫触锛岄噸鏂板彂璧峰紓姝ヨ姹�
+                                News.error("WMS鍏ュ簱璇锋眰澶辫触锛岄噸鏂板彂璧疯姹傦紝barcode={}锛宻tationId={}锛宺esponse={}", barcode,
+                                        stationIdVal, response);
+                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
+                                        stationProtocol.getPalletHeight());
+                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+                                continue;
+                            }
+
+                            // 瑙f瀽鍝嶅簲
+                            JSONObject jsonObject = JSON.parseObject(response);
+                            if (jsonObject.getInteger("code").equals(200)) {
+                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+
+                                CreateInTaskParam taskParam = new CreateInTaskParam();
+                                taskParam.setTaskNo(dto.getTaskNo());
+                                taskParam.setLocNo(dto.getLocNo());
+                                taskParam.setTaskPri(dto.getTaskPri());
+                                taskParam.setBarcode(barcode);
+                                WrkMast wrkMast = commonService.createInTask(taskParam);
+
+                                StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO,
+                                        wrkMast.getWrkNo(), stationId, stationId, 0);
+                                if (command == null) {
+                                    News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                                    continue;
+                                }
+                                MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+                            } else {
+                                // 鎺ュ彛杩斿洖闈�200锛岄噸鏂板彂璧疯姹�
+                                News.error("WMS鍏ュ簱鎺ュ彛杩斿洖闈�200锛岄噸鏂板彂璧疯姹傦紝barcode={}锛宻tationId={}锛宺esponse={}", barcode,
+                                        stationIdVal, response);
+                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
+                                        stationProtocol.getPalletHeight());
+                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+                            }
+                        } else {
+                            // 3. 娌℃湁鍝嶅簲缁撴灉锛屾鏌ユ槸鍚︽湁璇锋眰姝e湪杩涜涓�
+                            if (!wmsOperateUtils.isAsyncRequestInProgress(barcode, stationIdVal)) {
+                                // 娌℃湁璇锋眰杩涜涓紝鍙戣捣鏂扮殑寮傛璇锋眰
+                                News.info("鍙戣捣寮傛WMS鍏ュ簱璇锋眰锛宐arcode={}锛宻tationId={}", barcode, stationIdVal);
+                                wmsOperateUtils.applyInTaskAsync(barcode, stationIdVal,
+                                        stationProtocol.getPalletHeight());
+                                redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 2);
+                            }
+                            // 濡傛灉鏈夎姹傝繘琛屼腑锛岀瓑寰呬笅娆″惊鐜啀妫�鏌�
+                        }
                     }
                 }
             }
+        } catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
@@ -182,9 +239,10 @@
                         && stationProtocol.getTaskNo() == 0
                         && stationProtocol.isEnableIn()
                 ) {
-                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0);
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.ENABLE_IN.id), stationId, entity.getBarcodeStation().getStationId(), 0);
                     MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
-                    redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 10);
+                    redisUtil.set(RedisKeyType.GENERATE_ENABLE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 15);
+                    News.info("{}绔欑偣鍚姩鍏ュ簱鎴愬姛锛屾暟鎹寘:{}", stationId, JSON.toJSONString(command));
                 }
             }
         }

--
Gitblit v1.9.1