From dd1af98f7e679290e5280e2aff58d7ff5237c5fb Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 11:17:11 +0800
Subject: [PATCH] 实现测试数据物理删除修订
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestConsoleDataServiceImpl.java | 35 +++++++++++++++++++++++++++++++++--
1 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestConsoleDataServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestConsoleDataServiceImpl.java
index 78ee125..b2ca305 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestConsoleDataServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestConsoleDataServiceImpl.java
@@ -71,6 +71,10 @@
if (action.getOperatorName() == null || action.getOperatorName().trim().isEmpty()) action.setOperatorName("未知用户");
action.setReason(action.getReason().trim());
action.setCreatedAtUtc(new Date());
+ if ("DELETE".equals(action.getOperationType())) {
+ applyPhysicalDelete(action);
+ return action.getActionId();
+ }
mapper.insertDataRevisionAction(action);
if ("IMPORT".equals(action.getOperationType()) && action.getChangesSummary() != null)
{
@@ -113,11 +117,38 @@
mapper.upsertDataOverride(item);
}
}
- // 删除仅写入 deleted 覆盖,保留设备原始采样和采集器事实供追溯。
- // btsSampleIds/collectorSampleIds 保留在接口中兼容旧调用方,但不再执行物理删除。
return action.getActionId();
}
+ /** 删除前先把完整当前记录写入修订摘要,再删除事实行。 */
+ private void applyPhysicalDelete(TTestDataRevisionAction action) {
+ List<Map<String,Object>> rows = new java.util.ArrayList<>();
+ List<Map<String,Object>> source = switch (action.getDataType()) {
+ case "REALTIME" -> mapper.selectPersistedFinalRealtimeRecords(action.getTestId());
+ case "STEP" -> mapper.selectPersistedFinalStepRecords(action.getTestId());
+ case "CYCLE" -> mapper.selectPersistedFinalCycleRecords(action.getTestId());
+ default -> List.of();
+ };
+ Set<String> wanted = new HashSet<>();
+ try { for (Object value : JSON.parseArray(action.getIdentitySummary())) wanted.add(String.valueOf(value)); }
+ catch (Exception e) { throw new ServiceException("身份摘要格式无效"); }
+ for (Map<String,Object> row : source) if (wanted.contains(String.valueOf(row.get("stableIdentity")))) rows.add(new java.util.LinkedHashMap<>(row));
+ action.setChangesSummary(JSON.toJSONString(rows));
+ mapper.insertDataRevisionAction(action);
+ List<Long> ids = new java.util.ArrayList<>();
+ for (String identity : wanted) {
+ String[] p = identity.split(":", -1);
+ try { if ("REALTIME".equals(action.getDataType()) && p.length == 2) ids.add(Long.valueOf(p[1]));
+ else if ("STEP".equals(action.getDataType()) && p.length == 2) ids.add(Long.valueOf(p[1]));
+ else if ("CYCLE".equals(action.getDataType()) && p.length == 2) ids.add(Long.valueOf(p[1]));
+ } catch (NumberFormatException ignored) { }
+ }
+ if (ids.isEmpty()) return;
+ if ("REALTIME".equals(action.getDataType())) mapper.deleteRealtimeRecordsByIds(action.getTestId(), ids);
+ if ("STEP".equals(action.getDataType())) mapper.deleteStepRecordsByIds(action.getTestId(), ids);
+ if ("CYCLE".equals(action.getDataType())) mapper.deleteCycleRecordsByIds(action.getTestId(), ids);
+ }
+
private void validateType(Long testId, String dataType)
{
if (testId == null || testId < 1) throw new ServiceException("测试ID无效");
--
Gitblit v1.7.1