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

---
 src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java |   62 ++++++++++++++++++++++++-------
 1 files changed, 48 insertions(+), 14 deletions(-)

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 bb7fbd8..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;
@@ -140,9 +141,11 @@
                     stationProtocol.setFullPlt(statusEntity.isFullPlt());
                     stationProtocol.setPalletHeight(statusEntity.getPalletHeight());
                     stationProtocol.setError(statusEntity.getError());
+                    stationProtocol.setErrorMsg(statusEntity.getErrorMsg());
                     stationProtocol.setBarcode(statusEntity.getBarcode());
                     stationProtocol.setRunBlock(statusEntity.isRunBlock());
                     stationProtocol.setEnableIn(statusEntity.isEnableIn());
+                    stationProtocol.setWeight(statusEntity.getWeight());
                 }
             }
         }
@@ -280,11 +283,20 @@
     }
 
     private void executeMoveWithSeg(StationCommand original) {
+        int stationCommandSendLength = 20;
+        Object systemConfigMapObj = redisUtil.get(RedisKeyType.SYSTEM_CONFIG_MAP.key);
+        if (systemConfigMapObj != null) {
+            try {
+                HashMap<String, String> systemConfigMap = (HashMap<String, String>) systemConfigMapObj;
+                String stationCommandSendLengthStr = systemConfigMap.get("stationCommandSendLength");
+                if(stationCommandSendLengthStr != null){
+                    stationCommandSendLength = Integer.parseInt(stationCommandSendLengthStr);
+                }
+            } catch (Exception ignore) {}
+        }
+
         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;
             }
@@ -294,7 +306,7 @@
             List<Integer> segmentEndIndices = new ArrayList<>();
             int idx = 0;
             while (idx < total) {
-                int end = Math.min(idx + 20, total) - 1;
+                int end = Math.min(idx + stationCommandSendLength, total) - 1;
                 segmentTargets.add(path.get(end));
                 segmentEndIndices.add(end);
                 idx = end + 1;
@@ -314,22 +326,30 @@
             segCmd.setNavigatePath(new ArrayList<>(path.subList(0, currentEndIdx + 1)));
             sendCommand(segCmd);
 
-            boolean finished = false;
-            while (!finished) {
+            long runTime = System.currentTimeMillis();
+            boolean firstRun = true;
+            while (true) {
                 try {
-                    Integer currentStationId = findCurrentStationByTask(original.getTaskNo());
-                    if (currentStationId == null) {
+                    StationProtocol currentStation = findCurrentStationByTask(original.getTaskNo());
+                    if (currentStation == null) {
+                        if(System.currentTimeMillis() - runTime > 1000 * 60){
+                            break;
+                        }
                         Thread.sleep(500);
                         continue;
                     }
-                    int currentIndex = path.indexOf(currentStationId);
+
+                    runTime = System.currentTimeMillis();
+                    if (!firstRun && currentStation.isRunBlock()) {
+                        break;
+                    }
+                    int currentIndex = path.indexOf(currentStation.getStationId());
                     if (currentIndex < 0) {
                         Thread.sleep(500);
                         continue;
                     }
                     int remaining = total - currentIndex - 1;
                     if (remaining <= 0) {
-                        finished = true;
                         break;
                     }
                     int currentSegEndIndex = path.indexOf(segmentTargets.get(segCursor));
@@ -349,19 +369,33 @@
                         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);
         }
     }
 
-    private Integer findCurrentStationByTask(Integer taskNo) {
+    private StationProtocol findCurrentStationByTask(Integer taskNo) {
         try {
             com.zy.asrs.service.DeviceConfigService deviceConfigService = SpringUtils.getBean(com.zy.asrs.service.DeviceConfigService.class);
             if (deviceConfigService == null) {
@@ -380,7 +414,7 @@
                 }
                 for (StationProtocol sp : m.values()) {
                     if (sp.getTaskNo() != null && sp.getTaskNo().equals(taskNo) && sp.isLoading()) {
-                        return sp.getStationId();
+                        return sp;
                     }
                 }
             }

--
Gitblit v1.9.1