From b8640dc78123f4be2483feed2f48b9183983f51f Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 13 四月 2026 14:11:54 +0800
Subject: [PATCH] #站点运行优化

---
 src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java b/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
index b3f358d..3cf4495 100644
--- a/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
+++ b/src/main/java/com/zy/core/utils/station/StationRerouteProcessor.java
@@ -51,6 +51,7 @@
 public class StationRerouteProcessor {
     private static final int OUT_ORDER_DISPATCH_LIMIT_SECONDS = 2;
     private static final long STATION_MOVE_RESET_WAIT_MS = 1000L;
+    private static final int RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS = 15 * 60;
 
     @Autowired
     private BasDevpService basDevpService;
@@ -447,15 +448,26 @@
         if (basDevp == null || stationThread == null || stationProtocol == null || wrkMast == null) {
             return;
         }
+        if (isDirectReassignContextStale(stationProtocol, wrkMast)) {
+            return;
+        }
         int currentTaskBufferCommandCount = countCurrentTaskBufferCommands(
                 stationProtocol.getTaskBufferItems(),
                 stationProtocol.getTaskNo()
         );
         if (currentTaskBufferCommandCount > 0) {
-            News.info("杈撻�佺珯鐐硅繍琛屽牭濉為噸鍒嗛厤宸茶烦杩囷紝缂撳瓨鍖轰粛瀛樺湪褰撳墠浠诲姟鍛戒护銆傜珯鐐瑰彿={}锛屽伐浣滃彿={}锛屽綋鍓嶄换鍔″懡浠ゆ暟={}",
+            News.info("杈撻�佺珯鐐硅繍琛屽牭濉為噸鍒嗛厤妫�娴嬪埌鏃у垎娈靛懡浠ゆ畫鐣欙紝灏嗗厛閲嶇疆鏈湴鍒嗘鐘舵�佸悗缁х画閲嶅彂銆傜珯鐐瑰彿={}锛屽伐浣滃彿={}锛屽綋鍓嶄换鍔″懡浠ゆ暟={}",
                     stationProtocol.getStationId(),
                     stationProtocol.getTaskNo(),
                     currentTaskBufferCommandCount);
+        }
+        if (!stationDispatchRuntimeStateSupport.tryAcquireRunBlockDirectReassignLock(
+                wrkMast.getWrkNo(),
+                stationProtocol.getStationId(),
+                RUN_BLOCK_DIRECT_REASSIGN_LIMIT_SECONDS)) {
+            News.info("杈撻�佺珯鐐硅繍琛屽牭濉為噸鍒嗛厤宸茶烦杩囷紝15鍒嗛挓鍐呬笉鍏佽閲嶅鐢宠銆傜珯鐐瑰彿={}锛屽伐浣滃彿={}",
+                    stationProtocol.getStationId(),
+                    wrkMast.getWrkNo());
             return;
         }
         String response = wmsOperateUtils.applyReassignTaskLocNo(wrkMast.getWrkNo(), stationProtocol.getStationId());
@@ -534,6 +546,7 @@
         if (!wrkMastService.updateById(wrkMast)) {
             return;
         }
+        stationDispatchRuntimeStateSupport.signalSegmentReset(wrkMast.getWrkNo(), STATION_MOVE_RESET_WAIT_MS);
         boolean offered = offerDevpCommandWithDedup(basDevp.getDevpNo(), command, "checkStationRunBlock_direct");
         if (!offered) {
             return;
@@ -551,6 +564,30 @@
         }
     }
 
+    private boolean isDirectReassignContextStale(StationProtocol stationProtocol, WrkMast wrkMast) {
+        if (stationProtocol == null || wrkMast == null || stationMoveCoordinator == null) {
+            return false;
+        }
+        Integer taskNo = wrkMast.getWrkNo();
+        Integer triggerStationId = stationProtocol.getStationId();
+        if (taskNo == null || taskNo <= 0 || triggerStationId == null) {
+            return false;
+        }
+        StationMoveSession session = stationMoveCoordinator.loadSession(taskNo);
+        if (session == null || !session.isActive()) {
+            return false;
+        }
+        Integer currentStationId = session.getCurrentStationId();
+        if (currentStationId == null || Objects.equals(currentStationId, triggerStationId)) {
+            return false;
+        }
+        News.info("杈撻�佺珯鐐硅繍琛屽牭濉為噸鍒嗛厤宸茶烦杩囷紝浠诲姟宸茬寮�瑙﹀彂绔欑偣銆傝Е鍙戠珯鐐�={}锛屽綋鍓嶇珯鐐�={}锛屽伐浣滃彿={}",
+                triggerStationId,
+                currentStationId,
+                taskNo);
+        return true;
+    }
+
     private int countCurrentTaskBufferCommands(List<StationTaskBufferItem> taskBufferItems, Integer currentTaskNo) {
         if (taskBufferItems == null || taskBufferItems.isEmpty() || currentTaskNo == null || currentTaskNo <= 0) {
             return 0;

--
Gitblit v1.9.1