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

---
 src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java |   99 +++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 78 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java b/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
index 99d4dd9..a0f0ae3 100644
--- a/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
+++ b/src/main/java/com/zy/core/network/fake/ZyStationFakeConnect.java
@@ -20,6 +20,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import java.util.Random;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -31,6 +32,7 @@
  * 杈撻�佺珯鍋囪繛鎺ワ紙妯℃嫙锛�
  */
 public class ZyStationFakeConnect implements ZyStationConnectApi {
+    private static final long DEFAULT_FAKE_RUN_BLOCK_TIMEOUT_MS = 10000L;
 
     private static int LOCK_STATION = 0;
     private HashMap<Integer, List<ZyStationStatusEntity>> deviceStatusMap = new HashMap<>();
@@ -129,6 +131,10 @@
         }
 
         if(commandType == StationCommandType.WRITE_INFO){
+            if (command.getBarcode() != null) {
+                updateStationBarcode(deviceNo, stationId, command.getBarcode());
+                return;
+            }
             if (taskNo == 9998 && targetStationId == 0) {
                 //鐢熸垚鍑哄簱绔欑偣浠跨湡鏁版嵁
                 generateFakeOutStationData(deviceNo, stationId);
@@ -199,6 +205,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);
+        }
+    }
+
     private void currentLevCommand(StationCommand command, boolean generateBarcode) {
         NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
         if (navigateUtils == null) {
@@ -209,14 +232,14 @@
         Integer stationId = command.getStationId();
         Integer targetStationId = command.getTargetStaNo();
 
-        List<NavigateNode> navigateNodes = null;
+        List<NavigateNode> navigateNodes = new ArrayList<>();
         try {
             navigateNodes = navigateUtils.calcByStationId(stationId, targetStationId);
         } catch (Exception e) {
             e.printStackTrace();
         }
 
-        if (navigateNodes == null) {
+        if (navigateNodes.isEmpty()) {
             return;
         }
 
@@ -237,16 +260,16 @@
         Integer stationId = command.getStationId();
         Integer targetStationId = command.getTargetStaNo();
 
-        List<NavigateNode> navigateNodes = null;
-        List<NavigateNode> targetNavigateNodes = null;
+        List<NavigateNode> navigateNodes = new ArrayList<>();
+        List<NavigateNode> targetNavigateNodes = new ArrayList<>();
 
         try {
-            BasStation startStation = basStationService.selectById(stationId);
+            BasStation startStation = basStationService.getById(stationId);
             if (startStation == null) {
                 return;
             }
 
-            BasStation targetStation = basStationService.selectById(targetStationId);
+            BasStation targetStation = basStationService.getById(targetStationId);
             if (targetStation == null) {
                 return;
             }
@@ -287,14 +310,22 @@
                     continue;
                 }
 
-                navigateNodes = navigateUtils.calcByStationId(stationId, liftStationId);
-                if(navigateNodes == null){
+                try {
+                    navigateNodes = navigateUtils.calcByStationId(stationId, liftStationId);
+                } catch (Exception e) {
+
+                }
+                if(navigateNodes.isEmpty()){
                     continue;
                 }
 
-                //璁$畻鎻愬崌鏈哄埌鐩爣绔欑殑璺緞
-                targetNavigateNodes = navigateUtils.calcByStationId(targetLiftStationId, targetStationId);
-                if(targetNavigateNodes == null) {
+                try {
+                    //璁$畻鎻愬崌鏈哄埌鐩爣绔欑殑璺緞
+                    targetNavigateNodes = navigateUtils.calcByStationId(targetLiftStationId, targetStationId);
+                } catch (Exception e) {
+
+                }
+                if(targetNavigateNodes.isEmpty()) {
                     continue;
                 }
             }
@@ -302,7 +333,7 @@
             e.printStackTrace();
         }
 
-        if (navigateNodes == null || targetNavigateNodes == null) {
+        if (navigateNodes.isEmpty() || targetNavigateNodes.isEmpty()) {
             return;
         }
 
@@ -317,6 +348,7 @@
         Integer targetStationDeviceNo = null;
 
         long executeTime = System.currentTimeMillis();
+        long runBlockTimeoutMs = getFakeRunBlockTimeoutMs();
         int i = 0;
         while (i < navigateNodes.size()) {
             if (Thread.currentThread().isInterrupted()) {
@@ -343,16 +375,9 @@
             }
 
             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;
-                    }
-                }
+                boolean fakeAllowCheckBlock = getFakeAllowCheckBlock();
 
-                if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > 1000 * 10) {
+                if (fakeAllowCheckBlock && System.currentTimeMillis() - executeTime > runBlockTimeoutMs) {
                     //璁ゅ畾鍫靛
                     boolean result = runBlockStation(taskNo, currentStationId, currentStationDeviceNo, taskNo, currentStationId);
                     if(!result) {
@@ -658,6 +683,38 @@
         return result;
     }
 
+    private boolean getFakeAllowCheckBlock() {
+        boolean fakeAllowCheckBlock = true;
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj instanceof Map) {
+            Map<?, ?> systemConfigMap = (Map<?, ?>) systemConfigMapObj;
+            Object value = systemConfigMap.get("fakeAllowCheckBlock");
+            if (value != null && !"Y".equals(String.valueOf(value))) {
+                fakeAllowCheckBlock = false;
+            }
+        }
+        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;
+    }
+
     private boolean checkTaskNoInArea(Integer taskNo) {
         Object fakeTaskNoAreaObj = redisUtil.get(RedisKeyType.FAKE_TASK_NO_AREA.key);
         if (fakeTaskNoAreaObj == null) {

--
Gitblit v1.9.1