From 644c041d75574ad0ce318c81dc15cb74849f816a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期四, 26 三月 2026 21:11:11 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java |   89 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 78 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
index f8d7abb..6f633a9 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV5Thread.java
@@ -28,6 +28,7 @@
 import com.zy.core.model.Task;
 import com.zy.core.model.command.StationCommand;
 import com.zy.core.model.protocol.StationProtocol;
+import com.zy.core.model.protocol.StationTaskBufferItem;
 import com.zy.core.network.DeviceConnectPool;
 import com.zy.core.network.ZyStationConnectDriver;
 import com.zy.core.network.entity.ZyStationStatusEntity;
@@ -171,6 +172,7 @@
                     stationProtocol.setEnableIn(statusEntity.isEnableIn());
                     stationProtocol.setWeight(statusEntity.getWeight());
                     stationProtocol.setTaskWriteIdx(statusEntity.getTaskWriteIdx());
+                    stationProtocol.setTaskBufferItems(statusEntity.getTaskBufferItems());
                 }
 
                 if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
@@ -238,6 +240,16 @@
                                      Integer stationId,
                                      Integer targetStationId,
                                      Integer palletSize) {
+        return getCommand(commandType, taskNo, stationId, targetStationId, palletSize, null);
+    }
+
+    @Override
+    public StationCommand getCommand(StationCommandType commandType,
+                                     Integer taskNo,
+                                     Integer stationId,
+                                     Integer targetStationId,
+                                     Integer palletSize,
+                                     Double pathLenFactor) {
         StationCommand stationCommand = new StationCommand();
         stationCommand.setTaskNo(taskNo);
         stationCommand.setStationId(stationId);
@@ -246,7 +258,7 @@
         stationCommand.setCommandType(commandType);
 
         if (commandType == StationCommandType.MOVE && !stationId.equals(targetStationId)) {
-            List<NavigateNode> nodes = calcPathNavigateNodes(taskNo, stationId, targetStationId);
+            List<NavigateNode> nodes = calcPathNavigateNodes(taskNo, stationId, targetStationId, pathLenFactor);
             return fillMoveCommandPath(stationCommand, nodes, taskNo, stationId, targetStationId);
         }
         return stationCommand;
@@ -257,11 +269,20 @@
                                                                  Integer stationId,
                                                                  Integer targetStationId,
                                                                  Integer palletSize) {
+        return getRunBlockRerouteCommand(taskNo, stationId, targetStationId, palletSize, null);
+    }
+
+    @Override
+    public synchronized StationCommand getRunBlockRerouteCommand(Integer taskNo,
+                                                                 Integer stationId,
+                                                                 Integer targetStationId,
+                                                                 Integer palletSize,
+                                                                 Double pathLenFactor) {
         if (taskNo == null || taskNo <= 0 || stationId == null || targetStationId == null) {
             return null;
         }
         if (Objects.equals(stationId, targetStationId)) {
-            return getCommand(StationCommandType.MOVE, taskNo, stationId, targetStationId, palletSize);
+            return getCommand(StationCommandType.MOVE, taskNo, stationId, targetStationId, palletSize, pathLenFactor);
         }
 
         RunBlockRerouteState rerouteState = loadRunBlockRerouteState(taskNo, stationId);
@@ -281,7 +302,7 @@
         rerouteState.setPlanCount((rerouteState.getPlanCount() == null ? 0 : rerouteState.getPlanCount()) + 1);
         rerouteState.setLastPlanTime(System.currentTimeMillis());
 
-        List<List<NavigateNode>> candidatePathList = calcCandidatePathNavigateNodes(taskNo, stationId, targetStationId);
+        List<List<NavigateNode>> candidatePathList = calcCandidatePathNavigateNodes(taskNo, stationId, targetStationId, pathLenFactor);
         if (candidatePathList.isEmpty()) {
             saveRunBlockRerouteState(rerouteState);
             log.warn("杈撻�佺嚎鍫靛閲嶈鍒掑け璐ワ紝鍊欓�夎矾寰勪负绌猴紝taskNo={}, planCount={}, stationId={}, targetStationId={}",
@@ -334,6 +355,47 @@
     }
 
     @Override
+    public synchronized boolean clearPath(Integer taskNo) {
+        if (taskNo == null || taskNo <= 0) {
+            return false;
+        }
+        if (zyStationConnectDriver == null) {
+            return false;
+        }
+        List<StationProtocol> status = getStatus();
+        if (status == null || status.isEmpty()) {
+            return false;
+        }
+
+        boolean found = false;
+        boolean success = true;
+        for (StationProtocol stationProtocol : status) {
+            List<StationTaskBufferItem> taskBufferItems = stationProtocol == null ? null : stationProtocol.getTaskBufferItems();
+            if (taskBufferItems == null || taskBufferItems.isEmpty()) {
+                continue;
+            }
+            Integer stationId = stationProtocol.getStationId();
+            for (StationTaskBufferItem item : taskBufferItems) {
+                if (item == null || !Objects.equals(taskNo, item.getTaskNo())) {
+                    continue;
+                }
+                found = true;
+                if (!zyStationConnectDriver.clearTaskBufferSlot(stationId, item.getSlotIdx())) {
+                    success = false;
+                    log.warn("杈撻�佺珯缂撳瓨鍖烘畫鐣欒矾寰勬竻鐞嗗け璐ャ�俿tationId={}, slotIdx={}, taskNo={}",
+                            stationId, item.getSlotIdx(), item.getTaskNo());
+                    continue;
+                }else {
+                    success = true;
+                    log.warn("杈撻�佺珯缂撳瓨鍖烘畫鐣欒矾寰勬竻鐞嗘垚鍔熴�俿tationId={}, slotIdx={}, taskNo={}",
+                            stationId, item.getSlotIdx(), item.getTaskNo());
+                }
+            }
+        }
+        return found && success;
+    }
+
+    @Override
     public CommandResponse sendCommand(StationCommand command) {
         CommandResponse commandResponse = null;
         try {
@@ -342,6 +404,9 @@
             e.printStackTrace();
         } finally {
             BasStationOptService optService = SpringUtils.getBean(BasStationOptService.class);
+            if (optService == null) {
+                return commandResponse;
+            }
             List<ZyStationStatusEntity> statusListEntity = zyStationConnectDriver.getStatus();
             ZyStationStatusEntity matched = null;
             if (statusListEntity != null) {
@@ -364,12 +429,10 @@
                     null,
                     JSON.toJSONString(command),
                     JSON.toJSONString(matched),
-                    1,
+                    commandResponse != null && Boolean.TRUE.equals(commandResponse.getResult()) ? 1 : 0,
                     JSON.toJSONString(commandResponse)
             );
-            if (optService != null) {
-                optService.save(basStationOpt);
-            }
+            optService.save(basStationOpt);
         }
         return commandResponse;
     }
@@ -384,22 +447,26 @@
         return zyStationConnectDriver.readOriginCommand(address, length);
     }
 
-    private List<NavigateNode> calcPathNavigateNodes(Integer taskNo, Integer startStationId, Integer targetStationId) {
+    private List<NavigateNode> calcPathNavigateNodes(Integer taskNo,
+                                                     Integer startStationId,
+                                                     Integer targetStationId,
+                                                     Double pathLenFactor) {
         NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
         if (navigateUtils == null) {
             return new ArrayList<>();
         }
-        return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo);
+        return navigateUtils.calcByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
     }
 
     private List<List<NavigateNode>> calcCandidatePathNavigateNodes(Integer taskNo,
                                                                     Integer startStationId,
-                                                                    Integer targetStationId) {
+                                                                    Integer targetStationId,
+                                                                    Double pathLenFactor) {
         NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
         if (navigateUtils == null) {
             return new ArrayList<>();
         }
-        return navigateUtils.calcCandidatePathByStationId(startStationId, targetStationId, taskNo);
+        return navigateUtils.calcCandidatePathByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
     }
 
     private StationCommand buildMoveCommand(Integer taskNo,

--
Gitblit v1.9.1