From 4220194f54535388daad46136f8da0452441b806 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期三, 02 九月 2026 14:09:58 +0800
Subject: [PATCH] 补齐控制台来源身份与时间字段
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestDataQueryServiceImpl.java | 71 ++++++++++++++++++++++++++++++++++-
1 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestDataQueryServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestDataQueryServiceImpl.java
index 10226fb..51fcfb8 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestDataQueryServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestDataQueryServiceImpl.java
@@ -1,9 +1,13 @@
package com.ruoyi.system.service.impl;
import java.util.List;
+import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.HashMap;
+import com.alibaba.fastjson2.JSON;
import org.springframework.stereotype.Service;
import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.system.domain.TTestDataOverride;
import com.ruoyi.system.mapper.TTestMapper;
import com.ruoyi.system.service.ITTestService;
import com.ruoyi.system.service.ITestDataQueryService;
@@ -24,19 +28,80 @@
@Override public List<Map<String, Object>> records(Long testId)
{
requireTest(testId);
- return mapper.selectPersistedRecords(testId);
+ return applyEffectiveData(testId, "REALTIME", mapper.selectPersistedRecords(testId));
}
@Override public List<Map<String, Object>> steps(Long testId)
{
requireTest(testId);
- return mapper.selectPersistedSteps(testId);
+ return applyEffectiveData(testId, "STEP", mapper.selectPersistedSteps(testId));
}
@Override public List<Map<String, Object>> cycles(Long testId)
{
requireTest(testId);
- return mapper.selectPersistedCycles(testId);
+ return applyEffectiveData(testId, "CYCLE", mapper.selectPersistedCycles(testId));
+ }
+
+ /** 将最新人工覆盖应用到设备事实,删除只影响当前有效视图,不抹除原始采样。 */
+ private List<Map<String, Object>> applyEffectiveData(Long testId, String dataType,
+ List<Map<String, Object>> source)
+ {
+ List<TTestDataOverride> overrides = mapper.selectDataOverrides(testId, dataType);
+ if (source == null || source.isEmpty() || overrides == null || overrides.isEmpty())
+ return source == null ? List.of() : source;
+ Map<String, TTestDataOverride> byIdentity = new HashMap<>();
+ for (TTestDataOverride override : overrides)
+ if (override != null && override.getStableIdentity() != null)
+ byIdentity.put(override.getStableIdentity(), override);
+ List<Map<String, Object>> effective = new java.util.ArrayList<>(source.size());
+ for (Map<String, Object> row : source)
+ {
+ String identity = stableIdentity(dataType, row);
+ TTestDataOverride override = byIdentity.get(identity);
+ if (override != null && Boolean.TRUE.equals(override.getDeleted())) continue;
+ Map<String, Object> copy = new LinkedHashMap<>(row);
+ if (override != null && override.getFieldValues() != null
+ && !override.getFieldValues().isBlank())
+ {
+ try
+ {
+ Map<String, Object> values = JSON.parseObject(override.getFieldValues(), Map.class);
+ if (values != null) copy.putAll(values);
+ }
+ catch (RuntimeException ignored)
+ {
+ // 覆盖已由修订服务校验;解析异常时保留原始事实,避免查询整体失败。
+ }
+ }
+ effective.add(copy);
+ }
+ return effective;
+ }
+
+ private String stableIdentity(String dataType, Map<String, Object> row)
+ {
+ String adapterId = identityPart(row, "adapterId");
+ String devtype = identityPart(row, "devtype");
+ String deviceId = identityPart(row, "deviceId");
+ String subdevid = identityPart(row, "subdevid");
+ String channelId = identityPart(row, "channelId");
+ String cycleNo = value(row, "cycleNo");
+ String channelIdentity = String.join(":", adapterId, devtype, deviceId, subdevid, channelId);
+ if ("REALTIME".equals(dataType)) return channelIdentity + ":" + value(row, "sequenceId");
+ if ("STEP".equals(dataType)) return "step:" + channelIdentity + ":" + cycleNo + ":" + value(row, "stepNo");
+ return "cycle:" + channelIdentity + ":" + cycleNo;
+ }
+
+ private String identityPart(Map<String, Object> row, String key)
+ {
+ Object value = row == null ? null : row.get(key);
+ return value == null ? "" : String.valueOf(value);
+ }
+
+ private String value(Map<String, Object> row, String key)
+ {
+ return identityPart(row, key);
}
private void requireTest(Long testId)
--
Gitblit v1.7.1