瀏覽代碼

fix(cockpit): 补齐点位详情 freshness 标记

Kazerin 3 周之前
父節點
當前提交
3e9289d22c

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

@@ -66,6 +66,8 @@ class CockpitMonitoringPointDetailControllerTest {
                 .andExpect(jsonPath("$.data.requestId").value("point-detail-request-001"))
                 .andExpect(jsonPath("$.data.apiVersion").value("v1"))
                 .andExpect(jsonPath("$.data.readOnly").value(true))
+                .andExpect(jsonPath("$.data.freshness").value("CURRENT"))
+                .andExpect(jsonPath("$.data.staleReason").value("BEST_EFFORT_SOURCE"))
                 .andExpect(jsonPath("$.data.monitoringPointCode").value("MP-001"))
                 .andExpect(jsonPath("$.data.monitoringPointName").value("供水干管监测点"))
                 .andExpect(jsonPath("$.data.pointStatus").value("ALARM"))
@@ -210,6 +212,8 @@ class CockpitMonitoringPointDetailControllerTest {
                         .param("snapshotAt", "2026-09-02T10:00:00+08:00"))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.data.monitoringPointCode").value("MP-SNAP"))
+                .andExpect(jsonPath("$.data.freshness").value("CURRENT"))
+                .andExpect(jsonPath("$.data.staleReason").doesNotExist())
                 .andExpect(jsonPath("$.data.devices[0].deviceCode").value("EQ-001"));
 
         verifyNoInteractions(adapter);

+ 19 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/CockpitMonitoringPointDetailResponse.java

@@ -1,6 +1,7 @@
 package com.zksy.cockpit.point;
 
 import com.zksy.cockpit.foundation.CockpitCoordinateValidation;
+import com.zksy.cockpit.foundation.CockpitFreshnessStatus;
 
 import java.util.List;
 
@@ -8,6 +9,8 @@ public class CockpitMonitoringPointDetailResponse {
     private final String requestId;
     private final String apiVersion;
     private final boolean readOnly;
+    private final CockpitFreshnessStatus freshness;
+    private final String staleReason;
     private final String monitoringPointCode;
     private final String monitoringPointName;
     private final CockpitMonitoringPointStatus pointStatus;
@@ -24,9 +27,23 @@ public class CockpitMonitoringPointDetailResponse {
             CockpitMonitoringPointDeviceStatistics deviceStatistics,
             List<CockpitMonitoringPointDeviceCard> devices, CockpitCoordinateValidation coordinateValidation,
             List<CockpitMonitoringPointStatusEntry> statusDictionary) {
+        this(requestId, apiVersion, readOnly, CockpitFreshnessStatus.CURRENT, null,
+                monitoringPointCode, monitoringPointName, pointStatus, statusReasons, deviceStatistics,
+                devices, coordinateValidation, statusDictionary);
+    }
+
+    public CockpitMonitoringPointDetailResponse(String requestId, String apiVersion, boolean readOnly,
+            CockpitFreshnessStatus freshness, String staleReason,
+            String monitoringPointCode, String monitoringPointName, CockpitMonitoringPointStatus pointStatus,
+            List<CockpitMonitoringPointStatusReason> statusReasons,
+            CockpitMonitoringPointDeviceStatistics deviceStatistics,
+            List<CockpitMonitoringPointDeviceCard> devices, CockpitCoordinateValidation coordinateValidation,
+            List<CockpitMonitoringPointStatusEntry> statusDictionary) {
         this.requestId = requestId;
         this.apiVersion = apiVersion;
         this.readOnly = readOnly;
+        this.freshness = freshness;
+        this.staleReason = staleReason;
         this.monitoringPointCode = monitoringPointCode;
         this.monitoringPointName = monitoringPointName;
         this.pointStatus = pointStatus;
@@ -41,6 +58,8 @@ public class CockpitMonitoringPointDetailResponse {
     public String getRequestId() { return requestId; }
     public String getApiVersion() { return apiVersion; }
     public boolean isReadOnly() { return readOnly; }
+    public CockpitFreshnessStatus getFreshness() { return freshness; }
+    public String getStaleReason() { return staleReason; }
     public String getMonitoringPointCode() { return monitoringPointCode; }
     public String getMonitoringPointName() { return monitoringPointName; }
     public CockpitMonitoringPointStatus getPointStatus() { return pointStatus; }

+ 3 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/cockpit/point/CockpitMonitoringPointDetailService.java

@@ -4,6 +4,7 @@ import com.zksy.cockpit.foundation.CockpitCoordinateValidation;
 import com.zksy.cockpit.foundation.CockpitCoordinateValidator;
 import com.zksy.cockpit.foundation.CockpitErrorCategory;
 import com.zksy.cockpit.foundation.CockpitErrorPayload;
+import com.zksy.cockpit.foundation.CockpitFreshnessStatus;
 import com.zksy.cockpit.foundation.CockpitInvalidRequestException;
 import com.zksy.cockpit.foundation.CockpitMonitoringPointNotFoundException;
 import com.zksy.cockpit.foundation.CockpitSnapshotExpiredException;
@@ -87,6 +88,8 @@ public class CockpitMonitoringPointDetailService {
                 requestId,
                 "v1",
                 true,
+                CockpitFreshnessStatus.CURRENT,
+                isBlank(snapshotAt) ? "BEST_EFFORT_SOURCE" : null,
                 detail.getMonitoringPointCode(),
                 detail.getMonitoringPointName(),
                 pointStatus,