Explorar o código

Merge remote-tracking branch 'origin/master'

zengy hai 3 días
pai
achega
dbceed1c9f
Modificáronse 18 ficheiros con 443 adicións e 76 borrados
  1. 4 0
      docs/cockpit/README.md
  2. 10 5
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/BusinessCockpitDeviceFactResolverTest.java
  3. 40 0
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/BusinessCockpitMonitoringOverviewAdapterTest.java
  4. 67 20
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitHandlingEfficiencyControllerTest.java
  5. 40 0
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitHistoryAnalysisControllerTest.java
  6. 67 1
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitMultidimensionalAnalysisControllerTest.java
  7. 11 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/domain/WarningWorkflow.java
  8. 5 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/BusinessCockpitEventAdapter.java
  9. 10 3
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitHandlingEfficiencyService.java
  10. 4 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitHistoryAnalysisService.java
  11. 28 5
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitMultidimensionalAnalysisService.java
  12. 12 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitMultidimensionalAnalysisSnapshot.java
  13. 83 36
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/BusinessCockpitMonitoringOverviewAdapter.java
  14. 24 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewResponse.java
  15. 2 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewService.java
  16. 24 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewSnapshot.java
  17. 7 2
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/BusinessCockpitDeviceFactResolver.java
  18. 5 0
      zk-api-service/src/main/java/com/zksy/api/mapper/AutoWarningClosureMapper.java

+ 4 - 0
docs/cockpit/README.md

@@ -99,7 +99,11 @@
 - 事件行(`overview`/`warningResponse` 的 `events/current` 的 `EventItem`)携带 `coordinateValidation`,与地图/监测切片**同一校验实现**(`CockpitCoordinateValidator`);坐标结构非法、越界或落在主场景区外时 `renderable = false` 且给出 `reason`。
 - `monitoring/overview` 的 `devices[]` 是**逐设备台账行**(2026-10-22 追加):每行 = `deviceCode` / `deviceName` / `deviceType{code,name}` / `industry` / `monitoringState` / `monitoringPointCode` / `sampledAt` / `createdAt`,顺序为后端遍历顺序(稳定,调用方不重排)。**行数恒等于 `counts.equipmentCount`**(同一遍历产出,不是第二个口径),筛选(`industry`/`deviceType`)生效时两者同步收窄。它与 `monitoring/situation` 的 `abnormalEquipment[]` **不是一回事**:后者只装异常四态(WARNING/ALARM/EXPIRED/OFFLINE)设备,是「异常清单」;前者是**全部**智能设备的台账。缺值一律 `null`(`deviceName`/`monitoringPointCode`/`createdAt`),不拿编码冒充、不填 0。
 - 事件坐标按同一自动准入判定(不再依赖 `coordinateVerified`):区内且数值合法 → `VALID` / `renderable=true`。报警族在数据可得时另带 `thresholdMinValue`/`thresholdMaxValue`(预警族为 `null`)。
+- `monitoring/overview` 的 `devices[]` 逐行带 **`tags`**(票 133):`ALARM` / `WARNING` / `WORK_ORDER` 的命中项,**可叠加**(一台设备可同时是报警 + 预警 + 工单),无标签时为 `[]`。事实来源统一是 `BusinessCockpitDeviceFactResolver`:在线/报警取 `equipment_status.online_status / alarm_status`,预警取「未解除预警」(字典 `pre_alarm_status` 的 `PENDING/RECEIVED/PROCESSING/HANDLED`,**DRAFT 与 CLOSED 都不算**),工单取「未结束工单」。前端据此出「报警/预警/工单设备」计数,**不得再用报警流水二次推断**(CONTEXT.md 明令)。
 - `events/history-analysis` 同时返回两块内容:`rows[]` 是**小时桶聚合行**(趋势与行级处置率口径,不携带逐事件坐标/阈值);`events[]` 是**逐事件行**(票 61 新增,形状与 `events/current` 的 `EventItem` 同构),按 `eventTime` 倒序、同时间按 `eventNo` 升序,由 `page`/`pageSize`(默认 1/100,上限 1000)分页,元数据在 `pagination` 中,`pagination.total` 即窗口内事件总数。逐事件坐标仍只在 `events/current` 提供,历史逐事件行的 `coordinateValidation` 为 `null`。
+- 预警族三个事件端点(`events/history-analysis`、`events/handling-efficiency`、`events/multidimensional-analysis`)一律排除**草稿**(`DRAFT`)预警(票 126):草稿只是未发布的编辑稿,不进逐事件行、不进小时桶/六态分布/维度桶、不计 `pagination.total`,也**不进** `warningHandlingEfficiency` 的分母。判据与总览计数同一条——`status IS NULL OR UPPER(TRIM(status)) <> 'DRAFT'`,即状态为空/缺失的行**保留**,不因词表缺口被丢掉。`events/current` 的口径不同(排除 DRAFT 与 CLOSED),两处各自成立、互不覆盖。
+
+- **窗口判据的发布时间回退(票 130)**:预警族的时间窗以事件发布时刻(`early_warning.publish_time`)界定;当某条预警的发布时刻**缺失或不可解析**时,`events/history-analysis`、`events/handling-efficiency`、`events/multidimensional-analysis` 三条端点统一**回退到更新时间**(`update_time`)判窗与分桶——这是有前提的读数,不代表采集到了独立的发布时间,也不会把缺失的发布时刻伪装成存在(逐事件行排序仍按原值,缺发布时刻的排末尾)。与之配套,系统自动触发→自动解除的预警(从未经人工发布)会在自动解除时以生效时刻(`create_time`,即触发时刻)补写 `publish_time`(票 130);本回退保证即便历史行为空、或回填未及,已存在的预警也不会因发布时间缺失被窗口整批抹掉。此回退与上方「排除草稿」是两条独立判据:草稿在判窗前即被排除,不受回退影响;非草稿预警一律按上述回退判窗。报警族无此依赖(报警不读 `publish_time`)。
 
 ### 监测点详情设备坐标
 

+ 10 - 5
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/BusinessCockpitDeviceFactResolverTest.java

@@ -297,11 +297,16 @@ class BusinessCockpitDeviceFactResolverTest {
 
         assertTrue(resolver.resolve(device("DEV-5"), null).isWarning(), "小写 processing 也视为预警中");
 
-        when(earlyWarningService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(warning("released")));
-        assertTrue(resolver.resolve(device("DEV-5"), null).isWarning(), "RELEASED 已发布预警仍为当前预警");
-
-        when(earlyWarningService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(warning("CLOSED")));
-        assertFalse(resolver.resolve(device("DEV-5"), null).isWarning(), "CLOSED 预警不算预警中");
+        // 票 133:字典 pre_alarm_status 六态里「未解除」= PENDING/RECEIVED/PROCESSING/HANDLED;
+        // DRAFT(草稿)与 CLOSED(已解除)都不算,RELEASED 根本不在字典里、更不算。
+        for (String state : Arrays.asList("PENDING", "received", "PROCESSING", "HANDLED")) {
+            when(earlyWarningService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(warning(state)));
+            assertTrue(resolver.resolve(device("DEV-5"), null).isWarning(), state + " 属于未解除预警");
+        }
+        for (String state : Arrays.asList("DRAFT", "CLOSED", "RELEASED")) {
+            when(earlyWarningService.list(any(Wrapper.class))).thenReturn(Collections.singletonList(warning(state)));
+            assertFalse(resolver.resolve(device("DEV-5"), null).isWarning(), state + " 不算未解除预警");
+        }
     }
 
     @Test

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

