Browse Source

修正供水运行监测设备类型归属与无采样查询 (#67)

按 equipment_type.id 限定流量11、压力12及14、漏失13;默认列表保留无采样设备,带监测时间或数值条件时继续只返回命中采样的设备。
Kazerin 3 tuần trước cách đây
mục cha
commit
50a57116d8

+ 24 - 16
pipe-network-service/zksy-system/src/main/java/com/zksy/base/service/impl/MonitoringServiceImpl.java

@@ -69,13 +69,14 @@ public class MonitoringServiceImpl implements MonitoringService {
         Map<Integer, EquipmentType> typeMap = selectTypeMap(devices);
         Map<String, RadarData> radarMap = selectLatestRadar(devices, startTime, endTime, flowMin, flowMax);
         Map<String, TelemetryData> telemetryMap = selectLatestTelemetry(devices, startTime, endTime, flowMin, flowMax);
+        boolean measurementFiltered = startTime != null || endTime != null || flowMin != null || flowMax != null;
 
         List<FlowMonitoringVO> allRows = new ArrayList<>();
         for (EquipmentBase device : devices) {
             String code = device.getEquipmentCode();
             RadarData radar = radarMap.get(code);
             TelemetryData telemetry = telemetryMap.get(code);
-            if (radar == null && telemetry == null) {
+            if (measurementFiltered && radar == null && telemetry == null) {
                 continue;
             }
 
@@ -87,7 +88,7 @@ public class MonitoringServiceImpl implements MonitoringService {
                 vo.setInstantFlow(radar.getMeter1InstantFlow());
                 vo.setFlowSpeed(radar.getFlowSpeed());
                 vo.setMonitorTime(radar.getCreateTime());
-            } else {
+            } else if (telemetry != null) {
                 vo.setDataSource(TELEMETRY_SOURCE);
                 vo.setInstantFlow(telemetry.getMeter1InstantFlow());
                 vo.setPositiveTotal(telemetry.getMeter1PositiveTotal());
@@ -113,6 +114,7 @@ public class MonitoringServiceImpl implements MonitoringService {
 
         Map<Integer, EquipmentType> typeMap = selectTypeMap(devices);
         Map<String, FirefightingPressure> pressureMap = new HashMap<>();
+        boolean measurementFiltered = startTime != null || endTime != null || pressureMin != null || pressureMax != null;
         List<String> deviceCodes = deviceCodes(devices);
         if (!deviceCodes.isEmpty()) {
             List<FirefightingPressure> records = firefightingPressureMapper.selectList(
@@ -128,13 +130,15 @@ public class MonitoringServiceImpl implements MonitoringService {
         List<PressureMonitoringVO> allRows = new ArrayList<>();
         for (EquipmentBase device : devices) {
             FirefightingPressure pressure = pressureMap.get(device.getEquipmentCode());
-            if (pressure == null) {
+            if (measurementFiltered && pressure == null) {
                 continue;
             }
             PressureMonitoringVO vo = new PressureMonitoringVO();
             fillBaseFields(vo, device, typeMap.get(device.getEquipmentTypeId()));
-            vo.setPressureValue(pressure.getPressureValue());
-            vo.setMonitorTime(pressure.getCreateTime());
+            if (pressure != null) {
+                vo.setPressureValue(pressure.getPressureValue());
+                vo.setMonitorTime(pressure.getCreateTime());
+            }
             allRows.add(vo);
         }
         return pageOf(allRows, pageNum, pageSize);
@@ -153,6 +157,7 @@ public class MonitoringServiceImpl implements MonitoringService {
 
         Map<Integer, EquipmentType> typeMap = selectTypeMap(devices);
         Map<String, NoiseInfo> noiseMap = new HashMap<>();
+        boolean measurementFiltered = startTime != null || endTime != null || powerMin != null || powerMax != null;
         List<String> deviceCodes = deviceCodes(devices);
         if (!deviceCodes.isEmpty()) {
             List<NoiseInfo> records = noiseInfoMapper.selectList(
@@ -168,16 +173,18 @@ public class MonitoringServiceImpl implements MonitoringService {
         List<LeakageMonitoringVO> allRows = new ArrayList<>();
         for (EquipmentBase device : devices) {
             NoiseInfo noise = noiseMap.get(device.getEquipmentCode());
-            if (noise == null) {
+            if (measurementFiltered && noise == null) {
                 continue;
             }
             LeakageMonitoringVO vo = new LeakageMonitoringVO();
             fillBaseFields(vo, device, typeMap.get(device.getEquipmentTypeId()));
-            vo.setPower(noise.getPower());
-            vo.setGain(noise.getGain());
-            vo.setRms(noise.getRms());
-            vo.setCenterFrequency(noise.getCenterFrequency());
-            vo.setMonitorTime(noise.getCreateTime());
+            if (noise != null) {
+                vo.setPower(noise.getPower());
+                vo.setGain(noise.getGain());
+                vo.setRms(noise.getRms());
+                vo.setCenterFrequency(noise.getCenterFrequency());
+                vo.setMonitorTime(noise.getCreateTime());
+            }
             allRows.add(vo);
         }
         return pageOf(allRows, pageNum, pageSize);
@@ -515,16 +522,17 @@ public class MonitoringServiceImpl implements MonitoringService {
 
     /** Restrict monitoring pages and trends to the canonical water-supply monitoring types. */
     private Set<Integer> selectMonitoringTypeIds(String monitorKind) {
-        Integer typeId;
+        Set<Integer> typeIds;
         switch (monitorKind) {
             case "pressure":
-                typeId = EquipmentTypeEnum.PRESSURE_GAUGE.getId();
+                typeIds = Set.of(EquipmentTypeEnum.PRESSURE_GAUGE.getId(),
+                        EquipmentTypeEnum.FIRE_HYDRANT_PRESSURE_TERMINAL.getId());
                 break;
             case "leakage":
-                typeId = EquipmentTypeEnum.LEAK_MONITOR.getId();
+                typeIds = Collections.singleton(EquipmentTypeEnum.LEAK_MONITOR.getId());
                 break;
             case "flow":
-                typeId = EquipmentTypeEnum.ULTRASONIC_FLOWMETER.getId();
+                typeIds = Collections.singleton(EquipmentTypeEnum.ULTRASONIC_FLOWMETER.getId());
                 break;
             default:
                 return Collections.emptySet();
@@ -538,7 +546,7 @@ public class MonitoringServiceImpl implements MonitoringService {
             return Collections.emptySet();
         }
         return types.stream()
-                .filter(type -> typeId.equals(type.getId())
+                .filter(type -> typeIds.contains(type.getId())
                         && EquipmentTypeEnum.ROOT_WATER_SUPPLY_DEVICE.getId().equals(type.getParentId()))
                 .map(EquipmentType::getId)
                 .collect(Collectors.toSet());

+ 38 - 21
pipe-network-service/zksy-system/src/test/java/com/zksy/base/service/impl/MonitoringServiceImplTest.java

@@ -82,7 +82,8 @@ class MonitoringServiceImplTest {
                 type(1, "供水", 0),
                 type(11, "供水流量计", 1),
                 type(12, "供水压力计", 1),
-                type(13, "供水漏失监测器", 1)
+                type(13, "供水漏失监测器", 1),
+                type(14, "消火栓压力监测终端", 1)
         ));
         when(radarDataMapper.selectList(any())).thenReturn(Collections.emptyList());
         when(telemetryDataMapper.selectList(any())).thenReturn(Collections.emptyList());
@@ -161,7 +162,7 @@ class MonitoringServiceImplTest {
     }
 
     @Test
-    void leakagePaginationExcludesDevicesWithoutQualifyingMeasurements() {
+    void leakagePaginationKeepsUnmeasuredDevicesWhenNoMeasurementFilterIsApplied() {
         when(equipmentBaseMapper.selectList(any())).thenReturn(Arrays.asList(
                 device("leakage-1", "WS-LK-1", "漏失监测点1", "13", BASE_TIME),
                 device("leakage-2", "WS-LK-2", "漏失监测点2", "13", BASE_TIME.minusMinutes(1))
@@ -173,36 +174,52 @@ class MonitoringServiceImplTest {
         Page<LeakageMonitoringVO> page = service.getLeakageMonitorPage(
                 1, 10, null, null, null, null, null, null, null);
 
-        assertEquals(1, page.getTotal());
-        assertEquals(1, page.getRecords().size());
+        assertEquals(2, page.getTotal());
+        assertEquals(2, page.getRecords().size());
         assertEquals("leakage-1", page.getRecords().get(0).getEquipmentId());
         assertEquals(12D, page.getRecords().get(0).getPower());
         assertEquals(BASE_TIME, page.getRecords().get(0).getMonitorTime());
+        assertEquals("leakage-2", page.getRecords().get(1).getEquipmentId());
+        assertEquals(null, page.getRecords().get(1).getPower());
+        assertEquals(null, page.getRecords().get(1).getMonitorTime());
+
+        Page<LeakageMonitoringVO> filtered = service.getLeakageMonitorPage(
+                1, 10, null, null, null, null, null, 10D, null);
+        assertEquals(1, filtered.getTotal());
+        assertEquals("leakage-1", filtered.getRecords().get(0).getEquipmentId());
     }
 
     @Test
-    void monitoringPagesReturnAnEmptyPageWhenThereIsNoMeasurementData() {
-        when(equipmentBaseMapper.selectList(any())).thenReturn(Collections.singletonList(
-                device("flow-empty", "WS-FLOW-EMPTY", "无数据监测点", "11", BASE_TIME)
-        ));
-
+    void monitoringPagesKeepFourWaterDevicesInTheirTypesWithoutMeasurements() {
+        when(equipmentBaseMapper.selectList(any())).thenAnswer(invocation -> {
+            LambdaQueryWrapper<EquipmentBase> wrapper = invocation.getArgument(0);
+            Set<Object> allowedTypeIds = flattenWrapperValues(wrapper);
+            return Arrays.asList(
+                    device("flow", "TEST-FLOW", "测试流量计", "11", BASE_TIME),
+                    device("pressure", "TEST-PRESSURE", "测试压力计", "12", BASE_TIME),
+                    device("leakage", "TEST-LEAK", "测试漏失监测01", "13", BASE_TIME),
+                    device("hydrant", "TEST-HYDRANT", "测试消火栓", "14", BASE_TIME),
+                    device("drainage", "DRAIN-FLOW", "排水流量计", "17", BASE_TIME)
+            ).stream().filter(device -> allowedTypeIds.contains(device.getEquipmentTypeId()))
+                    .collect(Collectors.toList());
+        });
         Page<FlowMonitoringVO> flow = service.getFlowMonitorPage(1, 10, null, null, null, null, null, null, null);
-        assertEquals(0, flow.getTotal());
-        assertTrue(flow.getRecords().isEmpty());
+        assertEquals(1, flow.getTotal());
+        assertEquals("测试流量计", flow.getRecords().get(0).getEquipmentName());
+        assertEquals(null, flow.getRecords().get(0).getInstantFlow());
+        assertEquals(null, flow.getRecords().get(0).getMonitorTime());
 
-        when(equipmentBaseMapper.selectList(any())).thenReturn(Collections.singletonList(
-                device("pressure-empty", "WS-PR-EMPTY", "无数据监测点", "12", BASE_TIME)
-        ));
         Page<PressureMonitoringVO> pressure = service.getPressureMonitorPage(1, 10, null, null, null, null, null, null, null);
-        assertEquals(0, pressure.getTotal());
-        assertTrue(pressure.getRecords().isEmpty());
+        assertEquals(2, pressure.getTotal());
+        assertEquals(Set.of("测试压力计", "测试消火栓"), pressure.getRecords().stream()
+                .map(PressureMonitoringVO::getEquipmentName).collect(Collectors.toSet()));
+        assertTrue(pressure.getRecords().stream().allMatch(row -> row.getPressureValue() == null && row.getMonitorTime() == null));
 
-        when(equipmentBaseMapper.selectList(any())).thenReturn(Collections.singletonList(
-                device("leakage-empty", "WS-LK-EMPTY", "无数据监测点", "13", BASE_TIME)
-        ));
         Page<LeakageMonitoringVO> leakage = service.getLeakageMonitorPage(1, 10, null, null, null, null, null, null, null);
-        assertEquals(0, leakage.getTotal());
-        assertTrue(leakage.getRecords().isEmpty());
+        assertEquals(1, leakage.getTotal());
+        assertEquals("测试漏失监测01", leakage.getRecords().get(0).getEquipmentName());
+        assertEquals(null, leakage.getRecords().get(0).getPower());
+        assertEquals(null, leakage.getRecords().get(0).getMonitorTime());
     }
 
     @Test