Browse Source

Merge remote-tracking branch 'origin/master'

zengy 3 weeks ago
parent
commit
d66d9f7e25
18 changed files with 797 additions and 40 deletions
  1. 54 0
      pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/cockpit/CockpitCollectionRecordsController.java
  2. 293 0
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitCollectionRecordsControllerTest.java
  3. 46 0
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitMonitoringOverviewControllerTest.java
  4. 4 0
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitMonitoringPointDetailControllerTest.java
  5. 49 10
      pipe-network-service/zksy-admin/src/test/java/com/zksy/web/controller/cockpit/CockpitMonitoringPointStatusOrderTest.java
  6. 93 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/collectionRecords/CockpitCollectionRecordsResponse.java
  7. 87 0
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/collectionRecords/CockpitCollectionRecordsService.java
  8. 10 5
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/BusinessCockpitEventAdapter.java
  9. 7 2
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitCurrentEventsService.java
  10. 11 3
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitHandlingEfficiencyService.java
  11. 11 3
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/event/CockpitHistoryAnalysisService.java
  12. 25 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringDistributionService.java
  13. 25 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringOverviewService.java
  14. 23 1
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/monitoring/CockpitMonitoringSituationService.java
  15. 15 2
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/CockpitMonitoringPointStatus.java
  16. 39 10
      pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/CockpitMonitoringPointStatusResolver.java
  17. 2 1
      pipe-network-service/zksy-system/src/test/java/com/zksy/base/alarm/service/AlarmMobileServiceTest.java
  18. 3 1
      pipe-network-service/zksy-system/src/test/java/com/zksy/base/alarm/service/AlarmOperationsServiceTest.java

+ 54 - 0
pipe-network-service/zksy-admin/src/main/java/com/zksy/web/controller/cockpit/CockpitCollectionRecordsController.java

@@ -0,0 +1,54 @@
+package com.zksy.web.controller.cockpit;
+
+import com.zksy.cockpit.collectionRecords.CockpitCollectionRecordsResponse;
+import com.zksy.cockpit.collectionRecords.CockpitCollectionRecordsService;
+import com.zksy.cockpit.foundation.CockpitDeviceNotFoundException;
+import com.zksy.cockpit.foundation.CockpitInvalidRequestException;
+import com.zksy.common.core.domain.AjaxResult;
+import com.zksy.common.utils.uuid.IdUtils;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestHeader;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.util.UriUtils;
+
+import java.nio.charset.StandardCharsets;
+
+/** 驾驶舱公开只读入口,不改变管理端档案接口的授权。 */
+@RestController
+public class CockpitCollectionRecordsController {
+    private final CockpitCollectionRecordsService service;
+
+    public CockpitCollectionRecordsController(CockpitCollectionRecordsService service) {
+        this.service = service;
+    }
+
+    @GetMapping("/api/cockpit/v1/equipments/{deviceCode}/collection-records")
+    public ResponseEntity<AjaxResult> collectionRecords(
+            @PathVariable("deviceCode") String deviceCode,
+            @RequestHeader(value = "X-Request-Id", required = false) String requestId) {
+        String traceId = requestId == null || requestId.trim().isEmpty() ? IdUtils.fastSimpleUUID() : requestId;
+        try {
+            String decoded;
+            try {
+                decoded = UriUtils.decode(deviceCode, StandardCharsets.UTF_8);
+            } catch (IllegalArgumentException exception) {
+                throw new CockpitInvalidRequestException("设备编码不合法");
+            }
+            return ResponseEntity.ok(AjaxResult.success(service.load(traceId, decoded)));
+        } catch (CockpitInvalidRequestException exception) {
+            return failure(400, traceId, deviceCode, exception.getMessage());
+        } catch (CockpitDeviceNotFoundException exception) {
+            return failure(404, traceId, deviceCode, "设备不存在");
+        } catch (RuntimeException exception) {
+            return failure(500, traceId, deviceCode, "驾驶舱采集记录读取失败,暂不可用");
+        }
+    }
+
+    private ResponseEntity<AjaxResult> failure(int status, String requestId, String deviceCode, String message) {
+        CockpitCollectionRecordsResponse response = new CockpitCollectionRecordsResponse(
+                requestId, deviceCode, "FAILED", message, CockpitCollectionRecordsResponse.emptyView());
+        return ResponseEntity.status(status).body(new AjaxResult(status, message, response));
+    }
+}

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

