Junjie
21 小时以前 ed266efb662c5b8460ecc22e31a070a718f35f9c
src/main/java/com/zy/common/utils/NavigateSolution.java
@@ -399,12 +399,16 @@
    }
    private Integer extractStationId(NavigateNode node) {
        if (node == null || !"devp".equals(node.getNodeType())) {
        JSONObject valueObj = parseNodeValue(node == null ? null : node.getNodeValue());
        return valueObj == null ? null : valueObj.getInteger("stationId");
    }
    private JSONObject parseNodeValue(String nodeValue) {
        if (nodeValue == null || nodeValue.trim().isEmpty()) {
            return null;
        }
        try {
            JSONObject valueObj = JSON.parseObject(node.getNodeValue());
            return valueObj == null ? null : valueObj.getInteger("stationId");
            return JSON.parseObject(nodeValue);
        } catch (Exception ignore) {
            return null;
        }
@@ -503,18 +507,60 @@
    }
    public NavigateNode findStationNavigateNode(List<List<NavigateNode>> map, int stationId) {
        NavigateNode bestNode = null;
        int bestExternalConnectionCount = -1;
        int bestNeighborCount = -1;
        for(int x = 0; x < map.size(); x++) {
            for(int y = 0; y < map.get(0).size(); y++) {
                NavigateNode node = map.get(x).get(y);
                if("devp".equals(node.getNodeType())) {
                    JSONObject valueObj = JSON.parseObject(node.getNodeValue());
                    if(valueObj.getInteger("stationId") == stationId) {
                        return node;
                Integer currentStationId = extractStationId(node);
                if (currentStationId == null || currentStationId != stationId) {
                    continue;
                }
                ArrayList<NavigateNode> neighbors = extend_current_node(map, node);
                int externalConnectionCount = countExternalConnectionCount(stationId, neighbors);
                int neighborCount = neighbors == null ? 0 : neighbors.size();
                if (externalConnectionCount > bestExternalConnectionCount
                        || (externalConnectionCount == bestExternalConnectionCount && neighborCount > bestNeighborCount)) {
                    bestNode = node;
                    bestExternalConnectionCount = externalConnectionCount;
                    bestNeighborCount = neighborCount;
                    }
                }
            }
        return bestNode;
        }
        return null;
    private int countExternalConnectionCount(Integer currentStationId, List<NavigateNode> neighbors) {
        Set<Integer> connectedStationIdSet = new LinkedHashSet<>();
        if (neighbors == null || neighbors.isEmpty()) {
            return 0;
        }
        for (NavigateNode neighbor : neighbors) {
            connectedStationIdSet.addAll(resolveAdjacentStationIds(currentStationId, neighbor));
        }
        return connectedStationIdSet.size();
    }
    private Set<Integer> resolveAdjacentStationIds(Integer currentStationId, NavigateNode node) {
        Set<Integer> stationIdSet = new LinkedHashSet<>();
        JSONObject valueObj = parseNodeValue(node == null ? null : node.getNodeValue());
        if (valueObj == null) {
            return stationIdSet;
        }
        Integer directStationId = valueObj.getInteger("stationId");
        if (directStationId != null && !directStationId.equals(currentStationId)) {
            stationIdSet.add(directStationId);
        }
        if (valueObj.getJSONArray("bridgeStationIds") == null) {
            return stationIdSet;
        }
        for (Integer bridgeStationId : valueObj.getJSONArray("bridgeStationIds").toJavaList(Integer.class)) {
            if (bridgeStationId != null && !bridgeStationId.equals(currentStationId)) {
                stationIdSet.add(bridgeStationId);
            }
        }
        return stationIdSet;
    }
    public NavigateNode findTrackSiteNoNavigateNode(List<List<NavigateNode>> map, int trackSiteNo) {