From cd04aa8b887e82ec664e42f0bc353c079be1d2c5 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 27 四月 2026 17:57:19 +0800
Subject: [PATCH] fix: filter auto tune out station limits
---
src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java | 92 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 90 insertions(+), 2 deletions(-)
diff --git a/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java b/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
index 24fa5ce..d1b62d8 100644
--- a/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
+++ b/src/test/java/com/zy/ai/service/impl/AutoTuneSnapshotServiceImplTest.java
@@ -1,20 +1,41 @@
package com.zy.ai.service.impl;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.zy.asrs.entity.BasStation;
+import com.zy.asrs.entity.StationFlowCapacity;
+import com.zy.asrs.entity.WrkMast;
+import com.zy.asrs.service.BasStationService;
+import com.zy.asrs.service.StationFlowCapacityService;
+import com.zy.asrs.service.WrkMastService;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
+import org.springframework.test.util.ReflectionTestUtils;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
class AutoTuneSnapshotServiceImplTest {
+ private AutoTuneSnapshotServiceImpl service;
+
+ @BeforeEach
+ void setUp() {
+ service = new AutoTuneSnapshotServiceImpl();
+ }
+
@Test
void buildStationOutTaskLimitMapPreservesNullZeroAndNegativeLimits() {
- AutoTuneSnapshotServiceImpl service = new AutoTuneSnapshotServiceImpl();
-
Map<String, Integer> result = service.buildStationOutTaskLimitMap(Arrays.asList(
station(101, null),
station(102, 0),
@@ -28,10 +49,77 @@
assertEquals(5, result.get("104"));
}
+ @Test
+ void loadActiveTasksIncludesNullWrkStatusInGroupedCondition() {
+ WrkMastService wrkMastService = mock(WrkMastService.class);
+ when(wrkMastService.list(any(Wrapper.class))).thenReturn(Collections.emptyList());
+ ReflectionTestUtils.setField(service, "wrkMastService", wrkMastService);
+
+ ReflectionTestUtils.invokeMethod(service, "loadActiveTasks");
+
+ ArgumentCaptor<Wrapper<WrkMast>> wrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
+ verify(wrkMastService).list(wrapperCaptor.capture());
+ String sqlSegment = wrapperCaptor.getValue().getSqlSegment();
+ String normalizedSqlSegment = sqlSegment.replaceAll("\\s+", " ");
+ assertTrue(normalizedSqlSegment.contains("(wrk_sts NOT IN"));
+ assertTrue(normalizedSqlSegment.contains("OR wrk_sts IS NULL"));
+ }
+
+ @Test
+ void loadStationOutTaskLimitsOnlyQueriesConfiguredOutDirectionStations() {
+ BasStationService basStationService = mock(BasStationService.class);
+ StationFlowCapacityService stationFlowCapacityService = mock(StationFlowCapacityService.class);
+ ReflectionTestUtils.setField(service, "basStationService", basStationService);
+ ReflectionTestUtils.setField(service, "stationFlowCapacityService", stationFlowCapacityService);
+ when(stationFlowCapacityService.list(any(Wrapper.class))).thenReturn(Arrays.asList(
+ capacity(101, "OUT"),
+ capacity(102, "OUT")
+ ));
+ when(basStationService.list(any(Wrapper.class))).thenReturn(Arrays.asList(
+ station(101, 2),
+ station(102, 3)
+ ));
+
+ Map<String, Integer> result = ReflectionTestUtils.invokeMethod(service, "loadStationOutTaskLimits");
+
+ assertEquals(2, result.size());
+ assertEquals(2, result.get("101"));
+ assertEquals(3, result.get("102"));
+
+ ArgumentCaptor<Wrapper<StationFlowCapacity>> capacityWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
+ verify(stationFlowCapacityService).list(capacityWrapperCaptor.capture());
+ assertTrue(capacityWrapperCaptor.getValue().getSqlSegment().contains("direction_code ="));
+
+ ArgumentCaptor<Wrapper<BasStation>> stationWrapperCaptor = ArgumentCaptor.forClass(Wrapper.class);
+ verify(basStationService).list(stationWrapperCaptor.capture());
+ assertTrue(stationWrapperCaptor.getValue().getSqlSegment().contains("station_id IN"));
+ }
+
+ @Test
+ void loadStationOutTaskLimitsDoesNotQueryStationsWhenNoOutCapacityExists() {
+ BasStationService basStationService = mock(BasStationService.class);
+ StationFlowCapacityService stationFlowCapacityService = mock(StationFlowCapacityService.class);
+ ReflectionTestUtils.setField(service, "basStationService", basStationService);
+ ReflectionTestUtils.setField(service, "stationFlowCapacityService", stationFlowCapacityService);
+ when(stationFlowCapacityService.list(any(Wrapper.class))).thenReturn(Collections.emptyList());
+
+ Map<String, Integer> result = ReflectionTestUtils.invokeMethod(service, "loadStationOutTaskLimits");
+
+ assertTrue(result.isEmpty());
+ verify(basStationService, never()).list(any(Wrapper.class));
+ }
+
private BasStation station(Integer stationId, Integer outTaskLimit) {
BasStation station = new BasStation();
station.setStationId(stationId);
station.setOutTaskLimit(outTaskLimit);
return station;
}
+
+ private StationFlowCapacity capacity(Integer stationId, String directionCode) {
+ StationFlowCapacity capacity = new StationFlowCapacity();
+ capacity.setStationId(stationId);
+ capacity.setDirectionCode(directionCode);
+ return capacity;
+ }
}
--
Gitblit v1.9.1