From bdf43f554f9bc7f0de94e7530e79af9193341334 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 19 三月 2026 15:38:49 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java |   68 ++++++++++++++++++++++++++++++----
 1 files changed, 60 insertions(+), 8 deletions(-)

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 a39b1b7..d2cfe98 100644
--- a/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyStationFakeSegConnect.java
@@ -27,6 +27,7 @@
 import java.util.Arrays;
 
 public class ZyStationFakeSegConnect implements ZyStationConnectApi {
+    private static final long DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS = 10000L;
 
     // 绔欑偣绾ч攣锛氭瘡涓珯鐐圭嫭绔嬩竴鎶婇攣锛屾彁鍗囧苟鍙戞�ц兘
     private final Map<Integer, ReentrantLock> stationLocks = new ConcurrentHashMap<>();
@@ -128,7 +129,8 @@
             boolean initialized = false;
             // 涓婁竴姝ユ墽琛屾椂闂达紙鐢ㄤ簬鍫靛妫�娴嬶級
             long stepExecuteTime = System.currentTimeMillis();
-            // 閬垮厤鍦ㄥ埌杈剧洰鏍囧悗閲嶅鎵ц鍒颁綅閫昏緫
+            long runBlockTimeoutMs = getFakeRunBlockTimeoutMs();
+            // 浠呭湪姣忔鍒拌揪鐩爣鏃舵墽琛屼竴娆″埌浣嶅鐞嗭紝閬垮厤閲嶅鐢熸垚鏉$爜
             boolean arrivalHandled = false;
 
             while (true) {
@@ -145,6 +147,15 @@
                 StationCommand command = commandQueue.poll(100, TimeUnit.MILLISECONDS);
                 if (command != null) {
                     taskLastUpdateTime.put(taskNo, System.currentTimeMillis());
+                    List<Integer> newPath = command.getNavigatePath();
+                    Integer lastInQueue = getLastInQueue(pendingPathQueue);
+                    int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
+
+                    if (newPath != null && !newPath.isEmpty() && startIndex < 0) {
+                        News.info("[WCS Debug] 浠诲姟{}蹇界暐鏃犳硶琛旀帴鐨勬棫璺緞娈�: {}, 褰撳墠浣嶇疆: {}, 闃熷垪灏�: {}", taskNo,
+                                newPath, currentStationId, lastInQueue);
+                        continue;
+                    }
 
                     // 姣忔鎺ユ敹鍛戒护閮藉埛鏂扮洰鏍囷紝閬垮厤娌跨敤鏃х洰鏍囧鑷寸姸鎬佹姈鍔�
                     Integer commandTargetStationId = command.getTargetStaNo();
@@ -164,12 +175,7 @@
                     }
 
                     // 灏嗘柊璺緞杩藉姞鍒板緟鎵ц闃熷垪
-                    List<Integer> newPath = command.getNavigatePath();
                     if (newPath != null && !newPath.isEmpty()) {
-                        // 鑾峰彇闃熷垪涓渶鍚庝竴涓珯鐐癸紙鐢ㄤ簬琛旀帴鐐瑰幓閲嶏級
-                        Integer lastInQueue = getLastInQueue(pendingPathQueue);
-                        int startIndex = getPathAppendStartIndex(newPath, currentStationId, lastInQueue);
-
                         for (int i = startIndex; i < newPath.size(); i++) {
                             pendingPathQueue.offer(newPath.get(i));
                         }
@@ -244,7 +250,8 @@
                             if (!checkTaskNoInArea(taskNo)) {
                                 boolean fakeAllowCheckBlock = getFakeAllowCheckBlock();
 
-                                if (fakeAllowCheckBlock && System.currentTimeMillis() - stepExecuteTime > 10000) {
+                                if (fakeAllowCheckBlock
+                                        && System.currentTimeMillis() - stepExecuteTime > runBlockTimeoutMs) {
                                     // 璁ゅ畾鍫靛
                                     boolean result = runBlockStation(taskNo, currentStationId, currentDeviceNo, taskNo,
                                             currentStationId);
@@ -265,7 +272,7 @@
                     // 璺緞闃熷垪涓虹┖锛岀瓑寰呮柊鐨勫垎娈靛懡浠�
                     if (currentStationId != null && finalTargetStationId != null
                             && currentStationId.equals(finalTargetStationId)) {
-                        // 宸插埌杈剧洰鏍囷紝鍏堟墽琛屼竴娆″埌浣嶉�昏緫锛岀劧鍚庣户缁瓑寰呬笅涓�鏉$Щ鍔ㄥ懡浠�
+                        // 宸插埌杈惧綋鍓嶇洰鏍囧悗缁х画绛夊緟涓嬩竴鏉″垎娈靛懡浠わ紝閬垮厤鎺掑簭/缁曞湀鍦烘櫙鍚炴帀鍚庣画鍛戒护
                         if (!arrivalHandled) {
                             if (generateBarcode) {
                                 Integer targetDeviceNo = getDeviceNoByStationId(finalTargetStationId);
@@ -330,6 +337,11 @@
             if (idx >= 0) {
                 return idx + 1;
             }
+            return -1;
+        }
+
+        if (lastInQueue != null) {
+            return -1;
         }
 
         return 0;
@@ -387,6 +399,25 @@
         return fakeAllowCheckBlock;
     }
 
+    private long getFakeRunBlockTimeoutMs() {
+        long timeoutMs = DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS;
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj instanceof Map) {
+            Map<?, ?> systemConfigMap = (Map<?, ?>) systemConfigMapObj;
+            Object value = systemConfigMap.get("fakeRunBlockTimeoutMs");
+            if (value != null) {
+                try {
+                    long parsed = Long.parseLong(String.valueOf(value).trim());
+                    if (parsed > 0) {
+                        timeoutMs = parsed;
+                    }
+                } catch (Exception ignore) {
+                }
+            }
+        }
+        return timeoutMs;
+    }
+
     @Override
     public CommandResponse sendOriginCommand(String address, short[] data) {
         return new CommandResponse(true, "鍘熷鍛戒护宸插彈鐞嗭紙寮傛鎵ц锛�");
@@ -414,6 +445,10 @@
         }
 
         if (command.getCommandType() == StationCommandType.WRITE_INFO) {
+            if (command.getBarcode() != null) {
+                updateStationBarcode(deviceNo, stationId, command.getBarcode());
+                return;
+            }
             if (taskNo == 9998 && targetStationId == 0) {
                 // 鐢熸垚鍑哄簱绔欑偣浠跨湡鏁版嵁
                 generateFakeOutStationData(deviceNo, stationId);
@@ -469,6 +504,23 @@
         }
     }
 
+    private void updateStationBarcode(Integer deviceNo, Integer stationId, String barcode) {
+        List<ZyStationStatusEntity> statusList = deviceStatusMap.get(deviceNo);
+        if (statusList == null) {
+            return;
+        }
+
+        ZyStationStatusEntity status = statusList.stream()
+                .filter(item -> item.getStationId().equals(stationId)).findFirst().orElse(null);
+        if (status == null) {
+            return;
+        }
+
+        synchronized (status) {
+            status.setBarcode(barcode);
+        }
+    }
+
     // segmentedPathCommand 鏂规硶宸插垹闄わ紝鍔熻兘宸叉暣鍚堝埌 runTaskLoop
 
     private Integer getDeviceNoByStationId(Integer stationId) {

--
Gitblit v1.9.1