Pārlūkot izejas kodu

test(cockpit): 对齐未知类型保留后的事件测试

Kazerin 3 nedēļas atpakaļ
vecāks
revīzija
e741e560f7

+ 98 - 56
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitCurrentEventsControllerTest.java

@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -73,49 +74,58 @@ class CockpitCurrentEventsControllerTest {
                 .andExpect(jsonPath("$.data.filters.status").value(nullValue()))
                 .andExpect(jsonPath("$.data.pagination.page").value(1))
                 .andExpect(jsonPath("$.data.pagination.pageSize").value(100))
-                .andExpect(jsonPath("$.data.pagination.total").value(5))
+                .andExpect(jsonPath("$.data.pagination.total").value(6))
                 .andExpect(jsonPath("$.data.pagination.totalPages").value(1))
                 .andExpect(jsonPath("$.data.pagination.hasMore").value(false))
                 .andExpect(jsonPath("$.data.sections.events.state").value("SUCCESS"))
-                .andExpect(jsonPath("$.data.sections.events.data", hasSize(5)))
-                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-001"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].level").value(1))
-                .andExpect(jsonPath("$.data.sections.events.data[0].levelColor").value("RED"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].deviceCode").value("D-GAS-1"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].monitoringPointCode").value("MP-A-001"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].monitoringPointName").value("城区A-燃气1号点"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].industry").value("GAS"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].coordinateValidation.state").value("VALID"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].coordinateValidation.reason").value(nullValue()))
-                .andExpect(jsonPath("$.data.sections.events.data[0].coordinateValidation.renderable").value(true))
-                .andExpect(jsonPath("$.data.sections.events.data[0].coordinateValidation.crs").value("WGS84"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].thresholdMinValue").value(nullValue()))
-                .andExpect(jsonPath("$.data.sections.events.data[0].thresholdMaxValue").value(nullValue()))
-                .andExpect(jsonPath("$.data.sections.events.data[0].workOrderSummary.workOrderCode").value("WO-1"))
-                .andExpect(jsonPath("$.data.sections.events.data[0].workOrderSummary.stateCode").value(3))
-                .andExpect(jsonPath("$.data.sections.events.data[0].workOrderSummary.stateName").value("处理中"))
-                .andExpect(jsonPath("$.data.sections.events.data[1].eventNo").value("W-002"))
-                .andExpect(jsonPath("$.data.sections.events.data[1].levelColor").value("YELLOW"))
-                .andExpect(jsonPath("$.data.sections.events.data[1].workOrderSummary").value(nullValue()))
-                .andExpect(jsonPath("$.data.sections.events.data[2].eventNo").value("W-003"))
-                .andExpect(jsonPath("$.data.sections.events.data[2].levelColor").value("BLUE"))
-                .andExpect(jsonPath("$.data.sections.events.data[3].eventNo").value("W-004"))
-                .andExpect(jsonPath("$.data.sections.events.data[3].levelColor").value("GREEN"))
-                .andExpect(jsonPath("$.data.sections.events.data[3].coordinateValidation.state").value("INVALID"))
-                .andExpect(jsonPath("$.data.sections.events.data[3].coordinateValidation.reason").value("LONGITUDE_OUT_OF_RANGE"))
-                .andExpect(jsonPath("$.data.sections.events.data[3].coordinateValidation.renderable").value(false))
-                .andExpect(jsonPath("$.data.sections.events.data[3].monitoringPointCode").value(nullValue()))
-                .andExpect(jsonPath("$.data.sections.events.data[4].eventNo").value("W-005"))
-                .andExpect(jsonPath("$.data.sections.events.data[4].levelColor").value("UNKNOWN"))
+                .andExpect(jsonPath("$.data.sections.events.data", hasSize(6)))
+                // 42bdb3db:未登记类型 W-006 保留,按时间排到正式行业事件之前。
+                .andExpect(jsonPath("$.data.sections.events.data[*].eventNo").value(
+                        contains("W-006", "W-001", "W-002", "W-003", "W-004", "W-005")))
+                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-006"))
+                .andExpect(jsonPath("$.data.sections.events.data[0].industry").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[0].deviceCode").value("D-LEGACY"))
+                .andExpect(jsonPath("$.data.sections.events.data[0].workOrderSummary").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[1].eventNo").value("W-001"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].level").value(1))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-001')].levelColor").value(contains("RED")))
+                .andExpect(jsonPath("$.data.sections.events.data[1].deviceCode").value("D-GAS-1"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].monitoringPointCode").value("MP-A-001"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].monitoringPointName").value("城区A-燃气1号点"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].industry").value("GAS"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].coordinateValidation.state").value("VALID"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].coordinateValidation.reason").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[1].coordinateValidation.renderable").value(true))
+                .andExpect(jsonPath("$.data.sections.events.data[1].coordinateValidation.crs").value("WGS84"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].thresholdMinValue").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[1].thresholdMaxValue").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[1].workOrderSummary.workOrderCode").value("WO-1"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].workOrderSummary.stateCode").value(3))
+                .andExpect(jsonPath("$.data.sections.events.data[1].workOrderSummary.stateName").value("处理中"))
+                .andExpect(jsonPath("$.data.sections.events.data[2].eventNo").value("W-002"))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-002')].levelColor").value(contains("YELLOW")))
+                .andExpect(jsonPath("$.data.sections.events.data[2].workOrderSummary").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[3].eventNo").value("W-003"))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-003')].levelColor").value(contains("BLUE")))
+                .andExpect(jsonPath("$.data.sections.events.data[4].eventNo").value("W-004"))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-004')].levelColor").value(contains("GREEN")))
+                .andExpect(jsonPath("$.data.sections.events.data[4].coordinateValidation.state").value("INVALID"))
+                .andExpect(jsonPath("$.data.sections.events.data[4].coordinateValidation.reason").value("LONGITUDE_OUT_OF_RANGE"))
+                .andExpect(jsonPath("$.data.sections.events.data[4].coordinateValidation.renderable").value(false))
+                .andExpect(jsonPath("$.data.sections.events.data[4].monitoringPointCode").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[5].eventNo").value("W-005"))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-005')].levelColor").value(contains("UNKNOWN")))
                 // 2026-10-12 契约:W-005 坐标 110.381/28.461 落在主场景区内 → 可上图。
