From f38ca8a9f8454ac2eebdc268c89efd0e436b3cf2 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期三, 09 九月 2026 19:58:40 +0800
Subject: [PATCH] 修复化成报表漏识别导入充放电工步

---
 ruoyi-admin/src/test/java/com/battery/business/report/FormationRealReportTest.java |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/battery/business/report/FormationRealReportTest.java b/ruoyi-admin/src/test/java/com/battery/business/report/FormationRealReportTest.java
index 29922a8..7b6a3a2 100644
--- a/ruoyi-admin/src/test/java/com/battery/business/report/FormationRealReportTest.java
+++ b/ruoyi-admin/src/test/java/com/battery/business/report/FormationRealReportTest.java
@@ -108,6 +108,41 @@
     }
 
     @Test
+    void importedStepNamesSupplyDirectionWithoutInventingProtocolTypes() throws Exception
+    {
+        var discharge = step(1, null, "1", "0.25"); discharge.put("stepName", "恒流放电");
+        var rest = step(2, null, "1", null); rest.put("stepName", "搁置");
+        var charge = step(3, null, "4.2", "0.2"); charge.put("stepName", "恒流充电");
+        var ambiguous = step(4, "pulse", "99", "99"); ambiguous.put("stepName", "恒流充电");
+        when(data.steps(1L)).thenReturn(List.of(discharge, rest, charge, ambiguous));
+        var saved = create(request());
+        var choices = saved.getJSONObject("settings").getJSONObject("curveStepSelections").getJSONObject("1|11|1");
+        assertEquals(List.of(3), choices.getList("charge", Integer.class));
+        assertEquals(List.of(1), choices.getList("discharge", Integer.class));
+        assertEquals(250, saved.getJSONObject("calculatedValues").getBigDecimal("1|11|1|capacity1v").intValueExact());
+        var steps = saved.getJSONArray("items").getJSONObject(0).getJSONObject("chargeSteps").getJSONArray("1");
+        assertEquals("REST", steps.getJSONObject(1).getString("direction"));
+        assertEquals("UNKNOWN", steps.getJSONObject(3).getString("direction"));
+    }
+
+    @Test
+    void explicitSourceRefreshKeepsManualValuesAndHistoricalClassification() throws Exception
+    {
+        var imported = step(1, null, "1", "0.25");
+        when(data.steps(1L)).thenReturn(List.of(imported));
+        var first = create(request());
+        long id = first.getLongValue("id");
+        assertNull(first.getJSONObject("calculatedValues").get("1|11|1|capacity1v"));
+        imported.put("stepName", "恒流放电");
+        var refreshed = JSON.parseObject(JSON.toJSONString(service.refresh(id, new CompareReportEditRequest.Refresh(1, "重新读取实际工步"), 1, "操作员")));
+        assertEquals(250, refreshed.getJSONObject("calculatedValues").getBigDecimal("1|11|1|capacity1v").intValueExact());
+        assertEquals("2", refreshed.getJSONObject("settings").getJSONObject("values").getString("1|11|1|manual"));
+        var historical = JSON.parseObject(JSON.toJSONString(service.get(id, 1)));
+        assertNull(historical.getJSONObject("calculatedValues").get("1|11|1|capacity1v"));
+        assertEquals("UNKNOWN", historical.getJSONArray("items").getJSONObject(0).getJSONObject("chargeSteps").getJSONArray("1").getJSONObject(0).getString("direction"));
+    }
+
+    @Test
     void automaticDirectionSelectionExcludesUnknownAndKeepsAllRealChargeSteps() throws Exception
     {
         when(data.steps(1L)).thenReturn(List.of(step(1,"cc","4.1","0.1"),step(2,"unknown","99","99"),step(3,"cc","4.2","0.2"),step(4,"dc","1","0.25")));

--
Gitblit v1.7.1