|
|
@@ -6,12 +6,19 @@ import com.zksy.WaterSupply.WaterPlantInfo.service.IWaterPlantInfoService;
|
|
|
import com.zksy.WaterSupply.PumpStationInfo.domain.PumpStationType;
|
|
|
import com.zksy.WaterSupply.PumpStationInfo.domain.PumpStationInfo;
|
|
|
import com.zksy.WaterSupply.PumpStationInfo.service.IPumpStationInfoService;
|
|
|
+import com.zksy.WaterSupply.WaterFireHydrantInfo.domain.WaterFireHydrantInfo;
|
|
|
+import com.zksy.WaterSupply.WaterFireHydrantInfo.service.IWaterFireHydrantInfoService;
|
|
|
+import com.zksy.WaterSupply.WaterSourceInfo.domain.WaterSourceInfo;
|
|
|
+import com.zksy.WaterSupply.WaterSourceInfo.service.IWaterSourceInfoService;
|
|
|
+import com.zksy.WaterSupply.WaterUserInfo.domain.WaterUserInfo;
|
|
|
+import com.zksy.WaterSupply.WaterUserInfo.service.IWaterUserInfoService;
|
|
|
import com.zksy.base.domain.ManholeBase;
|
|
|
import com.zksy.base.domain.PipeNetworkBase;
|
|
|
import com.zksy.base.service.ManholeBaseService;
|
|
|
import com.zksy.base.service.PipeNetworkBaseService;
|
|
|
import com.zksy.cockpit.infrastructure.BusinessCockpitInfrastructureOperatingInformationAdapter;
|
|
|
import com.zksy.cockpit.infrastructure.CockpitInfrastructureOperatingInformationSnapshot;
|
|
|
+import com.zksy.drainage.domain.DrainageGateInfo;
|
|
|
import com.zksy.drainage.domain.DrainageStorageInfo;
|
|
|
import com.zksy.drainage.service.DrainageGateInfoService;
|
|
|
import com.zksy.drainage.service.DrainageStorageInfoService;
|
|
|
@@ -22,6 +29,7 @@ import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
@@ -179,6 +187,215 @@ class BusinessCockpitInfrastructureOperatingInformationAdapterTest {
|
|
|
assertTrue(snapshot.getMetrics().get(1).isAbnormal(), "非 0 状态如实标记为异常");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 水厂即使没有当前供水能力,也必须下发设施实体行(外部依赖票 01)。
|
|
|
+ *
|
|
|
+ * <p>旧实现把 {@code currentCapacity == null} 当作跳过条件,前端设施点图层只从运行信息
|
|
|
+ * 实体行枚举,于是库里带坐标的水厂永不上图。能力值如实为 null,不拿 0 冒充。</p>
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ void emitsWaterPlantEntityRowWhenCurrentCapacityMissing() {
|
|
|
+ WaterPlantInfo plant = new WaterPlantInfo();
|
|
|
+ plant.setId("7");
|
|
|
+ plant.setPlantCode("PLANT-007");
|
|
|
+ plant.setPlantName("第二水厂");
|
|
|
+ plant.setCurrentCapacity(null);
|
|
|
+ plant.setDesignCapacity(new BigDecimal("12.00"));
|
|
|
+ plant.setStatus("0");
|
|
|
+ plant.setUpdateTime(LocalDateTime.parse("2026-11-18T09:00:00"));
|
|
|
+
|
|
|
+ when(plantService.list()).thenReturn(Collections.singletonList(plant));
|
|
|
+ when(pumpStationService.list(any(Wrapper.class))).thenReturn(Collections.emptyList());
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(gateService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(storageService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(manholeBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ CockpitInfrastructureOperatingInformationSnapshot snapshot = adapter.load();
|
|
|
+
|
|
|
+ assertEquals(1, snapshot.getMetrics().size(), "能力值为空不能丢弃水厂实体行");
|
|
|
+ CockpitInfrastructureOperatingInformationSnapshot.SourceMetric metric = snapshot.getMetrics().get(0);
|
|
|
+ assertEquals("water_plant_current_supply", metric.getMetricCode());
|
|
|
+ assertEquals("WATER_PLANT", metric.getFacilityKind());
|
|
|
+ assertEquals("7", metric.getFacilityId());
|
|
|
+ assertNull(metric.getValue(), "缺失的当前能力如实为 null");
|
|
|
+ assertEquals(new BigDecimal("12.00"), metric.getCapacityValue());
|
|
|
+ assertEquals("PLANT-007", metric.getPointCodes().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 主键缺失时 facilityId 如实为 null,绝不下发字符串 "null"
|
|
|
+ * (票 01 判据 4:实体行的 facilityId 要能用于详情查询,不出现 404/500)。
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ void waterPlantWithoutPrimaryKeyHasNoQueryableFacilityId() {
|
|
|
+ WaterPlantInfo plant = new WaterPlantInfo();
|
|
|
+ plant.setId(null);
|
|
|
+ plant.setPlantCode("PLANT-NOID");
|
|
|
+ plant.setPlantName("无主键水厂");
|
|
|
+ when(plantService.list()).thenReturn(Collections.singletonList(plant));
|
|
|
+ when(pumpStationService.list(any(Wrapper.class))).thenReturn(Collections.emptyList());
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(gateService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(storageService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(manholeBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ CockpitInfrastructureOperatingInformationSnapshot.SourceMetric metric =
|
|
|
+ adapter.load().getMetrics().get(0);
|
|
|
+ assertNull(metric.getFacilityId(), "缺主键的行不能冒充可回查的 facilityId");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 缺业务编码的水厂仍不产指标(没有稳定身份就无法回查详情)。 */
|
|
|
+ @Test
|
|
|
+ void skipsWaterPlantWithoutBusinessCode() {
|
|
|
+ WaterPlantInfo plant = new WaterPlantInfo();
|
|
|
+ plant.setId("8");
|
|
|
+ plant.setPlantName("无编号水厂");
|
|
|
+ plant.setCurrentCapacity(new BigDecimal("3.00"));
|
|
|
+ when(plantService.list()).thenReturn(Collections.singletonList(plant));
|
|
|
+ when(pumpStationService.list(any(Wrapper.class))).thenReturn(Collections.emptyList());
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(gateService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(storageService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(manholeBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ assertTrue(adapter.load().getMetrics().isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 泵站即使没有设计流量,也必须下发设施实体行(外部依赖票 01);
|
|
|
+ * 设计流量如实为 null,不拿 0 冒充。
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ void emitsPumpStationEntityRowWhenDesignFlowMissing() {
|
|
|
+ PumpStationInfo pump = new PumpStationInfo();
|
|
|
+ pump.setId("11");
|
|
|
+ pump.setStationCode("PS-011");
|
|
|
+ pump.setStationName("城南加压泵站");
|
|
|
+ pump.setStationType(PumpStationType.WATER_SUPPLY);
|
|
|
+ pump.setDesignFlow(null);
|
|
|
+ pump.setStatus("检修");
|
|
|
+ pump.setUpdateTime(LocalDateTime.parse("2026-11-18T09:00:00"));
|
|
|
+
|
|
|
+ when(plantService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(pumpStationService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(pump));
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(gateService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(storageService.listAll()).thenReturn(Collections.emptyList());
|
|
|
+ when(manholeBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+
|
|
|
+ CockpitInfrastructureOperatingInformationSnapshot snapshot = adapter.load();
|
|
|
+
|
|
|
+ assertEquals(1, snapshot.getMetrics().size(), "设计流量为空不能丢弃泵站实体行");
|
|
|
+ CockpitInfrastructureOperatingInformationSnapshot.SourceMetric metric = snapshot.getMetrics().get(0);
|
|
|
+ assertEquals("water_supply_pump_station_design_flow", metric.getMetricCode());
|
|
|
+ assertEquals("PUMP_STATION", metric.getFacilityKind());
|
|
|
+ assertEquals("11", metric.getFacilityId());
|
|
|
+ assertNull(metric.getValue());
|
|
|
+ assertTrue(metric.isAbnormal(), "状态「检修」如实标记异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 九类设施必须各下发一条可枚举的实体行(外部依赖票 01)。
|
|
|
+ *
|
|
|
+ * <p>前端设施点图层唯一的实体来源就是这个端点的 {@code facilityKind + facilityId}:
|
|
|
+ * 少一类,图例上有这一类、图上却没有点。这里按当前库的类别清单(水厂、供水泵站、
|
|
|
+ * 排水泵站、水源地、闸门、调蓄设施、消火栓、用水户、窨井)各造一条,钉住九类全覆盖,
|
|
|
+ * 并要求每条都带可用于详情回查的稳定主键。</p>
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ void enumeratesEntityRowsForAllNineFacilityCategories() {
|
|
|
+ IWaterSourceInfoService waterSourceService = mock(IWaterSourceInfoService.class);
|
|
|
+ IWaterUserInfoService waterUserService = mock(IWaterUserInfoService.class);
|
|
|
+ IWaterFireHydrantInfoService hydrantService = mock(IWaterFireHydrantInfoService.class);
|
|
|
+ BusinessCockpitInfrastructureOperatingInformationAdapter fullAdapter =
|
|
|
+ new BusinessCockpitInfrastructureOperatingInformationAdapter(
|
|
|
+ plantService, pumpStationService, pipeNetworkBaseService, gateService, storageService,
|
|
|
+ manholeBaseService, waterUserService, hydrantService, waterSourceService);
|
|
|
+
|
|
|
+ WaterPlantInfo plant = new WaterPlantInfo();
|
|
|
+ plant.setId("1"); plant.setPlantCode("WP001"); plant.setPlantName("一水厂");
|
|
|
+ plant.setCurrentCapacity(null);
|
|
|
+ PumpStationInfo supply = new PumpStationInfo();
|
|
|
+ supply.setId("2"); supply.setStationCode("PS001"); supply.setStationName("供水泵站");
|
|
|
+ supply.setStationType(PumpStationType.WATER_SUPPLY); supply.setDesignFlow(null);
|
|
|
+ PumpStationInfo drainage = new PumpStationInfo();
|
|
|
+ drainage.setId("3"); drainage.setStationCode("PS002"); drainage.setStationName("排水泵站");
|
|
|
+ drainage.setStationType(PumpStationType.DRAINAGE);
|
|
|
+ DrainageGateInfo gate = new DrainageGateInfo();
|
|
|
+ gate.setFacilityId("g-1"); gate.setFacilityCode("G001"); gate.setFacilityName("闸门");
|
|
|
+ DrainageStorageInfo storage = new DrainageStorageInfo();
|
|
|
+ storage.setFacilityId("s-1"); storage.setFacilityCode("S001"); storage.setFacilityName("调蓄池");
|
|
|
+ WaterSourceInfo source = new WaterSourceInfo();
|
|
|
+ source.setId("ws-1"); source.setSourceId("WS001"); source.setSourceName("洮水水源地");
|
|
|
+ source.setLongitude(new BigDecimal("110.440")); source.setLatitude(new BigDecimal("28.450"));
|
|
|
+ WaterUserInfo user = new WaterUserInfo();
|
|
|
+ user.setId("u-1"); user.setUserCode("U001"); user.setUserName("自来水公司");
|
|
|
+ WaterFireHydrantInfo hydrant = new WaterFireHydrantInfo();
|
|
|
+ hydrant.setHydrantId("h-1"); hydrant.setHydrantCode("FH001"); hydrant.setHydrantName("中山路消火栓");
|
|
|
+ ManholeBase manhole = manhole("MH-001", "沅陵县窨井001", "0");
|
|
|
+
|
|
|
+ when(plantService.list()).thenReturn(Collections.singletonList(plant));
|
|
|
+ when(pumpStationService.list(any(Wrapper.class))).thenReturn(Arrays.asList(supply, drainage));
|
|
|
+ when(pipeNetworkBaseService.list()).thenReturn(Collections.emptyList());
|
|
|
+ when(gateService.listAll()).thenReturn(Collections.singletonList(gate));
|
|
|
+ when(storageService.listAll()).thenReturn(Collections.singletonList(storage));
|
|
|
+ when(manholeBaseService.list()).thenReturn(Collections.singletonList(manhole));
|
|
|
+ when(waterSourceService.list()).thenReturn(Collections.singletonList(source));
|
|
|
+ when(waterUserService.list()).thenReturn(Collections.singletonList(user));
|
|
|
+ when(hydrantService.list()).thenReturn(Collections.singletonList(hydrant));
|
|
|
+
|
|
|
+ List<CockpitInfrastructureOperatingInformationSnapshot.SourceMetric> metrics =
|
|
|
+ fullAdapter.load().getMetrics();
|
|
|
+
|
|
|
+ List<String> kinds = metrics.stream()
|
|
|
+ .map(CockpitInfrastructureOperatingInformationSnapshot.SourceMetric::getFacilityKind)
|
|
|
+ .sorted().collect(Collectors.toList());
|
|
|
+ assertEquals(Arrays.asList(
|
|
|
+ "DRAINAGE_GATE", "DRAINAGE_STORAGE", "MANHOLE", "PUMP_STATION", "PUMP_STATION",
|
|
|
+ "WATER_FIRE_HYDRANT", "WATER_PLANT", "WATER_SOURCE", "WATER_USER"),
|
|
|
+ kinds, "九类设施(泵站按供水/排水两条)都要有实体行,一条都不能少");
|
|
|
+ // 两条泵站分别落到供水/排水行业,供水泵站与排水泵站各 1 条(票 01 判据 1)。
|
|
|
+ assertEquals(Arrays.asList("DRAINAGE", "WATER_SUPPLY"), metrics.stream()
|
|
|
+ .filter(metric -> "PUMP_STATION".equals(metric.getFacilityKind()))
|
|
|
+ .map(CockpitInfrastructureOperatingInformationSnapshot.SourceMetric::getIndustry)
|
|
|
+ .sorted().collect(Collectors.toList()),
|
|
|
+ "供水泵站与排水泵站都要有实体行且行业归属正确");
|
|
|
+ for (CockpitInfrastructureOperatingInformationSnapshot.SourceMetric metric : metrics) {
|
|
|
+ assertTrue(metric.getFacilityId() != null && !metric.getFacilityId().trim().isEmpty()
|
|
|
+ && !"null".equals(metric.getFacilityId()),
|
|
|
+ metric.getFacilityKind() + " 的 facilityId 必须能用于详情回查");
|
|
|
+ assertTrue(Arrays.asList("WATER_PLANT", "PUMP_STATION", "WATER_SOURCE", "WATER_USER",
|
|
|
+ "WATER_FIRE_HYDRANT", "DRAINAGE_GATE", "DRAINAGE_STORAGE", "MANHOLE")
|
|
|
+ .contains(metric.getFacilityKind()),
|
|
|
+ "facilityKind 必须是前端可枚举的设施点类别");
|
|
|
+ }
|
|
|
+ CockpitInfrastructureOperatingInformationSnapshot.SourceMetric waterSource = metrics.stream()
|
|
|
+ .filter(metric -> "WATER_SOURCE".equals(metric.getFacilityKind()))
|
|
|
+ .findFirst().orElseThrow(AssertionError::new);
|
|
|
+ assertEquals("ws-1", waterSource.getFacilityId(), "水源地用主键作实体身份,与详情查询同源");
|
|
|
+ assertEquals("WATER_SUPPLY", waterSource.getIndustry());
|
|
|
+ assertEquals("处", waterSource.getUnit());
|
|
|
+ assertEquals("洮水水源地", waterSource.getMetricName());
|
|
|
+ assertEquals(BigDecimal.ONE, waterSource.getValue());
|
|
|
+ assertEquals("WS001", waterSource.getPointCodes().get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 水源地缺业务编号时不产实体行(与其他类别同一纪律:无稳定编码不上图)。 */
|
|
|
+ @Test
|
|
|
+ void skipsWaterSourceWithoutBusinessCode() {
|
|
|
+ IWaterSourceInfoService waterSourceService = mock(IWaterSourceInfoService.class);
|
|
|
+ BusinessCockpitInfrastructureOperatingInformationAdapter fullAdapter =
|
|
|
+ new BusinessCockpitInfrastructureOperatingInformationAdapter(
|
|
|
+ plantService, pumpStationService, pipeNetworkBaseService, gateService, storageService,
|
|
|
+ manholeBaseService, null, null, waterSourceService);
|
|
|
+ WaterSourceInfo source = new WaterSourceInfo();
|
|
|
+ source.setId("ws-2"); source.setSourceName("无编号水源地");
|
|
|
+ when(waterSourceService.list()).thenReturn(Collections.singletonList(source));
|
|
|
+
|
|
|
+ assertTrue(fullAdapter.load().getMetrics().isEmpty());
|
|
|
+ }
|
|
|
+
|
|
|
/** 没有窨井时不产指标(不拿 0 凑数)。 */
|
|
|
@Test
|
|
|
void emitsNoManholeMetricWhenThereAreNone() {
|