-                .andExpect(jsonPath("$.data.sections.events.data[4].coordinateValidation.state").value("VALID"))
-                .andExpect(jsonPath("$.data.sections.events.data[4].coordinateValidation.reason").value(nullValue()))
-                .andExpect(jsonPath("$.data.sections.events.data[4].coordinateValidation.renderable").value(true))
-                .andExpect(jsonPath("$.data.sections.events.data[4].workOrderSummary.stateName").value("已结案"))
+                .andExpect(jsonPath("$.data.sections.events.data[5].coordinateValidation.state").value("VALID"))
+                .andExpect(jsonPath("$.data.sections.events.data[5].coordinateValidation.reason").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[5].coordinateValidation.renderable").value(true))
+                .andExpect(jsonPath("$.data.sections.events.data[5].workOrderSummary.stateName").value("已结案"))
                 .andExpect(jsonPath("$.data.sections.workOrders.state").value("SUCCESS"))
                 .andExpect(jsonPath("$.data.sections.workOrders.reason").value("SUCCESS"))
                 .andExpect(jsonPath("$.data.mapFilter.mode").value("WARNING"))
-                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(5)));
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(6)))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(
+                        contains("D-DR-1", "D-GAS-1", "D-GAS-2", "D-LEGACY", "D-WS-1", "D-WS-2")));
     }
 
     @Test
@@ -146,20 +156,36 @@ class CockpitCurrentEventsControllerTest {
     void levelColorsFollowOneRedTwoYellowThreeBlueFourGreen() throws Exception {
         mockMvc.perform(get(ENDPOINT).param("mode", "WARNING"))
                 .andExpect(status().isOk())
-                .andExpect(jsonPath("$.data.sections.events.data[0].levelColor").value("RED"))
-                .andExpect(jsonPath("$.data.sections.events.data[1].levelColor").value("YELLOW"))
-                .andExpect(jsonPath("$.data.sections.events.data[2].levelColor").value("BLUE"))
-                .andExpect(jsonPath("$.data.sections.events.data[3].levelColor").value("GREEN"))
-                .andExpect(jsonPath("$.data.sections.events.data[4].levelColor").value("UNKNOWN"));
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-001')].levelColor").value(contains("RED")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-002')].levelColor").value(contains("YELLOW")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-003')].levelColor").value(contains("BLUE")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-004')].levelColor").value(contains("GREEN")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-005')].levelColor").value(contains("UNKNOWN")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-006')].levelColor").value(contains("RED")));
     }
 
     @Test