@@ -0,0 +1,293 @@
+package com.zksy.web.controller.cockpit;
+
+import com.zksy.base.domain.EquipmentBase;
+import com.zksy.base.domain.EquipmentType;
+import com.zksy.base.mapper.EquipmentBaseMapper;
+import com.zksy.base.mapper.EquipmentStatusMapper;
+import com.zksy.base.mapper.EquipmentTypeMapper;
+import com.zksy.base.perception.mapper.PerceptionMapper;
+import com.zksy.base.perception.service.impl.PerceptionServiceImpl;
+import com.zksy.base.warning.mapper.EquipmentWarningTypeMapper;
+import com.zksy.cockpit.collectionRecords.CockpitCollectionRecordsService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+/** 公开HTTP seam + 真实Service/profile,仅数据库读取边界使用fixture。 */
+class CockpitCollectionRecordsControllerTest {
+    static final String CODE = "TC-GS-202609020001";
+    static final String ID = "internal-equipment-uuid";
+    private EquipmentBaseMapper equipmentMapper;
+    private EquipmentTypeMapper typeMapper;
+    private PerceptionMapper recordsMapper;
+    private MockMvc mvc;
+
+    @BeforeEach
+    void setup() {
+        equipmentMapper = mock(EquipmentBaseMapper.class);
+        typeMapper = mock(EquipmentTypeMapper.class);
+        recordsMapper = mock(PerceptionMapper.class);
+        EquipmentBase base = new EquipmentBase();
+        base.setEquipmentId(ID);
+        base.setEquipmentCode(CODE);
+        base.setEquipmentTypeId(10);
+        when(equipmentMapper.selectOne(any())).thenAnswer(invocation -> {
+            com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<?> query = invocation.getArgument(0);
+            query.getSqlSegment();
+            return query.getParamNameValuePairs().containsValue(CODE) ? base : null;
+        });
+        when(equipmentMapper.selectById(ID)).thenReturn(base);
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("firefighting_pressure");
+        when(typeMapper.selectById(10)).thenReturn(type);
+        EquipmentWarningTypeMapper indicators = mock(EquipmentWarningTypeMapper.class);
+        when(indicators.selectList(any())).thenReturn(Collections.emptyList());
+        PerceptionServiceImpl profile = new PerceptionServiceImpl();
+        ReflectionTestUtils.setField(profile, "equipmentBaseMapper", equipmentMapper);
+        ReflectionTestUtils.setField(profile, "equipmentTypeMapper", typeMapper);
+        ReflectionTestUtils.setField(profile, "equipmentStatusMapper", mock(EquipmentStatusMapper.class));
+        ReflectionTestUtils.setField(profile, "perceptionMapper", recordsMapper);
+        ReflectionTestUtils.setField(profile, "equipmentWarningTypeMapper", indicators);
+        mvc = MockMvcBuilders.standaloneSetup(new CockpitCollectionRecordsController(
+                new CockpitCollectionRecordsService(equipmentMapper, profile)))
+                .setMessageConverters(new org.springframework.http.converter.json.MappingJackson2HttpMessageConverter())
+                .build();
+    }
+
+    @Test
+    void pressureRecordsExposeReferenceColumnsAndCreateTimeWithoutInternalId() throws Exception {
+        when(recordsMapper.selectLatestRecords("firefighting_pressure", "telemetering_station", CODE, 50))
+                .thenReturn(Collections.singletonList(record("2026-11-04T10:20:00", "pressure_value", 0)));
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records")
+                        .header("X-Request-Id", "collection-001"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.requestId").value("collection-001"))
+                .andExpect(jsonPath("$.data.apiVersion").value("v1"))
+                .andExpect(jsonPath("$.data.readOnly").value(true))
+                .andExpect(jsonPath("$.data.deviceCode").value(CODE))
+                .andExpect(jsonPath("$.data.state").value("READY"))
+                .andExpect(jsonPath("$.data.equipmentId").doesNotExist())
+                .andExpect(jsonPath("$.data.recordView.layout").value("wide"))
+                .andExpect(jsonPath("$.data.recordView.columns[1].key").value("pressure_value"))
+                .andExpect(jsonPath("$.data.recordView.columns[1].label").value("压力"))
+                .andExpect(jsonPath("$.data.recordView.columns[1].unit").value("MPa"))
+                .andExpect(jsonPath("$.data.recordView.columns[1].isAlarm").value(false))
+                .andExpect(jsonPath("$.data.recordView.rows[0].createTime").value("2026-11-04 10:20:00"))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].value").value("0"));
+    }
+
+    @Test
+    void invalidCodeIsBadRequestWithoutReadingDatabase() throws Exception {
+        mvc.perform(get("/api/cockpit/v1/equipments/%20/collection-records")
+                        .header("X-Request-Id", "invalid-001"))
+                .andExpect(status().isBadRequest())
+                .andExpect(jsonPath("$.data.state").value("FAILED"))
+                .andExpect(jsonPath("$.data.stateReason").value("设备编码不能为空"))
+                .andExpect(jsonPath("$.data.requestId").value("invalid-001"));
+        org.mockito.Mockito.verifyNoInteractions(equipmentMapper, recordsMapper);
+    }
+
+    @Test
+    void unknownBusinessCodeIsNotFoundNotEmpty() throws Exception {
+        org.mockito.Mockito.doReturn(null).when(equipmentMapper).selectOne(any());
+        mvc.perform(get("/api/cockpit/v1/equipments/MISSING/collection-records"))
+                .andExpect(status().isNotFound())
+                .andExpect(jsonPath("$.data.state").value("FAILED"))
+                .andExpect(jsonPath("$.data.stateReason").value("设备不存在"));
+        org.mockito.Mockito.verifyNoInteractions(recordsMapper);
+    }
+
+    @Test
+    void databaseFailureIsUnavailableNotSuccessfulEmpty() throws Exception {
+        org.mockito.Mockito.doThrow(new IllegalStateException("password secret database"))
+                .when(equipmentMapper).selectOne(any());
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isInternalServerError())
+                .andExpect(jsonPath("$.data.state").value("FAILED"))
+                .andExpect(jsonPath("$.data.stateReason").value("驾驶舱采集记录读取失败,暂不可用"))
+                .andExpect(jsonPath("$.data.recordView.rows").isEmpty());
+    }
+
+    @Test
+    void configuredCollectionWithNoRowsIsEmpty() throws Exception {
+        when(recordsMapper.selectLatestRecords("firefighting_pressure", "telemetering_station", CODE, 50))
+                .thenReturn(Collections.emptyList());
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.state").value("EMPTY"))
+                .andExpect(jsonPath("$.data.stateReason").value("暂无采集记录"))
+                .andExpect(jsonPath("$.data.recordView.columns[0].key").value("create_time"))
+                .andExpect(jsonPath("$.data.recordView.rows").isEmpty());
+    }
+
+    @Test
+    void unsupportedCollectionTableIsUnavailableNotEmpty() throws Exception {
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("not_a_whitelisted_collection");
+        when(typeMapper.selectById(10)).thenReturn(type);
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.state").value("UNAVAILABLE"))
+                .andExpect(jsonPath("$.data.stateReason").value("设备采集表未配置或暂不支持"))
+                .andExpect(jsonPath("$.data.recordView.rows").isEmpty());
+        org.mockito.Mockito.verifyNoInteractions(recordsMapper);
+    }
+
+    @Test
+    void missingSampleTimeAndNullValueRemainUnknownInsteadOfReportTimeOrZero() throws Exception {
+        when(recordsMapper.selectLatestRecords("firefighting_pressure", "telemetering_station", CODE, 50))
+                .thenReturn(Collections.singletonList(record(null, "pressure_value", null)));
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.recordView.rows[0].createTime").value(org.hamcrest.Matchers.nullValue()))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].value").value(org.hamcrest.Matchers.nullValue()))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].display").value("—"));
+    }
+
+    @Test
+    void environmentHistoryKeepsOnlyWaterQualityFactorsAndAllSampleTimes() throws Exception {
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("e_real_time_data");
+        when(typeMapper.selectById(10)).thenReturn(type);
+        Map<String, Object> cod = record("2026-11-04T10:20:00", "hum", 0);
+        cod.put("node_id", 2);
+        cod.put("temperature", 99);
+        Map<String, Object> ammonia = record("2026-11-04T10:20:00", "hum", 2);
+        ammonia.put("node_id", 3);
+        Map<String, Object> older = record("2026-11-04T10:19:00", "hum", 7);
+        older.put("node_id", 5);
+        when(recordsMapper.selectLatestRecords("e_real_time_data", "device_id", CODE, 50))
+                .thenReturn(java.util.Arrays.asList(cod, ammonia, older));
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.recordView.layout").value("long"))
+                .andExpect(jsonPath("$.data.recordView.columns.length()").value(2))
+                .andExpect(jsonPath("$.data.recordView.rows.length()").value(3))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells.length()").value(1))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].key").value("indicator"))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].display").value("化学需氧量(COD):0mg/L"))
+                .andExpect(jsonPath("$.data.recordView.rows[1].cells[0].display").value("氨氮:2mg/L"))
+                .andExpect(jsonPath("$.data.recordView.rows[2].createTime").value("2026-11-04 10:19:00"))
+                .andExpect(jsonPath("$.data.recordView.rows[2].cells[0].display").value("酸碱度(pH):7"));
+    }
+
+    @Test
+    void endpointCapsHistoryAtNewestFiftyCreateTimes() throws Exception {
+        java.util.List<Map<String, Object>> records = new java.util.ArrayList<>();
+        for (int minute = 0; minute < 55; minute++) {
+            records.add(record(LocalDateTime.parse("2026-11-04T10:00:00").plusMinutes(minute).toString(),
+                    "pressure_value", minute));
+        }
+        when(recordsMapper.selectLatestRecords("firefighting_pressure", "telemetering_station", CODE, 50))
+                .thenReturn(records);
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.recordView.rows.length()").value(50))
+                .andExpect(jsonPath("$.data.recordView.rows[0].createTime").value("2026-11-04 10:54:00"))
+                .andExpect(jsonPath("$.data.recordView.rows[49].createTime").value("2026-11-04 10:05:00"));
+    }
+
+    @Test
+    void unknownAlarmStatusIsNotFabricatedAsNormalWhileZeroRemainsNormal() throws Exception {
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("jg_device_data");
+        when(typeMapper.selectById(10)).thenReturn(type);
+        Map<String, Object> record = record("2026-11-04T10:20:00", "water_infiltration_alarm_status", null);
+        record.put("water_level_alarm_status", 0);
+        record.put("battery_level", 0);
+        when(recordsMapper.selectLatestRecords("jg_device_data", "imei_card_number", CODE, 50))
+                .thenReturn(Collections.singletonList(record));
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.recordView.columns[2].isAlarm").value(true))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[1].value").value(org.hamcrest.Matchers.nullValue()))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[1].display").value("—"))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[1].alarm").value(false))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[2].value").value("正常"))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[4].value").value("0"));
+    }
+
+    @Test
+    void internalIdCannotReplaceBusinessCodeAndMutationsAreRejected() throws Exception {
+        mvc.perform(get("/api/cockpit/v1/equipments/" + ID + "/collection-records"))
+                .andExpect(status().isNotFound());
+        mvc.perform(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post(
+                "/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isMethodNotAllowed());
+        org.mockito.Mockito.verifyNoInteractions(recordsMapper);
+    }
+
+    @Test
+    void noiseAudioPathAndReferenceColumnsArePassedThroughWithoutPrivateRecords() throws Exception {
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("noise_info");
+        when(typeMapper.selectById(10)).thenReturn(type);
+        Map<String, Object> record = record("2026-11-04T10:20:00", "filepath", "/device-audio/noise-001.wav");
+        record.put("rms", 0);
+        record.put("gain", 2);
+        record.put("center_frequency", 99);
+        when(recordsMapper.selectLatestRecords("noise_info", "encode", CODE, 50))
+                .thenReturn(Collections.singletonList(record));
+        String response = mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.recordView.columns.length()").value(5))
+                .andExpect(jsonPath("$.data.recordView.columns[4].key").value("filepath"))
+                .andExpect(jsonPath("$.data.recordView.columns[4].label").value("音频文件"))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].value").value("0"))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[3].value").value("/device-audio/noise-001.wav"))
+                .andExpect(jsonPath("$.data.base").doesNotExist())
+                .andExpect(jsonPath("$.data.records").doesNotExist())
+                .andReturn().getResponse().getContentAsString();
+        org.junit.jupiter.api.Assertions.assertFalse(response.contains("private-record-id"));
+        org.junit.jupiter.api.Assertions.assertFalse(response.contains(ID));
+    }
+
+    @Test
+    void missingLongFactorRemainsNullWithChineseDisplay() throws Exception {
+        EquipmentType type = new EquipmentType();
+        type.setOrigCollTable("e_real_time_data");
+        when(typeMapper.selectById(10)).thenReturn(type);
+        Map<String, Object> record = record(null, "hum", null);
+        record.put("node_id", 3);
+        when(recordsMapper.selectLatestRecords("e_real_time_data", "device_id", CODE, 50))
+                .thenReturn(Collections.singletonList(record));
+        mvc.perform(get("/api/cockpit/v1/equipments/" + CODE + "/collection-records"))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].value").value(org.hamcrest.Matchers.nullValue()))
+                .andExpect(jsonPath("$.data.recordView.rows[0].cells[0].display").value("氨氮:—"));
+    }
+
+    @Test
+    void malformedEncodingAndEmbeddedControlCharacterAreInvalidBeforeDatabaseRead() throws Exception {
+        mvc.perform(get("/api/cockpit/v1/equipments/%ZZ/collection-records"))
+                .andExpect(status().isBadRequest())
+                .andExpect(jsonPath("$.data.stateReason").value("设备编码不合法"));
+        mvc.perform(get("/api/cockpit/v1/equipments/TC%0AGS/collection-records"))
+                .andExpect(status().isBadRequest())
+                .andExpect(jsonPath("$.data.stateReason").value("设备编码不合法"));
+        org.mockito.Mockito.verifyNoInteractions(equipmentMapper, recordsMapper);
+    }
+
+    static Map<String, Object> record(String time, String key, Object value) {
+        Map<String, Object> record = new LinkedHashMap<>();
+        record.put("create_time", time == null ? null : LocalDateTime.parse(time));
+        record.put(key, value);
+        record.put("report_time", LocalDateTime.parse("2027-01-01T00:00:00"));
+        record.put("id", "private-record-id");
+        return record;
+    }
+}

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

