Junjie
2026-04-27 57451dc26944cb99f9b16c81044d44f7fce681c9
fix: keep flow topology independent from capacity
2个文件已修改
37 ■■■■ 已修改文件
src/main/java/com/zy/ai/service/impl/FlowTopologySnapshotServiceImpl.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/ai/service/impl/FlowTopologySnapshotServiceImpl.java
@@ -50,7 +50,7 @@
        Integer targetStationId = capacity.getStationId();
        Integer bufferCapacity = defaultInt(capacity.getBufferCapacity());
        List<Integer> adjacentStationIds = sortedList(adjacencyMap == null ? null : adjacencyMap.get(targetStationId));
        List<Integer> flowStationIds = buildFlowStationIds(targetStationId, adjacentStationIds, bufferCapacity);
        List<Integer> flowStationIds = buildFlowStationIds(targetStationId, adjacentStationIds);
        List<AutoTuneStationRuntimeItem> flowRuntimeItems = filterRuntimeByStationIds(stationRuntimeSnapshot, flowStationIds);
        RuntimeCount runtimeCount = calculateRuntimeCount(flowRuntimeItems);
@@ -143,18 +143,13 @@
    }
    private List<Integer> buildFlowStationIds(Integer targetStationId,
                                             List<Integer> adjacentStationIds,
                                             Integer bufferCapacity) {
                                             List<Integer> adjacentStationIds) {
        LinkedHashSet<Integer> stationIds = new LinkedHashSet<>();
        if (targetStationId != null) {
            stationIds.add(targetStationId);
        }
        stationIds.addAll(sortedList(adjacentStationIds));
        List<Integer> flowStationIds = new ArrayList<>(stationIds);
        if (bufferCapacity == null || bufferCapacity <= 0 || flowStationIds.size() <= bufferCapacity) {
            return flowStationIds;
        }
        return new ArrayList<>(flowStationIds.subList(0, bufferCapacity));
        return new ArrayList<>(stationIds);
    }
    private List<AutoTuneStationRuntimeItem> filterRuntimeByStationIds(List<AutoTuneStationRuntimeItem> runtimeItems,
src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java
@@ -70,6 +70,32 @@
        assertEquals("OUT", result.getDirectionCode());
    }
    @Test
    void flowStationIdsAndCountsAreNotTruncatedByBufferCapacity() {
        FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
        StationFlowCapacity capacity = capacity(101, "OUT", 1);
        Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
        adjacency.put(101, Arrays.asList(104, 102, 103));
        AutoTuneFlowTopologyItem item = service.buildTopologyItem(
                capacity,
                adjacency,
                Arrays.asList(
                        runtime(101, 1, 0, 0),
                        runtime(102, 1, 1, 0),
                        runtime(103, 1, 0, 9001),
                        runtime(104, 0, 0, 0)
                )
        );
        assertEquals(Arrays.asList(101, 102, 103, 104), item.getFlowStationIds());
        assertEquals(2, item.getOccupiedCount());
        assertEquals(1, item.getLoadingCount());
        assertEquals(1, item.getTaskHoldingCount());
        assertEquals(1, item.getNonAutoingCount());
        assertEquals(0, item.getFreeCount());
    }
    private StationFlowCapacity capacity(Integer stationId, String directionCode, Integer bufferCapacity) {
        StationFlowCapacity capacity = new StationFlowCapacity();
        capacity.setStationId(stationId);