-    void unknownOrNonFormalEventTypesAreDroppedFromTheList() throws Exception {
+    void unknownEventTypesStayVisibleUntilAnIndustryFilterIsApplied() throws Exception {
         mockMvc.perform(get(ENDPOINT).param("mode", "WARNING"))
                 .andExpect(status().isOk())
-                .andExpect(jsonPath("$.data.pagination.total").value(5))
-                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-001"))
-                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(5)));
+                .andExpect(jsonPath("$.data.pagination.total").value(6))
+                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-006"))
+                .andExpect(jsonPath("$.data.sections.events.data[0].industry").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[0].deviceCode").value("D-LEGACY"))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-007')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(6)))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(
+                        contains("D-DR-1", "D-GAS-1", "D-GAS-2", "D-LEGACY", "D-WS-1", "D-WS-2")));
+
+        // 未登记类型保留不等于归入燃气;旧井盖夹具仍为 industry=null,保持原样。
+        mockMvc.perform(get(ENDPOINT).param("mode", "WARNING").param("industry", "GAS"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.pagination.total").value(2))
+                .andExpect(jsonPath("$.data.sections.events.data[*].eventNo").value(contains("W-001", "W-002")))
+                .andExpect(jsonPath("$.data.sections.events.data[*].industry").value(contains("GAS", "GAS")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-006')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.mapFilter.industry").value("GAS"))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(contains("D-GAS-1", "D-GAS-2")));
     }
 
     @Test
@@ -181,8 +207,10 @@ class CockpitCurrentEventsControllerTest {
         mockMvc.perform(get(ENDPOINT).param("mode", "WARNING"))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.sections.events.state").value("SUCCESS"))
-                .andExpect(jsonPath("$.data.sections.events.data", hasSize(5)))
+                .andExpect(jsonPath("$.data.sections.events.data", hasSize(6)))
+                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-006"))
                 .andExpect(jsonPath("$.data.sections.events.data[0].workOrderSummary").value(nullValue()))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-001')].workOrderSummary").value(contains(nullValue())))
                 .andExpect(jsonPath("$.data.sections.workOrders.state").value("FAILED"))
                 .andExpect(jsonPath("$.data.sections.workOrders.reason").value("WORK_ORDER_SECTION_UNAVAILABLE"))
                 .andExpect(jsonPath("$.data.sections.workOrders.message").value("工单状态分区暂不可用"));
@@ -210,20 +238,26 @@ class CockpitCurrentEventsControllerTest {
                         .param("page", "1")
                         .param("pageSize", "2"))
                 .andExpect(status().isOk())
-                .andExpect(jsonPath("$.data.pagination.total").value(5))
+                .andExpect(jsonPath("$.data.pagination.total").value(6))
                 .andExpect(jsonPath("$.data.pagination.totalPages").value(3))
                 .andExpect(jsonPath("$.data.pagination.hasMore").value(true))
                 .andExpect(jsonPath("$.data.sections.events.data", hasSize(2)))
-                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-001"))
-                .andExpect(jsonPath("$.data.sections.events.data[1].eventNo").value("W-002"));
+                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-006"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].eventNo").value("W-001"))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(
+                        contains("D-DR-1", "D-GAS-1", "D-GAS-2", "D-LEGACY", "D-WS-1", "D-WS-2")));
 
         mockMvc.perform(get(ENDPOINT)
                         .param("mode", "WARNING")
                         .param("page", "3")
                         .param("pageSize", "2"))
                 .andExpect(status().isOk())
-                .andExpect(jsonPath("$.data.sections.events.data", hasSize(1)))
-                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-005"))
+                .andExpect(jsonPath("$.data.sections.events.data", hasSize(2)))
+                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-004"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].eventNo").value("W-005"))
+                .andExpect(jsonPath("$.data.pagination.total").value(6))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(
+                        contains("D-DR-1", "D-GAS-1", "D-GAS-2", "D-LEGACY", "D-WS-1", "D-WS-2")))
                 .andExpect(jsonPath("$.data.pagination.hasMore").value(false));
     }
 
@@ -242,15 +276,21 @@ class CockpitCurrentEventsControllerTest {
                         .param("industry", "WATER_SUPPLY"))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.pagination.total").value(2))