@@ -11,6 +11,8 @@ import com.zksy.base.service.MonitorPointService;
 import com.zksy.cockpit.monitoring.BusinessCockpitMonitoringOverviewAdapter;
 import com.zksy.cockpit.monitoring.CockpitMonitoringOverviewSnapshot;
 import com.zksy.cockpit.monitoring.CockpitMonitoringOverviewService;
+import com.zksy.cockpit.point.BusinessCockpitDeviceFactResolver;
+import com.zksy.cockpit.point.CockpitMonitoringPointDeviceSnapshot;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
@@ -42,6 +44,7 @@ class BusinessCockpitMonitoringOverviewAdapterTest {
     private EquipmentBaseService equipmentBaseService;
     private EquipmentStatusService equipmentStatusService;
     private EquipmentTypeService equipmentTypeService;
+    private BusinessCockpitDeviceFactResolver deviceFactResolver;
     private BusinessCockpitMonitoringOverviewAdapter adapter;
 
     @BeforeEach
@@ -50,8 +53,10 @@ class BusinessCockpitMonitoringOverviewAdapterTest {
         equipmentBaseService = mock(EquipmentBaseService.class);
         equipmentStatusService = mock(EquipmentStatusService.class);
         equipmentTypeService = mock(EquipmentTypeService.class);
+        deviceFactResolver = mock(BusinessCockpitDeviceFactResolver.class);
         adapter = new BusinessCockpitMonitoringOverviewAdapter(
                 monitorPointService, equipmentBaseService, equipmentStatusService, equipmentTypeService,
+                deviceFactResolver,
                 Clock.fixed(Instant.parse("2026-09-02T02:00:00Z"), ZoneOffset.UTC));
     }
 
@@ -156,6 +161,41 @@ class BusinessCockpitMonitoringOverviewAdapterTest {
         assertEquals(Collections.singletonList("EMPTY"), response.getMapFilter().getPointCodes());
     }
 
+    /**
+     * 票 133:设备行必须带「可叠加标签」——一台设备可以同时是报警 + 预警 + 工单;
+     * 标签只从设备事实解析器取,不在适配器里用报警流水反推。
+     */
+    @Test
+    void deviceRowsCarryStackableAlarmWarningWorkOrderTags() {
+        stubPoints(Collections.emptyList());
+        stubTypes(Collections.singletonList(type(22, "combustible_gas_detector", "可燃气体检测仪", "3")));
+        EquipmentBase both = device("D-1", "BOTH-1", "22");
+        EquipmentBase alarmOnly = device("D-2", "ALARM-1", "22");
+        when(equipmentBaseService.list()).thenReturn(Arrays.asList(both, alarmOnly));
+        when(equipmentStatusService.list()).thenReturn(Collections.emptyList());
+        when(deviceFactResolver.resolve(any(), any())).thenAnswer(invocation -> {
+            EquipmentBase target = invocation.getArgument(0);
+            boolean isBoth = "BOTH-1".equals(target.getEquipmentCode());
+            CockpitMonitoringPointDeviceSnapshot fact = mock(CockpitMonitoringPointDeviceSnapshot.class);
+            when(fact.isAlarm()).thenReturn(true);
+            when(fact.isWarning()).thenReturn(isBoth);
+            when(fact.isWorkOrderInProgress()).thenReturn(isBoth);
+            return fact;
+        });
+
+        CockpitMonitoringOverviewSnapshot snapshot = adapter.load();
+
+        assertEquals(Arrays.asList("ALARM", "WARNING", "WORK_ORDER"), tagsOf(snapshot, "BOTH-1"),
+                "一台设备可同时带报警/预警/工单三个标签");
+        assertEquals(Collections.singletonList("ALARM"), tagsOf(snapshot, "ALARM-1"));
+    }
+
+    private static List<String> tagsOf(CockpitMonitoringOverviewSnapshot snapshot, String deviceCode) {
+        return snapshot.getDevices().stream()
+                .filter(d -> deviceCode.equals(d.getDeviceCode()))
+                .findFirst().orElseThrow().getTags();
+    }
+
     // ---- helpers ----
 
     /**

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

@@ -89,10 +89,11 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.eventFamily").value("WARNING"))
                 .andExpect(jsonPath("$.data.filters.eventFamily").value("WARNING"))
                 .andExpect(jsonPath("$.data.filters.workOrderState").value(nullValue()))
-                // 事件口径两族共用(真实计数,不是第二轮读数)。
-                .andExpect(jsonPath("$.data.summary.totalEvents").value(9))
+                // 事件口径两族共用(真实计数,不是第二轮读数);EW-008 是草稿,已按票 126 排除。
+                .andExpect(jsonPath("$.data.summary.totalEvents").value(8))
                 .andExpect(jsonPath("$.data.summary.linkedWorkOrderCount").value(6))
-                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(3))
+                // EW-008 是草稿且无工单:排除后缺失数随之 3 → 2。
+                .andExpect(jsonPath("$.data.summary.missingWorkOrderCount").value(2))
                 // 票 74:**工单口径**对预警族不成立 → 显式 null(不是 0,也不是别的族的数)。
                 .andExpect(jsonPath("$.data.summary.handledCount").value(nullValue()))
                 .andExpect(jsonPath("$.data.summary.inProgressCount").value(nullValue()))
@@ -100,11 +101,12 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.summary.handlingEfficiency").value(nullValue()))
                 .andExpect(jsonPath("$.data.summary.averageDuration").value(nullValue()))
                 .andExpect(jsonPath("$.data.workOrderStateCounts").value(nullValue()))
-                // 六个已知态全铺;EW-LEGACY 状态为空,另计 UNKNOWN,桶和仍为 9。
+                // 六个已知态全铺;EW-008 是草稿(票 126),DRAFT 桶保留但计 0;
+                // EW-LEGACY 状态为空,另计 UNKNOWN,桶和仍为 8。
                 .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))
+                .andExpect(jsonPath("$.data.warningStateCounts[0].count").value(0))
                 .andExpect(jsonPath("$.data.warningStateCounts[1].stateCode").value("PENDING"))
                 .andExpect(jsonPath("$.data.warningStateCounts[1].stateName").value("待接收"))
                 .andExpect(jsonPath("$.data.warningStateCounts[1].count").value(1))
@@ -120,10 +122,10 @@ class CockpitHandlingEfficiencyControllerTest {
                 .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)。
+                // 已解除率=已解除 ÷ 窗口内全部预警数(含未知类型,3/8;草稿不进分母)。
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.numerator").value(3))
-                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(9))
-                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.value").value("0.3333"))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(8))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.value").value("0.3750"))
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.state").value("AVAILABLE"))
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.basis")
                         .value("CLOSED_WARNINGS_OVER_WINDOW_WARNINGS"))
@@ -132,18 +134,18 @@ 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(9)))
+                .andExpect(jsonPath("$.data.events", hasSize(8)))
                 .andExpect(jsonPath("$.data.events[0].eventNo").value("EW-007"))
                 .andExpect(jsonPath("$.data.events[0].hasWorkOrder").value(true))
                 .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")))
+                        "EW-007", "EW-006", "EW-005", "EW-004", "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.pagination.total").value(8))
                 .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")))
+                        "D-DR-1", "D-DR-2", "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"))
@@ -151,7 +153,7 @@ class CockpitHandlingEfficiencyControllerTest {
                 .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[1].eventCount").value(2))
                 .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"))
@@ -250,6 +252,33 @@ class CockpitHandlingEfficiencyControllerTest {
                 .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(3));
     }
 
+
+    /**
+     * 票 130:预警的 publish_time 为空、update_time 有值时,窗口判据必须回退到 update_time,
+     * 该预警不得被整批抹掉。当前夹具都显式给了发布时间,覆盖不到这个缺陷。
+     */
+    @Test
+    void warningWithMissingPublishTimeButPresentUpdateTimeStaysInWindow() throws Exception {
+        when(adapter.load()).thenReturn(fixtureWithPublishTimeMissing());
+
+        mockMvc.perform(get(ENDPOINT)
+                        .param("eventFamily", "WARNING")
+                        .param("startTime", START)
+                        .param("endTime", END))
+                .andExpect(status().isOk())
+                // 发布时刻为空、update_time 在窗内 → 仍计一条,六态桶不再全 0 且求和等于总数。
+                .andExpect(jsonPath("$.data.summary.totalEvents").value(1))
+                .andExpect(jsonPath("$.data.pagination.total").value(1))
+                .andExpect(jsonPath("$.data.events", hasSize(1)))
+                .andExpect(jsonPath("$.data.events[0].eventNo").value("EW-NOPUB"))
+                // 只含已知状态时六态齐全(无 UNKNOWN 桶);CLOSED 为第六个(索引 5)。
+                .andExpect(jsonPath("$.data.warningStateCounts", hasSize(6)))
+                .andExpect(jsonPath("$.data.warningStateCounts[5].stateCode").value("CLOSED"))
+                .andExpect(jsonPath("$.data.warningStateCounts[5].count").value(1))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.denominator").value(1))
+                .andExpect(jsonPath("$.data.summary.warningHandlingEfficiency.numerator").value(1));
+    }
+
     @Test
     void warningFamilyEmptyWindowReportsTypedEmptyStatesInsteadOfFakeZero() throws Exception {
         mockMvc.perform(get(ENDPOINT)
@@ -341,12 +370,12 @@ class CockpitHandlingEfficiencyControllerTest {
                         .param("startTime", START)
                         .param("endTime", END))
                 .andExpect(status().isOk())
-                .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.summary.missingWorkOrderCount").value(2))
+                .andExpect(jsonPath("$.data.events", hasSize(8)))
+                .andExpect(jsonPath("$.data.summary.totalEvents").value(8))
+                .andExpect(jsonPath("$.data.events[?(@.hasWorkOrder == false)].eventNo").value(contains("EW-005", "EW-LEGACY")))
                 .andExpect(jsonPath("$.data.events[?(@.eventNo == 'EW-LEGACY')].deviceCode").value(contains("D-LEGACY")))
-                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(9)));
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(8)));
 
         // EventItem 不公开 industry;以真实筛选结果证明未知类型未被归入燃气。
         mockMvc.perform(get(ENDPOINT)
@@ -600,8 +629,9 @@ class CockpitHandlingEfficiencyControllerTest {
     }
 
     /**
-     * 主样本:9 条在范围内预警;`EW-LEGACY` 类型未登记但全域保留,状态为空计 UNKNOWN。
-     * 已知状态覆盖六态 —— DRAFT 1 / PENDING 1 / RECEIVED 1 / PROCESSING 1 / HANDLED 1 / CLOSED 3,
+     * 主样本:9 条预警,其中 `EW-008` 是草稿(DRAFT)—— 服务层必须排除(票 126),故响应按 8 条计;
+     * `EW-LEGACY` 类型未登记但全域保留,状态为空计 UNKNOWN。
+     * 已知状态覆盖六态 —— DRAFT 0(草稿已排除)/ PENDING 1 / RECEIVED 1 / PROCESSING 1 / HANDLED 1 / CLOSED 3,
      * 其中三条 CLOSED 的 `update_time` 分别距发布 0.50h / 2.00h / 1.00h。
      */
     private static CockpitHandlingEfficiencySnapshot fixture() {
@@ -758,6 +788,23 @@ class CockpitHandlingEfficiencyControllerTest {
                         scopeOrder("WO-U", 0, "GAS_SENSOR", null)));
     }
 
