| | |
| | | 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) |
| | | { |
| | |
| | | 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无效"); |