+                .andExpect(jsonPath("$.data.sections.events.data[*].eventNo").value(contains("W-003", "W-005")))
+                .andExpect(jsonPath("$.data.sections.events.data[?(@.eventNo == 'W-006')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(contains("D-WS-1", "D-WS-2")))
                 .andExpect(jsonPath("$.data.mapFilter.industry").value("WATER_SUPPLY"));
 
         mockMvc.perform(get(ENDPOINT)
                         .param("mode", "WARNING")
                         .param("status", "ACTIVE"))
                 .andExpect(status().isOk())
-                .andExpect(jsonPath("$.data.pagination.total").value(3))
-                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-001"))
-                .andExpect(jsonPath("$.data.sections.events.data[2].eventNo").value("W-005"))
+                .andExpect(jsonPath("$.data.pagination.total").value(4))
+                .andExpect(jsonPath("$.data.sections.events.data[0].eventNo").value("W-006"))
+                .andExpect(jsonPath("$.data.sections.events.data[1].eventNo").value("W-001"))
+                .andExpect(jsonPath("$.data.sections.events.data[3].eventNo").value("W-005"))
+                .andExpect(jsonPath("$.data.sections.events.data[*].eventNo").value(contains("W-006", "W-001", "W-002", "W-005")))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(contains("D-GAS-1", "D-GAS-2", "D-LEGACY", "D-WS-2")))
                 .andExpect(jsonPath("$.data.mapFilter.status").value("ACTIVE"));
     }
 
@@ -324,14 +364,16 @@ class CockpitCurrentEventsControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.filters.district").value(nullValue()))
                 .andExpect(jsonPath("$.data.filters.districtName").value("未分区"))
-                .andExpect(jsonPath("$.data.pagination.total").value(2));
+                .andExpect(jsonPath("$.data.pagination.total").value(3))
+                .andExpect(jsonPath("$.data.sections.events.data[*].eventNo").value(contains("W-006", "W-004", "W-005")))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(contains("D-DR-1", "D-LEGACY", "D-WS-2")));
 
         // 不传=全域
         mockMvc.perform(get(ENDPOINT).param("mode", "WARNING"))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.filters.district").value(nullValue()))
                 .andExpect(jsonPath("$.data.filters.districtName").value(nullValue()))
-                .andExpect(jsonPath("$.data.pagination.total").value(5));
+                .andExpect(jsonPath("$.data.pagination.total").value(6));
 
         // 报警模式同一套语义(片区是事件族共同维度,不是预警专属)
         mockMvc.perform(get(ENDPOINT).param("mode", "ALARM").param("district", "2"))

+ 53 - 14
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitHandlingEfficiencyControllerTest.java

@@ -22,6 +22,7 @@ import java.time.ZoneOffset;
 import java.util.Arrays;
 import java.util.Collections;
 
+import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -85,9 +86,9 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.filters.eventFamily").value("WARNING"))
                 .andExpect(jsonPath("$.data.filters.workOrderState").value(nullValue()))
                 // 事件口径两族共用(真实计数,不是第二轮读数)。
-                .andExpect(jsonPath("$.data.summary.totalEvents").value(8))
+                .andExpect(jsonPath("$.data.summary.totalEvents").value(9))
                 .andExpect(jsonPath("$.data.summary.linkedWorkOrderCount").value(6))
-                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(2))
+                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(3))
                 // 票 74:**工单口径**对预警族不成立 → 显式 null(不是 0,也不是别的族的数)。
                 .andExpect(jsonPath("$.data.summary.handledCount").value(nullValue()))
                 .andExpect(jsonPath("$.data.summary.inProgressCount").value(nullValue()))
@@ -95,8 +96,8 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.summary.handlingEfficiency").value(nullValue()))
                 .andExpect(jsonPath("$.data.summary.averageDuration").value(nullValue()))
                 .andExpect(jsonPath("$.data.workOrderStateCounts").value(nullValue()))
-                // 预警自身六态全铺(缺的态计 0),顺序即 WarningWorkflow 主线。
-                .andExpect(jsonPath("$.data.warningStateCounts", hasSize(6)))
+                // 六个已知态全铺;EW-LEGACY 状态为空,另计 UNKNOWN,桶和仍为 9。
+                .andExpect(jsonPath("$.data.warningStateCounts", hasSize(7)))
                 .andExpect(jsonPath("$.data.warningStateCounts[0].stateCode").value("DRAFT"))
                 .andExpect(jsonPath("$.data.warningStateCounts[0].stateName").value("草稿"))
                 .andExpect(jsonPath("$.data.warningStateCounts[0].count").value(1))
