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

---
 src/main/java/com/zy/core/model/command/StationCommand.java         |    2 
 src/main/java/com/zy/core/plugin/NormalProcess.java                 |  162 ++++--
 src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java        |   25 
 src/main/java/com/zy/core/utils/WmsOperateUtils.java                |  146 +++++-
 src/main/java/com/zy/core/enums/RedisKeyType.java                   |    2 
 src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java |  605 ++++++++++++--------------
 src/main/java/com/zy/core/plugin/FakeProcess.java                   |  326 ++++++++------
 7 files changed, 724 insertions(+), 544 deletions(-)

diff --git a/src/main/java/com/zy/core/enums/RedisKeyType.java b/src/main/java/com/zy/core/enums/RedisKeyType.java
index 2e623ae..cb3ece2 100644
--- a/src/main/java/com/zy/core/enums/RedisKeyType.java
+++ b/src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -49,6 +49,8 @@
     DUAL_CRN_OUT_TASK_STATION_INFO("dual_crn_out_task_station_info_"),
 
     CURRENT_CIRCLE_TASK_CRN_NO("current_circle_task_crn_no_"),
+    ASYNC_WMS_IN_TASK_REQUEST("async_wms_in_task_request_"),
+    ASYNC_WMS_IN_TASK_RESPONSE("async_wms_in_task_response_"),
     AI_CHAT_HISTORY("ai_chat_history_"),
     AI_CHAT_META("ai_chat_meta_"),
     MAIN_PROCESS_PSEUDOCODE("main_process_pseudocode"),
diff --git a/src/main/java/com/zy/core/model/command/StationCommand.java b/src/main/java/com/zy/core/model/command/StationCommand.java
index 825fea0..a896e33 100644
--- a/src/main/java/com/zy/core/model/command/StationCommand.java
+++ b/src/main/java/com/zy/core/model/command/StationCommand.java
@@ -19,6 +19,8 @@
 
     private List<Integer> navigatePath;
 
+    private List<Integer> originalNavigatePath;
+
     private StationCommandType commandType;
 
 }
diff --git a/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java b/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
index 1687d61..a493189 100644
--- a/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
@@ -3,8 +3,6 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.zy.asrs.entity.DeviceConfig;
-import com.zy.asrs.utils.Utils;
-import com.zy.common.model.NavigateNode;
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
 import com.zy.core.enums.RedisKeyType;
@@ -24,12 +22,14 @@
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.Map;
-import java.util.function.Supplier;
+import java.util.Arrays;
 
 public class ZyStationFakeSegConnect implements ZyStationConnectApi {
 
-    private static int LOCK_STATION = 0;
+    // 绔欑偣绾ч攣锛氭瘡涓珯鐐圭嫭绔嬩竴鎶婇攣锛屾彁鍗囧苟鍙戞�ц兘
+    private final Map<Integer, ReentrantLock> stationLocks = new ConcurrentHashMap<>();
     private HashMap<Integer, List<ZyStationStatusEntity>> deviceStatusMap = new HashMap<>();
     private HashMap<Integer, DeviceConfig> deviceConfigMap = new HashMap<>();
     private RedisUtil redisUtil;
@@ -60,8 +60,7 @@
                                     && statusEntity.isLoading()
                                     && statusEntity.getTaskNo() > 0
                                     && !statusEntity.isRunBlock()
-                                    && !statusEntity.getStationId().equals(statusEntity.getTargetStaNo())
-                            ) {
+                                    && !statusEntity.getStationId().equals(statusEntity.getTargetStaNo())) {
                                 BlockingQueue<StationCommand> commands = taskQueues.get(statusEntity.getTaskNo());
                                 if (commands == null) {
                                     statusEntity.setRunBlock(true);
@@ -76,7 +75,7 @@
                 }
             }
         });
-        checkThread.start();
+        // checkThread.start();
         return true;
     }
 
