yeg
2026-09-09 b837cc1f88e6fa14442f66eecb59c45464dd7bb3
battery-business/src/main/java/com/battery/business/report/FormationReportService.java
@@ -56,12 +56,12 @@
    /** 列表来源名称取自已保存版本,测试删除后仍保留筛选与识别信息。 */
    public List<Summary> list()
    {
        return reports.list().stream().map(summary -> {
            var version = reports.get(summary.id());
            var sources = items(JSON.parseObject(version.snapshotJson()));
        return reports.listWithSnapshots().stream().map(summary -> {
            // 最新快照由一次列表 SQL 带出,避免每份报表再执行一次版本查询。
            var sources = items(JSON.parseObject(summary.snapshotJson()));
            return new Summary(summary.id(), summary.name(), summary.creator(), summary.createdAt(),
                    String.join("、", sources.stream().map(item -> item.source().name()).distinct().toList()),
                    String.join("、", sources.stream().map(item -> item.source().batteryGroup()).distinct().toList()), version.versionNo());
                    String.join("、", sources.stream().map(item -> item.source().batteryGroup()).distinct().toList()), summary.versionNo());
        }).toList();
    }
@@ -99,7 +99,8 @@
            var actual = Stream.of(rows, realtime,
                    batteryRows(steps.computeIfAbsent(selection.testId(), data::steps), battery)).flatMap(List::stream)
                    .map(this::cycleNo).filter(no -> no > 0).distinct().sorted().toList();
            items.add(new Item(candidate(test, battery), actual, rows, metrics(rows, actual), battery.getFields(), chargeSteps(steps.get(selection.testId()), realtime, battery, actual), curves(realtime, actual), stepCurves(realtime, actual)));
            // 图表只需按循环共享的曲线;逐工步曲线会重复保存同一批采样,造成详情响应膨胀。
            items.add(new Item(candidate(test, battery), actual, rows, metrics(rows, actual), battery.getFields(), chargeSteps(steps.get(selection.testId()), realtime, battery, actual), curves(realtime, actual), null));
        }
        return new Matrix(items, items.stream().flatMap(item -> item.cycleNos().stream()).distinct().sorted().toList());
    }
@@ -353,18 +354,32 @@
            Map<Integer, ChargeStep> found = new java.util.TreeMap<>();
            // 实时记录只补充实际范围身份,不代替缺失的工步终止电压。
            for (var row : realtime) if (cycleNo(row) == cycle && number(row.get("stepNo")) > 0) {
                String type = String.valueOf(row.getOrDefault("stepType", ""));
                found.putIfAbsent(number(row.get("stepNo")), new ChargeStep(number(row.get("stepNo")), String.valueOf(row.getOrDefault("stepName", "")), type, null, directions.resolve(type), null));
                String type = Objects.toString(row.get("stepType"), "");
                String name = Objects.toString(row.get("stepName"), "");
                found.putIfAbsent(number(row.get("stepNo")), new ChargeStep(number(row.get("stepNo")), name, type, null, stepDirection(type, name), null));
            }
            if (rows != null) for (var row : rows) if (Objects.equals(battery.getBatteryNo(), row.get("batteryNo")) && cycleNo(row) == cycle && number(row.get("stepNo")) > 0) {
                String type = String.valueOf(row.getOrDefault("stepType", ""));
                found.put(number(row.get("stepNo")), new ChargeStep(number(row.get("stepNo")), String.valueOf(row.getOrDefault("stepName", "")), type, decimal(row.get("endVoltage")), directions.resolve(type), decimal(row.get("capacity"))));
                String type = Objects.toString(row.get("stepType"), "");
                String name = Objects.toString(row.get("stepName"), "");
                found.put(number(row.get("stepNo")), new ChargeStep(number(row.get("stepNo")), name, type, decimal(row.get("endVoltage")), stepDirection(type, name), decimal(row.get("capacity"))));
            }
            result.put(cycle, new ArrayList<>(found.values()));
        }
        return result;
    }
    private int number(Object value) { return value instanceof Number n ? n.intValue() : 0; }
    private Direction stepDirection(String type, String name)
    {
        // 甲方 Excel 只提供工步名称;有协议类型时禁止用名称覆盖未知/混合类型。
        if (!type.isBlank()) return directions.resolve(type);
        return switch (name.trim()) {
            case "恒流充电" -> Direction.CHARGE;
            case "恒流放电" -> Direction.DISCHARGE;
            case "搁置", "静置" -> Direction.REST;
            default -> Direction.UNKNOWN;
        };
    }
    private BigDecimal decimal(Object value) { return value instanceof Number n ? new BigDecimal(n.toString()) : null; }
    private Set<String> valueKeys(List<FormationField> fields, List<Item> items)