@@ -112,10 +113,13 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.warningStateCounts[5].stateCode").value("CLOSED"))
                 .andExpect(jsonPath("$.data.warningStateCounts[5].stateName").value("已解除"))
                 .andExpect(jsonPath("$.data.warningStateCounts[5].count").value(3))
-                // 已解除率=已解除 ÷ 窗口内预警数(3/8),基线与工单口径不同名。
+                .andExpect(jsonPath("$.data.warningStateCounts[6].stateCode").value("UNKNOWN"))
+                .andExpect(jsonPath("$.data.warningStateCounts[6].stateName").value("未知"))
+                .andExpect(jsonPath("$.data.warningStateCounts[6].count").value(1))
+                // 已解除率=已解除 ÷ 窗口内全部预警数(含未知类型,3/9)。
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.numerator").value(3))
-                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(8))
-                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.value").value("0.3750"))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(9))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.value").value("0.3333"))
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.state").value("AVAILABLE"))
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.basis")
                         .value("CLOSED_WARNINGS_OVER_WINDOW_WARNINGS"))
@@ -124,16 +128,28 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.summary.warningDuration.unit").value("HOURS"))
                 .andExpect(jsonPath("$.data.summary.warningDuration.sampleCount").value(3))
                 .andExpect(jsonPath("$.data.summary.warningDuration.state").value("AVAILABLE"))
-                .andExpect(jsonPath("$.data.events", hasSize(8)))
+                .andExpect(jsonPath("$.data.events", hasSize(9)))
                 .andExpect(jsonPath("$.data.events[0].eventNo").value("EW-007"))
                 .andExpect(jsonPath("$.data.events[0].hasWorkOrder").value(true))
-                .andExpect(jsonPath("$.data.pagination.total").value(8))
+                .andExpect(jsonPath("$.data.events[*].eventNo").value(contains(
+                        "EW-007", "EW-006", "EW-005", "EW-004", "EW-008", "EW-003", "EW-LEGACY", "EW-002", "EW-001")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')].deviceCode").value(contains("D-LEGACY")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')].hasWorkOrder").value(contains(false)))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')].workOrderStateCode").value(contains(nullValue())))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')].levelColor").value(contains("RED")))
+                .andExpect(jsonPath("$.data.pagination.total").value(9))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(contains(
+                        "D-DR-1", "D-DR-2", "D-DR-3", "D-GAS-1", "D-GAS-2", "D-GAS-3", "D-LEGACY", "D-WS-1", "D-WS-2")))
                 // 趋势桶:事件发布量照实给,工单结案量与结案时长两族口径 → null。
                 .andExpect(jsonPath("$.data.durationTrend", hasSize(5)))
                 .andExpect(jsonPath("$.data.durationTrend[0].timeBucket").value("2026-09-02T08:00:00+08:00"))
                 .andExpect(jsonPath("$.data.durationTrend[0].eventCount").value(2))
                 .andExpect(jsonPath("$.data.durationTrend[0].handledCount").value(nullValue()))
                 .andExpect(jsonPath("$.data.durationTrend[0].averageDuration").value(nullValue()))
+                .andExpect(jsonPath("$.data.durationTrend[1].timeBucket").value("2026-09-02T09:00:00+08:00"))
+                .andExpect(jsonPath("$.data.durationTrend[1].eventCount").value(3))
+                .andExpect(jsonPath("$.data.durationTrend[2].eventCount").value(2))
+                .andExpect(jsonPath("$.data.durationTrend[3].eventCount").value(2))
                 .andExpect(jsonPath("$.data.durationTrend[4].timeBucket").value("2026-09-02T12:00:00+08:00"))
                 .andExpect(jsonPath("$.data.durationTrend[4].eventCount").value(0));
     }
@@ -321,9 +337,32 @@ class CockpitHandlingEfficiencyControllerTest {
                         .param("startTime", START)
                         .param("endTime", END))
                 .andExpect(status().isOk())
