| | |
| | | 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; |
| | |
| | | @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 deviceId = value(row, "deviceId"); |
| | | String channelId = value(row, "channelId"); |
| | | String cycleNo = value(row, "cycleNo"); |
| | | if ("REALTIME".equals(dataType)) return deviceId + ":" + channelId + ":" + value(row, "sequenceId"); |
| | | if ("STEP".equals(dataType)) return "step:" + deviceId + ":" + channelId + ":" + cycleNo + ":" + value(row, "stepNo"); |
| | | return "cycle:" + deviceId + ":" + channelId + ":" + cycleNo; |
| | | } |
| | | |
| | | private String value(Map<String, Object> row, String key) |
| | | { |
| | | Object value = row == null ? null : row.get(key); |
| | | return value == null ? "" : String.valueOf(value); |
| | | } |
| | | |
| | | private void requireTest(Long testId) |