整理化成报表验收后的业务约束注释
补充能量效率依赖冻结、计算边界及版本追加持锁前置条件,业务行为保持不变。
后端全量测试、可执行包构建和化成四组隔离测试通过。
| | |
| | | private Matrix freeze(Matrix matrix, List<FormationField> fields) |
| | | { |
| | | Set<String> selected = new HashSet<>(fields.stream().filter(field -> "metric".equals(field.kind())).map(FormationField::key).toList()); |
| | | // 能量效率依赖两项原始能量,即使未展示它们也须冻结,保证快照可复算。 |
| | | if (selected.contains("energyEfficiency")) selected.addAll(List.of("chargeEnergy", "dischargeEnergy")); |
| | | var frozen = matrix.items().stream().map(item -> { |
| | | var rows = item.cycles().stream().map(row -> { |
| | |
| | | if (matches.size() == 1) for (String key : FormationField.METRIC_UNITS.keySet()) |
| | | if (matches.get(0).get(key) instanceof Number number) values.put(key, new BigDecimal(number.toString())); |
| | | BigDecimal charge = values.get("chargeEnergy"), discharge = values.get("dischargeEnergy"); |
| | | // 分母必须为正;允许结果超过 100%,不截断计算结果。 |
| | | if (charge != null && discharge != null && charge.signum() > 0) |
| | | values.put("energyEfficiency", discharge.multiply(BigDecimal.valueOf(100)).divide(charge, MathContext.DECIMAL128)); |
| | | result.put(Integer.toString(no), values); |
| | |
| | | JSON.toJSONString(Map.of("reportId", id, "reportName", name, "operatorId", operatorId)), new Timestamp(System.currentTimeMillis())); |
| | | } |
| | | |
| | | /** 只追加版本并更新列表名称;业务事务保证两步同时成功。 */ |
| | | /** 在业务事务和报表锁内追加版本并更新列表名称;调用前须校验最新基准并分配版本号。 */ |
| | | public void append(long id, int versionNo, String name, String snapshot, long operatorId, String operatorName, String summary) |
| | | { |
| | | jdbc.update(sql("insert into t_compare_report_version(report_id,version_no,snapshot_json,operator_id,operator_name,created_at_utc,change_summary) values(?,?,?,?,?,?,?)"), |