From 720e0926fa1c94b952c26e111206c5d6e1ed5ba2 Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期二, 21 四月 2026 15:59:49 +0800
Subject: [PATCH] Merge branch 'master' of http://47.97.1.152:5880/r/zy-wcs-master

---
 src/main/java/com/zy/core/move/StationMoveCoordinator.java |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/zy/core/move/StationMoveCoordinator.java b/src/main/java/com/zy/core/move/StationMoveCoordinator.java
index 2e6c0c3..2f167e1 100644
--- a/src/main/java/com/zy/core/move/StationMoveCoordinator.java
+++ b/src/main/java/com/zy/core/move/StationMoveCoordinator.java
@@ -5,6 +5,7 @@
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.enums.RedisKeyType;
 import com.zy.core.model.command.StationCommand;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -20,10 +21,13 @@
 import java.util.Objects;
 import java.util.function.Supplier;
 
+@Slf4j
 @Component
 public class StationMoveCoordinator {
 
     private static final int SESSION_EXPIRE_SECONDS = 60 * 60 * 24;
+    private static final long TASK_DISPATCH_LOCK_SLOW_THRESHOLD_MS = 50L;
+    private static final long RECORD_DISPATCH_SLOW_THRESHOLD_MS = 50L;
     private final Map<Integer, ReentrantLock> taskDispatchLocks = new ConcurrentHashMap<>();
 
     @Autowired
@@ -79,6 +83,7 @@
         if (session == null || !session.isActive()) {
             return;
         }
+        log.info("markCancelPending, taskNo={}, routeVersion={}, cancelReason={}", taskNo, session.getRouteVersion(), cancelReason);
         session.setStatus(StationMoveSession.STATUS_CANCEL_PENDING);
         session.setCancelReason(cancelReason);
         saveSession(session);
@@ -91,12 +96,18 @@
         if (taskNo == null || taskNo <= 0) {
             return supplier.get();
         }
-        // 鍚屼竴浠诲姟鐨勫垏璺拰鍒嗘鍙戦�佸繀椤诲叡浜竴鎶婇攣锛岄伩鍏嶆棫 routeVersion 鍦ㄧ嚎绋嬫櫄鍒版椂缁х画鎶婁笂涓�鏉℃鍛戒护鍐欏嚭鍘汇��
         ReentrantLock lock = taskDispatchLocks.computeIfAbsent(taskNo, key -> new ReentrantLock());
+        long waitStartMs = System.currentTimeMillis();
         lock.lock();
+        long lockWaitMs = System.currentTimeMillis() - waitStartMs;
+        long holdStartMs = System.currentTimeMillis();
         try {
             return supplier.get();
         } finally {
+            long holdMs = System.currentTimeMillis() - holdStartMs;
+            if (lockWaitMs > TASK_DISPATCH_LOCK_SLOW_THRESHOLD_MS || holdMs > TASK_DISPATCH_LOCK_SLOW_THRESHOLD_MS) {
+                log.warn("taskDispatchLock slow, taskNo={}, lockWaitMs={}ms, lockHoldMs={}ms", taskNo, lockWaitMs, holdMs);
+            }
             lock.unlock();
         }
     }
@@ -135,6 +146,7 @@
             return null;
         }
 
+        long startMs = System.currentTimeMillis();
         StationMoveSession current = loadSession(taskNo);
         long now = System.currentTimeMillis();
         String pathSignature = buildPathSignature(command);
@@ -174,6 +186,16 @@
 
         command.setRouteVersion(session.getRouteVersion());
         saveSession(session);
+        long recordDispatchCostMs = System.currentTimeMillis() - startMs;
+        log.info("recordDispatch done, taskNo={}, routeVersion={}, reuse={}, prevRouteVersion={}, dispatchStationId={}, triggerName={}, recordDispatchCostMs={}ms",
+                taskNo, session.getRouteVersion(), reuseCurrent,
+                current == null ? null : current.getRouteVersion(),
+                dispatchStationId, triggerName, recordDispatchCostMs);
+        if (recordDispatchCostMs > RECORD_DISPATCH_SLOW_THRESHOLD_MS) {
+            log.warn("recordDispatch slow, taskNo={}, dispatchStationId={}, triggerName={}, recordDispatchCostMs={}ms, pathSize={}",
+                    taskNo, dispatchStationId, triggerName, recordDispatchCostMs,
+                    fullPathStationIds == null ? 0 : fullPathStationIds.size());
+        }
 
         if (circleRoute) {
             saveLegacyCircleCommand(taskNo, command);
@@ -190,6 +212,7 @@
             clearLegacyCircleCommand(taskNo);
             return null;
         }
+        log.info("cancelSession, taskNo={}, routeVersion={}, cancelReason=reroute_cancelled", taskNo, session.getRouteVersion());
         session.setStatus(StationMoveSession.STATUS_CANCELLED);
         session.setCancelReason("reroute_cancelled");
         saveSession(session);
@@ -241,8 +264,11 @@
         }
         StationMoveSession session = sessionRegistry.load(taskNo);
         if (session == null || !Objects.equals(session.getRouteVersion(), routeVersion)) {
+            log.warn("updateTerminal skipped: session mismatch, taskNo={}, cmdRouteVersion={}, sessionRouteVersion={}, targetStatus={}, cancelReason={}",
+                    taskNo, routeVersion, session == null ? null : session.getRouteVersion(), status, cancelReason);
             return;
         }
+        log.info("updateTerminal, taskNo={}, routeVersion={}, status={}, cancelReason={}", taskNo, routeVersion, status, cancelReason);
         session.setCurrentStationId(currentStationId);
         session.setStatus(status);
         session.setCancelReason(cancelReason);

--
Gitblit v1.9.1