Browse Source

fix(cockpit): exclude boundary mismatches from industry counts (#19)

Kazerin 2 days ago
parent
commit
5ae1e0c19e

+ 22 - 0
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitDeviceBoundaryControllerTest.java

@@ -152,6 +152,28 @@ class CockpitDeviceBoundaryControllerTest {
                 .andExpect(jsonPath("$.data.statistics.typeKindMismatchCount").value(1));
     }
 
+    @Test
+    void mismatchedDeviceTypeIsExcludedFromFormalIndustryStatistics() throws Exception {
+        when(adapter.load()).thenReturn(new CockpitDeviceBoundarySnapshot(
+                Arrays.asList(
+                        new SourceType("WATER_SUPPLY_SENSOR", "供水压力计", "WATER_SUPPLY", null, "SMART_DEVICE"),
+                        new SourceType("WATER_PLANT", "水厂", "WATER_SUPPLY", null, "FACILITY")),
+                Collections.emptyList(),
+                Arrays.asList(
+                        new SourceDevice("EQ-WS-001", "供水压力计-001", "WATER_SUPPLY_SENSOR"),
+                        new SourceDevice("EQ-MISMATCH-001", "误挂设施类型的设备-001", "WATER_PLANT"))));
+
+        mockMvc.perform(get("/api/cockpit/v1/device-boundary"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.devices[0].formalScope").value(true))
+                .andExpect(jsonPath("$.data.devices[1].formalScope").value(false))
+                .andExpect(jsonPath("$.data.devices[1].typeResolution").value("TYPE_KIND_MISMATCH"))
+                .andExpect(jsonPath("$.data.statistics.smartDeviceCount").value(2))
+                .andExpect(jsonPath("$.data.statistics.formalSmartDeviceCount").value(1))
+                .andExpect(jsonPath("$.data.statistics.industries.waterSupply.smartDeviceCount").value(1))
+                .andExpect(jsonPath("$.data.statistics.typeKindMismatchCount").value(1));
+    }
+
     @Test
     void mutatingRequestIsRejectedBeforeReadAdapterIsCalled() throws Exception {
         mockMvc.perform(post("/api/cockpit/v1/device-boundary"))

+ 10 - 8
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/device/CockpitDeviceBoundaryService.java

@@ -127,14 +127,16 @@ public class CockpitDeviceBoundaryService {
             }
         }
         for (CockpitDeviceBoundary device : devices) {
-            CockpitIndustryStatistics industryStatistics = industryBucket(industries, device.getIndustry());
-            if (industryStatistics != null) {
-                industryStatistics.addSmartDevice();
-            }
-            if ("DRAINAGE".equals(device.getIndustry()) && "RAINWATER".equals(device.getDrainageScope())) {
-                industries.get("drainage").addRainwaterSmartDevice();
-            } else if ("DRAINAGE".equals(device.getIndustry()) && "SEWAGE".equals(device.getDrainageScope())) {
-                industries.get("drainage").addSewageSmartDevice();
+            if (device.isFormalScope()) {
+                CockpitIndustryStatistics industryStatistics = industryBucket(industries, device.getIndustry());
+                if (industryStatistics != null) {
+                    industryStatistics.addSmartDevice();
+                }
+                if ("DRAINAGE".equals(device.getIndustry()) && "RAINWATER".equals(device.getDrainageScope())) {
+                    industries.get("drainage").addRainwaterSmartDevice();
+                } else if ("DRAINAGE".equals(device.getIndustry()) && "SEWAGE".equals(device.getDrainageScope())) {
+                    industries.get("drainage").addSewageSmartDevice();
+                }
             }
         }