#
Junjie
1 天以前 fd5f427018a1d308da9fcb4104c9f5340419ee78
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("站点路径规则命中但无可达路径,ruleCode={},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] 站点路径候选全部被过滤,因分叉口插入环线主干会影响主干道,startStationId={},endStationId={}",
                        resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getStartStationId(),
                        resolvedPolicy.getRuleEntity() == null ? null : resolvedPolicy.getRuleEntity().getEndStationId());
                        startStationId, endStationId);
            }
            return new ArrayList<>();
        }
@@ -670,6 +714,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) {
@@ -1196,42 +1250,7 @@
                                           StationTrafficSnapshot trafficSnapshot,
                                           LoopMergeGuardContext loopMergeGuardContext,
                                           Set<LoopMergeEntry> mandatoryLoopMergeEntrySet) {
        if (path == null || path.size() < 2 || loopMergeGuardContext == null || loopMergeGuardContext.loopStationIdSet.isEmpty()) {
            return true;
        }
        List<Integer> stationIdList = extractStationIdList(path);
        if (stationIdList.size() < 2) {
            return true;
        }
        for (int i = 1; i < stationIdList.size(); i++) {
            Integer prevStationId = stationIdList.get(i - 1);
            Integer currentStationId = stationIdList.get(i);
            if (prevStationId == null || currentStationId == null) {
                continue;
            }
            if (loopMergeGuardContext.loopStationIdSet.contains(prevStationId)
                    || !loopMergeGuardContext.loopStationIdSet.contains(currentStationId)) {
                continue;
            }
            Set<Integer> trunkNeighborSet = loopMergeGuardContext.loopNeighborMap.getOrDefault(currentStationId, Collections.emptySet());
            if (trunkNeighborSet.size() < 2) {
                continue;
            }
            LoopMergeEntry currentEntry = new LoopMergeEntry(prevStationId, currentStationId);
            for (Integer trunkNeighborStationId : trunkNeighborSet) {
                if (isStationOccupiedForLoopMerge(trunkNeighborStationId, statusMap, trafficSnapshot)) {
                    return false;
                }
            }
            boolean mandatoryEntry = mandatoryLoopMergeEntrySet != null && mandatoryLoopMergeEntrySet.contains(currentEntry);
            if (!mandatoryEntry && !isLoopTrunkVeryIdle(currentStationId, loopMergeGuardContext, statusMap, trafficSnapshot)) {
                return false;
            }
        }
        // 环线并入保护已停用:允许候选路径直接参与后续评分。
        return true;
    }