@@ -309,6 +309,52 @@ class CockpitMonitoringOverviewControllerTest {
         assertEquals(Collections.singletonList("EMPTY"), response.getMapFilter().getPointCodes());
     }
 
+    /**
+     * 图例池(本端点)必须跟随 equipment_status 变化重建,不能被进程内旧快照永久冻结。
+     *
+     * <p>现场故障 2026-11-10:设备已开机、点位详情 online=true,但图例一直「在线 0」——
+     * 因为 {@code refreshIfNeeded()} 见 {@code state != null} 就直接复用,而生产没有调用方推 delta。
+     * 这里用可推进的时钟证明:超过 TTL 后必须重新读适配器,并反映新的在线台数。
+     */
+    @Test
+    void staleSnapshotIsRebuiltSoLegendOnlineCountFollowsEquipmentStatus() throws Exception {
+        java.util.concurrent.atomic.AtomicReference<Instant> now =
+                new java.util.concurrent.atomic.AtomicReference<>(Instant.parse("2026-09-02T02:00:00Z"));
+        service = new CockpitMonitoringOverviewService(adapter, new Clock() {
+            @Override
+            public java.time.ZoneId getZone() {
+                return ZoneOffset.UTC;
+            }
+
+            @Override
+            public Clock withZone(java.time.ZoneId zone) {
+                return this;
+            }
+
+            @Override
+            public Instant instant() {
+                return now.get();
+            }
+        });
+        mockMvc = MockMvcBuilders
+                .standaloneSetup(new CockpitMonitoringOverviewController(service))
+                .build();
+
+        // 第一次:全离线快照(模拟设备未开机时建下的快照)
+        when(adapter.load()).thenReturn(allOfflineFixture());
+        mockMvc.perform(get(ENDPOINT))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.status.onlineCount").value(0));
+
+        // 设备开机后同一路径必须重建,不能继续回 0
+        when(adapter.load()).thenReturn(fixture());
+        now.set(Instant.parse("2026-09-02T02:05:00Z"));
+        mockMvc.perform(get(ENDPOINT))
+                .andExpect(status().isOk())
+                .andExpect(jsonPath("$.data.status.onlineCount").value(3));
+        org.mockito.Mockito.verify(adapter, org.mockito.Mockito.times(2)).load();
+    }
+
     private static CockpitMonitoringOverviewSnapshot fixture() {
         return new CockpitMonitoringOverviewSnapshot(
                 "2026-09-02T09:59:50+08:00",

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

@@ -104,6 +104,10 @@ class CockpitMonitoringPointDetailControllerTest {
                 .andExpect(jsonPath("$.data.statusDictionary[0].status").value("ALARM"))
                 .andExpect(jsonPath("$.data.statusDictionary[0].label").value("报警"))
                 .andExpect(jsonPath("$.data.statusDictionary[0].priority").value(1))
+                // 2026-11-06:枚举按「监测点聚合序」排列 —— WARNING(2) 在 WORK_ORDER(3) 之前。
+                .andExpect(jsonPath("$.data.statusDictionary[1].status").value("WARNING"))
+                .andExpect(jsonPath("$.data.statusDictionary[1].label").value("预警"))
+                .andExpect(jsonPath("$.data.statusDictionary[1].priority").value(2))
                 .andExpect(jsonPath("$.data.statusDictionary[2].status").value("WORK_ORDER"))
                 .andExpect(jsonPath("$.data.statusDictionary[2].label").value("工单处置"))
                 .andExpect(jsonPath("$.data.statusDictionary[2].priority").value(3))

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

@@ -11,13 +11,22 @@ import java.util.Collections;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
- * 票 71 契约:单设备业务处置序 =「未转工单的报警 &gt; 工单处置 &gt; 预警」(维护者 2026-10-22 裁定 Q1=A)。
+ * 两张状态序的契约(维护者 2026-11-06 重述《点位特效显示规则》,取代 2026-10-22 的 Q1=A 与 Q2)。
  *
- * <p>覆盖本次新增的二路(无报警时「有未结束工单」压过「有未解决预警」)、票 52 的窄三路
- * (全部未处理报警被未结束工单承接 → WORK_ORDER),并钉住两条同日裁定:
- * Q2(枚举 priority 与点位聚合语义不变)、Q3({@code monitoring/situation} 不跟随,另行在适配器注释留档)。
+ * <p>规则把<b>设备点</b>与<b>监测点</b>分开,且两者优先级<b>刻意不同</b>:
+ * <ul>
+ *   <li><b>设备点</b>(本类前半):报警 &gt; 工单处置 &gt; 预警 &gt; 独立设备。报警全被未结束工单承接时
+ *       显示工单处置(蓝),只要有一条未转工单就显示报警(红)。→ {@code deviceStatus()}</li>
+ *   <li><b>监测点</b>(本类后半):按关联设备里**最高档的显示状态**聚合,
+ *       报警 &gt; 预警 &gt; 工单处置;全离线则离线;无关联设备则无设备。→ {@code resolve()} 的
+ *       {@code min(priority)},priority 由枚举给。</li>
+ * </ul>
  *
- * <p>注:这些是判定逻辑的纯测试;真实后端复验(改序后 map-snapshot 读数)需后端部署后再做。
+ * <p>2026-11-02 曾把枚举 WARNING/WORK_ORDER 对调(2/3 → 3/2)以对齐设备序,副作用是把点位聚合
+ * 一起改成「报警 &gt; 工单 &gt; 预警」,与本规则相反;现已按规则恢复。本类同时钉住「恢复后的枚举序」
+ * 与「设备序不受枚举影响」两件事,防止将来任一侧又被另一侧的重排带走。
+ *
+ * <p>注:这些是判定逻辑的纯测试;真实后端复验(map-snapshot / 点位详情读数)需后端部署后再做。
  */
 class CockpitMonitoringPointStatusOrderTest {
 
@@ -66,9 +75,14 @@ class CockpitMonitoringPointStatusOrderTest {
                 CockpitMonitoringPointStatusResolver.deviceStatus(device(false, false, false, false)));
     }
 
-    /** Q2:枚举优先级一个字都没动(前端两张词表 / 图例排序 / t09 闸门因此零改动)。 */
+    /**
+     * 监测点聚合序(维护者 2026-11-06 规则「监测点」一节):报警 &gt; 预警 &gt; 工单处置。
+     *
+     * <p>这条被 2026-11-02 的对调改坏过(当时是 报警 &gt; 工单 &gt; 预警),本测试是它的回归钉子:
+     * 再有人为了设备序去动这个枚举,这里必须红。
+     */
     @Test
-    void enumPriorityIsUnchanged() {
+    void enumPriorityIsPointAggregationOrder() {
         assertEquals(1, CockpitMonitoringPointStatus.ALARM.getPriority());
         assertEquals(2, CockpitMonitoringPointStatus.WARNING.getPriority());
         assertEquals(3, CockpitMonitoringPointStatus.WORK_ORDER.getPriority());
@@ -77,9 +91,15 @@ class CockpitMonitoringPointStatusOrderTest {
         assertEquals(6, CockpitMonitoringPointStatus.EMPTY.getPriority());
     }
 
-    /** Q2:点位聚合仍取 min(priority),不被单设备业务序倒灌。 */
+    /**
+     * 监测点聚合取 min(priority):关联设备里有一台预警、一台工单处置 → 监测点显示预警。
+     *
+     * <p>这是「报警 &gt; 预警 &gt; 工单处置」的直接体现。注意被聚合的那台工单设备**自身**仍是
+     * 工单处置(设备序报警&gt;工单&gt;预警),两种显示各自成立 —— 见
+     * {@code deviceAndPointOrdersAreIndependent}。
+     */
     @Test
-    void pointAggregationStillUsesEnumPriority() {
+    void pointAggregationPutsWarningAboveWorkOrder() {
         CockpitMonitoringPointDeviceSnapshot warningOnly = device("D-W", true, false, true, false);
         CockpitMonitoringPointDeviceSnapshot warningWithOpenWorkOrder = device("D-WO", true, false, true, true);
 
@@ -89,7 +109,7 @@ class CockpitMonitoringPointStatusOrderTest {
                 "两台设备时聚合取 WARNING(2) < WORK_ORDER(3)");
     }
 
-    /** 单设备点位的自动跟随:改序的直接后果,固定下来防回退。 */
+    /** 工单处置设备**单独**在点位上时,点位按它聚合为工单处置(没有更高档的兄弟)。 */
     @Test
     void singleDevicePointFollowsDeviceOrder() {
         assertEquals(CockpitMonitoringPointStatus.WORK_ORDER,
@@ -97,6 +117,25 @@ class CockpitMonitoringPointStatusOrderTest {
                         device("D-WO", true, false, true, true))));
     }
 
+    /**
+     * 两张序**独立**:同一台设备自身显示「工单处置」,若与一台预警设备同点位聚合,点位显示「预警」。
+     *
+     * <p>钉住的是「一次重排不能同时满足两套规则」这件事本身 —— 2026-11-02 那次对调正是因为
+     * 拿同一份枚举去服务两处,才一边合规一边违规。
+     */
+    @Test
+    void deviceAndPointOrdersAreIndependent() {
+        CockpitMonitoringPointDeviceSnapshot workOrderDevice = device("D-WO", true, false, true, true);
+        assertEquals(CockpitMonitoringPointStatus.WORK_ORDER,
+                CockpitMonitoringPointStatusResolver.deviceStatus(workOrderDevice),
+                "设备点:无报警时工单处置压过预警(报警>工单>预警)");
+
+        assertEquals(CockpitMonitoringPointStatus.WARNING,
+                CockpitMonitoringPointStatusResolver.resolve(
+                        Arrays.asList(workOrderDevice, device("D-W", true, false, true, false))),
+                "监测点:聚合按 报警>预警>工单(预警压过工单)");
+    }
+
     private static CockpitMonitoringPointDeviceSnapshot device(
             boolean online, boolean alarm, boolean warning, boolean workOrderInProgress) {
         return device("DEVICE-1", online, alarm, warning, workOrderInProgress);

+ 93 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/collectionRecords/CockpitCollectionRecordsResponse.java

@@ -0,0 +1,93 @@
+package com.zksy.cockpit.collectionRecords;
+
+import java.util.Collections;
+import java.util.List;
+
+/** 驾驶舱采集记录专用契约:不包含设备档案、原始记录或内部主键。 */
+public class CockpitCollectionRecordsResponse {
+    private final String requestId;
+    private final String deviceCode;
+    private final String state;
+    private final String stateReason;
+    private final RecordView recordView;
+
+    public CockpitCollectionRecordsResponse(String requestId, String deviceCode, String state,
+                                           String stateReason, RecordView recordView) {
+        this.requestId = requestId;
+        this.deviceCode = deviceCode;
+        this.state = state;
+        this.stateReason = stateReason;
+        this.recordView = recordView;
+    }
+
+    public String getRequestId() { return requestId; }
+    public String getApiVersion() { return "v1"; }
+    public boolean isReadOnly() { return true; }
+    public String getDeviceCode() { return deviceCode; }
+    public String getState() { return state; }
+    public String getStateReason() { return stateReason; }
+    public RecordView getRecordView() { return recordView; }
+
+    public static RecordView emptyView() {
+        return new RecordView("wide", Collections.emptyList(), Collections.emptyList());
+    }
+
+    public static class RecordView {
+        private final String layout;
+        private final List<Column> columns;
+        private final List<Row> rows;
+        public RecordView(String layout, List<Column> columns, List<Row> rows) {
+            this.layout = layout;
+            this.columns = columns;
+            this.rows = rows;
+        }
+        public String getLayout() { return layout; }
+        public List<Column> getColumns() { return columns; }
+        public List<Row> getRows() { return rows; }
+    }
+
+    public static class Column {
+        private final String key;
+        private final String label;
+        private final String unit;
+        private final boolean isAlarm;
+        public Column(String key, String label, String unit, boolean isAlarm) {
+            this.key = key;
+            this.label = label;
+            this.unit = unit;
+            this.isAlarm = isAlarm;
+        }
+        public String getKey() { return key; }
+        public String getLabel() { return label; }
+        public String getUnit() { return unit; }
+        public boolean getIsAlarm() { return isAlarm; }
+    }
+
+    public static class Row {
+        private final String createTime;
+        private final List<Cell> cells;
+        public Row(String createTime, List<Cell> cells) {
+            this.createTime = createTime;
+            this.cells = cells;
+        }
+        public String getCreateTime() { return createTime; }
+        public List<Cell> getCells() { return cells; }
+    }
+
+    public static class Cell {
+        private final String key;
+        private final String value;
+        private final String display;
+        private final boolean alarm;
+        public Cell(String key, String value, String display, boolean alarm) {
+            this.key = key;
+            this.value = value;
+            this.display = display;
+            this.alarm = alarm;
+        }
+        public String getKey() { return key; }
+        public String getValue() { return value; }
+        public String getDisplay() { return display; }
+        public boolean isAlarm() { return alarm; }
+    }
+}

+ 87 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/collectionRecords/CockpitCollectionRecordsService.java

@@ -0,0 +1,87 @@
+package com.zksy.cockpit.collectionRecords;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.zksy.base.domain.EquipmentBase;
+import com.zksy.base.mapper.EquipmentBaseMapper;
+import com.zksy.base.perception.domain.vo.EquipmentProfileVO;
+import com.zksy.base.perception.service.PerceptionService;
+import com.zksy.cockpit.foundation.CockpitDeviceNotFoundException;
+import com.zksy.cockpit.foundation.CockpitInvalidRequestException;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+/** 复用感知档案的展示边界,不复制各原始采集表的字段或单位定义。 */
+@Service
+public class CockpitCollectionRecordsService {
+    private static final int MAX_RECORDS = 50;
+    private final EquipmentBaseMapper equipmentMapper;
+    private final PerceptionService perceptionService;
+
+    public CockpitCollectionRecordsService(EquipmentBaseMapper equipmentMapper, PerceptionService perceptionService) {
+        this.equipmentMapper = equipmentMapper;
+        this.perceptionService = perceptionService;
+    }
+
+    public CockpitCollectionRecordsResponse load(String requestId, String deviceCode) {
+        if (deviceCode == null || deviceCode.trim().isEmpty()) {
+            throw new CockpitInvalidRequestException("设备编码不能为空");
+        }
+        deviceCode = deviceCode.trim();
+        if (deviceCode.length() > 128 || deviceCode.matches(".*[\\x00-\\x20/\\\\%].*")) {
+            throw new CockpitInvalidRequestException("设备编码不合法");
+        }
+        EquipmentBase equipment = equipmentMapper.selectOne(new QueryWrapper<EquipmentBase>()
+                .eq("equipment_code", deviceCode));
+        if (equipment == null) {
+            throw new CockpitDeviceNotFoundException("设备不存在");
+        }
+        EquipmentProfileVO profile = perceptionService.getProfile(equipment.getEquipmentId());
+        if (profile.getIdColumn() == null || profile.getIdColumn().trim().isEmpty()) {
+            return new CockpitCollectionRecordsResponse(requestId, deviceCode, "UNAVAILABLE",
+                    "设备采集表未配置或暂不支持", CockpitCollectionRecordsResponse.emptyView());
+        }
+        EquipmentProfileVO.RecordView source = profile.getRecordView();
+        List<CockpitCollectionRecordsResponse.Column> columns = new ArrayList<>();
+        for (EquipmentProfileVO.RecordColumn column : source.getColumns()) {
+            columns.add(new CockpitCollectionRecordsResponse.Column(column.getKey(), column.getLabel(),
+                    column.getUnit(), column.isAlarm()));
+        }
+        List<CockpitCollectionRecordsResponse.Row> rows = new ArrayList<>();
+        int rowIndex = 0;
+        for (EquipmentProfileVO.RecordRow row : source.getRows()) {
+            Map<String, Object> raw = profile.getRecords() != null && rowIndex < profile.getRecords().size()
+                    ? profile.getRecords().get(rowIndex) : null;
+            rowIndex++;
+            List<CockpitCollectionRecordsResponse.Cell> cells = new ArrayList<>();
+            for (EquipmentProfileVO.RecordCell cell : row.getCells()) {
+                // 原profile将缺失报警值显示成正常;仅按已有列key恢复未知,不另建字段映射。
+                boolean missing = "wide".equals(source.getLayout()) && raw != null && raw.get(cell.getKey()) == null;
+                boolean unknownFactor = "long".equals(source.getLayout()) && "indicator".equals(cell.getKey())
+                        && cell.getDisplay() != null && cell.getDisplay().endsWith(":—");
+                cells.add(new CockpitCollectionRecordsResponse.Cell(cell.getKey(),
+                        missing || unknownFactor || "—".equals(cell.getValue()) ? null : cell.getValue(),
+                        missing ? "—" : indicatorDisplay(cell.getKey(), cell.getDisplay()), !missing && cell.isAlarm()));
+            }
+            rows.add(new CockpitCollectionRecordsResponse.Row(
+                    row.getCreateTime() == null || row.getCreateTime().trim().isEmpty() ? null : row.getCreateTime(), cells));
+        }
+        // 查询本身按create_time倒序取50条;契约再次封顶,不合并相同时刻。
+        rows.sort(Comparator.comparing(CockpitCollectionRecordsResponse.Row::getCreateTime,
+                Comparator.nullsLast(Comparator.reverseOrder())));
+        if (rows.size() > MAX_RECORDS) { rows = new ArrayList<>(rows.subList(0, MAX_RECORDS)); }
+        return new CockpitCollectionRecordsResponse(requestId, deviceCode,
+                rows.isEmpty() ? "EMPTY" : "READY", rows.isEmpty() ? "暂无采集记录" : "采集记录读取成功",
+                new CockpitCollectionRecordsResponse.RecordView(source.getLayout(), columns, rows));
+    }
+
+    private String indicatorDisplay(String key, String display) {
+        if (!"indicator".equals(key) || display == null) { return display; }
+        if (display.startsWith("COD:")) { return "化学需氧量(COD):" + display.substring(4); }
+        if (display.startsWith("PH:")) { return "酸碱度(pH):" + display.substring(3); }
+        return display;
+    }
+}

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

@@ -54,8 +54,13 @@ public class BusinessCockpitEventAdapter {
 
     private static final ZoneId BUSINESS_ZONE = ZoneId.of("Asia/Shanghai");
     private static final DateTimeFormatter TIMESTAMP = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
-    private static final List<String> CURRENT_WARNING_STATUSES = java.util.Arrays.asList(
-            "PENDING", "RECEIVED", "PROCESSING", "HANDLING");
+    /**
+     * 「当前预警」的排除口径(维护者 2026-11-05):预警状态为
+     * DRAFT/PENDING/RECEIVED/PROCESSING/HANDLED/CLOSED,**除草稿与已解除外都算预警状态**
+     * —— 已处置(HANDLED)仍需核查,照旧进入当前列表;认不出/缺失的状态按「不能证明已排除」
+     * 保留,不因词表缺口把进行中的预警藏掉。
+     */
+    private static final Set<String> EXCLUDED_WARNING_STATUSES = new HashSet<>(Arrays.asList("DRAFT", "CLOSED"));
 
     private final EquipmentBaseService equipmentBaseService;
     private final EquipmentTypeService equipmentTypeService;
@@ -820,11 +825,11 @@ public class BusinessCockpitEventAdapter {
     }
 
     private static boolean isCurrentWarning(EarlyWarning warning) {
-        return warning != null && isCurrentStatus(warning.getStatus());
+        return warning != null && !isExcludedWarningStatus(warning.getStatus());
     }
 
-    private static boolean isCurrentStatus(String status) {
-        return status != null && CURRENT_WARNING_STATUSES.contains(status.trim().toUpperCase());
+    private static boolean isExcludedWarningStatus(String status) {
+        return status != null && EXCLUDED_WARNING_STATUSES.contains(status.trim().toUpperCase());
     }
 
     private static boolean isOpenWorkOrder(Integer status) {

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

@@ -193,7 +193,12 @@ public class CockpitCurrentEventsService {
                 continue;
             }
             CockpitCurrentEventsSnapshot.SourceType type = resolveType(types, warning.getTypeCode());
-            if (!inScope(type, industry)) {
+            // 维护者 2026-11-05:预警条目不得因设备/类型解析不出而被丢——无法归入行业时
+            // 行业按 null 如实带出(未分区/未知),只有显式行业筛选才排除它。
+            if (type != null && !inScope(type, industry)) {
+                continue;
+            }
+            if (type == null && industry != null) {
                 continue;
             }
             if (level != null && !level.equals(warning.getLevel())) {
@@ -221,7 +226,7 @@ public class CockpitCurrentEventsService {
                     warning.getMonitoringPointCode(),
                     warning.getMonitoringPointName(),
                     warning.getLocation(),
-                    type.getIndustry(),
+                    type == null ? null : type.getIndustry(),
                     warning.getLongitude(),
                     warning.getLatitude(),
                     warning.isCoordinateVerified(),

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

@@ -481,7 +481,11 @@ public class CockpitHandlingEfficiencyService {
                 ? warningFacts(snapshot, types, industry, level, district)
                 : alarmFacts(snapshot, types, industry, level, district);
         for (EventFact fact : facts) {
+            // 发布时刻缺失时退回更新时间(不把已存在的预警从窗口里抹掉)。
             OffsetDateTime eventTime = parseEventTime(fact.eventTime);
+            if (eventTime == null) {
+                eventTime = parseEventTime(fact.updateTime);
+            }
             if (eventTime == null) {
                 continue;
             }
@@ -579,11 +583,15 @@ public class CockpitHandlingEfficiencyService {
             String industry) {
         CockpitHandlingEfficiencySnapshot.SourceType type =
                 isBlank(typeCode) ? null : types.get(typeCode.trim());
-        if (type == null
-                || !SMART_DEVICE.equals(type.getObjectKind())
+        // 维护者 2026-11-05:预警条目不得因类型解析不出而被丢;行业如实为 null,
+        // 只有显式行业筛选才排除。
+        if (type == null) {
+            return industry == null;
+        }
+        if (!SMART_DEVICE.equals(type.getObjectKind())
                 || type.getIndustry() == null
                 || !INDUSTRIES.contains(type.getIndustry())) {
-            return false;
+            return industry == null;
         }
         return industry == null || industry.equals(type.getIndustry());
     }

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

@@ -240,7 +240,11 @@ public class CockpitHistoryAnalysisService {
                     || !CockpitDistrict.matches(district, warning.getDistrict())) {
                 continue;
             }
+            // 发布时刻缺失时退回更新时间(不把已存在的预警从历史里抹掉)。
             OffsetDateTime eventTime = parseEventTime(warning.getEventTime());
+            if (eventTime == null) {
+                eventTime = parseEventTime(warning.getUpdatedTime());
+            }
             if (eventTime == null) {
                 continue;
             }
@@ -313,11 +317,15 @@ public class CockpitHistoryAnalysisService {
             String industry) {
         CockpitHistoryAnalysisSnapshot.SourceType type =
                 isBlank(typeCode) ? null : types.get(typeCode.trim());
-        if (type == null
-                || !SMART_DEVICE.equals(type.getObjectKind())
+        // 维护者 2026-11-05:历史预警/报警条目不得因类型解析不出而被丢;
+        // 行业如实为 null(未知),只有显式行业筛选才排除。
+        if (type == null) {
+            return industry == null;
+        }
+        if (!SMART_DEVICE.equals(type.getObjectKind())
                 || type.getIndustry() == null
                 || !INDUSTRIES.contains(type.getIndustry())) {
-            return false;
+            return industry == null;
         }
         return industry == null || industry.equals(type.getIndustry());
     }

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

@@ -51,9 +51,18 @@ public class CockpitMonitoringDistributionService {
     private static final String TYPE_KIND_MISMATCH = "TYPE_KIND_MISMATCH";
     private static final String NON_FORMAL_INDUSTRY = "NON_FORMAL_INDUSTRY";
 
+    /**
+     * 当前快照最长复用时长(仅对**未指定 snapshotAt** 的请求生效)。指定了 snapshotAt 的调用
+     * 属于历史快照契约,必须原样返回那个快照,不能被 TTL 改写。
+     * 为什么需要:设备在线状态是快速变化的事实,生产没有调用方推 delta,快照不重建就会永久冻结。
+     */
+    private static final java.time.Duration SNAPSHOT_TTL = java.time.Duration.ofSeconds(30);
+
     private final CockpitMonitoringDistributionAdapter adapter;
     private final Clock clock;
     private RuntimeState state;
+    /** 当前快照的构建时刻(判 TTL 用);与 {@code snapshotAt}(数据快照时间)语义不同。 */
+    private OffsetDateTime stateBuiltAt;
 
     public CockpitMonitoringDistributionService(
             CockpitMonitoringDistributionAdapter adapter,
@@ -179,7 +188,8 @@ public class CockpitMonitoringDistributionService {
     }
 
     private synchronized void refreshIfNeeded(String snapshotAt) {
-        if (state != null) {
+        // 指定 snapshotAt=要那份历史快照,保持既有语义直接复用;未指定才按 TTL 重建。
+        if (state != null && (snapshotAt != null || (stateBuiltAt != null && !isExpired()))) {
             return;
         }
         CockpitMonitoringDistributionSnapshot loaded = adapter.load(snapshotAt);
@@ -227,6 +237,20 @@ public class CockpitMonitoringDistributionService {
             }
         }
         state = new RuntimeState(snapshot, devices);
+        stateBuiltAt = businessNow();
+    }
+
+    /** 当前快照是否已超过 {@link #SNAPSHOT_TTL};时钟异常时按「已过期」保守重建。 */
+    private boolean isExpired() {
+        try {
+            return stateBuiltAt.plus(SNAPSHOT_TTL).isBefore(businessNow());
+        } catch (RuntimeException ignored) {
+            return true;
+        }
+    }
+
+    private OffsetDateTime businessNow() {
+        return clock.instant().atZone(ZoneId.of("Asia/Shanghai")).toOffsetDateTime();
     }
 
     private CockpitMonitoringDistributionResponse build(

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

@@ -33,9 +33,19 @@ public class CockpitMonitoringOverviewService {
             "GAS", "WATER_SUPPLY", "DRAINAGE", "MANHOLE");
     private static final String SMART_DEVICE = "SMART_DEVICE";
 
+    /**
+     * 快照最长复用时长。设备在线/报警是**快速变化**的事实(equipment_status 每次心跳都可能变),
+     * 而快照只在进程内建一次、生产也没有任何调用方推 delta 进来,于是图例会把开机前的
+     * 全离线快照一直当成当前值(2026-11-10 现场:设备已在线,图例仍「在线 0」)。
+     * 超过这个时长就重建,代价是一次库读,收益是图例不会永久冻结。
+     */
+    private static final java.time.Duration SNAPSHOT_TTL = java.time.Duration.ofSeconds(30);
+
     private final CockpitMonitoringOverviewAdapter adapter;
     private final Clock clock;
     private RuntimeState state;
+    /** 快照构建时刻(判 TTL 用);与 {@code updatedAt}(数据时间)语义不同,不混用。 */
+    private OffsetDateTime stateBuiltAt;
 
     public CockpitMonitoringOverviewService(
             CockpitMonitoringOverviewAdapter adapter,
@@ -130,7 +140,7 @@ public class CockpitMonitoringOverviewService {
     }
 
     private void refreshIfNeeded() {
-        if (state != null) {
+        if (state != null && stateBuiltAt != null && !isExpired()) {
             return;
         }
         CockpitMonitoringOverviewSnapshot snapshot = adapter.load();
@@ -153,6 +163,20 @@ public class CockpitMonitoringOverviewService {
             }
         }
         state = new RuntimeState(snapshot, devices);
+        stateBuiltAt = businessNow();
+    }
+
+    /** 快照是否已超过 {@link #SNAPSHOT_TTL};时钟异常时按「已过期」保守重建。 */
+    private boolean isExpired() {
+        try {
+            return stateBuiltAt.plus(SNAPSHOT_TTL).isBefore(businessNow());
+        } catch (RuntimeException ignored) {
+            return true;
+        }
+    }
+
+    private OffsetDateTime businessNow() {
+        return clock.instant().atZone(BUSINESS_ZONE).toOffsetDateTime();
     }
 
     private CockpitMonitoringOverviewResponse build(

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

@@ -55,9 +55,17 @@ public class CockpitMonitoringSituationService {
     private static final DateTimeFormatter TIMESTAMP =
             DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
 
+    /**
+     * 快照最长复用时长:设备指标状态是快速变化的事实,而生产没有调用方推 delta 进来,
+     * 快照不设 TTL 就会把开机前的旧状态永久当成当前值(2026-11-10 现场:在线设备被算进离线)。
+     */
+    private static final java.time.Duration SNAPSHOT_TTL = java.time.Duration.ofSeconds(30);
+
     private final CockpitMonitoringSituationAdapter adapter;
     private final Clock clock;
     private RuntimeState state;
+    /** 快照构建时刻(判 TTL 用);与响应里的 {@code updatedAt} 语义不同。 */
+    private OffsetDateTime stateBuiltAt;
 
     public CockpitMonitoringSituationService(
             CockpitMonitoringSituationAdapter adapter,
@@ -177,7 +185,7 @@ public class CockpitMonitoringSituationService {
     }
 
     private synchronized void refreshIfNeeded() {
-        if (state != null) {
+        if (state != null && stateBuiltAt != null && !isExpired()) {
             return;
         }
         CockpitMonitoringSituationSnapshot loaded = adapter.load();
@@ -199,6 +207,20 @@ public class CockpitMonitoringSituationService {
             }
         }
         state = new RuntimeState(snapshot, devices);
+        stateBuiltAt = businessNow();
+    }
+
+    /** 快照是否已超过 {@link #SNAPSHOT_TTL};时钟异常时按「已过期」保守重建。 */
+    private boolean isExpired() {
+        try {
+            return stateBuiltAt.plus(SNAPSHOT_TTL).isBefore(businessNow());
+        } catch (RuntimeException ignored) {
+            return true;
+        }
+    }
+
+    private OffsetDateTime businessNow() {
+        return clock.instant().atZone(BUSINESS_ZONE).toOffsetDateTime();
     }
 
     private CockpitMonitoringSituationResponse build(

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

@@ -1,9 +1,22 @@
 package com.zksy.cockpit.point;
 
+/**
+ * 监测点位**聚合状态**的六个取值与优先级(维护者 2026-11-06 重述《点位特效显示规则》)。
+ *
+ * <p><b>这里的 priority 只服务「监测点聚合」</b>:{@link CockpitMonitoringPointStatusResolver#resolve}
+ * 取 {@code min(priority)},即「关联设备里最高档的显示状态」——规则原文:报警 &gt; 预警 &gt; 工单处置,
+ * 全离线则离线,没有关联设备则无设备。它**不**用来排设备点自身的显示序(那是
+ * {@link CockpitMonitoringPointStatusResolver#deviceStatus} 的业务处置序:报警 &gt; 工单 &gt; 预警)。
+ *
+ * <p>两张序此前共用一个枚举,2026-11-02 把本枚举的 WARNING/WORK_ORDER 对调(2/3 → 3/2)以贴合
+ * 设备序,副作用是**点位聚合被一起改成了 报警 &gt; 工单 &gt; 预警**,与维护者规则相反。
+ * 现在按规则把聚合序恢复 报警(1) &gt; 预警(2) &gt; 工单(3) &gt; 正常(4) &gt; 离线(5) &gt; 无设备(6),
+ * 设备序仍留在解析器的判定链里,两者从此各自成立。
+ */
 public enum CockpitMonitoringPointStatus {
     ALARM(1, "报警"),
-    WARNING(3, "预警"),
-    WORK_ORDER(2, "工单处置"),
+    WARNING(2, "预警"),
+    WORK_ORDER(3, "工单处置"),
     NORMAL(4, "正常"),
     OFFLINE(5, "离线"),
     EMPTY(6, "无设备");

+ 39 - 10
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/CockpitMonitoringPointStatusResolver.java

@@ -9,6 +9,21 @@ public final class CockpitMonitoringPointStatusResolver {
     private CockpitMonitoringPointStatusResolver() {
     }
 
+    /**
+     * 监测点聚合状态(维护者 2026-11-06 重述《点位特效显示规则》的「监测点」一节)。
+     *
+     * <p>规则原文:监测点按**内部关联设备的显示状态**改变显示,优先级
+     * <b>报警 &gt; 预警 &gt; 工单处置</b>;关联设备全是离线则离线;没有关联设备则「无设备监测点」。
+     * 每台设备的显示状态先按 {@link #deviceStatus} 求出(设备序是 报警 &gt; 工单 &gt; 预警),
+     * 再在这里取**最高档那一个**。
+     *
+     * <p>注意两张序**必须分开**:设备说「我这台在工单处置」、其所在监测点说「我这个点位还有别的
+     * 设备在预警」并不矛盾 —— 前者回答「这台设备最该看什么」,后者回答「这个点位最该看什么」。
+     * 用同一张 priority 表服务两处会在其中一处必然违规(2026-11-02 的对调就是这样把点位序改坏的)。
+     *
+     * <p>监测点自身<b>不进入</b>顶部图例的设备计数池(唯一例外是「无设备监测点」),
+     * 设备标签筛选与计数由前端全局设备池负责,不由这里的聚合结果替代。
+     */
     public static CockpitMonitoringPointStatus resolve(List<CockpitMonitoringPointDeviceSnapshot> devices) {
         return safeDevices(devices).stream()
                 .map(CockpitMonitoringPointStatusResolver::deviceStatus)
@@ -62,21 +77,35 @@ public final class CockpitMonitoringPointStatusResolver {
     }
 
     /**
-     * 单设备业务状态(维护者 2026-10-22 裁定:未转工单的报警 &gt; 工单处置 &gt; 预警)。
+     * 单设备**显示状态**(维护者 2026-11-06 重述《点位特效显示规则》的「设备点」一节)。
      *
-     * <p>判定序(**业务处置序**,不是枚举优先级序):
+     * <p>规则原文:
+     * <ol>
+     *   <li>无任何标签时只区分在线/离线;</li>
+     *   <li>有标签时按 报警 &gt; 工单 &gt; 预警 &gt; 独立设备 展示;</li>
+     *   <li>全部报警都有承接的工单 → 蓝(工单处置),只要还有一条报警未关联工单 → 红(报警);
+     *       「报警」指设备状态表 {@code alarm_status} 为报警,不另数报警流水;</li>
+     *   <li>工单全部进入终态后,仍有未解除的预警/报警 → 仍显示对应黄/红;</li>
+     *   <li>无报警/预警/工单且在线的设备,用「独立设备」黄绿区分是否关联监测点。</li>
+     * </ol>
+     *
+     * <p>判定链(**业务处置序**,与点位聚合的枚举 priority 序**刻意不同**):
      * <ol>
      *   <li>报警标志为真:该设备全部未处理报警都已由未结束工单承接 → {@code WORK_ORDER}
-     *       (票 52 / 2026-10-17 裁定,保留);否则 {@code ALARM} —— 「查不到承接」不等于「已承接」;</li>
-     *   <li>否则存在未结束工单 → {@code WORK_ORDER}(票 71 / 2026-10-22 新增:压在预警之前);</li>
-     *   <li>否则存在未解决预警 → {@code WARNING};</li>
-     *   <li>否则 {@code online ? NORMAL : OFFLINE}。</li>
+     *       (票 52 / 2026-10-17 裁定,对应规则③的「全部已承接 → 蓝」);否则 {@code ALARM}
+     *       —— 「查不到承接」不等于「已承接」,对应规则③的「只要还有一条未关联 → 红」;</li>
+     *   <li>否则存在未结束工单 → {@code WORK_ORDER}(对应规则④:工单未终态时压过预警);</li>
+     *   <li>否则存在未解决预警 → {@code WARNING}(对应规则④后半:工单终态后预警照常显黄);</li>
+     *   <li>否则 {@code online ? NORMAL : OFFLINE}(对应规则①/⑤)。</li>
      * </ol>
      *
-     * <p>边界(2026-10-22 同日裁定):枚举 {@code priority} 与点位聚合 {@code min(priority)}
-     * <b>不变</b>(Q2);{@code monitoring/situation} 的 {@code metricStatus()} 按设备事实判、
-     * <b>不跟随</b>本序(Q3)—— 同一设备可能「地图 = 工单处置、运行监测异常清单 = 预警」,
-     * 那是裁定结果,不是缺陷。
+     * <p>报警事实来自设备状态表 {@code equipment_status.alarm_status}(维护者 2026-11-10 决定:
+     * 以该表的设备状态为准更快;判定错属后端数据问题,不在驾驶舱另算一套)。因此这里不做
+     * 「报警流水 vs 状态表标志」的二次推断——状态表写什么就显示什么。
+     *
+     * <p>边界:{@link CockpitMonitoringPointStatus#getPriority()} 只服务点位聚合
+     * ({@link #resolve} 的 {@code min(priority)},报警 &gt; 预警 &gt; 工单,见枚举注释);
+     * {@code monitoring/situation} 的 {@code metricStatus()} 按设备事实判、<b>不跟随</b>本序(2026-10-22 Q3)。
      */
     public static CockpitMonitoringPointStatus deviceStatus(CockpitMonitoringPointDeviceSnapshot device) {
         if (device.isAlarm()) {

+ 2 - 1
pipe-network-service/zksy-system/src/test/java/com/zksy/base/alarm/service/AlarmMobileServiceTest.java

@@ -30,7 +30,8 @@ class AlarmMobileServiceTest {
     private final AlarmReviewMapper reviewQueries = mock(AlarmReviewMapper.class);
     private final AlarmLogMapper logs = mock(AlarmLogMapper.class);
     private final ISysDictDataService dictionaries = mock(ISysDictDataService.class);
-    private final AlarmOperationsService operations = new AlarmOperationsService(queries, scope, logs, dictionaries);
+    private final AlarmOperationsService operations = new AlarmOperationsService(queries, scope, logs, dictionaries,
+            mock(WorkOrderService.class));
     private final AlarmReviewAttachmentService attachments = mock(AlarmReviewAttachmentService.class);
     private final AlarmReviewService reviews = new AlarmReviewService(reviewQueries, mock(AlarmDataMapper.class), logs,
             scope, attachments, mock(WorkOrderService.class), mock(SysUserMapper.class), dictionaries);

+ 3 - 1
pipe-network-service/zksy-system/src/test/java/com/zksy/base/alarm/service/AlarmOperationsServiceTest.java

@@ -19,7 +19,9 @@ class AlarmOperationsServiceTest {
     private final AlarmReviewScopeService scope = mock(AlarmReviewScopeService.class);
     private final AlarmLogMapper logs = mock(AlarmLogMapper.class);
     private final com.zksy.system.service.ISysDictDataService dictionaries = mock(com.zksy.system.service.ISysDictDataService.class);
-    private final AlarmOperationsService service = new AlarmOperationsService(mapper, scope, logs, dictionaries);
+    /** 详情/处置链路要回联工单(服务构造第 5 参);测试只验读取口径,用 mock 即可。 */
+    private final com.zksy.ops.service.WorkOrderService workOrders = mock(com.zksy.ops.service.WorkOrderService.class);
+    private final AlarmOperationsService service = new AlarmOperationsService(mapper, scope, logs, dictionaries, workOrders);
     private final AlarmQuery query = new AlarmQuery();
     private final AlarmVO alarm = new AlarmVO();
     @BeforeEach void setup() {