From 0c336d5c5c0596691c9b33c08643c03486d47d5f Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 27 四月 2026 18:56:39 +0800
Subject: [PATCH] refactor: move station buffer capacity to bas station

---
 src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java |   59 ++++++++++++++++++++++++++++-------------------------------
 1 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java b/src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java
index 02b6565..d5d160d 100644
--- a/src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java
+++ b/src/test/java/com/zy/ai/service/FlowTopologySnapshotServiceImplTest.java
@@ -3,7 +3,7 @@
 import com.zy.ai.domain.autotune.AutoTuneFlowTopologyItem;
 import com.zy.ai.domain.autotune.AutoTuneStationRuntimeItem;
 import com.zy.ai.service.impl.FlowTopologySnapshotServiceImpl;
-import com.zy.asrs.entity.StationFlowCapacity;
+import com.zy.asrs.entity.BasStation;
 import org.junit.jupiter.api.Test;
 
 import java.util.Arrays;
@@ -12,19 +12,17 @@
 import java.util.Map;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
 class FlowTopologySnapshotServiceImplTest {
 
     @Test
     void buildTopologyItemUsesExplicitDirectionAndTargetStation() {
         FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
-        StationFlowCapacity capacity = capacity(101, "OUT", 3);
+        BasStation station = station(101, 3);
         Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
         adjacency.put(101, Arrays.asList(103, 102));
 
         AutoTuneFlowTopologyItem item = service.buildTopologyItem(
-                capacity,
+                station,
                 adjacency,
                 Arrays.asList(runtime(101, 1, 0, 0), runtime(102, 1, 1, 0))
         );
@@ -40,12 +38,12 @@
     @Test
     void undirectedGraphOnlyPopulatesAdjacentAndFlowStations() {
         FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
-        StationFlowCapacity capacity = capacity(201, "IN", 4);
+        BasStation station = station(201, 4);
         Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
         adjacency.put(201, Arrays.asList(203, 202));
 
         AutoTuneFlowTopologyItem item = service.buildTopologyItem(
-                capacity,
+                station,
                 adjacency,
                 Arrays.asList(runtime(202, 1, 1, 0), runtime(203, 1, 0, 8001))
         );
@@ -76,30 +74,14 @@
     }
 
     @Test
-    void findCapacityUsesStationIdAndDirectionCode() {
-        FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
-        List<StationFlowCapacity> capacities = Arrays.asList(
-                capacity(101, "IN", 2),
-                capacity(101, "OUT", 4),
-                capacity(102, "OUT", 8)
-        );
-
-        StationFlowCapacity result = service.findCapacity(capacities, 101, "OUT");
-
-        assertNotNull(result);
-        assertEquals(4, result.getBufferCapacity());
-        assertEquals("OUT", result.getDirectionCode());
-    }
-
-    @Test
     void flowStationIdsAndCountsAreNotTruncatedByBufferCapacity() {
         FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
-        StationFlowCapacity capacity = capacity(101, "OUT", 1);
+        BasStation station = station(101, 1);
         Map<Integer, List<Integer>> adjacency = new LinkedHashMap<>();
         adjacency.put(101, Arrays.asList(104, 102, 103));
 
         AutoTuneFlowTopologyItem item = service.buildTopologyItem(
-                capacity,
+                station,
                 adjacency,
                 Arrays.asList(
                         runtime(101, 1, 0, 0),
@@ -117,12 +99,27 @@
         assertEquals(0, item.getFreeCount());
     }
 
-    private StationFlowCapacity capacity(Integer stationId, String directionCode, Integer bufferCapacity) {
-        StationFlowCapacity capacity = new StationFlowCapacity();
-        capacity.setStationId(stationId);
-        capacity.setDirectionCode(directionCode);
-        capacity.setBufferCapacity(bufferCapacity);
-        return capacity;
+    @Test
+    void missingOutBufferCapacityKeepsFreeCountUnknown() {
+        FlowTopologySnapshotServiceImpl service = new FlowTopologySnapshotServiceImpl();
+        BasStation station = station(101, null);
+
+        AutoTuneFlowTopologyItem item = service.buildTopologyItem(
+                station,
+                new LinkedHashMap<>(),
+                Arrays.asList(runtime(101, 1, 1, 0))
+        );
+
+        assertEquals(null, item.getBufferCapacity());
+        assertEquals(null, item.getFreeCount());
+        assertEquals(1, item.getOccupiedCount());
+    }
+
+    private BasStation station(Integer stationId, Integer outBufferCapacity) {
+        BasStation station = new BasStation();
+        station.setStationId(stationId);
+        station.setOutBufferCapacity(outBufferCapacity);
+        return station;
     }
 
     private AutoTuneStationRuntimeItem runtime(Integer stationId, Integer autoing, Integer loading, Integer taskNo) {

--
Gitblit v1.9.1