yeg
2026-09-02 409b5ac5a3b160eacb1fefa6a10bf97b5f6860d7
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TestDataQueryServiceImpl.java
@@ -28,7 +28,12 @@
    @Override public List<Map<String, Object>> records(Long testId)
    {
        requireTest(testId);
        return applyEffectiveData(testId, "REALTIME", mapper.selectPersistedRecords(testId));
        List<Map<String, Object>> source = new java.util.ArrayList<>();
        List<Map<String, Object>> cabinet = mapper.selectPersistedRecords(testId);
        List<Map<String, Object>> collector = mapper.selectPersistedCollectorRecords(testId);
        if (cabinet != null) source.addAll(cabinet);
        if (collector != null) source.addAll(collector);
        return applyEffectiveData(testId, "REALTIME", source);
    }
    @Override public List<Map<String, Object>> steps(Long testId)
@@ -47,17 +52,32 @@
    private List<Map<String, Object>> applyEffectiveData(Long testId, String dataType,
            List<Map<String, Object>> source)
    {
        List<Map<String, Object>> effective = new java.util.ArrayList<>(
                source == null ? List.<Map<String, Object>>of() : source);
        List<Map<String, Object>> imports = mapper.selectConsoleImportRecords(testId, dataType);
        for (Map<String, Object> imported : imports == null ? List.<Map<String, Object>>of() : imports)
        {
            try
            {
                @SuppressWarnings("unchecked")
                Map<String, Object> row = (Map<String, Object>) (Map<?, ?>) JSON.parseObject(
                        String.valueOf(imported.get("rowValues")), Map.class);
                row.put("stableIdentity", imported.get("stableIdentity"));
                effective.add(row);
            }
            catch (RuntimeException ignored) { }
        }
        List<TTestDataOverride> overrides = mapper.selectDataOverrides(testId, dataType);
        if (source == null || source.isEmpty() || overrides == null || overrides.isEmpty())
            return source == null ? List.of() : source;
        if (effective.isEmpty() || overrides == null || overrides.isEmpty()) return effective;
        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)
        List<Map<String, Object>> filtered = new java.util.ArrayList<>(effective.size());
        for (Map<String, Object> row : effective)
        {
            String identity = stableIdentity(dataType, row);
            String identity = row.get("stableIdentity") == null ? stableIdentity(dataType, row)
                    : String.valueOf(row.get("stableIdentity"));
            TTestDataOverride override = byIdentity.get(identity);
            if (override != null && Boolean.TRUE.equals(override.getDeleted())) continue;
            Map<String, Object> copy = new LinkedHashMap<>(row);
@@ -74,25 +94,37 @@
                    // 覆盖已由修订服务校验;解析异常时保留原始事实,避免查询整体失败。
                }
            }
            effective.add(copy);
            filtered.add(copy);
        }
        return effective;
        return filtered;
    }
    private String stableIdentity(String dataType, Map<String, Object> row)
    {
        String deviceId = value(row, "deviceId");
        String channelId = value(row, "channelId");
        if ("REALTIME".equals(dataType) && "COLLECTOR".equals(String.valueOf(row.get("sourceType"))))
            return String.join(":", "collector", identityPart(row, "collectorId"),
                    identityPart(row, "channelCode"), value(row, "sequenceId"), identityPart(row, "metricCode"));
        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");
        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;
        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)
    {
        Object value = row == null ? null : row.get(key);
        return value == null ? "" : String.valueOf(value);
        return identityPart(row, key);
    }
    private void requireTest(Long testId)