+    /**
+     * 票 130:一条发布于「空」、仅 update_time 有值的已解除预警(update_time 落在窗内)。
+     * 发布时刻 eventTime 传 null,update_time 传 10:30(窗口 08:00–12:00 内)。
+     */
+    private static CockpitHandlingEfficiencySnapshot fixtureWithPublishTimeMissing() {
+        return new CockpitHandlingEfficiencySnapshot(
+                "2026-09-02T11:59:50+08:00",
+                types(),
+                Collections.singletonList(
+                        warningWithWorkflow("EW-NOPUB", 2, null, "GAS_SENSOR",
+                                "D-GAS-1", "燃气浓度计-001", WarningWorkflow.CLOSED,
+                                "2026-09-02T10:30:00+08:00")),
+                Collections.emptyList(),
+                Collections.emptyList(),
+                Collections.emptyList());
+    }
+
     private static java.util.List<CockpitHandlingEfficiencySnapshot.SourceType> types() {
         return Arrays.asList(
                 new CockpitHandlingEfficiencySnapshot.SourceType(

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

@@ -128,6 +128,38 @@ class CockpitHistoryAnalysisControllerTest {
                 .andExpect(jsonPath("$.data.rows[3].handlingEfficiency.value").value("0.0000"));
     }
 
+    /**
+     * 票 126:草稿(DRAFT)预警只是未发布的编辑稿,不属于历史事件 —— 不进逐事件行、不进小时桶、
+     * 不计 pagination.total;状态为空/缺失的行仍保留(词表缺口不得把行藏掉,与总览既有判据一致)。
+     */
+    @Test
+    void draftWarningsAreExcludedFromRowsBucketsAndPaginationTotal() throws Exception {
+        when(adapter.load()).thenReturn(new CockpitHistoryAnalysisSnapshot(
+                "2026-09-02T02:00:00+08:00",
+                Arrays.asList(type("GAS_SENSOR", "GAS")),
+                Arrays.asList(
+                        warningWithStatus("HW-PENDING", 2, "2026-09-02T00:10:00+08:00", "GAS_SENSOR", "D-1", "PENDING"),
+                        warningWithStatus("HW-DRAFT", 2, "2026-09-02T00:20:00+08:00", "GAS_SENSOR", "D-2", "DRAFT"),
+                        warningWithStatus("HW-NOSTATUS", 2, "2026-09-02T00:30:00+08:00", "GAS_SENSOR", "D-3", null)),
+                Collections.emptyList(),
+                Collections.emptyList(),
+                Collections.emptyList()));
+
+        mockMvc.perform(get(ENDPOINT)
+                        .param("eventFamily", "WARNING")
+                        .param("startTime", START)
+                        .param("endTime", END))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.summary.eventCount").value(2))
+                .andExpect(jsonPath("$.data.events", hasSize(2)))
+                .andExpect(jsonPath("$.data.events[*].eventNo").value(contains("HW-NOSTATUS", "HW-PENDING")))
+                .andExpect(jsonPath("$.data.events[?(@.eventNo == 'HW-DRAFT')]", hasSize(0)))
+                .andExpect(jsonPath("$.data.pagination.total").value(2))
+                // 小时桶同口径:00:00 桶只数到保留的两条,草稿不进桶。
+                .andExpect(jsonPath("$.data.rows[?(@.timeBucket == '2026-09-02T00:00:00+08:00')].eventCount")
+                        .value(contains(2)));
+    }
+
     /**
      * 票 77:片区在历史分析上真的生效 —— 事件行与汇总处置率的工单范围**同一片区口径**。
      *
@@ -568,6 +600,14 @@ class CockpitHistoryAnalysisControllerTest {
                 no, level, eventTime, typeCode, deviceCode, null, null, null, null, district);
     }
 
+    /** 票 126:带业务状态的预警样本(DRAFT 用于验证草稿排除)。 */
+    private static CockpitHistoryAnalysisSnapshot.SourceWarning warningWithStatus(
+            String no, Integer level, String eventTime, String typeCode, String deviceCode,
+            String status) {
+        return new CockpitHistoryAnalysisSnapshot.SourceWarning(
+                no, level, eventTime, typeCode, deviceCode, status, null, null, null, null);
+    }
+
     private static CockpitHistoryAnalysisSnapshot.SourceAlarm alarm(
             String id, Integer level, String eventTime, String typeCode, String deviceCode) {
         return alarm(id, level, eventTime, typeCode, deviceCode, null);

+ 67 - 1
pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitMultidimensionalAnalysisControllerTest.java

@@ -92,6 +92,56 @@ class CockpitMultidimensionalAnalysisControllerTest {
                 .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(8)));
     }
 
+    /**
+     * 票 126:草稿(DRAFT)不是对外读数 —— 不进任何维度桶、不进 totalCount、不进 mapFilter;
+     * 状态缺失的行仍保留(词表缺口不得把行藏掉)。
+     */
+    @Test
+    void warningFamilyExcludesDraftWarningsFromEveryDimension() throws Exception {
+        when(adapter.load()).thenReturn(new CockpitMultidimensionalAnalysisSnapshot(
+                "2026-09-02T15:59:50+08:00",
+                Arrays.asList(type("GAS_SENSOR", "燃气浓度计", "GAS")),
+                Arrays.asList(
+                        warning("MD-PENDING", "GAS_CONCENTRATION", "浓度超限", 2,
+                                "2026-09-02T09:00:00+08:00", 0, "GAS_SENSOR", "D-1", "PENDING"),
+                        warning("MD-DRAFT", "GAS_CONCENTRATION", "浓度超限", 2,
+                                "2026-09-02T09:10:00+08:00", 0, "GAS_SENSOR", "D-2", "DRAFT"),
+                        warning("MD-NOSTATUS", "GAS_CONCENTRATION", "浓度超限", 2,
+                                "2026-09-02T09:20:00+08:00", 0, "GAS_SENSOR", "D-3", null)),
+                Collections.emptyList()));
+
+        mockMvc.perform(get(ENDPOINT)
+                        .param("eventFamily", "WARNING")
+                        .param("startTime", START)
+                        .param("endTime", END))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.totalCount").value(2))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(2)));
+    }
+
+    /**
+     * 票 130:预警 publish_time 为空、update_time 在窗内时,多维窗口判据必须回退到 update_time,
+     * 该预警不得被整批抹掉(总数为 0)。
+     */
+    @Test
+    void warningWithMissingPublishTimeButPresentUpdateTimeIsCounted() throws Exception {
+        when(adapter.load()).thenReturn(new CockpitMultidimensionalAnalysisSnapshot(
+                "2026-09-02T15:59:50+08:00",
+                Arrays.asList(type("GAS_SENSOR", "燃气浓度计", "GAS")),
+                Arrays.asList(
+                        warningWithUpdateTime("MD-NOPUB", "GAS_CONCENTRATION", "浓度超限", 2,
+                                null, "2026-09-02T09:30:00+08:00", 0, "GAS_SENSOR", "D-1", "CLOSED")),
+                Collections.emptyList()));
+
+        mockMvc.perform(get(ENDPOINT)
+                        .param("eventFamily", "WARNING")
+                        .param("startTime", START)
+                        .param("endTime", END))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.totalCount").value(1))
+                .andExpect(jsonPath("$.data.mapFilter.deviceCodes", hasSize(1)));
+    }
+
     @Test
     void alarmFamilyIsIsolatedFromWarnings() throws Exception {
         mockMvc.perform(get(ENDPOINT)
@@ -500,7 +550,23 @@ class CockpitMultidimensionalAnalysisControllerTest {
             String no, String eventType, String cause, Integer level, String eventTime,
             Integer district, String typeCode, String deviceCode) {
         return new CockpitMultidimensionalAnalysisSnapshot.SourceWarning(
-                no, eventType, cause, level, eventTime, district, typeCode, deviceCode);
+                no, eventType, cause, level, eventTime, null, district, typeCode, deviceCode, null);
+    }
+
+    /** 票 126:带业务状态的样本(DRAFT 用于验证草稿排除);票 130:更新时刻留空。 */
+    private static CockpitMultidimensionalAnalysisSnapshot.SourceWarning warning(
+            String no, String eventType, String cause, Integer level, String eventTime,
+            Integer district, String typeCode, String deviceCode, String status) {
+        return new CockpitMultidimensionalAnalysisSnapshot.SourceWarning(
+                no, eventType, cause, level, eventTime, null, district, typeCode, deviceCode, status);
+    }
+
+    /** 票 130:带更新时刻的样本 —— 发布时刻为 null、更新时刻在窗内,验证窗口回退。 */
+    private static CockpitMultidimensionalAnalysisSnapshot.SourceWarning warningWithUpdateTime(
+            String no, String eventType, String cause, Integer level, String eventTime, String updateTime,
+            Integer district, String typeCode, String deviceCode, String status) {
+        return new CockpitMultidimensionalAnalysisSnapshot.SourceWarning(
+                no, eventType, cause, level, eventTime, updateTime, district, typeCode, deviceCode, status);
     }
 
     private static CockpitMultidimensionalAnalysisSnapshot.SourceAlarm alarm(

+ 11 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/domain/WarningWorkflow.java

@@ -4,6 +4,7 @@ import com.zksy.common.exception.ServiceException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
 
 /** 预警业务状态的唯一主线;已处置仍需核查,只有已解除才是终态。 */
 public final class WarningWorkflow {
@@ -20,6 +21,16 @@ public final class WarningWorkflow {
         return EarlyWarningStatusEnum.labelOf(state);
     }
 
+    /**
+     * 草稿:保存了但还没发布的编辑稿,不属于任何对外读数(历史/效率/分析的计数一律排除)。
+     *
+     * <p>空或缺失状态**不是**草稿 —— 认不出的状态按「不能证明是草稿」保留,
+     * 与总览计数判据({@code status IS NULL OR UPPER(TRIM(status)) <> 'DRAFT'})同一语义。
+     */
+    public static boolean isDraft(String state) {
+        return state != null && DRAFT.equals(state.trim().toUpperCase(Locale.ROOT));
+    }
+
     public static void requireState(EarlyWarning warning, String operation, String... allowed) {
         if (warning == null) throw new ServiceException("预警不存在");
         if (!Arrays.asList(allowed).contains(warning.getStatus())) {

+ 5 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/BusinessCockpitEventAdapter.java

@@ -587,9 +587,13 @@ public class BusinessCockpitEventAdapter {
                         null,
                         level(item.warning.getWarningLevel()),
                         offsetTime(item.warning.getPublishTime()),
+                        // 发布时刻缺失时,服务层可回退到更新时间判窗/分桶;不改写 eventTime,排序仍按原值。
+                        offsetTime(item.warning.getUpdateTime()),
                         districtCode(item.warning.getDeviceCode(), facts),
                         typeCode(item.warning.getDeviceCode(), facts),
-                        trimToNull(item.warning.getDeviceCode())))
+                        trimToNull(item.warning.getDeviceCode()),
+                        // 票 126:状态随快照下传,供服务层排除草稿(与历史/效率同一判据)。
+                        trimToNull(item.warning.getStatus())))
                 .collect(Collectors.toList());
     }
 

+ 10 - 3
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitHandlingEfficiencyService.java

@@ -530,7 +530,10 @@ public class CockpitHandlingEfficiencyService {
             return facts;
         }
         for (CockpitHandlingEfficiencySnapshot.SourceWarning warning : snapshot.getWarnings()) {
+            // 票 126:草稿(DRAFT)未发布,不进逐事件行,也不进六态分布与处置率分母
+            // (同一份 facts 派生全部读数,故只在这一处排除即全口径一致)。
             if (warning == null
+                    || WarningWorkflow.isDraft(warning.getStatus())
                     || !inScope(types, warning.getTypeCode(), industry)
                     || (level != null && !level.equals(warning.getLevel()))
                     || !CockpitDistrict.matches(district, warning.getDistrict())) {
@@ -603,11 +606,15 @@ public class CockpitHandlingEfficiencyService {
     private static List<EventFact> inWindow(List<EventFact> facts, TimeWindow window) {
         List<EventFact> result = new ArrayList<>();
         for (EventFact fact : facts) {
-            OffsetDateTime eventTime = parseEventTime(fact.eventTime);
-            if (eventTime == null) {
+            OffsetDateTime reference = parseEventTime(fact.eventTime);
+            if (reference == null) {
+                // 发布时刻缺失时退回更新时间,仅用于判窗;不写回 eventTime,排序仍按原值为 null 排末尾。
+                reference = parseEventTime(fact.updateTime);
+            }
+            if (reference == null) {
                 continue;
             }
-            if (eventTime.isBefore(window.start) || eventTime.isAfter(window.end)) {
+            if (reference.isBefore(window.start) || reference.isAfter(window.end)) {
                 continue;
             }
             result.add(fact);

+ 4 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitHistoryAnalysisService.java

@@ -1,5 +1,6 @@
 package com.zksy.cockpit.event;
 
+import com.zksy.base.warning.domain.WarningWorkflow;
 import com.zksy.cockpit.foundation.CockpitDistrict;
 import com.zksy.cockpit.foundation.CockpitErrorCategory;
 import com.zksy.cockpit.foundation.CockpitErrorPayload;
@@ -234,7 +235,10 @@ public class CockpitHistoryAnalysisService {
             return rows;
         }
         for (CockpitHistoryAnalysisSnapshot.SourceWarning warning : snapshot.getWarnings()) {
+            // 票 126:草稿(DRAFT)只是未发布的编辑稿,不属于历史事件 —— 不进 events[]、
+            // 不进小时桶、不计 pagination.total。状态为空/缺失不算草稿(词表缺口不得把行藏掉)。
             if (warning == null
+                    || WarningWorkflow.isDraft(warning.getStatus())
                     || !inScope(types, warning.getTypeCode(), industry)
                     || (level != null && !level.equals(warning.getLevel()))
                     || !CockpitDistrict.matches(district, warning.getDistrict())) {

+ 28 - 5
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitMultidimensionalAnalysisService.java

@@ -1,5 +1,6 @@
 package com.zksy.cockpit.event;
 
+import com.zksy.base.warning.domain.WarningWorkflow;
 import com.zksy.cockpit.foundation.CockpitDistrict;
 import com.zksy.cockpit.foundation.CockpitErrorCategory;
 import com.zksy.cockpit.foundation.CockpitErrorPayload;
@@ -311,7 +312,11 @@ public class CockpitMultidimensionalAnalysisService {
             labels.put(key, key);
         }
         for (Fact fact : facts) {
-            ZonedDateTime day = fact.eventTime.atZoneSameInstant(BUSINESS_ZONE).truncatedTo(ChronoUnit.DAYS);
+            OffsetDateTime reference = referenceTime(fact);
+            if (reference == null) {
+                continue;   // 理论上进不了 scoped(已被 inWindow 过滤),防御性保留
+            }
+            ZonedDateTime day = reference.atZoneSameInstant(BUSINESS_ZONE).truncatedTo(ChronoUnit.DAYS);
             String key = DAY.format(day);
             if (counts.containsKey(key)) {
                 counts.merge(key, 1, Integer::sum);
@@ -355,7 +360,8 @@ public class CockpitMultidimensionalAnalysisService {
             return facts;
         }
         for (CockpitMultidimensionalAnalysisSnapshot.SourceWarning warning : snapshot.getWarnings()) {
-            if (warning == null) {
+            // 票 126:草稿不进任何维度计数(与历史/效率同一判据);状态缺失不算草稿。
+            if (warning == null || WarningWorkflow.isDraft(warning.getStatus())) {
                 continue;
             }
             CockpitMultidimensionalAnalysisSnapshot.SourceType type = resolveType(types, warning.getTypeCode());
@@ -367,6 +373,7 @@ public class CockpitMultidimensionalAnalysisService {
                     warning.getCause(),
                     warning.getLevel(),
                     parseEventTime(warning.getEventTime()),
+                    parseEventTime(warning.getUpdateTime()),   // ← 新增
                     warning.getDistrict(),
                     type.getIndustry(),
                     type.getCode(),
@@ -395,6 +402,7 @@ public class CockpitMultidimensionalAnalysisService {
                     alarm.getCause(),
                     alarm.getLevel(),
                     parseEventTime(alarm.getEventTime()),
+                    null,                                        // ← 报警族不回退
                     alarm.getDistrict(),
                     type.getIndustry(),
                     type.getCode(),
@@ -419,11 +427,22 @@ public class CockpitMultidimensionalAnalysisService {
         return type;
     }
 
+    /**
+     * 判窗/分桶的参照时刻:优先事件发布时刻,缺失时回退到更新时间(有前提的读数)。
+     * 回退值仅用于判定,**不写回 {@link Fact#eventTime}** —— 事件排序仍按原值,
+     * 缺失如实排末尾,不假装发布时刻存在。
+     */
+    private static OffsetDateTime referenceTime(Fact fact) {
+        return fact.eventTime != null ? fact.eventTime : fact.updateTime;
+    }
+
     private static boolean inWindow(Fact fact, TimeWindow window) {
-        if (fact.eventTime == null) {
+        // 判窗用参照时刻(发布时刻缺失时回退更新时间);两者皆空才丢。
+        OffsetDateTime reference = referenceTime(fact);
+        if (reference == null) {
             return false;
         }
-        return !fact.eventTime.isBefore(window.start) && !fact.eventTime.isAfter(window.end);
+        return !reference.isBefore(window.start) && !reference.isAfter(window.end);
     }
 
     private static Map<String, CockpitMultidimensionalAnalysisSnapshot.SourceType> types(
@@ -565,17 +584,21 @@ public class CockpitMultidimensionalAnalysisService {
         private final String cause;
         private final Integer level;
         private final OffsetDateTime eventTime;
+        /** 更新时间;发布时刻缺失时作为判窗/分桶的回退时刻(仅判定,不写回 eventTime)。 */
+        private final OffsetDateTime updateTime;
         private final Integer district;
         private final String industry;
         private final String deviceType;
         private final String deviceCode;
 
         private Fact(String eventType, String cause, Integer level, OffsetDateTime eventTime,
-                Integer district, String industry, String deviceType, String deviceCode) {
+                     OffsetDateTime updateTime, Integer district, String industry,
+                     String deviceType, String deviceCode) {
             this.eventType = eventType;
             this.cause = cause;
             this.level = level;
             this.eventTime = eventTime;
+            this.updateTime = updateTime;
             this.district = district;
             this.industry = industry;
             this.deviceType = deviceType;

+ 12 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitMultidimensionalAnalysisSnapshot.java

@@ -66,9 +66,13 @@ public class CockpitMultidimensionalAnalysisSnapshot {
         private final String cause;
         private final Integer level;
         private final String eventTime;
+        /** 预警记录最后更新时间;发布时刻缺失时,服务层以它回退判窗/分桶(仅判定,不改写 eventTime)。 */
+        private final String updateTime;
         private final Integer district;
         private final String typeCode;
         private final String deviceCode;
+        /** 预警业务状态(原值);用于排除草稿(票 126),未知/缺失如实保留。 */
+        private final String status;
 
         public SourceWarning(
                 String warningNo,
@@ -76,17 +80,21 @@ public class CockpitMultidimensionalAnalysisSnapshot {
                 String cause,
                 Integer level,
                 String eventTime,
+                String updateTime,
                 Integer district,
                 String typeCode,
-                String deviceCode) {
+                String deviceCode,
+                String status) {
             this.warningNo = warningNo;
             this.warningType = warningType;
             this.cause = cause;
             this.level = level;
             this.eventTime = eventTime;
+            this.updateTime = updateTime;
             this.district = district;
             this.typeCode = typeCode;
             this.deviceCode = deviceCode;
+            this.status = status;
         }
 
         public String getWarningNo() { return warningNo; }
@@ -94,10 +102,13 @@ public class CockpitMultidimensionalAnalysisSnapshot {
         public String getCause() { return cause; }
         public Integer getLevel() { return level; }
         public String getEventTime() { return eventTime; }
+        /** 预警记录最后更新时间;发布时刻缺失时,服务层以它回退判窗/分桶(仅判定,不改写 eventTime)。 */
+        public String getUpdateTime() { return updateTime; }
         /** 片区编码(0-城南 1-城北 2-太常,权威来源 equipment_base.district);未分区为 {@code null},不猜。 */
         public Integer getDistrict() { return district; }
         public String getTypeCode() { return typeCode; }
         public String getDeviceCode() { return deviceCode; }
+        public String getStatus() { return status; }
     }
 
     public static class SourceAlarm {

+ 83 - 36
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/BusinessCockpitMonitoringOverviewAdapter.java

@@ -11,6 +11,8 @@ import com.zksy.base.service.MonitorPointService;
 import com.zksy.cockpit.foundation.CockpitCreatedAt;
 import com.zksy.cockpit.foundation.CockpitDistrict;
 import com.zksy.cockpit.foundation.CockpitTypeIndustry;
+import com.zksy.cockpit.point.BusinessCockpitDeviceFactResolver;
+import com.zksy.cockpit.point.CockpitMonitoringPointDeviceSnapshot;
 import org.springframework.context.annotation.Primary;
 import org.springframework.stereotype.Component;
 
@@ -55,6 +57,8 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
     private final EquipmentBaseService equipmentBaseService;
     private final EquipmentStatusService equipmentStatusService;
     private final EquipmentTypeService equipmentTypeService;
+    /** 票 133:设备状态标签(报警/预警/工单)的唯一事实源,避免各适配器各写一份四表查询。 */
+    private final BusinessCockpitDeviceFactResolver deviceFacts;
     private final Clock clock;
 
     public BusinessCockpitMonitoringOverviewAdapter(
@@ -62,11 +66,13 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
             EquipmentBaseService equipmentBaseService,
             EquipmentStatusService equipmentStatusService,
             EquipmentTypeService equipmentTypeService,
+            BusinessCockpitDeviceFactResolver deviceFacts,
             Clock clock) {
         this.monitorPointService = monitorPointService;
         this.equipmentBaseService = equipmentBaseService;
         this.equipmentStatusService = equipmentStatusService;
         this.equipmentTypeService = equipmentTypeService;
+        this.deviceFacts = deviceFacts;
         this.clock = clock;
     }
 
@@ -138,42 +144,8 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
             }
         }
 
-        List<CockpitMonitoringOverviewSnapshot.SourceDevice> devices = new ArrayList<>();
-        for (EquipmentBase device : ledger) {
-            if (device == null || isBlank(device.getEquipmentCode())) {
-                continue;
-            }
-            String deviceCode = device.getEquipmentCode().trim();
-            EquipmentType type = device.getEquipmentTypeId() == null
-                    ? null
-                    : types.get(device.getEquipmentTypeId());
-
-            EquipmentStatus status = statusBatchReady
-                    ? statusById.get(device.getEquipmentId())
-                    : null;
-            if (!statusBatchReady) {
-                try {
-                    status = equipmentStatusService.getByDeviceCode(deviceCode);
-                } catch (Exception ignored) {
-                    // 状态缺失按 UNKNOWN 上报,不阻断概览
-                }
-            }
-            devices.add(new CockpitMonitoringOverviewSnapshot.SourceDevice(
-                    deviceCode,
-                    // 执行票 62:设备台账要显示名称(缺名如实为 null,不拿编码冒充)。
-                    isBlank(device.getEquipmentName()) ? null : device.getEquipmentName().trim(),
-                    type == null || type.getId() == null ? null : String.valueOf(type.getId()),
-                    monitoringState(status),
-                    status == null || status.getStatusUpdateTime() == null
-                            ? null
-                            : TIME_FORMATTER.format(status.getStatusUpdateTime()
-                                    .atZone(BUSINESS_ZONE).toOffsetDateTime()),
-                    pointCodeByDevice.get(deviceCode),
-                    // 数据时间=记录创建时间(equipment_base.create_time),与 sampledAt 分离
-                    CockpitCreatedAt.format(device.getCreateTime()),
-                    // 设备自身片区(equipment_base.district)即权威来源;脏值由 codeOf 归一为未分区
-                    CockpitDistrict.codeOf(device.getDistrict())));
-        }
+        List<CockpitMonitoringOverviewSnapshot.SourceDevice> devices =
+                deviceRows(ledger, types, statusById, statusBatchReady, pointCodeByDevice);
 
         List<CockpitMonitoringOverviewSnapshot.SourceType> sourceTypes = types.values().stream()
                 .filter(type -> type.getId() != null)
@@ -199,6 +171,81 @@ public class BusinessCockpitMonitoringOverviewAdapter implements CockpitMonitori
         return Integer.valueOf(1).equals(status.getOnlineStatus()) ? "ONLINE" : "OFFLINE";
     }
 
+    /**
+     * 设备台账 → 设备行。票 133:额外带 ALARM / WARNING / WORK_ORDER 三个**可叠加标签**。
+     *
+     * <p>标签事实只从 {@link BusinessCockpitDeviceFactResolver} 取(在线/报警=equipment_status、
+     * 预警=未解除预警、工单=未结束工单);本适配器不另写四表查询,也不用报警流水二次推断
+     * (CONTEXT.md「设备预警/报警统计」「点位特效显示规则」两节都明令禁止)。
+     */
+    private List<CockpitMonitoringOverviewSnapshot.SourceDevice> deviceRows(
+            List<EquipmentBase> ledger,
+            Map<Integer, EquipmentType> types,
+            Map<String, EquipmentStatus> statusById,
+            boolean statusBatchReady,
+            Map<String, String> pointCodeByDevice) {
+        List<CockpitMonitoringOverviewSnapshot.SourceDevice> devices = new ArrayList<>();
+        deviceFacts.prepareBatch(ledger);
+        try {
+            for (EquipmentBase device : ledger) {
+                if (device == null || isBlank(device.getEquipmentCode())) {
+                    continue;
+                }
+                String deviceCode = device.getEquipmentCode().trim();
+                EquipmentType type = device.getEquipmentTypeId() == null
+                        ? null
+                        : types.get(device.getEquipmentTypeId());
+
+                EquipmentStatus status = statusBatchReady
+                        ? statusById.get(device.getEquipmentId())
+                        : null;
+                if (!statusBatchReady) {
+                    try {
+                        status = equipmentStatusService.getByDeviceCode(deviceCode);
+                    } catch (Exception ignored) {
+                        // 状态缺失按 UNKNOWN 上报,不阻断概览
+                    }
+                }
+                devices.add(new CockpitMonitoringOverviewSnapshot.SourceDevice(
+                        deviceCode,
+                        // 执行票 62:设备台账要显示名称(缺名如实为 null,不拿编码冒充)。
+                        isBlank(device.getEquipmentName()) ? null : device.getEquipmentName().trim(),
+                        type == null || type.getId() == null ? null : String.valueOf(type.getId()),
+                        monitoringState(status),
+                        status == null || status.getStatusUpdateTime() == null
+                                ? null
+                                : TIME_FORMATTER.format(status.getStatusUpdateTime()
+                                        .atZone(BUSINESS_ZONE).toOffsetDateTime()),
+                        pointCodeByDevice.get(deviceCode),
+                        // 数据时间=记录创建时间(equipment_base.create_time),与 sampledAt 分离
+                        CockpitCreatedAt.format(device.getCreateTime()),
+                        // 设备自身片区(equipment_base.district)即权威来源;脏值由 codeOf 归一为未分区
+                        CockpitDistrict.codeOf(device.getDistrict()),
+                        tagsOf(device, type)));
+            }
+        } finally {
+            deviceFacts.clearBatch();
+        }
+        return devices;
+    }
+
+    /** 单台设备的状态标签(可叠加):报警/预警/工单任一成立即入列,都不成立时为空列表。 */
+    private List<String> tagsOf(EquipmentBase device, EquipmentType type) {
+        CockpitMonitoringPointDeviceSnapshot fact =
+                deviceFacts.resolve(device, type == null ? null : type.getTypeName());
+        List<String> tags = new ArrayList<>();
+        if (fact != null && fact.isAlarm()) {
+            tags.add("ALARM");
+        }
+        if (fact != null && fact.isWarning()) {
+            tags.add("WARNING");
+        }
+        if (fact != null && fact.isWorkOrderInProgress()) {
+            tags.add("WORK_ORDER");
+        }
+        return tags;
+    }
+
     private Map<Integer, EquipmentType> equipmentTypes() {
         Map<Integer, EquipmentType> result = new HashMap<>();
         for (EquipmentType type : safeList(equipmentTypeService.list())) {

+ 24 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewResponse.java

@@ -253,6 +253,11 @@ public class CockpitMonitoringOverviewResponse {
          */
         private final Integer district;
         private final String districtName;
+        /**
+         * 设备状态标签(票 133):{@code ALARM} / {@code WARNING} / {@code WORK_ORDER} 的命中项,可叠加。
+         * 空数组=无业务标签;未提供时同样给空数组,不用 null 让前端猜。
+         */
+        private final java.util.List<String> tags;
 
         public Device(
                 String deviceCode,
@@ -264,7 +269,7 @@ public class CockpitMonitoringOverviewResponse {
                 String sampledAt,
                 String createdAt) {
             this(deviceCode, deviceName, deviceType, industry, monitoringState,
-                    monitoringPointCode, sampledAt, createdAt, null, null);
+                    monitoringPointCode, sampledAt, createdAt, null, null, null);
         }
 
         public Device(
@@ -278,6 +283,22 @@ public class CockpitMonitoringOverviewResponse {
                 String createdAt,
                 Integer district,
                 String districtName) {
+            this(deviceCode, deviceName, deviceType, industry, monitoringState,
+                    monitoringPointCode, sampledAt, createdAt, district, districtName, null);
+        }
+
+        public Device(
+                String deviceCode,
+                String deviceName,
+                DeviceType deviceType,
+                String industry,
+                String monitoringState,
+                String monitoringPointCode,
+                String sampledAt,
+                String createdAt,
+                Integer district,
+                String districtName,
+                java.util.List<String> tags) {
             this.deviceCode = deviceCode;
             this.deviceName = deviceName;
             this.deviceType = deviceType;
@@ -288,6 +309,7 @@ public class CockpitMonitoringOverviewResponse {
             this.createdAt = createdAt;
             this.district = district;
             this.districtName = districtName;
+            this.tags = tags == null ? java.util.Collections.emptyList() : tags;
         }
 
         public String getDeviceCode() { return deviceCode; }
@@ -300,6 +322,7 @@ public class CockpitMonitoringOverviewResponse {
         public String getCreatedAt() { return createdAt; }
         public Integer getDistrict() { return district; }
         public String getDistrictName() { return districtName; }
+        public java.util.List<String> getTags() { return tags; }
     }
 
     public static class TypeDistribution {

+ 2 - 1
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewService.java

@@ -309,7 +309,8 @@ public class CockpitMonitoringOverviewService {
                     source == null ? null : source.getCreatedAt(),
                     // 逐行带片区(票 81):前端可本地分解,不用猜这台设备算哪个片区
                     runtime.district,
-                    CockpitDistrict.nameOf(runtime.district)));
+                    CockpitDistrict.nameOf(runtime.district),
+                    source == null ? null : source.getTags()));
         }
 
         return new CockpitMonitoringOverviewResponse(

+ 24 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewSnapshot.java

@@ -59,6 +59,12 @@ public class CockpitMonitoringOverviewSnapshot {
          * 这是本端点唯一的片区事实来源 —— 设备台账逐行带片区,服务层据此筛。
          */
         private final Integer district;
+        /**
+         * 设备状态标签(票 133):{@code ALARM} / {@code WARNING} / {@code WORK_ORDER} 中命中的若干项,
+         * 可同时存在(一台设备可以既有报警又有未结束工单)。空列表=没有任何业务标签。
+         * 事实来源见 {@code BusinessCockpitDeviceFactResolver},本层只携带、不推导。
+         */
+        private final List<String> tags;
 
         public SourceDevice(
                 String deviceCode,
@@ -102,6 +108,21 @@ public class CockpitMonitoringOverviewSnapshot {
                 String pointCode,
                 String createdAt,
                 Integer district) {
+            this(deviceCode, deviceName, typeCode, monitoringState,
+                    sampledAt, pointCode, createdAt, district, null);
+        }
+
+        /** 票 133:带状态标签的设备行。 */
+        public SourceDevice(
+                String deviceCode,
+                String deviceName,
+                String typeCode,
+                String monitoringState,
+                String sampledAt,
+                String pointCode,
+                String createdAt,
+                Integer district,
+                List<String> tags) {
             this.deviceCode = deviceCode;
             this.deviceName = deviceName;
             this.typeCode = typeCode;
@@ -110,6 +131,7 @@ public class CockpitMonitoringOverviewSnapshot {
             this.pointCode = pointCode;
             this.createdAt = createdAt;
             this.district = district;
+            this.tags = tags;
         }
 
         public String getDeviceCode() { return deviceCode; }
@@ -120,6 +142,8 @@ public class CockpitMonitoringOverviewSnapshot {
         public String getPointCode() { return pointCode; }
         public String getCreatedAt() { return createdAt; }
         public Integer getDistrict() { return district; }
+        /** 状态标签(可叠加);未提供时为空列表(不臆造 ALARM/WARNING)。 */
+        public List<String> getTags() { return tags == null ? java.util.Collections.emptyList() : tags; }
     }
 
     public static class SourceMonitoringPoint {

+ 7 - 2
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/BusinessCockpitDeviceFactResolver.java

@@ -43,9 +43,14 @@ public class BusinessCockpitDeviceFactResolver {
     private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
     private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
 
-    /** 未关闭的预警状态:现网取值含 PENDING/PROCESSING 等。 */
+    /**
+     * 未解除的预警状态(票 133):取值域是字典 {@code pre_alarm_status} 的六态
+     * DRAFT/PENDING/RECEIVED/PROCESSING/HANDLED/CLOSED 中的**未解除集合**——
+     * 草稿(DRAFT)与已解除(CLOSED)都不算未解除,与总览计数的同一规格 §4。
+     * 此前写的是 HANDLING/RELEASED,这两个值在字典里不存在,永远命中不了。
+     */
     private static final Set<String> OPEN_WARNING_STATUS = new LinkedHashSet<>(
-            Arrays.asList("PENDING", "PROCESSING", "HANDLING", "RELEASED"));
+            Arrays.asList("PENDING", "RECEIVED", "PROCESSING", "HANDLED"));
 
     /** 报警记录未处理:{@code alarm_data.alarm_status},见 {@code AlarmRecordStatusEnum.UNHANDLED}。 */
     private static final Integer UNHANDLED_ALARM_STATUS = 0;

+ 5 - 0
zk-api-service/src/main/java/com/zksy/api/mapper/AutoWarningClosureMapper.java

@@ -10,7 +10,12 @@ public interface AutoWarningClosureMapper {
             + "AND status='DRAFT' ORDER BY create_time DESC LIMIT 1 FOR UPDATE")
     EarlyWarning lockDraft(@Param("deviceCode") String deviceCode, @Param("marker") String marker);
 
+    // 票 130:本条只关闭未发布的自动草稿(status='DRAFT'),publish_time 必为空。
+    // 自动触发→自动解除从未经过人工发布,故以生效时刻(create_time,即触发时刻)补写
+    // publish_time,避免该预警因发布时间缺失被效率/多维的窗口整批抹掉;COALESCE 保证
+    // 若已有真实发布时刻绝不覆盖。
     @Update("UPDATE app_user.early_warning SET status='CLOSED', stage_deadline=NULL, "
+            + "publish_time=COALESCE(publish_time, create_time), "
             + "update_by='系统自动', update_time=#{now} WHERE warning_id=#{id} AND status='DRAFT'")
     int closeDraft(@Param("id") String id, @Param("now") LocalDateTime now);