-                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(2))
-                .andExpect(jsonPath("$.data.events", hasSize(8)))
-                .andExpect(jsonPath("$.data.summary.totalEvents").value(8));
+                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(3))
+                .andExpect(jsonPath("$.data.events", hasSize(9)))
+                .andExpect(jsonPath("$.data.summary.totalEvents").value(9))
+                .andExpect(jsonPath("$.data.events[?(@.hasWorkOrder == false)].eventNo").value(contains("EW-005", "EW-008", "EW-LEGACY")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')].deviceCode").value(contains("D-LEGACY")))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(9)));
+
+        // EventItem 不公开 industry;以真实筛选结果证明未知类型未被归入燃气。
+        mockMvc.perform(get(ENDPOINT)
+                        .param("eventFamily", "WARNING")
+                        .param("industry", "GAS")
+                        .param("startTime", START)
+                        .param("endTime", END))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.filters.industry").value("GAS"))
+                .andExpect(jsonPath("$.data.summary.totalEvents").value(3))
+                .andExpect(jsonPath("$.data.summary.linkedWorkOrderCount").value(3))
+                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(0))
+                .andExpect(jsonPath("$.data.events[*].eventNo").value(contains("EW-006", "EW-002", "EW-001")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.warningStateCounts", hasSize(6)))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.numerator").value(1))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(3))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.value").value("0.3333"))
+                .andExpect(jsonPath("$.data.pagination.total").value(3))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes").value(contains("D-GAS-1", "D-GAS-2", "D-GAS-3")));
     }
 
     @Test
@@ -559,8 +598,8 @@ class CockpitHandlingEfficiencyControllerTest {
     }
 
     /**
-     * 主样本:8 条在范围内预警(`EW-LEGACY` 的类型不在设备类型表里,被行业范围判定排除),
-     * 状态覆盖六态 —— DRAFT 1 / PENDING 1 / RECEIVED 1 / PROCESSING 1 / HANDLED 1 / CLOSED 3,
+     * 主样本:9 条在范围内预警;`EW-LEGACY` 类型未登记但全域保留,状态为空计 UNKNOWN。
+     * 已知状态覆盖六态 —— DRAFT 1 / PENDING 1 / RECEIVED 1 / PROCESSING 1 / HANDLED 1 / CLOSED 3,
      * 其中三条 CLOSED 的 `update_time` 分别距发布 0.50h / 2.00h / 1.00h。
      */
     private static CockpitHandlingEfficiencySnapshot fixture() {

+ 60 - 16
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitHistoryAnalysisControllerTest.java

@@ -23,6 +23,7 @@ import java.time.ZoneOffset;
 import java.util.Arrays;
 import java.util.Collections;
 
+import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -81,23 +82,34 @@ class CockpitHistoryAnalysisControllerTest {
                 .andExpect(jsonPath("$.data.filters.eventFamily").value("WARNING"))
                 .andExpect(jsonPath("$.data.filters.level").value(nullValue()))
                 .andExpect(jsonPath("$.data.filters.industry").value(nullValue()))
-                .andExpect(jsonPath("$.data.summary.eventCount").value(5))
+                .andExpect(jsonPath("$.data.summary.eventCount").value(7))
                 .andExpect(jsonPath("$.data.summary.handledCount").value(2))
                 .andExpect(jsonPath("$.data.summary.handlingEfficiency.value").value("0.4000"))
                 .andExpect(jsonPath("$.data.summary.handlingEfficiency.numerator").value(2))
                 .andExpect(jsonPath("$.data.summary.handlingEfficiency.denominator").value(5))
                 .andExpect(jsonPath("$.data.summary.handlingEfficiency.state").value("AVAILABLE"))
                 .andExpect(jsonPath("$.data.rows", hasSize(4)))
-                .andExpect(jsonPath("$.data.events", hasSize(5)))
+                .andExpect(jsonPath("$.data.events", hasSize(7)))
+                .andExpect(jsonPath("$.data.events[*].eventNo").value(contains(
+                        "HW-005", "HW-004", "HW-003", "HW-002", "HW-LEGACY", "HW-MH", "HW-001")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-LEGACY')].industry").value(contains(nullValue())))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-LEGACY')].deviceCode").value(contains("D-LEGACY")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-MH')].industry").value(contains(nullValue())))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-MH')].deviceCode").value(contains("D-MH")))
                 .andExpect(jsonPath("$.data.pagination.page").value(1))
                 .andExpect(jsonPath("$.data.pagination.pageSize").value(100))
-                .andExpect(jsonPath("$.data.pagination.total").value(5))
-                .andExpect(jsonPath("$.data.rows[0].timeBucket").value(BUCKET_23))                .andExpect(jsonPath("$.data.rows[0].eventCount").value(1))
+                .andExpect(jsonPath("$.data.pagination.total").value(7))
+                .andExpect(jsonPath("$.data.rows[0].timeBucket").value(BUCKET_23))
+                .andExpect(jsonPath("$.data.rows[0].eventCount").value(2))
                 .andExpect(jsonPath("$.data.rows[0].handledCount").value(1))
