瀏覽代碼

fix(cockpit): 预警报警事件编码改用业务编号、按编号回查详情(票65)

Kazerin 5 天之前
父節點
當前提交
8f5ea702f6

+ 4 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/alarm/mapper/AlarmOperationsMapper.java

@@ -16,6 +16,10 @@ public interface AlarmOperationsMapper {
     Page<AlarmVO> selectPage(Page<AlarmVO> page, @Param("query") AlarmQuery query, @Param("typeIds") List<Integer> typeIds);
     Page<AlarmVO> selectReminders(Page<AlarmVO> page, @Param("query") AlarmQuery query, @Param("typeIds") List<Integer> typeIds);
     AlarmVO selectDetail(@Param("id") String id, @Param("query") AlarmQuery query, @Param("typeIds") List<Integer> typeIds);
+    /** 驾驶舱免鉴权只读详情:不按登录用户范围裁剪。 */
+    AlarmVO selectCockpitDetail(@Param("id") String id);
+    /** 驾驶舱只读详情:按业务编号(alarm_no)回查。 */
+    AlarmVO selectCockpitDetailByNo(@Param("alarmNo") String alarmNo);
     List<Map<String, Object>> countByLevel(@Param("query") AlarmQuery query, @Param("typeIds") List<Integer> typeIds,
             @Param("unhandledStatus") int unhandledStatus, @Param("handledStatus") int handledStatus);
     AlarmDashboardVO selectDashboardCounts(@Param("query") AlarmQuery query, @Param("typeIds") List<Integer> typeIds,

+ 3 - 0
pipe-network-service/zksy-system/src/main/java/com/zksy/base/warning/mapper/EarlyWarningMapper.java

@@ -34,6 +34,9 @@ public interface EarlyWarningMapper extends BaseMapper<EarlyWarning> {
 
     Map<String, Object> selectWarningDetail(@Param("warningId") String warningId);
 
+    /** 驾驶舱只读详情:列表下发业务编号(warning_no),详情按编号回查(主键仍在结果里)。 */
+    Map<String, Object> selectWarningDetailByNo(@Param("warningNo") String warningNo);
+
     IPage<Map<String, Object>> selectMobileWarnings(
             Page<?> page,
             @Param("scope") WarningAccessScope scope,

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

@@ -354,6 +354,7 @@ public class BusinessCockpitEventAdapter {
         EquipmentBase device = facts.devicesByCode.get(normalize(alarm.getDeviceCode()));
         return new CockpitCurrentEventsSnapshot.SourceAlarm(
                 trimToNull(alarm.getId()),
+                trimToNull(alarm.getAlarmNo()),
                 firstNonBlank(warningTypeName(metadata), alarm.getWarningCode()),
                 null,
                 level(alarm.getAlarmLevel()),
@@ -442,6 +443,7 @@ public class BusinessCockpitEventAdapter {
             EquipmentBase device = facts.devicesByCode.get(normalize(alarm.getDeviceCode()));
             result.add(new CockpitHistoryAnalysisSnapshot.SourceAlarm(
                     trimToNull(alarm.getId()),
+                    trimToNull(alarm.getAlarmNo()),
                     level(alarm.getAlarmLevel()),
                     offsetTime(alarm.getCreateTime()),
                     typeCode(alarm.getDeviceCode(), facts),

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

@@ -160,6 +160,8 @@ public class CockpitCurrentEventsResponse {
 
     public static class EventItem {
         private final String eventNo;
+        /** 业务编号:预警 warningNo / 报警 alarmNo。界面上屏用它,eventNo 只作内部键。 */
+        private final String eventCode;
         private final String eventName;
         private final String eventType;
         private final Integer level;
@@ -184,6 +186,7 @@ public class CockpitCurrentEventsResponse {
 
         public EventItem(
                 String eventNo,
+                String eventCode,
                 String eventName,
                 String eventType,
                 Integer level,
@@ -206,6 +209,7 @@ public class CockpitCurrentEventsResponse {
                 BigDecimal thresholdMaxValue,
                 WorkOrderSummary workOrderSummary) {
             this.eventNo = eventNo;
+            this.eventCode = eventCode;
             this.eventName = eventName;
             this.eventType = eventType;
             this.level = level;
@@ -230,6 +234,8 @@ public class CockpitCurrentEventsResponse {
         }
 
         public String getEventNo() { return eventNo; }
+
+        public String getEventCode() { return eventCode; }
         public String getEventName() { return eventName; }
         public String getEventType() { return eventType; }
         public Integer getLevel() { return level; }

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

@@ -206,6 +206,7 @@ public class CockpitCurrentEventsService {
                 continue;
             }
             rows.add(new EventRow(
+                    warning.getWarningNo(),
                     warning.getWarningNo(),
                     warning.getWarningName(),
                     warning.getWarningType(),
@@ -260,6 +261,7 @@ public class CockpitCurrentEventsService {
             }
             rows.add(new EventRow(
                     alarm.getAlarmId(),
+                    alarm.getAlarmNo(),
                     alarm.getWarningName(),
                     alarm.getWarningType(),
                     alarm.getLevel(),
@@ -322,6 +324,12 @@ public class CockpitCurrentEventsService {
         return result;
     }
 
+    /** 首选非空:展示编号缺失时退回内部键(不编造、不留空)。 */
+    private static String firstNonBlank(String preferred, String fallback) {
+        if (preferred != null && !preferred.trim().isEmpty()) return preferred.trim();
+        return fallback == null ? null : fallback.trim();
+    }
+
     private static String stateName(Integer stateCode) {
         return CockpitWorkOrderStateDictionary.byCode(stateCode) == null
                 ? null
@@ -448,6 +456,8 @@ public class CockpitCurrentEventsService {
 
     private static class EventRow {
         private final String eventNo;
+        /** 上屏用的业务编号(预警 warningNo / 报警 alarmNo);与内部键 eventNo 分开。 */
+        private final String eventCode;
         private final String eventName;
         private final String eventType;
         private final Integer level;
@@ -470,6 +480,7 @@ public class CockpitCurrentEventsService {
 
         private EventRow(
                 String eventNo,
+                String eventCode,
                 String eventName,
                 String eventType,
                 Integer level,
@@ -490,6 +501,7 @@ public class CockpitCurrentEventsService {
                 BigDecimal thresholdMinValue,
                 BigDecimal thresholdMaxValue) {
             this.eventNo = eventNo;
+            this.eventCode = eventCode;
             this.eventName = eventName;
             this.eventType = eventType;
             this.level = level;
@@ -520,6 +532,7 @@ public class CockpitCurrentEventsService {
             String key = eventNo == null ? null : eventNo.trim();
             return new CockpitCurrentEventsResponse.EventItem(
                     eventNo,
+                    firstNonBlank(eventCode, eventNo),
                     eventName,
                     eventType,
                     level,

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

@@ -233,6 +233,8 @@ public class CockpitCurrentEventsSnapshot {
 
     public static class SourceAlarm {
         private final String alarmId;
+        /** 业务编号(alarm_no):上屏用它,主键只用于内部关联。 */
+        private final String alarmNo;
         private final String warningName;
         private final String warningType;
         private final Integer level;
@@ -255,6 +257,7 @@ public class CockpitCurrentEventsSnapshot {
         /** 报警片区(原始编码,未归一见 {@code CockpitDistrict});无设备/未识别时为 null=未分区。 */
         private final Integer district;
 
+        /** 兼容重载:不传业务编号时退回主键(既有测试/旧适配器用)。 */
         public SourceAlarm(
                 String alarmId,
                 String warningName,
@@ -277,7 +280,37 @@ public class CockpitCurrentEventsSnapshot {
                 BigDecimal thresholdMinValue,
                 BigDecimal thresholdMaxValue,
                 Integer district) {
+            this(alarmId, null, warningName, warningType, level, status, eventTime, updatedTime,
+                    value, unit, deviceCode, deviceName, monitoringPointCode, monitoringPointName,
+                    location, typeCode, longitude, latitude, coordinateVerified,
+                    thresholdMinValue, thresholdMaxValue, district);
+        }
+
+        public SourceAlarm(
+                String alarmId,
+                String alarmNo,
+                String warningName,
+                String warningType,
+                Integer level,
+                String status,
+                String eventTime,
+                String updatedTime,
+                BigDecimal value,
+                String unit,
+                String deviceCode,
+                String deviceName,
+                String monitoringPointCode,
+                String monitoringPointName,
+                String location,
+                String typeCode,
+                BigDecimal longitude,
+                BigDecimal latitude,
+                boolean coordinateVerified,
+                BigDecimal thresholdMinValue,
+                BigDecimal thresholdMaxValue,
+                Integer district) {
             this.alarmId = alarmId;
+            this.alarmNo = alarmNo;
             this.warningName = warningName;
             this.warningType = warningType;
             this.level = level;
@@ -304,6 +337,10 @@ public class CockpitCurrentEventsSnapshot {
             return alarmId;
         }
 
+        public String getAlarmNo() {
+            return alarmNo;
+        }
+
         public String getWarningName() {
             return warningName;
         }

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

@@ -166,6 +166,7 @@ public class CockpitHistoryAnalysisResponse {
     public static class EventItem extends CockpitCurrentEventsResponse.EventItem {
         public EventItem(
                 String eventNo,
+                String eventCode,
                 String eventName,
                 String eventType,
                 Integer level,
@@ -187,7 +188,7 @@ public class CockpitHistoryAnalysisResponse {
                 BigDecimal thresholdMinValue,
                 BigDecimal thresholdMaxValue,
                 CockpitCurrentEventsResponse.WorkOrderSummary workOrderSummary) {
-            super(eventNo, eventName, eventType, level, levelColor, status, eventTime, updatedTime,
+            super(eventNo, eventCode, eventName, eventType, level, levelColor, status, eventTime, updatedTime,
                     value, unit, deviceCode, deviceName, monitoringPointCode, monitoringPointName,
                     location, industry, longitude, latitude, coordinateValidation,
                     thresholdMinValue, thresholdMaxValue, workOrderSummary);

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

@@ -245,6 +245,7 @@ public class CockpitHistoryAnalysisService {
                 continue;
             }
             rows.add(new EventRow(
+                    warning.getWarningNo(),
                     warning.getWarningNo(),
                     warning.getWarningNo(),
                     warning.getTypeCode(),
@@ -287,6 +288,7 @@ public class CockpitHistoryAnalysisService {
             }
             rows.add(new EventRow(
                     alarm.getAlarmId(),
+                    firstNonBlank(alarm.getAlarmNo(), alarm.getAlarmId()),
                     isBlank(alarm.getEventName()) ? alarm.getAlarmId() : alarm.getEventName(),
                     alarm.getTypeCode(),
                     alarm.getLevel(),
@@ -550,10 +552,17 @@ public class CockpitHistoryAnalysisService {
         return value == null || value.trim().isEmpty();
     }
 
+    /** 首选非空(业务编号优先,缺失时退回内部键 —— 不编造、不留空)。 */
+    private static String firstNonBlank(String preferred, String fallback) {
+        if (!isBlank(preferred)) return preferred.trim();
+        return isBlank(fallback) ? null : fallback.trim();
+    }
+
     /** 逐事件行(领域内形状):聚合与逐事件清单共用一份事实。 */
     private static class EventRow {
         private final String eventNo;
         private final String eventName;
+        private final String eventCode;
         private final String eventType;
         private final Integer level;
         private final String status;
@@ -570,6 +579,7 @@ public class CockpitHistoryAnalysisService {
 
         private EventRow(
                 String eventNo,
+                String eventCode,
                 String eventName,
                 String eventType,
                 Integer level,
@@ -585,6 +595,7 @@ public class CockpitHistoryAnalysisService {
                 BigDecimal minValue,
                 BigDecimal maxValue) {
             this.eventNo = eventNo;
+            this.eventCode = eventCode;
             this.eventName = eventName;
             this.eventType = eventType;
             this.level = level;
@@ -609,6 +620,7 @@ public class CockpitHistoryAnalysisService {
         private CockpitHistoryAnalysisResponse.EventItem toItem() {
             return new CockpitHistoryAnalysisResponse.EventItem(
                     eventNo,
+                    eventCode,
                     isBlank(eventName) ? eventNo : eventName,
                     eventType,
                     level,

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

@@ -239,6 +239,8 @@ public class CockpitHistoryAnalysisSnapshot {
 
     public static class SourceAlarm {
         private final String alarmId;
+        /** 业务编号(alarm_no):上屏用它,主键只用于内部关联(维护者 2026-10-29)。 */
+        private final String alarmNo;
         private final Integer level;
         private final String eventTime;
         private final String typeCode;
@@ -255,20 +257,31 @@ public class CockpitHistoryAnalysisSnapshot {
         /** 报警片区(原始编码,未归一见 {@code CockpitDistrict});无设备/未识别时为 null=未分区。 */
         private final Integer district;
 
-        /** 聚合最小字段(既有测试/空适配器用)。 */
+        /** 兼容重载:不带业务编号时退回主键(既有测试/旧适配器用)。 */
         public SourceAlarm(
                 String alarmId,
                 Integer level,
                 String eventTime,
                 String typeCode,
-                String deviceCode) {
-            this(alarmId, level, eventTime, typeCode, deviceCode,
-                    null, null, null, null, null, null, null, null, null, null);
+                String deviceCode,
+                String eventName,
+                String status,
+                String deviceName,
+                String location,
+                String updatedTime,
+                BigDecimal value,
+                String unit,
+                BigDecimal minValue,
+                BigDecimal maxValue,
+                Integer district) {
+            this(alarmId, null, level, eventTime, typeCode, deviceCode, eventName, status,
+                    deviceName, location, updatedTime, value, unit, minValue, maxValue, district);
         }
 
         /** 票 61:逐事件行展示字段(业务适配器用)。 */
         public SourceAlarm(
                 String alarmId,
+                String alarmNo,
                 Integer level,
                 String eventTime,
                 String typeCode,
@@ -284,6 +297,7 @@ public class CockpitHistoryAnalysisSnapshot {
                 BigDecimal maxValue,
                 Integer district) {
             this.alarmId = alarmId;
+            this.alarmNo = alarmNo;
             this.level = level;
             this.eventTime = eventTime;
             this.typeCode = typeCode;
@@ -304,6 +318,10 @@ public class CockpitHistoryAnalysisSnapshot {
             return alarmId;
         }
 
+        public String getAlarmNo() {
+            return alarmNo;
+        }
+
         public Integer getLevel() {
             return level;
         }

+ 10 - 0
pipe-network-service/zksy-system/src/main/resources/mapper/base/AlarmOperationsMapper.xml

@@ -88,6 +88,16 @@
         SELECT <include refid="columns"/> <include refid="joins"/> WHERE a.id = #{id}
         <include refid="com.zksy.base.alarm.mapper.AlarmReviewMapper.scope"/>
     </select>
+    <!-- 驾驶舱免鉴权只读域用:不按登录用户范围裁剪(范围条件在 scope 片段里)。 -->
+    <select id="selectCockpitDetail" resultMap="alarm">
+        SELECT <include refid="columns"/> <include refid="joins"/> WHERE a.id = #{id}
+    </select>
+    <!-- 驾驶舱列表下发的是业务编号(alarm_no),详情按编号回查;同样不按用户范围裁剪。 -->
+    <select id="selectCockpitDetailByNo" resultMap="alarm">
+        SELECT <include refid="columns"/> <include refid="joins"/> WHERE a.alarm_no = #{alarmNo}
+        ORDER BY a.create_time DESC NULLS LAST
+        LIMIT 1
+    </select>
     <select id="selectReminders" resultMap="alarm">
         SELECT <include refid="columns"/>, l.oper_desc AS latest_operation,
             COALESCE(l.oper_time, a.update_time, a.create_time) AS latest_operation_time

+ 22 - 0
pipe-network-service/zksy-system/src/main/resources/mapper/warning/EarlyWarningMapper.xml

@@ -1099,6 +1099,28 @@
         WHERE w.warning_id = #{warningId}
     </select>
 
+    <!-- 驾驶舱只读详情用:列表下发的是**业务编号**(warning_no),详情要的是主键(warning_id)。
+         两条口径都在契约里,因此按编号回查一次,不要求前端改拿主键。 -->
+    <select id="selectWarningDetailByNo" resultType="java.util.Map">
+        SELECT w.*, (SELECT wt.warning_name FROM app_user.warning_type wt WHERE wt.warning_code=w.warning_type ORDER BY wt.id LIMIT 1) AS warning_type_name,
+            (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='alert_level' AND dict_value=w.warning_level AND status='0' ORDER BY dict_sort LIMIT 1) AS warning_level_name,
+            (SELECT dict_label FROM app_user.sys_dict_data WHERE dict_type='pre_alarm_status' AND dict_value=w.status AND status='0' ORDER BY dict_sort LIMIT 1) AS status_name,
+            COALESCE(NULLIF(TRIM(hu.nick_name), ''), w.handler) AS handler_name,
+            COALESCE(NULLIF(TRIM(ru.nick_name), ''), w.reviewer) AS reviewer_name,
+            COALESCE(NULLIF(TRIM(pu.nick_name), ''), w.publisher) AS publisher_name,
+            COALESCE(NULLIF(TRIM(cu.nick_name), ''), w.create_by) AS creator_name,
+            COALESCE(eb.equipment_location, w.location) AS location
+        FROM early_warning w
+        LEFT JOIN app_user.sys_user hu ON hu.user_name = w.handler
+        LEFT JOIN app_user.sys_user ru ON ru.user_name = w.reviewer
+        LEFT JOIN app_user.sys_user pu ON pu.user_name = w.publisher
+        LEFT JOIN app_user.sys_user cu ON cu.user_name = w.create_by
+        LEFT JOIN app_user.equipment_base eb ON eb.equipment_code = w.device_code
+        WHERE w.warning_no = #{warningNo}
+        ORDER BY w.create_time DESC NULLS LAST
+        LIMIT 1
+    </select>
+
     <select id="selectStatistics" resultType="java.util.Map">
         SELECT
             COUNT(*) AS total,