From d2f410e1149597b9743c5e195f6b54a1504cf2d4 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 20 三月 2026 20:18:26 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/common/utils/NavigateUtils.java |   68 ++++++++++++++++++++++++++++++---
 1 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NavigateUtils.java b/src/main/java/com/zy/common/utils/NavigateUtils.java
index 11ec85c..152b125 100644
--- a/src/main/java/com/zy/common/utils/NavigateUtils.java
+++ b/src/main/java/com/zy/common/utils/NavigateUtils.java
@@ -73,10 +73,21 @@
     private StationTaskTraceRegistry stationTaskTraceRegistry;
 
     public synchronized List<NavigateNode> calcByStationId(Integer startStationId, Integer endStationId) {
-        return calcByStationId(startStationId, endStationId, null);
+        return calcByStationId(startStationId, endStationId, null, false);
     }
 
     public synchronized List<NavigateNode> calcByStationId(Integer startStationId, Integer endStationId, Integer currentTaskNo) {
+        return calcByStationId(startStationId, endStationId, currentTaskNo, false);
+    }
+
+    public synchronized List<NavigateNode> calcReachablePathByStationId(Integer startStationId, Integer endStationId) {
+        return calcByStationId(startStationId, endStationId, null, true);
+    }
+
+    private synchronized List<NavigateNode> calcByStationId(Integer startStationId,
+                                                            Integer endStationId,
+                                                            Integer currentTaskNo,
+                                                            boolean reachabilityOnly) {
         BasStation startStation = basStationService.getById(startStationId);
         if (startStation == null) {
             throw new CoolException("鏈壘鍒拌 璧风偣 瀵瑰簲鐨勭珯鐐规暟鎹�");
@@ -130,7 +141,9 @@
 
         startTime = System.currentTimeMillis();
         News.info("[WCS Debug] 绔欑偣璺緞鏉冮噸寮�濮嬪垎鏋�,startStationId={},endStationId={}", startStationId, endStationId);
-        List<NavigateNode> list = findStationBestPathTwoStage(allList, resolvedPolicy, currentTaskNo);
+        List<NavigateNode> list = reachabilityOnly
+                ? findStationReachablePath(allList, resolvedPolicy, startStationId, endStationId)
+                : findStationBestPathTwoStage(allList, resolvedPolicy, currentTaskNo, startStationId, endStationId);
         News.info("[WCS Debug] 绔欑偣璺緞鏉冮噸鍒嗘瀽瀹屾垚锛岃�楁椂锛歿}ms", System.currentTimeMillis() - startTime);
 
         //鍘婚噸
@@ -288,9 +301,42 @@
         return new StationPathResolvedPolicy();
     }
 
+    private List<NavigateNode> findStationReachablePath(List<List<NavigateNode>> allList,
+                                                        StationPathResolvedPolicy resolvedPolicy,
+                                                        Integer startStationId,
+                                                        Integer endStationId) {
+        if (allList == null || allList.isEmpty()) {
+            return new ArrayList<>();
+        }
+
+        StationPathRuleConfig ruleConfig = resolvedPolicy.getRuleConfig() == null
+                ? new StationPathRuleConfig()
+                : resolvedPolicy.getRuleConfig();
+
+        List<List<NavigateNode>> filteredCandidates = applyRuleFilters(allList, ruleConfig, true);
+        if (filteredCandidates.isEmpty() && hasWaypoint(ruleConfig) && !strictWaypoint(ruleConfig)) {
+            filteredCandidates = applyRuleFilters(allList, ruleConfig, false);
+            News.info("[WCS Debug] 绔欑偣璺緞鍙揪鎬ц鍒欏凡闄嶇骇锛屽拷鐣ュ叧閿�旂粡鐐圭害鏉熷悗閲嶈瘯");
+        }
+        if (filteredCandidates.isEmpty()) {
+            if (resolvedPolicy.matchedRule()) {
+                News.warn("绔欑偣璺緞瑙勫垯鍛戒腑浣嗘棤鍙揪璺緞锛宺uleCode={},startStationId={},endStationId={}",
+                        resolvedPolicy.getRuleEntity() == null ? "" : resolvedPolicy.getRuleEntity().getRuleCode(),
+                        startStationId, endStationId);
+                return new ArrayList<>();
+            }
+            filteredCandidates = allList;
+        }
+
+        filteredCandidates.sort((left, right) -> compareReachabilityPath(left, right));
+        return filteredCandidates.isEmpty() ? new ArrayList<>() : filteredCandidates.get(0);
+    }
+
     private List<NavigateNode> findStationBestPathTwoStage(List<List<NavigateNode>> allList,
                                                            StationPathResolvedPolicy resolvedPolicy,
-                                                           Integer currentTaskNo) {
+                                                           Integer currentTaskNo,
+                                                           Integer startStationId,
+                                                           Integer endStationId) {
         if (allList == null || allList.isEmpty()) {
             return new ArrayList<>();
         }
@@ -353,12 +399,10 @@
         if (metricsList.isEmpty()) {
             if (globalPolicy.forceSkipPassOtherOutStation && skippedByOtherOutStation > 0) {
                 News.warn("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽洜缁忚繃鍏朵粬鍑哄簱绔欑偣,startStationId={},endStationId={}",
-                        resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getStartStationId(),
-                        resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getEndStationId());
+                        startStationId, endStationId);
             } else if (skippedByLoopMergeGuard > 0) {
                 News.warn("[WCS Debug] 绔欑偣璺緞鍊欓�夊叏閮ㄨ杩囨护锛屽洜鍒嗗弶鍙f彃鍏ョ幆绾夸富骞蹭細褰卞搷涓诲共閬�,startStationId={},endStationId={}",
-                        resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getStartStationId(),
-                        resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getEndStationId());
+                        startStationId, endStationId);
             }
             return new ArrayList<>();
         }
@@ -672,6 +716,16 @@
         return count;
     }
 
+    private int compareReachabilityPath(List<NavigateNode> left, List<NavigateNode> right) {
+        int leftLen = left == null ? Integer.MAX_VALUE : left.size();
+        int rightLen = right == null ? Integer.MAX_VALUE : right.size();
+        int leftTurnCount = countTurnCount(left);
+        int rightTurnCount = countTurnCount(right);
+        int leftLiftCount = countLiftTransferCount(left);
+        int rightLiftCount = countLiftTransferCount(right);
+        return compareDouble(leftLen, rightLen, leftTurnCount, rightTurnCount, leftLiftCount, rightLiftCount);
+    }
+
     private int countLiftTransferCount(List<NavigateNode> path) {
         int count = 0;
         for (NavigateNode node : safeList(path)) {

--
Gitblit v1.9.1