-                .andExpect(jsonPath("$.data.rows[0].handlingEfficiency.value").value("1.0000"))
+                .andExpect(jsonPath("$.data.rows[0].handlingEfficiency.value").value("0.5000"))
+                .andExpect(jsonPath("$.data.rows[0].handlingEfficiency.numerator").value(1))
+                .andExpect(jsonPath("$.data.rows[0].handlingEfficiency.denominator").value(2))
                 .andExpect(jsonPath("$.data.rows[0].mapFilter.deviceCodes[0]").value("D-GAS-1"))
+                .andExpect(jsonPath("$.data.rows[0].mapFilter.deviceCodes").value(contains("D-GAS-1", "D-MH")))
                 .andExpect(jsonPath("$.data.rows[1].timeBucket").value(BUCKET_00))
-                .andExpect(jsonPath("$.data.rows[1].eventCount").value(2))
+                .andExpect(jsonPath("$.data.rows[1].eventCount").value(3))
+                .andExpect(jsonPath("$.data.rows[1].mapFilter.deviceCodes").value(contains("D-GAS-2", "D-LEGACY", "D-WS-1")))
                 .andExpect(jsonPath("$.data.rows[1].handledCount").value(0))
                 .andExpect(jsonPath("$.data.rows[1].handlingEfficiency.value").value("0.0000"))
                 .andExpect(jsonPath("$.data.rows[1].handlingEfficiency.state").value("AVAILABLE"))
@@ -157,7 +169,10 @@ class CockpitHistoryAnalysisControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.filters.district").value(nullValue()))
                 .andExpect(jsonPath("$.data.filters.districtName").value("未分区"))
-                .andExpect(jsonPath("$.data.summary.eventCount").value(2));
+                .andExpect(jsonPath("$.data.summary.eventCount").value(4))
+                .andExpect(jsonPath("$.data.events[*].eventNo").value(contains("HW-005", "HW-004", "HW-LEGACY", "HW-MH")))
+                .andExpect(jsonPath("$.data.summary.handlingEfficiency.numerator").value(0))
+                .andExpect(jsonPath("$.data.summary.handlingEfficiency.denominator").value(1));
 
         // 不传=全域(双字段都为空,不是「未分区」)
         mockMvc.perform(get(ENDPOINT)
@@ -167,7 +182,7 @@ class CockpitHistoryAnalysisControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.filters.district").value(nullValue()))
                 .andExpect(jsonPath("$.data.filters.districtName").value(nullValue()))
-                .andExpect(jsonPath("$.data.summary.eventCount").value(5));
+                .andExpect(jsonPath("$.data.summary.eventCount").value(7));
     }
 
     @Test
@@ -207,15 +222,19 @@ class CockpitHistoryAnalysisControllerTest {
                         .param("endTime", END))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.rows[0].timeBucket").value("2026-09-01T23:00:00+08:00"))
-                .andExpect(jsonPath("$.data.rows[0].eventCount").value(1))
+                .andExpect(jsonPath("$.data.rows[0].eventCount").value(2))
+                .andExpect(jsonPath("$.data.rows[0].mapFilter.deviceCodes").value(contains("D-GAS-1", "D-MH")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-001')].eventTime").value(contains("2026-09-01T23:30:00+08:00")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-MH')].eventTime").value(contains("2026-09-01T23:59:00+08:00")))
                 .andExpect(jsonPath("$.data.rows[1].timeBucket").value("2026-09-02T00:00:00+08:00"))