@@ -94,7 +93,8 @@
         }
         DeviceConfig deviceConfig = deviceConfigMap.get(deviceNo);
         if (statusList.isEmpty()) {
-            List<ZyStationStatusEntity> init = JSON.parseArray(deviceConfig.getFakeInitStatus(), ZyStationStatusEntity.class);
+            List<ZyStationStatusEntity> init = JSON.parseArray(deviceConfig.getFakeInitStatus(),
+                    ZyStationStatusEntity.class);
             if (init != null) {
                 statusList.addAll(init);
                 for (ZyStationStatusEntity status : statusList) {
@@ -125,13 +125,16 @@
         // 澶勭悊闈炵Щ鍔ㄥ懡浠�
         if (command.getCommandType() != StationCommandType.MOVE) {
             handleCommand(deviceNo, command);
-        }else {
+        } else {
+            // 灏嗙Щ鍔ㄥ懡浠よ拷鍔犲埌浠诲姟闃熷垪锛堟敮鎸佸垎娈典笅鍙戯級
             taskQueues.computeIfAbsent(taskNo, k -> new LinkedBlockingQueue<>()).offer(command);
             taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
 
+            // 鍙湁浠诲姟鏈惎鍔ㄦ椂鎵嶅惎鍔ㄦ墽琛屽櫒锛屽悗缁垎娈靛懡浠や粎杩藉姞鍒伴槦鍒�
             if (taskRunning.putIfAbsent(taskNo, true) == null) {
                 executor.submit(() -> runTaskLoop(deviceNo, taskNo));
             }
+            // 鍚庣画鍒嗘鍛戒护涓嶅啀杩斿洖閿欒锛屾甯歌拷鍔犲埌闃熷垪
         }
 
         return new CommandResponse(true, "鍛戒护宸插彈鐞嗭紙寮傛鎵ц锛�");
@@ -139,138 +142,171 @@
 
     private void runTaskLoop(Integer deviceNo, Integer taskNo) {
         try {
-            // 鐢ㄤ簬瀛樺偍褰撳墠浠诲姟寰呮墽琛岀殑瀹屾暣璺緞闃熷垪
-            BlockingQueue<Integer> pathQueue = new LinkedBlockingQueue<>();
-            // 褰撳墠鏄惁姝e湪鎵ц绉诲姩
-            boolean isMoving = false;
-            // 褰撳墠绉诲姩鍒扮殑璺緞绱㈠紩
-            int currentPathIndex = 0;
-            // 瀹屾暣璺緞璁板綍
-            List<Integer> fullPath = new ArrayList<>();
-            
-            StationCommand initialCommand = null;
+            // 寰呮墽琛岀殑璺緞闃熷垪锛堝瓨鍌ㄧ珯鐐笽D搴忓垪锛�
+            LinkedBlockingQueue<Integer> pendingPathQueue = new LinkedBlockingQueue<>();
+            // 褰撳墠鎵�鍦ㄧ珯鐐笽D
+            Integer currentStationId = null;
+            // 鏈�缁堢洰鏍囩珯鐐笽D
             Integer finalTargetStationId = null;
+            // 鏄惁闇�瑕佺敓鎴愭潯鐮�
             boolean generateBarcode = false;
+            // 鏄惁宸插垵濮嬪寲璧风偣
+            boolean initialized = false;
+            // 涓婁竴姝ユ墽琛屾椂闂达紙鐢ㄤ簬鍫靛妫�娴嬶級
             long stepExecuteTime = System.currentTimeMillis();
 
             while (true) {
+                if (Thread.currentThread().isInterrupted()) {
+                    break;
+                }
+
                 BlockingQueue<StationCommand> commandQueue = taskQueues.get(taskNo);
                 if (commandQueue == null) {
                     break;
                 }
 
-                // 灏濊瘯鑾峰彇鏂板懡浠わ紝濡傛灉娌℃湁鏂板懡浠ゅ垯缁х画鎵ц鐜版湁璺緞
+                // 灏濊瘯鑾峰彇鏂扮殑鍒嗘鍛戒护
                 StationCommand command = commandQueue.poll(100, TimeUnit.MILLISECONDS);
                 if (command != null) {
-                    stepExecuteTime = System.currentTimeMillis();
                     taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
-                    
-                    if (initialCommand == null) {
-                        initialCommand = command;
+
+                    // 棣栨鎺ユ敹鍛戒护鏃跺垵濮嬪寲
+                    if (finalTargetStationId == null) {
                         finalTargetStationId = command.getTargetStaNo();
                         if (checkTaskNoInArea(taskNo)) {
                             generateBarcode = true;
                         }
                     }
 
+                    // 灏嗘柊璺緞杩藉姞鍒板緟鎵ц闃熷垪
                     List<Integer> newPath = command.getNavigatePath();
                     if (newPath != null && !newPath.isEmpty()) {
-                        // 濡傛灉鏄涓�娈佃矾寰�
-                        if (fullPath.isEmpty()) {
-                            fullPath.addAll(newPath);
-                            for (Integer stationId : newPath) {
-                                pathQueue.offer(stationId);
-                            }
-                        } else {
-                            // 杩藉姞璺緞锛岄渶瑕佸幓閲嶈鎺ョ偣
-                            Integer lastStationId = fullPath.get(fullPath.size() - 1);
-                            int startIndex = 0;
-                            if (!newPath.isEmpty() && newPath.get(0).equals(lastStationId)) {
-                                startIndex = 1;
-                            }
-                            for (int i = startIndex; i < newPath.size(); i++) {
-                                Integer stationId = newPath.get(i);
-                                fullPath.add(stationId);
-                                pathQueue.offer(stationId);
-                            }
+                        // 鑾峰彇闃熷垪涓渶鍚庝竴涓珯鐐癸紙鐢ㄤ簬琛旀帴鐐瑰幓閲嶏級
+                        Integer lastInQueue = getLastInQueue(pendingPathQueue);
+                        if (lastInQueue == null) {
+                            lastInQueue = currentStationId;
                         }
+
+                        int startIndex = 0;
+                        // 濡傛灉鏂拌矾寰勭殑璧风偣涓庡綋鍓嶄綅缃垨闃熷垪鏈熬閲嶅锛屽垯璺宠繃
+                        if (lastInQueue != null && !newPath.isEmpty() && newPath.get(0).equals(lastInQueue)) {
+                            startIndex = 1;
+                        }
+
+                        for (int i = startIndex; i < newPath.size(); i++) {
+                            pendingPathQueue.offer(newPath.get(i));
+                        }
+
+                        News.info("[WCS Debug] 浠诲姟{}杩藉姞璺緞娈�: {} -> 闃熷垪澶у皬: {}", taskNo, newPath, pendingPathQueue.size());
                     }
                 }
 
                 // 鎵ц绉诲姩閫昏緫
-                if (!pathQueue.isEmpty()) {
-                    // 濡傛灉鍒氬紑濮嬶紝鍏堝垵濮嬪寲褰撳墠浣嶇疆
-                    if (currentPathIndex == 0 && !fullPath.isEmpty()) {
-                         Integer startStationId = fullPath.get(0);
-                         Integer deviceId = getDeviceNoByStationId(startStationId);
-                         if (deviceId != null) {
-                             initStationMove(taskNo, startStationId, deviceId, taskNo, finalTargetStationId, true, null);
-                         }
-                    }
+                if (!pendingPathQueue.isEmpty()) {
+                    Integer nextStationId = pendingPathQueue.peek();
 
-                    // 鍙栧嚭涓嬩竴涓洰鏍囩偣
-                    Integer nextStationId = pathQueue.peek(); // 杩欓噷鐨勯�昏緫闇�瑕佹敼涓洪�愪釜琛岃蛋
-                    // 瀹為檯琛岃蛋閫昏緫搴旇鏄湪杩欓噷娑堣垂 pathQueue
-                    // 涓轰簡绠�鍖栵紝鎴戜滑灏� pathQueue 杞负 stationMoveByPathIds 鐨勯�昏緫锛屼絾杩欓噷闇�瑕佹敼閫犳垚姝ヨ繘寮�
-                    
-                    // 閲嶆柊璁捐锛歳unTaskLoop 璐熻矗涓嶆柇娑堣垂 pathQueue 骞舵墽琛屽崟姝ョЩ鍔�
-                    if (nextStationId != null) {
-                        Integer currentStationId = fullPath.get(currentPathIndex);
-                        if (currentStationId.equals(nextStationId)) {
-                            pathQueue.poll(); // 绉婚櫎宸插埌杈剧殑鐐�
+                    // 濡傛灉灏氭湭鍒濆鍖栬捣鐐�
+                    if (!initialized && currentStationId == null) {
+                        // 浼樺厛鏌ユ壘鎵樼洏褰撳墠瀹為檯浣嶇疆锛堟敮鎸佸牭濉炲悗閲嶈矾鐢卞満鏅級
+                        Integer actualCurrentStationId = findCurrentStationIdByTask(taskNo);
+                        if (actualCurrentStationId != null) {
+                            // 鎵惧埌浜嗗綋鍓嶆墭鐩樹綅缃紝浣跨敤瀹為檯浣嶇疆浣滀负璧风偣
+                            currentStationId = actualCurrentStationId;
+                            initialized = true;
+
+                            // 娓呴櫎璇ョ珯鐐圭殑 runBlock 鏍囪锛堝牭濉炴仮澶嶏級
+                            Integer deviceId = getDeviceNoByStationId(currentStationId);
+                            if (deviceId != null) {
+                                clearRunBlock(currentStationId, deviceId);
+                            }
+
+                            // 濡傛灉璺緞璧风偣涓庡綋鍓嶄綅缃浉鍚岋紝绉婚櫎璧风偣閬垮厤閲嶅
+                            if (nextStationId.equals(currentStationId)) {
+                                pendingPathQueue.poll();
+                            }
+
+                            stepExecuteTime = System.currentTimeMillis();
+                            News.info("[WCS Debug] 浠诲姟{}鎭㈠鎵ц锛屽綋鍓嶄綅缃�: {}", taskNo, currentStationId);
                             continue;
                         }
-                        
-                        // 鎵ц浠� currentStationId 鍒� nextStationId 鐨勭Щ鍔�
-                        Integer currentDeviceNo = getDeviceNoByStationId(currentStationId);
-                        Integer nextDeviceNo = getDeviceNoByStationId(nextStationId);
-                        
-                        if (currentDeviceNo != null && nextDeviceNo != null) {
-                            boolean moveSuccess = stationMoveToNext(taskNo, currentStationId, currentDeviceNo, nextStationId, nextDeviceNo, taskNo, finalTargetStationId);
-                            if (moveSuccess) {
-                                currentPathIndex++;
-                                pathQueue.poll();
-                                stepExecuteTime = System.currentTimeMillis();
-                                sleep(1000); // 妯℃嫙鑰楁椂
-                            } else {
-                                if (!checkTaskNoInArea(taskNo)) {
-                                    boolean fakeAllowCheckBlock = true;
-                                    Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
-                                    if (systemConfigMapObj != null) {
-                                        HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
-                                        if (systemConfigMap.get("fakeAllowCheckBlock") != null && !systemConfigMap.get("fakeAllowCheckBlock").equals("Y")) {
-                                            fakeAllowCheckBlock = false;
-                                        }
-                                    }
 
-                                    if (fakeAllowCheckBlock && System.currentTimeMillis() - stepExecuteTime > 1000 * 10) {
-                                        //璁ゅ畾鍫靛
-                                        boolean result = runBlockStation(taskNo, currentStationId, currentDeviceNo, taskNo, currentStationId);
-                                        if(result) {
-                                            break;
-                                        }
+                        // 鏈壘鍒板綋鍓嶄綅缃紙棣栨鎵ц锛夛紝棣栦釜绔欑偣灏辨槸璧风偣
+                        currentStationId = nextStationId;
+                        Integer deviceId = getDeviceNoByStationId(currentStationId);
+                        if (deviceId != null) {
+                            boolean result = initStationMove(taskNo, currentStationId, deviceId, taskNo,
+                                    finalTargetStationId, true, null);
+                            if (result) {
+                                initialized = true;
+                                pendingPathQueue.poll(); // 绉婚櫎璧风偣
+                                stepExecuteTime = System.currentTimeMillis();
+                                News.info("[WCS Debug] 浠诲姟{}鍒濆鍖栬捣鐐�: {}", taskNo, currentStationId);
+                            }
+                        }
+                        sleep(500);
+                        continue;
+                    }
+
+                    // 鎵ц浠庡綋鍓嶇珯鐐瑰埌涓嬩竴绔欑偣鐨勭Щ鍔�
+                    Integer currentDeviceNo = getDeviceNoByStationId(currentStationId);
+                    Integer nextDeviceNo = getDeviceNoByStationId(nextStationId);
+
+                    if (currentDeviceNo != null && nextDeviceNo != null) {
+                        boolean moveSuccess = stationMoveToNext(taskNo, currentStationId, currentDeviceNo,
+                                nextStationId, nextDeviceNo, taskNo, finalTargetStationId);
+                        if (moveSuccess) {
+                            currentStationId = nextStationId;
+                            pendingPathQueue.poll();
+                            stepExecuteTime = System.currentTimeMillis();
+                            News.info("[WCS Debug] 浠诲姟{}绉诲姩鍒扮珯鐐�: {}, 鍓╀綑闃熷垪: {}", taskNo, currentStationId,
+                                    pendingPathQueue.size());
+                            sleep(1000); // 妯℃嫙绉诲姩鑰楁椂
+                        } else {
+                            // 绉诲姩澶辫触锛屾鏌ユ槸鍚﹀牭濉�
+                            if (!checkTaskNoInArea(taskNo)) {
+                                boolean fakeAllowCheckBlock = getFakeAllowCheckBlock();
+
+                                if (fakeAllowCheckBlock && System.currentTimeMillis() - stepExecuteTime > 10000) {
+                                    // 璁ゅ畾鍫靛
+                                    boolean result = runBlockStation(taskNo, currentStationId, currentDeviceNo, taskNo,
+                                            currentStationId);
+                                    if (result) {
+                                        News.info("[WCS Debug] 浠诲姟{}鍦ㄧ珯鐐箋}琚爣璁颁负鍫靛", taskNo, currentStationId);
+                                        pendingPathQueue.clear();
+                                        break;
                                     }
                                 }
-                                sleep(1000); // 澶辫触閲嶈瘯绛夊緟
                             }
-                        } else {
-                            pathQueue.poll(); // 鏃犳硶鎵ц锛岃烦杩�
+                            sleep(500); // 澶辫触閲嶈瘯绛夊緟
                         }
+                    } else {
+                        // 鏃犳硶鑾峰彇璁惧鍙凤紝璺宠繃璇ョ珯鐐�
+                        pendingPathQueue.poll();
                     }
                 } else {
-                    // 闃熷垪涓虹┖锛屾鏌ユ槸鍚﹁秴鏃�
-                    Long lastTime = taskLastUpdateTime.get(taskNo);
-                    if (lastTime != null && System.currentTimeMillis() - lastTime > 30000) {
-                        // 瀹屾垚浠诲姟鍚庢竻鐞�
-                        if (fullPath.size() > 0 && generateBarcode) {
-                             Integer lastStation = fullPath.get(fullPath.size()-1);
-                             Integer lastDevice = getDeviceNoByStationId(lastStation);
-                             if (lastDevice != null) {
-                                 generateStationBarcode(taskNo, finalTargetStationId, lastDevice);
-                             }
+                    // 璺緞闃熷垪涓虹┖锛岀瓑寰呮柊鐨勫垎娈靛懡浠�
+                    if (currentStationId != null && finalTargetStationId != null
+                            && currentStationId.equals(finalTargetStationId)) {
+                        // 宸插埌杈炬渶缁堢洰鏍囷紝姝e父缁撴潫
+                        if (generateBarcode) {
+                            Integer targetDeviceNo = getDeviceNoByStationId(finalTargetStationId);
+                            if (targetDeviceNo != null) {
+                                generateStationBarcode(taskNo, finalTargetStationId, targetDeviceNo);
+                                News.info("[WCS Debug] 浠诲姟{}鍒拌揪鐩爣{}骞剁敓鎴愭潯鐮�", taskNo, finalTargetStationId);
+                            }
                         }
                         break;
                     }
+
+                    // 鏈埌杈炬渶缁堢洰鏍囷紝绛夊緟鏂扮殑鍒嗘鍛戒护
+                    Long lastTime = taskLastUpdateTime.get(taskNo);
+                    if (lastTime != null && System.currentTimeMillis() - lastTime > 30000) {
+                        // 瓒呮椂锛�30绉掑唴娌℃湁鏀跺埌鏂板垎娈靛懡浠�
+                        News.info("[WCS Debug] 浠诲姟{}绛夊緟鍒嗘瓒呮椂锛屽綋鍓嶄綅缃�: {}, 鐩爣: {}", taskNo, currentStationId,
+                                finalTargetStationId);
+                        break;
+                    }
+                    // 缁х画绛夊緟鏂板垎娈靛懡浠わ紙涓嶅仛浠讳綍浜嬫儏锛屼笅涓�杞惊鐜細灏濊瘯鑾峰彇鏂板懡浠わ級
                 }
             }
         } catch (InterruptedException e) {
@@ -279,7 +315,35 @@
             taskQueues.remove(taskNo);
             taskLastUpdateTime.remove(taskNo);
             taskRunning.remove(taskNo);
+            News.info("[WCS Debug] 浠诲姟{}鎵ц缁撴潫骞舵竻鐞嗚祫婧�", taskNo);
         }
+    }
+
+    /**
+     * 鑾峰彇闃熷垪涓渶鍚庝竴涓厓绱狅紙涓嶇Щ闄わ級
+     */
+    private Integer getLastInQueue(LinkedBlockingQueue<Integer> queue) {
+        Integer last = null;
+        for (Integer item : queue) {
+            last = item;
+        }
+        return last;
+    }
+
+    /**
+     * 鑾峰彇鏄惁鍏佽妫�鏌ュ牭濉炵殑閰嶇疆
+     */
+    private boolean getFakeAllowCheckBlock() {
+        boolean fakeAllowCheckBlock = true;
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj != null) {
+            HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+            String value = systemConfigMap.get("fakeAllowCheckBlock");
+            if (value != null && !value.equals("Y")) {
+                fakeAllowCheckBlock = false;
+            }
+        }
+        return fakeAllowCheckBlock;
     }
 
     @Override
@@ -310,7 +374,7 @@
 
         if (command.getCommandType() == StationCommandType.WRITE_INFO) {
             if (taskNo == 9998 && targetStationId == 0) {
-                //鐢熸垚鍑哄簱绔欑偣浠跨湡鏁版嵁
+                // 鐢熸垚鍑哄簱绔欑偣浠跨湡鏁版嵁
                 generateFakeOutStationData(deviceNo, stationId);
                 return;
             }
@@ -319,12 +383,7 @@
         if (taskNo > 0 && taskNo != 9999 && taskNo != 9998 && stationId == targetStationId) {
             generateStationData(deviceNo, taskNo, stationId, targetStationId);
         }
-
-        List<Integer> navigatePath = command.getNavigatePath();
-        if (navigatePath != null && !navigatePath.isEmpty()) {
-            segmentedPathCommand(command, generateBarcode);
-            return;
-        }
+        // 娉ㄦ剰锛歁OVE 绫诲瀷鐨勫懡浠ょ幇宸插湪 sendCommand 涓鐞嗭紝handleCommand 浠呭鐞嗛潪 MOVE 鍛戒护
     }
 
     private void generateFakeOutStationData(Integer deviceNo, Integer stationId) {
@@ -369,32 +428,7 @@
         }
     }
 
-    private void segmentedPathCommand(StationCommand command, boolean generateBarcode) {
-        Integer taskNo = command.getTaskNo();
-        Integer finalTargetStationId = command.getTargetStaNo();
-        List<Integer> path = command.getNavigatePath();
-        if (path == null || path.isEmpty()) {
-            return;
-        }
-        
-        Integer currentStationId = findCurrentStationIdByTask(taskNo);
-        int startIdx = 0;
-        if (currentStationId != null) {
-            int idx = path.indexOf(currentStationId);
-            if (idx >= 0) {
-                startIdx = idx;
-            }
-        }
-        
-        Integer segmentTargetStationId = path.get(path.size() - 1);
-        int endIdx = path.size() - 1;
-        
-        boolean isFinalSegment = segmentTargetStationId.equals(finalTargetStationId);
-        boolean appendMode = currentStationId != null && path.indexOf(currentStationId) >= 0;
-        boolean generateBarcodeFinal = generateBarcode && isFinalSegment;
-        
-        stationMoveByPathIds(path, taskNo, finalTargetStationId, false, generateBarcodeFinal, startIdx, endIdx, appendMode);
-    }
+    // segmentedPathCommand 鏂规硶宸插垹闄わ紝鍔熻兘宸叉暣鍚堝埌 runTaskLoop
 
     private Integer getDeviceNoByStationId(Integer stationId) {
         for (Integer devNo : deviceStatusMap.keySet()) {
@@ -426,116 +460,7 @@
         return null;
     }
 
-    private boolean stationMoveByPathIds(List<Integer> stationPath, Integer taskNo, Integer targetStationId, boolean clearData, boolean generateBarcode, int startIdx, int endIdx, boolean appendMode) {
-        Integer lastStationId = null;
-        Integer targetStationDeviceNo = getDeviceNoByStationId(targetStationId);
-        long executeTime = System.currentTimeMillis();
-        int i = Math.max(0, startIdx);
-        while (i < stationPath.size() && i <= endIdx) {
-            if (Thread.currentThread().isInterrupted()) {
-                return false;
-            }
-            Integer currentStationId = stationPath.get(i);
-            Integer currentStationDeviceNo = getDeviceNoByStationId(currentStationId);
-            if (currentStationDeviceNo == null) {
-                return false;
-            }
-
-            Integer nextStationId = null;
-            Integer nextStationDeviceNo = null;
-            try {
-                nextStationId = stationPath.get(i + 1);
-                nextStationDeviceNo = getDeviceNoByStationId(nextStationId);
-            } catch (Exception ignore) {}
-
-            if (!checkTaskNoInArea(taskNo)) {
-                boolean fakeAllowCheckBlock = true;
-                Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
-                if (systemConfigMapObj != null) {
-                    HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
-                    if (!systemConfigMap.get("fakeAllowCheckBlock").equals("Y")) {
-                        fakeAllowCheckBlock = false;
-                    }
-                }
-
-                if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > 1000 * 10) {
-                    boolean result = runBlockStation(taskNo, currentStationId, currentStationDeviceNo, taskNo, currentStationId);
-                    if(!result) {
-                        continue;
-                    }
-                    return false;
-                }
-            }
-
-            if (i == startIdx && !appendMode) {
-                boolean result = initStationMove(taskNo, currentStationId, currentStationDeviceNo, taskNo, targetStationId, true, null);
-                if (!result) {
-                    continue;
-                }
-                sleep(1000);
-                if (Thread.currentThread().isInterrupted()) {
-                    return false;
-                }
-            }
-
-            if (nextStationId != null && nextStationDeviceNo != null) {
-                boolean result = stationMoveToNext(taskNo, currentStationId, currentStationDeviceNo, nextStationId, nextStationDeviceNo, taskNo, targetStationId);
-                if (!result) {
-                    continue;
-                }
-                lastStationId = currentStationId;
-            }
-
-            if (currentStationId.equals(targetStationId)) {
-                break;
-            }
-
-            i++;
-            executeTime = System.currentTimeMillis();
-            sleep(1000);
-            if (Thread.currentThread().isInterrupted()) {
-                return false;
-            }
-        }
-
-        if (generateBarcode) {
-            if (lastStationId != null && targetStationDeviceNo != null) {
-                while (true) {
-                    if (Thread.currentThread().isInterrupted()) {
-                        break;
-                    }
-                    boolean result = generateStationBarcode(taskNo, targetStationId, targetStationDeviceNo);
-                    sleep(1000);
-                    if (!result) {
-                        continue;
-                    }
-                    break;
-                }
-            }
-        }
-
-        if (clearData) {
-            sleep(10000);
-            if (Thread.currentThread().isInterrupted()) {
-                return true;
-            }
-            if (lastStationId != null && targetStationDeviceNo != null) {
-                while (true) {
-                    if (Thread.currentThread().isInterrupted()) {
-                        break;
-                    }
-                    boolean result = clearStation(targetStationDeviceNo, taskNo, targetStationId);
-                    sleep(1000);
-                    if (!result) {
-                        continue;
-                    }
-                    break;
-                }
-            }
-        }
-
-        return true;
-    }
+    // stationMoveByPathIds 鏂规硶宸插垹闄わ紝鍔熻兘宸叉暣鍚堝埌 runTaskLoop
 
     private void sleep(long ms) {
         try {
@@ -545,32 +470,40 @@
         }
     }
 
-    public synchronized boolean setLockStation(Integer uuid) {
-        if (LOCK_STATION == 0) {
-            LOCK_STATION = uuid;
-            return true;
-        }else {
-            if(LOCK_STATION == uuid) {
-                return true;
-            }
-        }
-        return false;
+    /**
+     * 鑾峰彇绔欑偣閿侊紝濡傛灉涓嶅瓨鍦ㄥ垯鍒涘缓
+     */
+    private ReentrantLock getStationLock(Integer stationId) {
+        return stationLocks.computeIfAbsent(stationId, k -> new ReentrantLock());
     }
 
-    public synchronized boolean releaseLockStation(Integer uuid) {
-        if (LOCK_STATION != uuid) {
-            return false;
+    /**
+     * 鎸夐『搴忛攣瀹氬涓珯鐐癸紙閬垮厤姝婚攣锛�
+     */
+    private void lockStations(Integer... stationIds) {
+        Integer[] sorted = Arrays.copyOf(stationIds, stationIds.length);
+        Arrays.sort(sorted);
+        for (Integer stationId : sorted) {
+            getStationLock(stationId).lock();
         }
-
-        LOCK_STATION = 0;
-        return true;
     }
 
-    public synchronized boolean updateStationData(Integer lockTaskNo, Integer stationId, Integer deviceNo, Integer taskNo, Integer targetStaNo, Boolean isLoading, String barcode, Boolean runBlock) {
-        if (LOCK_STATION != lockTaskNo) {
-            return false;
+    /**
+     * 鎸夐�嗗簭瑙i攣澶氫釜绔欑偣
+     */
+    private void unlockStations(Integer... stationIds) {
+        Integer[] sorted = Arrays.copyOf(stationIds, stationIds.length);
+        Arrays.sort(sorted);
+        for (int i = sorted.length - 1; i >= 0; i--) {
+            getStationLock(sorted[i]).unlock();
         }
+    }
 
+    /**
+     * 鏇存柊绔欑偣鏁版嵁锛堣皟鐢ㄥ墠蹇呴』宸叉寔鏈夎绔欑偣鐨勯攣锛�
+     */
+    private boolean updateStationDataInternal(Integer stationId, Integer deviceNo, Integer taskNo, Integer targetStaNo,
+            Boolean isLoading, String barcode, Boolean runBlock) {
         List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
         if (statusList == null) {
             return false;
@@ -605,8 +538,13 @@
         return true;
     }
 
-    public synchronized boolean initStationMove(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo, Integer taskNo, Integer targetStationId, Boolean isLoading, String barcode) {
-        boolean executeResult = lockExecute(lockTaskNo, () -> {
+    /**
+     * 鍒濆鍖栫珯鐐圭Щ鍔紙浣跨敤绔欑偣绾ч攣锛�
+     */
+    public boolean initStationMove(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo,
+            Integer taskNo, Integer targetStationId, Boolean isLoading, String barcode) {
+        lockStations(currentStationId);
+        try {
             List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
             if (statusList == null) {
                 return false;
@@ -625,25 +563,28 @@
                 }
             }
 
-            boolean result = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, taskNo, targetStationId, isLoading, barcode, false);
-            if (!result) {
-                return false;
-            }
-            return true;
-        });
-
-        return executeResult;
+            return updateStationDataInternal(currentStationId, currentStationDeviceNo, taskNo, targetStationId,
+                    isLoading, barcode, false);
+        } finally {
+            unlockStations(currentStationId);
+        }
     }
 
-    public synchronized boolean stationMoveToNext(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo, Integer nextStationId, Integer nextStationDeviceNo, Integer taskNo, Integer targetStaNo) {
-        boolean executeResult = lockExecute(lockTaskNo, () -> {
+    /**
+     * 绔欑偣绉诲姩鍒颁笅涓�涓綅缃紙浣跨敤绔欑偣绾ч攣锛屾寜ID椤哄簭鑾峰彇閿侀伩鍏嶆閿侊級
+     */
+    public boolean stationMoveToNext(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo,
+            Integer nextStationId, Integer nextStationDeviceNo, Integer taskNo, Integer targetStaNo) {
+        // 鍚屾椂閿佸畾褰撳墠绔欑偣鍜屼笅涓�涓珯鐐癸紙鎸塈D椤哄簭锛岄伩鍏嶆閿侊級
+        lockStations(currentStationId, nextStationId);
+        try {
             List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
             if (statusList == null) {
                 return false;
             }
 
             List<ZyStationStatusEntity> nextStatusList = deviceStatusMap.get(nextStationDeviceNo);
-            if (statusList == null) {
+            if (nextStatusList == null) {
                 return false;
             }
 
@@ -661,23 +602,31 @@
                 return false;
             }
 
-            boolean result = updateStationData(lockTaskNo, nextStationId, nextStationDeviceNo, taskNo, targetStaNo, true, null, false);
+            boolean result = updateStationDataInternal(nextStationId, nextStationDeviceNo, taskNo, targetStaNo, true,
+                    null, false);
             if (!result) {
                 return false;
             }
 
-            boolean result2 = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, 0, 0, false, "", false);
+            boolean result2 = updateStationDataInternal(currentStationId, currentStationDeviceNo, 0, 0, false, "",
+                    false);
             if (!result2) {
                 return false;
             }
 
             return true;
-        });
-        return executeResult;
+        } finally {
+            unlockStations(currentStationId, nextStationId);
+        }
     }
 
-    public synchronized boolean generateStationBarcode(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo) {
-        boolean executeResult = lockExecute(lockTaskNo, () -> {
+    /**
+     * 鐢熸垚绔欑偣鏉$爜锛堜娇鐢ㄧ珯鐐圭骇閿侊級
+     */
+    public boolean generateStationBarcode(Integer lockTaskNo, Integer currentStationId,
+            Integer currentStationDeviceNo) {
+        lockStations(currentStationId);
+        try {
             List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
             if (statusList == null) {
                 return false;
@@ -693,20 +642,21 @@
             Random random = new Random();
 
             String barcodeTime = String.valueOf(System.currentTimeMillis());
-            String barcode = String.valueOf(random.nextInt(10)) + String.valueOf(random.nextInt(10)) + barcodeTime.substring(7);
+            String barcode = String.valueOf(random.nextInt(10)) + String.valueOf(random.nextInt(10))
+                    + barcodeTime.substring(7);
 
-            boolean result = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, null, null, null, barcode, null);
-            if (!result) {
-                return false;
-            }
-            return true;
-        });
-
-        return executeResult;
+            return updateStationDataInternal(currentStationId, currentStationDeviceNo, null, null, null, barcode, null);
+        } finally {
+            unlockStations(currentStationId);
+        }
     }
 
-    public synchronized boolean clearStation(Integer deviceNo, Integer lockTaskNo, Integer currentStationId) {
-        boolean executeResult = lockExecute(lockTaskNo, () -> {
+    /**
+     * 娓呴櫎绔欑偣鏁版嵁锛堜娇鐢ㄧ珯鐐圭骇閿侊級
+     */
+    public boolean clearStation(Integer deviceNo, Integer lockTaskNo, Integer currentStationId) {
+        lockStations(currentStationId);
+        try {
             List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
             if (statusList == null) {
                 return false;
@@ -719,18 +669,19 @@
                 return false;
             }
 
-            boolean result = updateStationData(deviceNo, lockTaskNo, currentStationId, 0, 0, false, "", false);
-            if (!result) {
-                return false;
-            }
-            return true;
-        });
-
-        return executeResult;
+            return updateStationDataInternal(currentStationId, deviceNo, 0, 0, false, "", false);
+        } finally {
+            unlockStations(currentStationId);
+        }
     }
 
-    public synchronized boolean runBlockStation(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo, Integer taskNo, Integer blockStationId) {
-        boolean executeResult = lockExecute(lockTaskNo, () -> {
+    /**
+     * 鏍囪绔欑偣鍫靛锛堜娇鐢ㄧ珯鐐圭骇閿侊級
+     */
+    public boolean runBlockStation(Integer lockTaskNo, Integer currentStationId, Integer currentStationDeviceNo,
+            Integer taskNo, Integer blockStationId) {
+        lockStations(currentStationId);
+        try {
             List<ZyStationStatusEntity> statusList = deviceStatusMap.get(currentStationDeviceNo);
             if (statusList == null) {
                 return false;
@@ -743,24 +694,38 @@
                 return false;
             }
 
-            boolean result = updateStationData(lockTaskNo, currentStationId, currentStationDeviceNo, taskNo, blockStationId, true, "", true);
-            if (!result) {
-                return false;
-            }
-            return true;
-        });
-
-        return executeResult;
+            return updateStationDataInternal(currentStationId, currentStationDeviceNo, taskNo, blockStationId, true, "",
+                    true);
+        } finally {
+            unlockStations(currentStationId);
+        }
     }
 
-    public boolean lockExecute(Integer taskNo, Supplier<Boolean> function) {
-        if (!setLockStation(taskNo)) {
-            return false;
-        }
+    /**
+     * 娓呴櫎绔欑偣鍫靛鏍囪锛堝牭濉炴仮澶嶆椂浣跨敤锛�
+     */
+    public void clearRunBlock(Integer stationId, Integer deviceNo) {
+        lockStations(stationId);
+        try {
+            List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
+            if (statusList == null) {
+                return;
+            }
 
-        boolean result = function.get();
-        releaseLockStation(taskNo);
-        return result;
+            ZyStationStatusEntity currentStatus = statusList.stream()
+                    .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
+
+            if (currentStatus == null) {
+                return;
+            }
+
+            if (currentStatus.isRunBlock()) {
+                currentStatus.setRunBlock(false);
+                News.info("[WCS Debug] 绔欑偣{}鍫靛鏍囪宸叉竻闄�", stationId);
+            }
+        } finally {
+            unlockStations(stationId);
+        }
     }
 
     private boolean checkTaskNoInArea(Integer taskNo) {
@@ -773,7 +738,7 @@
         Integer start = data.getInteger("start");
         Integer end = data.getInteger("end");
 
-        if(taskNo >= start && taskNo <= end) {
+        if (taskNo >= start && taskNo <= end) {
             return true;
         }
 
diff --git a/src/main/java/com/zy/core/plugin/FakeProcess.java b/src/main/java/com/zy/core/plugin/FakeProcess.java
index f4b1702..16a90f8 100644
--- a/src/main/java/com/zy/core/plugin/FakeProcess.java
+++ b/src/main/java/com/zy/core/plugin/FakeProcess.java
@@ -53,7 +53,7 @@
     private static final long METHOD_TIMEOUT_MS = 15000; // 15绉掕秴鏃�
     private static final ExecutorService timeoutExecutor = Executors.newCachedThreadPool();
 
-    private static Map<Integer,Long> stationStayTimeMap = new ConcurrentHashMap<>();
+    private static Map<Integer, Long> stationStayTimeMap = new ConcurrentHashMap<>();
     private static volatile String enableFake = "N";
     private static volatile String fakeRealTaskRequestWms = "N";
     private static volatile String fakeGenerateInTask = "Y";
@@ -88,8 +88,9 @@
 
     /**
      * 甯﹁秴鏃朵繚鎶ゆ墽琛屾柟娉�
+     * 
      * @param taskName 浠诲姟鍚嶇О锛堢敤浜庢棩蹇楋級
-     * @param task 瑕佹墽琛岀殑浠诲姟
+     * @param task     瑕佹墽琛岀殑浠诲姟
      */
     private void executeWithTimeout(String taskName, Runnable task) {
         Future<?> future = timeoutExecutor.submit(task);
@@ -110,23 +111,23 @@
         long startTime = System.currentTimeMillis();
         asyncFakeRun();
 
-        //璇锋眰鐢熸垚鍏ュ簱浠诲姟
+        // 璇锋眰鐢熸垚鍏ュ簱浠诲姟
         executeWithTimeout("generateStoreWrkFile", this::generateStoreWrkFile);
 
-        //鎵ц鍫嗗灈鏈轰换鍔�
+        // 鎵ц鍫嗗灈鏈轰换鍔�
         executeWithTimeout("crnIoExecute", crnOperateUtils::crnIoExecute);
-        //鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�-鍏峰浠跨湡鑳藉姏
+        // 鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�-鍏峰浠跨湡鑳藉姏
         executeWithTimeout("crnIoExecuteFinish", this::crnIoExecuteFinish);
-        //鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
+        // 鎵ц杈撻�佺珯鐐瑰叆搴撲换鍔�
         executeWithTimeout("stationInExecute", stationOperateProcessUtils::stationInExecute);
-        //鎵ц杈撻�佺珯鐐瑰嚭搴撲换鍔�
+        // 鎵ц杈撻�佺珯鐐瑰嚭搴撲换鍔�
         executeWithTimeout("stationOutExecute", stationOperateProcessUtils::stationOutExecute);
-        //妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
+        // 妫�娴嬭緭閫佺珯鐐瑰嚭搴撲换鍔℃墽琛屽畬鎴�
         executeWithTimeout("stationOutExecuteFinish", stationOperateProcessUtils::stationOutExecuteFinish);
 
-        //鎵ц鍙屽伐浣嶅爢鍨涙満浠诲姟
+        // 鎵ц鍙屽伐浣嶅爢鍨涙満浠诲姟
         executeWithTimeout("dualCrnIoExecute", dualCrnOperateProcessUtils::dualCrnIoExecute);
-        //鍙屽伐浣嶅爢鍨涙満浠诲姟鎵ц瀹屾垚
+        // 鍙屽伐浣嶅爢鍨涙満浠诲姟鎵ц瀹屾垚
         executeWithTimeout("dualCrnIoExecuteFinish", dualCrnOperateProcessUtils::dualCrnIoExecuteFinish);
 
         News.info("[WCS Debug] 涓荤嚎绋婻un鎵ц瀹屾垚,鑰楁椂:{}ms", System.currentTimeMillis() - startTime);
@@ -140,22 +141,26 @@
         asyncFakeRunThread = new Thread(() -> {
             while (!Thread.currentThread().isInterrupted()) {
                 try {
-                    Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
+                    Config enableFakeConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
                     if (enableFakeConfig != null) {
                         enableFake = enableFakeConfig.getValue();
                     }
 
-                    Config fakeRealTaskRequestWmsConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
+                    Config fakeRealTaskRequestWmsConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
                     if (fakeRealTaskRequestWmsConfig != null) {
                         fakeRealTaskRequestWms = fakeRealTaskRequestWmsConfig.getValue();
                     }
 
-                    Config fakeGenerateInTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask"));
+                    Config fakeGenerateInTaskConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateInTask"));
                     if (fakeGenerateInTaskConfig != null) {
                         fakeGenerateInTask = fakeGenerateInTaskConfig.getValue();
                     }
 
-                    Config fakeGenerateOutTaskConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
+                    Config fakeGenerateOutTaskConfig = configService
+                            .selectOne(new EntityWrapper<Config>().eq("code", "fakeGenerateOutTask"));
                     if (fakeGenerateOutTaskConfig != null) {
                         fakeGenerateOutTask = fakeGenerateOutTaskConfig.getValue();
                     }
@@ -165,20 +170,20 @@
                         continue;
                     }
 
-                    //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
+                    // 妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
                     checkInStationHasTask();
-                    //鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
+                    // 鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
                     generateFakeInTask();
-                    //鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
+                    // 鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
                     generateFakeOutTask();
-                    //璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
+                    // 璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
                     calcAllStationStayTime();
-                    //妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
+                    // 妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
                     checkOutStationStayTimeOut();
-                    //妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
+                    // 妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
                     checkInStationCrnTake();
 
-                    //妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
+                    // 妫�娴嬭緭閫佺珯鐐规槸鍚﹁繍琛屽牭濉�
                     stationOperateProcessUtils.checkStationRunBlock();
 
                     // 闂撮殧
@@ -196,8 +201,8 @@
         asyncFakeRunThread.start();
     }
 
-    //妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
-    private void checkInStationHasTask() {
+    // 妫�娴嬪叆搴撶珯鏄惁鏈変换鍔$敓鎴愶紝骞朵豢鐪熺敓鎴愭ā鎷熷叆搴撶珯鐐规暟鎹�
+    private synchronized void checkInStationHasTask() {
         if (!enableFake.equals("Y")) {
             return;
         }
@@ -209,7 +214,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -218,7 +223,7 @@
             List<StationObjModel> list = basDevp.getInStationList$();
             for (StationObjModel entity : list) {
                 Integer stationId = entity.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -228,16 +233,17 @@
                 }
 
                 Object lock = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId);
-                if(lock != null){
+                if (lock != null) {
                     continue;
                 }
 
-                //婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬叆搴撴暟鎹�
+                // 婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬叆搴撴暟鎹�
                 if (stationProtocol.isAutoing()
                         && !stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() == 0
-                ) {
-                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId, entity.getBarcodeStation().getStationId(), 0);
+                        && stationProtocol.getTaskNo() == 0) {
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE,
+                            commonService.getWorkNo(WrkIoType.FAKE_TASK_NO.id), stationId,
+                            entity.getBarcodeStation().getStationId(), 0);
                     MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                     redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 5);
                 }
@@ -245,8 +251,8 @@
         }
     }
 
-    //鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
-    private void generateFakeInTask() {
+    // 鐢熸垚浠跨湡妯℃嫙鍏ュ簱浠诲姟
+    private synchronized void generateFakeInTask() {
         if (!enableFake.equals("Y")) {
             return;
         }
@@ -262,7 +268,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -271,7 +277,7 @@
             List<StationObjModel> list = basDevp.getBarcodeStationList$();
             for (StationObjModel model : list) {
                 Integer stationId = model.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -285,22 +291,23 @@
                     continue;
                 }
 
-                //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
+                // 婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
                 if (stationProtocol.isAutoing()
                         && stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() > 0
-                ) {
+                        && stationProtocol.getTaskNo() > 0) {
                     if (Cools.isEmpty(stationProtocol.getBarcode())) {
                         continue;
                     }
 
-                    //妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+                    // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
+                    List<WrkMast> wrkMasts = wrkMastService
+                            .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                     if (!wrkMasts.isEmpty()) {
                         continue;
                     }
 
-                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
+                    List<LocMast> locMastList = locMastService
+                            .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
                     if (locMastList.isEmpty()) {
                         continue;
                     }
@@ -326,8 +333,9 @@
                     taskParam.setBarcode(stationProtocol.getBarcode());
                     WrkMast wrkMast = commonService.createInTask(taskParam);
 
-                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(), stationId, stationId, 0);
-                    if(command == null){
+                    StationCommand command = stationThread.getCommand(StationCommandType.MOVE, wrkMast.getWrkNo(),
+                            stationId, stationId, 0);
+                    if (command == null) {
                         News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
                         continue;
                     }
@@ -338,8 +346,8 @@
         }
     }
 
-    //鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
-    private void generateFakeOutTask() {
+    // 鐢熸垚浠跨湡妯℃嫙鍑哄簱浠诲姟
+    private synchronized void generateFakeOutTask() {
         if (!enableFake.equals("Y")) {
             return;
         }
@@ -355,7 +363,7 @@
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
-            if(stationThread == null){
+            if (stationThread == null) {
                 continue;
             }
 
@@ -364,7 +372,7 @@
             List<StationObjModel> list = basDevp.getOutStationList$();
             for (StationObjModel entity : list) {
                 Integer stationId = entity.getStationId();
-                if(!stationMap.containsKey(stationId)){
+                if (!stationMap.containsKey(stationId)) {
                     continue;
                 }
 
@@ -374,16 +382,16 @@
                 }
 
                 Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId);
-                if(object != null){
+                if (object != null) {
                     return;
                 }
 
-                //婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬嚭搴撴暟鎹�
+                // 婊¤冻鑷姩銆佹棤鐗┿�佸伐浣滃彿0锛岀敓鎴愬嚭搴撴暟鎹�
                 if (stationProtocol.isAutoing()
                         && !stationProtocol.isLoading()
-                        && stationProtocol.getTaskNo() == 0
-                ) {
-                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
+                        && stationProtocol.getTaskNo() == 0) {
+                    List<LocMast> locMastList = locMastService
+                            .selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
                     if (locMastList.isEmpty()) {
                         continue;
                     }
@@ -419,7 +427,7 @@
 
             int conveyorStationTaskLimit = 30;
             String conveyorStationTaskLimitStr = systemConfigMap.get("conveyorStationTaskLimit");
-            if(conveyorStationTaskLimitStr != null){
+            if (conveyorStationTaskLimitStr != null) {
                 conveyorStationTaskLimit = Integer.parseInt(conveyorStationTaskLimitStr);
             }
             int currentStationTaskCount = stationOperateProcessUtils.getCurrentStationTaskCount();
@@ -449,17 +457,17 @@
                         continue;
                     }
 
-                    //婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
+                    // 婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
                     if (stationProtocol.isAutoing()
                             && stationProtocol.isLoading()
-                            && stationProtocol.getTaskNo() > 0
-                    ) {
+                            && stationProtocol.getTaskNo() > 0) {
                         if (Cools.isEmpty(stationProtocol.getBarcode())) {
                             continue;
                         }
 
-                        //妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                        List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+                        // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
+                        List<WrkMast> wrkMasts = wrkMastService
+                                .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                         if (!wrkMasts.isEmpty()) {
                             continue;
                         }
@@ -468,30 +476,62 @@
                         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);
+                        String barcode = stationProtocol.getBarcode();
+                        Integer stationIdVal = stationProtocol.getStationId();
 
-                            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);
+                        // 1. 棣栧厛鏌ヨ鏄惁鏈夊凡瀹屾垚鐨勫紓姝ュ搷搴�
+                        String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal);
 
-                            StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, wrkMast.getWrkNo(), stationId, stationId, 0);
-                            if (command == null) {
-                                News.taskInfo(wrkMast.getWrkNo(), "鑾峰彇杈撻�佺嚎鍛戒护澶辫触");
+                        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;
                             }
-                            MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
+
+                            // 瑙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);
+                            }
+                            // 濡傛灉鏈夎姹傝繘琛屼腑锛岀瓑寰呬笅娆″惊鐜啀妫�鏌�
                         }
                     }
                 }
@@ -501,8 +541,8 @@
         }
     }
 
-    //璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
-    public void calcAllStationStayTime() {
+    // 璁$畻鎵�鏈夌珯鐐瑰仠鐣欐椂闂�
+    public synchronized void calcAllStationStayTime() {
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
@@ -512,30 +552,33 @@
 
             List<StationProtocol> list = stationThread.getStatus();
             for (StationProtocol stationProtocol : list) {
-                if (stationProtocol.getTaskNo() > 0 && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
+                if (stationProtocol.getTaskNo() > 0
+                        && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                     stationStayTimeMap.put(stationProtocol.getStationId(), System.currentTimeMillis());
                 }
 
-                if(stationProtocol.getTaskNo() <= 0 && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
+                if (stationProtocol.getTaskNo() <= 0
+                        && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                     stationStayTimeMap.remove(stationProtocol.getStationId());
                 }
             }
         }
     }
 
-    //妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
-    public void checkOutStationStayTimeOut() {
+    // 妫�娴嬪嚭搴撶珯鐐瑰仠鐣欐槸鍚﹁秴鏃�
+    public synchronized void checkOutStationStayTimeOut() {
         List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
         for (BasDevp basDevp : basDevps) {
             List<StationObjModel> outStationList = basDevp.getOutStationList$();
-            if(outStationList.isEmpty()){
+            if (outStationList.isEmpty()) {
                 News.info("杈撻�佺嚎:{} 鍑哄簱绔欑偣鏈缃�", basDevp.getDevpNo());
                 continue;
             }
 
             for (StationObjModel stationObjModel : outStationList) {
-                Object lock = redisUtil.get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
-                if(lock != null){
+                Object lock = redisUtil
+                        .get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
+                if (lock != null) {
                     continue;
                 }
 
@@ -544,31 +587,36 @@
                     continue;
                 }
 
-                if(System.currentTimeMillis() - stayTime > 1000 * 15) {
-                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
-                    if(stationThread == null){
+                if (System.currentTimeMillis() - stayTime > 1000 * 15) {
+                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                            stationObjModel.getDeviceNo());
+                    if (stationThread == null) {
                         continue;
                     }
 
-                    StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0);
-                    if(command == null){
+                    StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0,
+                            stationObjModel.getStationId(), 0, 0);
+                    if (command == null) {
                         continue;
                     }
 
                     MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                    redisUtil.set(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                    News.info("杈撻�佺珯鐐瑰嚭搴撻噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
+                    redisUtil.set(
+                            RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(),
+                            "lock", 10);
+                    News.info("杈撻�佺珯鐐瑰嚭搴撻噸缃懡浠や笅鍙戞垚鍔燂紝绔欑偣鍙�={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                            JSON.toJSONString(command));
                 }
             }
         }
     }
 
-    //妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
-    public void checkInStationCrnTake() {
+    // 妫�娴嬪叆搴撶珯鐐瑰爢鍨涙満鏄惁鍙栬蛋璐х墿
+    public synchronized void checkInStationCrnTake() {
         List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
         for (BasCrnp basCrnp : basCrnps) {
             List<StationObjModel> inStationList = basCrnp.getInStationList$();
-            if(inStationList.isEmpty()){
+            if (inStationList.isEmpty()) {
                 News.info("鍫嗗灈鏈�:{} 鍏ュ簱绔欑偣鏈缃�", basCrnp.getCrnNo());
                 continue;
             }
@@ -578,7 +626,7 @@
         List<BasDualCrnp> basDualCrnps = basDualCrnpService.selectList(new EntityWrapper<>());
         for (BasDualCrnp basDualCrnp : basDualCrnps) {
             List<StationObjModel> inStationList = basDualCrnp.getInStationList$();
-            if(inStationList.isEmpty()){
+            if (inStationList.isEmpty()) {
                 News.info("鍙屽伐浣嶅爢鍨涙満:{} 鍏ュ簱绔欑偣鏈缃�", basDualCrnp.getCrnNo());
                 continue;
             }
@@ -586,15 +634,17 @@
         }
     }
 
-    private void checkInStationListCrnTake(List<StationObjModel> inStationList) {
+    private synchronized void checkInStationListCrnTake(List<StationObjModel> inStationList) {
         for (StationObjModel stationObjModel : inStationList) {
-            Object lock = redisUtil.get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
-            if(lock != null){
+            Object lock = redisUtil
+                    .get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
+            if (lock != null) {
                 continue;
             }
 
-            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
-            if(stationThread == null){
+            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                    stationObjModel.getDeviceNo());
+            if (stationThread == null) {
                 continue;
             }
 
@@ -604,19 +654,24 @@
                 continue;
             }
 
-            if(stationProtocol.getTaskNo() > 0) {
-                StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0, stationObjModel.getStationId(), 0, 0);
-                if(command == null){
+            if (stationProtocol.getTaskNo() > 0) {
+                StationCommand command = stationThread.getCommand(StationCommandType.RESET, 0,
+                        stationObjModel.getStationId(), 0, 0);
+                if (command == null) {
                     continue;
                 }
 
                 WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                 if (wrkMast == null) {
                     MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                    redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                    News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(task_over)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
-                }else {
-                    if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
+                    redisUtil.set(
+                            RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(),
+                            "lock", 10);
+                    News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(task_over)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                            JSON.toJSONString(command));
+                } else {
+                    if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts
+                            && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
                         Integer crnNo = wrkMast.getCrnNo();
                         if (crnNo != null) {
                             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo);
@@ -624,16 +679,20 @@
                                 continue;
                             }
                             CrnProtocol crnProtocol = crnThread.getStatus();
-                            if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING) && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) {
+                            if (!crnProtocol.getStatusType().equals(CrnStatusType.PUT_MOVING)
+                                    && !crnProtocol.getStatusType().equals(CrnStatusType.PUTTING)) {
                                 continue;
                             }
 
                             MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
-                        }else {
+                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key
+                                    + stationObjModel.getStationId(), "lock", 10);
+                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                                    JSON.toJSONString(command));
+                        } else {
                             Integer dualCrnNo = wrkMast.getDualCrnNo();
-                            DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn, dualCrnNo);
+                            DualCrnThread dualCrnThread = (DualCrnThread) SlaveConnection.get(SlaveType.DualCrn,
+                                    dualCrnNo);
                             if (dualCrnThread == null) {
                                 continue;
                             }
@@ -653,8 +712,10 @@
                             }
 
                             MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
-                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
-                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(), JSON.toJSONString(command));
+                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key
+                                    + stationObjModel.getStationId(), "lock", 10);
+                            News.info("杈撻�佺珯鐐归噸缃懡浠や笅鍙戞垚鍔�(crn_fetch)锛岀珯鐐瑰彿={}锛屽懡浠ゆ暟鎹�={}", stationObjModel.getStationId(),
+                                    JSON.toJSONString(command));
                         }
                     }
                 }
@@ -662,26 +723,25 @@
         }
     }
 
-    //鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�
-    public void crnIoExecuteFinish() {
+    // 鍫嗗灈鏈轰换鍔℃墽琛屽畬鎴�
+    public synchronized void crnIoExecuteFinish() {
         List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
         for (BasCrnp basCrnp : basCrnps) {
             CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
-            if(crnThread == null){
+            if (crnThread == null) {
                 continue;
             }
 
             CrnProtocol crnProtocol = crnThread.getStatus();
-            if(crnProtocol == null){
+            if (crnProtocol == null) {
                 continue;
             }
 
             if (crnProtocol.getMode() == CrnModeType.AUTO.id
                     && crnProtocol.getTaskNo() > 0
-                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id
-            ) {
+                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id) {
                 Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo());
-                if(lock != null){
+                if (lock != null) {
                     continue;
                 }
 
@@ -693,14 +753,14 @@
                 }
 
                 Long updateWrkSts = null;
-                if(wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts){
+                if (wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts) {
                     updateWrkSts = WrkStsType.COMPLETE_INBOUND.sts;
-                }else if(wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts){
+                } else if (wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts) {
                     updateWrkSts = WrkStsType.OUTBOUND_RUN_COMPLETE.sts;
 
-                    //鐢熸垚浠跨湡绔欑偣鏁版嵁
+                    // 鐢熸垚浠跨湡绔欑偣鏁版嵁
                     List<StationObjModel> outStationList = basCrnp.getOutStationList$();
-                    if(outStationList.isEmpty()){
+                    if (outStationList.isEmpty()) {
                         News.info("鍫嗗灈鏈�:{} 鍑哄簱绔欑偣鏈缃�", basCrnp.getCrnNo());
                         continue;
                     }
@@ -710,17 +770,19 @@
                             continue;
                         }
 
-                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
+                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp,
+                                stationObjModel.getDeviceNo());
                         if (stationThread == null) {
                             continue;
                         }
-                        //鐢熸垚浠跨湡绔欑偣鏁版嵁
-                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998, wrkMast.getSourceStaNo(), 0, 0);
+                        // 鐢熸垚浠跨湡绔欑偣鏁版嵁
+                        StationCommand command = stationThread.getCommand(StationCommandType.WRITE_INFO, 9998,
+                                wrkMast.getSourceStaNo(), 0, 0);
                         MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                     }
-                }else if(wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts){
+                } else if (wrkMast.getWrkSts() == WrkStsType.LOC_MOVE_RUN.sts) {
                     updateWrkSts = WrkStsType.COMPLETE_LOC_MOVE.sts;
-                }else{
+                } else {
                     News.error("鍫嗗灈鏈哄浜庣瓑寰呯‘璁や笖浠诲姟瀹屾垚鐘舵�侊紝浣嗗伐浣滅姸鎬佸紓甯搞�傚爢鍨涙満鍙�={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                     continue;
                 }
@@ -734,7 +796,7 @@
                     News.info("鍫嗗灈鏈轰换鍔$姸鎬佹洿鏂版垚鍔燂紝鍫嗗灈鏈哄彿={}锛屽伐浣滃彿={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                 }
 
-                redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10);
+                redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock", 10);
             }
         }
     }
diff --git a/src/main/java/com/zy/core/plugin/NormalProcess.java b/src/main/java/com/zy/core/plugin/NormalProcess.java
index b58d1dd..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;
 
@@ -81,81 +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.isInEnable()
-                        && stationProtocol.getTaskNo() > 0
-                ) {
-                    if (stationProtocol.getError() > 0) {
-                        Object backLock = redisUtil.get(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationId);
-                        if (backLock != null) {
+                List<StationObjModel> list = basDevp.getBarcodeStationList$();
+                for (StationObjModel entity : list) {
+                    Integer stationId = entity.getStationId();
+                    if (!stationMap.containsKey(stationId)) {
+                        continue;
+                    }
+
+                    StationProtocol stationProtocol = stationMap.get(stationId);
+                    if (stationProtocol == null) {
+                        continue;
+                    }
+
+                    // 婊¤冻鑷姩銆佹湁鐗┿�佹湁宸ヤ綔鍙凤紝鐢熸垚鍏ュ簱鏁版嵁
+                    if (stationProtocol.isAutoing()
+                            && stationProtocol.isLoading()
+                            && stationProtocol.getTaskNo() > 0) {
+                        if (Cools.isEmpty(stationProtocol.getBarcode())) {
                             continue;
                         }
 
-                        //鎶ヨ鍥為��
-                        StationCommand command = stationThread.getCommand(StationCommandType.MOVE, commonService.getWorkNo(WrkIoType.STATION_BACK.id), stationId, entity.getBackStation().getStationId(), 0);
-                        MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
-                        redisUtil.set(RedisKeyType.GENERATE_STATION_BACK_LIMIT.key + stationId, "lock", 15);
-                        News.info("{}绔欑偣鎶ヨ鍥為��鎴愬姛锛屾暟鎹寘:{}", stationId, JSON.toJSONString(command));
-                        continue;
-                    }
+                        // 妫�娴嬩换鍔℃槸鍚︾敓鎴�
+                        List<WrkMast> wrkMasts = wrkMastService
+                                .selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
+                        if (!wrkMasts.isEmpty()) {
+                            continue;
+                        }
 
-                    if (Cools.isEmpty(stationProtocol.getBarcode())) {
-                        continue;
-                    }
+                        Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
+                        if (lock != null) {
+                            continue;
+                        }
 
-                    //妫�娴嬩换鍔℃槸鍚︾敓鎴�
-                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
-                    if (!wrkMasts.isEmpty()) {
-                        continue;
-                    }
+                        String barcode = stationProtocol.getBarcode();
+                        Integer stationIdVal = stationProtocol.getStationId();
 
-                    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);
+                        // 1. 棣栧厛鏌ヨ鏄惁鏈夊凡瀹屾垚鐨勫紓姝ュ搷搴�
+                        String response = wmsOperateUtils.queryAsyncInTaskResponse(barcode, stationIdVal);
 
-                    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);
+                        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;
+                            }
 
-                        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);
+                            // 瑙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();
         }
     }
 
diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
index 7f518aa..92cadb7 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
@@ -2,6 +2,7 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
@@ -295,10 +296,7 @@
         }
 
         if(original.getCommandType() == StationCommandType.MOVE){
-            List<Integer> path = original.getNavigatePath();
-            if (path == null || path.isEmpty()) {
-                path = calcPathStationIds(original.getStationId(), original.getTargetStaNo());
-            }
+            List<Integer> path = JSON.parseArray(JSON.toJSONString(original.getNavigatePath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class);
             if (path == null || path.isEmpty()) {
                 return;
             }
@@ -329,6 +327,7 @@
             sendCommand(segCmd);
 
             long runTime = System.currentTimeMillis();
+            boolean firstRun = true;
             while (true) {
                 try {
                     StationProtocol currentStation = findCurrentStationByTask(original.getTaskNo());
@@ -341,7 +340,7 @@
                     }
 
                     runTime = System.currentTimeMillis();
-                    if (currentStation.isRunBlock()) {
+                    if (!firstRun && currentStation.isRunBlock()) {
                         break;
                     }
                     int currentIndex = path.indexOf(currentStation.getStationId());
@@ -370,12 +369,26 @@
                         nextCmd.setCommandType(original.getCommandType());
                         nextCmd.setPalletSize(original.getPalletSize());
                         nextCmd.setNavigatePath(new ArrayList<>(path.subList(currentStartIdx, currentEndIdx + 1)));
-                        sendCommand(nextCmd);
+                        nextCmd.setOriginalNavigatePath(path);
+                        while (true) {
+                            CommandResponse commandResponse = sendCommand(nextCmd);
+                            if (commandResponse == null) {
+                                Thread.sleep(200);
+                                continue;
+                            }
+
+                            if (commandResponse.getResult()) {
+                                break;
+                            }
+
+                            Thread.sleep(200);
+                        }
                     }
                     Thread.sleep(500);
                 } catch (Exception e) {
                     break;
                 }
+                firstRun = false;
             }
         }else {
             sendCommand(original);
diff --git a/src/main/java/com/zy/core/utils/WmsOperateUtils.java b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
index 79e7e1e..42e682a 100644
--- a/src/main/java/com/zy/core/utils/WmsOperateUtils.java
+++ b/src/main/java/com/zy/core/utils/WmsOperateUtils.java
@@ -54,7 +54,7 @@
     @Autowired
     private RedisUtil redisUtil;
 
-    //鐢宠鍏ュ簱浠诲姟
+    // 鐢宠鍏ュ簱浠诲姟
     public synchronized String applyInTask(String barcode, Integer sourceStaNo, Integer locType1) {
         Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
         if (systemConfigMapObj == null) {
@@ -70,7 +70,7 @@
         }
 
         String wmsSystemInUrl = systemConfigMap.get("wmsSystemInUrl");
-        if(wmsSystemInUrl == null){
+        if (wmsSystemInUrl == null) {
             News.error("鏈厤缃甒MS鍏ュ簱鎺ュ彛鍦板潃锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemInUrl");
             return null;
         }
@@ -79,14 +79,15 @@
         String response = null;
         int result = 0;
         try {
-            BasStation basStation = basStationService.selectOne(new EntityWrapper<BasStation>().eq("station_id", sourceStaNo));
-            if(basStation == null){
+            BasStation basStation = basStationService
+                    .selectOne(new EntityWrapper<BasStation>().eq("station_id", sourceStaNo));
+            if (basStation == null) {
                 News.error("绔欑偣{}涓嶅瓨鍦�", sourceStaNo);
                 return null;
             }
 
             String stationNo = String.valueOf(sourceStaNo);
-            if(!Cools.isEmpty(basStation.getStationAlias())){
+            if (!Cools.isEmpty(basStation.getStationAlias())) {
                 stationNo = basStation.getStationAlias();
             }
 
@@ -106,15 +107,19 @@
                 JSONObject jsonObject = JSON.parseObject(response);
                 if (jsonObject.getInteger("code") == 200) {
                     result = 1;
-                    News.info("璇锋眰WMS鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
-                }else {
-                    News.info("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
+                    News.info("璇锋眰WMS鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+                            JSON.toJSONString(requestParam), response);
+                } else {
+                    News.info("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+                            JSON.toJSONString(requestParam), response);
                 }
-            }else {
-                News.info("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
+            } else {
+                News.info("璇锋眰WMS鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+                        JSON.toJSONString(requestParam), response);
             }
         } catch (Exception e) {
-            News.error("璇锋眰WMS鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response, e);
+            News.error("璇锋眰WMS鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemInUrl,
+                    JSON.toJSONString(requestParam), response, e);
         } finally {
             HttpRequestLog httpRequestLog = new HttpRequestLog();
             httpRequestLog.setName(wmsUrl + wmsSystemInUrl);
@@ -127,7 +132,81 @@
         return response;
     }
 
-    //鐢宠浠诲姟閲嶆柊鍒嗛厤搴撲綅
+    /**
+     * 寮傛鐢宠鍏ュ簱浠诲姟 - 闈為樆濉炵増鏈�
+     * 灏嗚姹傛彁浜ゅ埌绾跨▼姹犲紓姝ユ墽琛岋紝缁撴灉瀛樺偍鍒癛edis涓�
+     * 
+     * @param barcode     鎵樼洏鐮�
+     * @param sourceStaNo 绔欑偣缂栧彿
+     * @param locType1    鎵樼洏楂樺害
+     */
+    public void applyInTaskAsync(String barcode, Integer sourceStaNo, Integer locType1) {
+        String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + sourceStaNo;
+        String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + sourceStaNo;
+
+        // 妫�鏌ユ槸鍚﹀凡鏈夎姹傚湪杩涜涓�
+        Object existingRequest = redisUtil.get(requestKey);
+        if (existingRequest != null) {
+            return; // 宸叉湁璇锋眰鍦ㄨ繘琛屼腑锛岃烦杩�
+        }
+
+        // 鏍囪璇锋眰杩涜涓紝璁剧疆60绉掕秴鏃�
+        redisUtil.set(requestKey, "processing", 60);
+
+        // 鎻愪氦寮傛浠诲姟
+        new Thread(() -> {
+            try {
+                String response = applyInTask(barcode, sourceStaNo, locType1);
+                if (response != null) {
+                    // 瀛樺偍鍝嶅簲缁撴灉锛岃缃�60绉掕秴鏃�
+                    redisUtil.set(responseKey, response, 60);
+                    News.info("寮傛WMS鍏ュ簱璇锋眰瀹屾垚锛宐arcode={}锛宻tationId={}锛宺esponse={}", barcode, sourceStaNo, response);
+                } else {
+                    // 璇锋眰澶辫触锛屽瓨鍌ㄥけ璐ユ爣璁�
+                    redisUtil.set(responseKey, "FAILED", 10);
+                    News.error("寮傛WMS鍏ュ簱璇锋眰澶辫触锛宐arcode={}锛宻tationId={}", barcode, sourceStaNo);
+                }
+            } catch (Exception e) {
+                News.error("寮傛WMS鍏ュ簱璇锋眰寮傚父锛宐arcode={}锛宻tationId={}锛宔rror={}", barcode, sourceStaNo, e.getMessage());
+                redisUtil.set(responseKey, "ERROR:" + e.getMessage(), 10);
+            } finally {
+                // 娓呴櫎璇锋眰杩涜涓爣璁�
+                redisUtil.del(requestKey);
+            }
+        }).start();
+    }
+
+    /**
+     * 鏌ヨ寮傛鍏ュ簱浠诲姟璇锋眰缁撴灉
+     * 
+     * @param barcode   鎵樼洏鐮�
+     * @param stationId 绔欑偣缂栧彿
+     * @return 鍝嶅簲缁撴灉锛宯ull琛ㄧず杩樻湭瀹屾垚鎴栨湭鎵惧埌
+     */
+    public String queryAsyncInTaskResponse(String barcode, Integer stationId) {
+        String responseKey = RedisKeyType.ASYNC_WMS_IN_TASK_RESPONSE.key + barcode + "_" + stationId;
+        Object response = redisUtil.get(responseKey);
+        if (response != null) {
+            // 鑾峰彇鍚庡垹闄わ紝閬垮厤閲嶅澶勭悊
+            redisUtil.del(responseKey);
+            return response.toString();
+        }
+        return null;
+    }
+
+    /**
+     * 妫�鏌ユ槸鍚︽湁寮傛璇锋眰姝e湪杩涜涓�
+     * 
+     * @param barcode   鎵樼洏鐮�
+     * @param stationId 绔欑偣缂栧彿
+     * @return true琛ㄧず姝e湪璇锋眰涓�
+     */
+    public boolean isAsyncRequestInProgress(String barcode, Integer stationId) {
+        String requestKey = RedisKeyType.ASYNC_WMS_IN_TASK_REQUEST.key + barcode + "_" + stationId;
+        return redisUtil.get(requestKey) != null;
+    }
+
+    // 鐢宠浠诲姟閲嶆柊鍒嗛厤搴撲綅
     public synchronized String applyReassignTaskLocNo(Integer taskNo, Integer stationId) {
         String wmsUrl = null;
         Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
@@ -141,7 +220,8 @@
         }
 
         String wmsSystemReassignInTaskUrl = null;
-        Config wmsSystemReassignInTaskUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
+        Config wmsSystemReassignInTaskUrlConfig = configService
+                .selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemReassignInTaskUrl"));
         if (wmsSystemReassignInTaskUrlConfig != null) {
             wmsSystemReassignInTaskUrl = wmsSystemReassignInTaskUrlConfig.getValue();
         }
@@ -184,15 +264,19 @@
                 JSONObject jsonObject = JSON.parseObject(response);
                 if (jsonObject.getInteger("code") == 200) {
                     result = 1;
-                    News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+                    News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl,
+                            JSON.toJSONString(requestParam), response);
                 } else {
-                    News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+                    News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}",
+                            wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
                 }
             } else {
-                News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response);
+                News.info("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemReassignInTaskUrl,
+                        JSON.toJSONString(requestParam), response);
             }
         } catch (Exception e) {
-            News.error("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛� response锛歿}", wmsUrl + wmsSystemReassignInTaskUrl, JSON.toJSONString(requestParam), response, e);
+            News.error("璇锋眰鐢宠浠诲姟閲嶆柊鍒嗛厤鍏ュ簱鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛� response锛歿}", wmsUrl + wmsSystemReassignInTaskUrl,
+                    JSON.toJSONString(requestParam), response, e);
         } finally {
             HttpRequestLog httpRequestLog = new HttpRequestLog();
             httpRequestLog.setName(wmsUrl + wmsSystemReassignInTaskUrl);
@@ -205,7 +289,7 @@
         return response;
     }
 
-    //鐢宠鍦ㄥ簱搴撲綅鏇存崲搴撲綅
+    // 鐢宠鍦ㄥ簱搴撲綅鏇存崲搴撲綅
     public synchronized String applyChangeLocNo(String locNo) {
         String wmsUrl = null;
         Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
@@ -219,12 +303,13 @@
         }
 
         String wmsSystemChangeLocNoUrl = null;
-        Config wmsSystemChangeLocNoUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
+        Config wmsSystemChangeLocNoUrlConfig = configService
+                .selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemChangeLocNoUrl"));
         if (wmsSystemChangeLocNoUrlConfig != null) {
             wmsSystemChangeLocNoUrl = wmsSystemChangeLocNoUrlConfig.getValue();
         }
 
-        if(wmsSystemChangeLocNoUrl == null){
+        if (wmsSystemChangeLocNoUrl == null) {
             News.error("鏈厤缃敵璇峰湪搴撳簱浣嶆洿鎹㈠簱浣嶆帴鍙e湴鍧�锛岄厤缃枃浠禖ode缂栫爜锛歸msSystemChangeLocNoUrl");
             return null;
         }
@@ -246,7 +331,8 @@
                 crnRows.addAll(list);
             }
         } else if (findCrnNoResult.getCrnType().equals(SlaveType.DualCrn)) {
-            BasDualCrnp basDualCrnp = basDualCrnpService.selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
+            BasDualCrnp basDualCrnp = basDualCrnpService
+                    .selectOne(new EntityWrapper<BasDualCrnp>().eq("crn_no", crnNo));
             if (basDualCrnp == null) {
                 return null;
             }
@@ -254,7 +340,7 @@
             for (List<Integer> list : rowList) {
                 crnRows.addAll(list);
             }
-        }else {
+        } else {
             throw new CoolException("鏈煡璁惧绫诲瀷");
         }
 
@@ -277,15 +363,19 @@
                 JSONObject jsonObject = JSON.parseObject(response);
                 if (jsonObject.getInteger("code") == 200) {
                     result = 1;
-                    News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
-                }else {
-                    News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
+                    News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛鎴愬姛锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl,
+                            JSON.toJSONString(requestParam), response);
+                } else {
+                    News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛澶辫触锛屾帴鍙h繑鍥濩ode寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}",
+                            wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
                 }
-            }else {
-                News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response);
+            } else {
+                News.info("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛澶辫触锛屾帴鍙f湭鍝嶅簲锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl,
+                        JSON.toJSONString(requestParam), response);
             }
         } catch (Exception e) {
-            News.error("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl, JSON.toJSONString(requestParam), response, e);
+            News.error("璇锋眰WMS鐢宠鏇存崲搴撲綅鎺ュ彛寮傚父锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + wmsSystemChangeLocNoUrl,
+                    JSON.toJSONString(requestParam), response, e);
         } finally {
             HttpRequestLog httpRequestLog = new HttpRequestLog();
             httpRequestLog.setName(wmsUrl + wmsSystemChangeLocNoUrl);

--
Gitblit v1.9.1