|
|
@@ -1,6 +1,9 @@
|
|
|
package com.zksy.cockpit.event;
|
|
|
|
|
|
import com.zksy.base.alarm.dto.AlarmVO;
|
|
|
+import com.zksy.base.alarm.domain.AlarmLog;
|
|
|
+import com.zksy.base.alarm.enums.AlarmLogOperTypeEnum;
|
|
|
+import com.zksy.base.alarm.mapper.AlarmLogMapper;
|
|
|
import com.zksy.base.alarm.mapper.AlarmOperationsMapper;
|
|
|
import com.zksy.base.warning.domain.WarningSupervision;
|
|
|
import com.zksy.base.warning.mapper.AlarmWarningRelMapper;
|
|
|
@@ -8,14 +11,23 @@ import com.zksy.base.warning.mapper.EarlyWarningMapper;
|
|
|
import com.zksy.base.warning.mapper.WarningAttachmentMapper;
|
|
|
import com.zksy.base.warning.mapper.WarningDisposalMapper;
|
|
|
import com.zksy.base.warning.mapper.WarningSupervisionMapper;
|
|
|
+import com.zksy.ops.dto.WorkOrderDetailVO;
|
|
|
+import com.zksy.ops.service.WorkOrderService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.zksy.base.warning.domain.WarningAttachment;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* 驾驶舱只读事件详情(维护者 2026-10-29)。
|
|
|
@@ -39,6 +51,8 @@ public class CockpitEventDetailService {
|
|
|
private final WarningAttachmentMapper attachments;
|
|
|
private final WarningSupervisionMapper supervisions;
|
|
|
private final AlarmWarningRelMapper linkedAlarms;
|
|
|
+ private final AlarmLogMapper alarmLogs;
|
|
|
+ private final WorkOrderService workOrders;
|
|
|
|
|
|
/**
|
|
|
* 预警详情:基本信息 + 处置记录 + 附件 + 督办 + 关联报警(各段独立成败)。
|
|
|
@@ -86,7 +100,97 @@ public class CockpitEventDetailService {
|
|
|
}
|
|
|
String key = eventId.trim();
|
|
|
AlarmVO detail = alarms.selectCockpitDetailByNo(key);
|
|
|
- return detail != null ? detail : alarms.selectCockpitDetail(key);
|
|
|
+ if (detail == null) detail = alarms.selectCockpitDetail(key);
|
|
|
+ if (detail == null) return null;
|
|
|
+
|
|
|
+ // 与 WARNING 详情同一套只读投影:处置轨迹与附件都是顶层数组,无数据返回空数组。
|
|
|
+ // 记录/附件读失败只降级这两段,不把基础报警详情打崩。
|
|
|
+ List<AlarmLog> history = alarmHistory(detail.getId());
|
|
|
+ detail.setDisposalHistory(alarmDisposalHistory(history));
|
|
|
+ detail.setAttachmentList(alarmAttachments(detail, history));
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 报警操作流水:免鉴权读取底层 alarm_log,不经过需要登录态的 admin 端点。 */
|
|
|
+ private List<AlarmLog> alarmHistory(String alarmId) {
|
|
|
+ if (alarmId == null || alarmId.trim().isEmpty()) return Collections.emptyList();
|
|
|
+ try {
|
|
|
+ List<AlarmLog> history = alarmLogs.selectHistory(alarmId.trim());
|
|
|
+ return history == null ? Collections.emptyList() : history;
|
|
|
+ } catch (RuntimeException error) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> alarmDisposalHistory(List<AlarmLog> history) {
|
|
|
+ if (history == null || history.isEmpty()) return Collections.emptyList();
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (AlarmLog log : history) {
|
|
|
+ if (log == null) continue;
|
|
|
+ AlarmLogOperTypeEnum type = AlarmLogOperTypeEnum.fromCode(log.getOperType());
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
+ item.put("operationName", type == null ? "历史操作" : type.getLabel());
|
|
|
+ item.put("operatedAt", formatAlarmTime(log.getOperTime()));
|
|
|
+ item.put("operatorName", log.getOperUserName() == null ? "" : log.getOperUserName());
|
|
|
+ item.put("operationDesc", log.getOperDesc() == null ? "" : log.getOperDesc());
|
|
|
+ item.put("operType", log.getOperType());
|
|
|
+ item.put("attachments", splitUrls(log.getAttachUrl()));
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> alarmAttachments(AlarmVO detail, List<AlarmLog> history) {
|
|
|
+ Map<String, Map<String, Object>> byUrl = new LinkedHashMap<>();
|
|
|
+ addAttachment(byUrl, detail.getEquipmentImage(), "设备图片");
|
|
|
+ if (history != null) {
|
|
|
+ for (AlarmLog log : history) {
|
|
|
+ if (log != null) addAttachment(byUrl, log.getAttachUrl(), "报警附件");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ WorkOrderDetailVO order = detail.getWorkOrderDetail();
|
|
|
+ if (order == null && detail.getWorkOrderId() != null) {
|
|
|
+ try {
|
|
|
+ order = workOrders.getDetail(detail.getWorkOrderId());
|
|
|
+ } catch (RuntimeException ignored) {
|
|
|
+ // 工单不作为报警详情的前置条件;附件段失败只返回已有附件。
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (order != null && order.getOrder() != null) {
|
|
|
+ addAttachment(byUrl, order.getOrder().getMaintenanceBeforeImg(), "维修前");
|
|
|
+ addAttachment(byUrl, order.getOrder().getMaintenanceAfterImg(), "维修后");
|
|
|
+ }
|
|
|
+ return new ArrayList<>(byUrl.values());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void addAttachment(Map<String, Map<String, Object>> byUrl, String raw, String type) {
|
|
|
+ for (String url : splitUrls(raw)) {
|
|
|
+ if (byUrl.containsKey(url)) continue;
|
|
|
+ Map<String, Object> item = new LinkedHashMap<>();
|
|
|
+ item.put("name", fileName(url));
|
|
|
+ item.put("url", url);
|
|
|
+ item.put("type", type);
|
|
|
+ byUrl.put(url, item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<String> splitUrls(String raw) {
|
|
|
+ if (raw == null || raw.trim().isEmpty()) return Collections.emptyList();
|
|
|
+ Set<String> urls = new LinkedHashSet<>();
|
|
|
+ for (String part : raw.split(",")) {
|
|
|
+ String url = part == null ? "" : part.trim();
|
|
|
+ if (!url.isEmpty()) urls.add(url);
|
|
|
+ }
|
|
|
+ return new ArrayList<>(urls);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String fileName(String url) {
|
|
|
+ int slash = url.lastIndexOf('/');
|
|
|
+ return slash >= 0 ? url.substring(slash + 1) : url;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String formatAlarmTime(LocalDateTime time) {
|
|
|
+ return time == null ? "" : time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
}
|
|
|
|
|
|
/** 下划线列名 → 驼峰键(SQL Map 与 Java Bean 输出口径对齐)。 */
|