+                .andExpect(jsonPath("$.data.rows[1].eventCount").value(3))
                 .andExpect(jsonPath("$.data.rows[2].timeBucket").value("2026-09-02T01:00:00+08:00"));
     }
 
     @Test
     void handledScopeCountsOnlyClosedStateFiveOrders() throws Exception {
         CockpitHistoryAnalysisResponse response = service("WARNING", START, END);
-        assertEquals(5, response.getSummary().getEventCount());
+        assertEquals(7, response.getSummary().getEventCount());
         assertEquals(2, response.getSummary().getHandledCount());
         // 汇总处置率=状态 5 ÷ 状态 0–6 工单数(决策票 06)→ 2/5。
         assertEquals("0.4000", response.getSummary().getHandlingEfficiency().getValue().toPlainString());
@@ -276,7 +295,13 @@ class CockpitHistoryAnalysisControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.summary.eventCount").value(2))
                 .andExpect(jsonPath("$.data.summary.handledCount").value(1))
-                .andExpect(jsonPath("$.data.events", hasSize(2)));
+                .andExpect(jsonPath("$.data.events", hasSize(2)))
+                .andExpect(jsonPath("$.data.events[*].eventNo").value(contains("HW-002", "HW-001")))
+                .andExpect(jsonPath("$.data.events[*].industry").value(contains("GAS", "GAS")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-LEGACY')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-MH')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.rows[0].mapFilter.deviceCodes").value(contains("D-GAS-1")))
+                .andExpect(jsonPath("$.data.rows[1].mapFilter.deviceCodes").value(contains("D-GAS-2")));
     }
 
     @Test
@@ -291,16 +316,19 @@ class CockpitHistoryAnalysisControllerTest {
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.pagination.page").value(1))
                 .andExpect(jsonPath("$.data.pagination.pageSize").value(2))
-                .andExpect(jsonPath("$.data.pagination.total").value(5))
-                .andExpect(jsonPath("$.data.pagination.totalPages").value(3))
+                .andExpect(jsonPath("$.data.pagination.total").value(7))
+                .andExpect(jsonPath("$.data.pagination.totalPages").value(4))
                 .andExpect(jsonPath("$.data.pagination.hasMore").value(true))
                 .andExpect(jsonPath("$.data.events", hasSize(2)))
                 .andExpect(jsonPath("$.data.events[0].eventNo").value("HW-005"))
                 .andExpect(jsonPath("$.data.events[0].eventTime").value("2026-09-02T01:50:00+08:00"))
-                .andExpect(jsonPath("$.data.events[0].levelColor").value("RED"))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-005')].levelColor").value(contains("RED")))
                 .andExpect(jsonPath("$.data.events[0].deviceCode").value("D-WS-2"))
                 .andExpect(jsonPath("$.data.events[0].industry").value("WATER_SUPPLY"))
-                .andExpect(jsonPath("$.data.events[1].eventNo").value("HW-004"));
+                .andExpect(jsonPath("$.data.events[1].eventNo").value("HW-004"))
+                // 小时桶/map 范围不由当前页反推;未在首屏的两个未知行仍参与桶统计。
+                .andExpect(jsonPath("$.data.rows[0].mapFilter.deviceCodes").value(contains("D-GAS-1", "D-MH")))
+                .andExpect(jsonPath("$.data.rows[1].mapFilter.deviceCodes").value(contains("D-GAS-2", "D-LEGACY", "D-WS-1")));
 
         mockMvc.perform(get(ENDPOINT)
                         .param("eventFamily", "WARNING")
@@ -309,8 +337,24 @@ class CockpitHistoryAnalysisControllerTest {
                         .param("page", "3")
                         .param("pageSize", "2"))
                 .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.events", hasSize(2)))
+                .andExpect(jsonPath("$.data.events[0].eventNo").value("HW-LEGACY"))
+                .andExpect(jsonPath("$.data.events[0].industry").value(nullValue()))
+                .andExpect(jsonPath("$.data.events[1].eventNo").value("HW-MH"))
+                .andExpect(jsonPath("$.data.events[1].industry").value(nullValue()))
+                .andExpect(jsonPath("$.data.pagination.total").value(7))
+                .andExpect(jsonPath("$.data.pagination.hasMore").value(true));
+
+        mockMvc.perform(get(ENDPOINT)
+                        .param("eventFamily", "WARNING")
+                        .param("startTime", START)
+                        .param("endTime", END)
+                        .param("page", "4")
+                        .param("pageSize", "2"))
+                .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.events", hasSize(1)))
                 .andExpect(jsonPath("$.data.events[0].eventNo").value("HW-001"))
+                .andExpect(jsonPath("$.data.pagination.total").value(7))
                 .andExpect(jsonPath("$.data.pagination.hasMore").value(false));
 
         // 越界页:事件为空但仍返回成功信封与真实 total(不由当前页反推)。
@@ -322,7 +366,7 @@ class CockpitHistoryAnalysisControllerTest {
                         .param("pageSize", "2"))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.events", hasSize(0)))
-                .andExpect(jsonPath("$.data.pagination.total").value(5))
+                .andExpect(jsonPath("$.data.pagination.total").value(7))
                 .andExpect(jsonPath("$.data.pagination.hasMore").value(false));
     }