|
|
@@ -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;
|
|
|
|
|
|
/**
|
|
|
* 预警详情:基本信息 + 处置记录 + 附件 + 督办 + 关联报警(各段独立成败)。
|
|
|
@@ -65,7 +79,9 @@ public class CockpitEventDetailService {
|
|
|
Map<String, Object> camel = camelize(basicInfo);
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("basicInfo", camel);
|
|
|
- result.put("disposalHistory", safe(() -> disposals.selectDisposalList(warningId)));
|
|
|
+ List<Map<String, Object>> disposalHistory = safe(() -> disposals.selectDisposalList(warningId));
|
|
|
+ redactDisposalUserNames(disposalHistory, camel);
|
|
|
+ result.put("disposalHistory", disposalHistory == null ? Collections.emptyList() : disposalHistory);
|
|
|
result.put("attachmentList", safe(() -> attachments.selectList(
|
|
|
new LambdaQueryWrapper<WarningAttachment>().eq(WarningAttachment::getWarningId, warningId))));
|
|
|
result.put("supervisionList", safe(() -> supervisions.selectByWarningId(warningId),
|
|
|
@@ -74,6 +90,42 @@ public class CockpitEventDetailService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 驾驶舱不展示 sys_user.user_name(隐私):处置内容里历史拼进去的用户名,
|
|
|
+ * 在只读投影里替换成同一条记录的 nick_name;查不到昵称就清空,不回退到用户名。
|
|
|
+ */
|
|
|
+ private static void redactDisposalUserNames(List<Map<String, Object>> history, Map<String, Object> basic) {
|
|
|
+ if (history == null || history.isEmpty()) return;
|
|
|
+ Map<String, String> aliases = new LinkedHashMap<>();
|
|
|
+ addUserAlias(aliases, basic.get("handler"), basic.get("handlerName"));
|
|
|
+ addUserAlias(aliases, basic.get("reviewer"), basic.get("reviewerName"));
|
|
|
+ addUserAlias(aliases, basic.get("publisher"), basic.get("publisherName"));
|
|
|
+ addUserAlias(aliases, basic.get("createBy"), basic.get("creatorName"));
|
|
|
+ for (Map<String, Object> row : history) {
|
|
|
+ if (row == null) continue;
|
|
|
+ addUserAlias(aliases, row.get("disposal_user"), row.get("disposal_user_name"));
|
|
|
+ }
|
|
|
+ if (aliases.isEmpty()) return;
|
|
|
+ List<Map.Entry<String, String>> entries = new ArrayList<>(aliases.entrySet());
|
|
|
+ entries.sort((left, right) -> Integer.compare(right.getKey().length(), left.getKey().length()));
|
|
|
+ for (Map<String, Object> row : history) {
|
|
|
+ if (row == null) continue;
|
|
|
+ Object content = row.get("disposal_content");
|
|
|
+ if (!(content instanceof String) || ((String) content).trim().isEmpty()) continue;
|
|
|
+ String text = (String) content;
|
|
|
+ for (Map.Entry<String, String> entry : entries) {
|
|
|
+ text = text.replace(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ row.put("disposal_content", text);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void addUserAlias(Map<String, String> aliases, Object userName, Object nickName) {
|
|
|
+ String raw = userName == null ? "" : String.valueOf(userName).trim();
|
|
|
+ if (raw.isEmpty()) return;
|
|
|
+ aliases.put(raw, nickName == null ? "" : String.valueOf(nickName).trim());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 报警详情:与移动端同一份 VO(设备名/位置/类型/工单/单位都由同一条 SQL 回填)。
|
|
|
*
|
|
|
@@ -86,7 +138,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 输出口径对齐)。 */
|