From f522c9ffa487e3710d691e8b98df8c4f0cfafd43 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 20:07:26 +0800
Subject: [PATCH] 支持模拟器逐通道参数与工步方案配置

---
 ruoyi-admin/src/test/java/com/battery/business/runtime/RedisStateStoreTest.java |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/battery/business/runtime/RedisStateStoreTest.java b/ruoyi-admin/src/test/java/com/battery/business/runtime/RedisStateStoreTest.java
index 3e3c3ce..ecc55f3 100644
--- a/ruoyi-admin/src/test/java/com/battery/business/runtime/RedisStateStoreTest.java
+++ b/ruoyi-admin/src/test/java/com/battery/business/runtime/RedisStateStoreTest.java
@@ -39,6 +39,45 @@
 class RedisStateStoreTest
 {
     @Test
+    void channelParametersAndPlanSurviveRedisRestartAndOnlineChanges() throws Exception
+    {
+        var stored = new AtomicReference<Object>();
+        var configuration = new com.battery.device.simulator.BtsSimulatorStateStore.ChannelConfiguration(
+                new java.math.BigDecimal("-3.123456"), new java.math.BigDecimal("8.125"),
+                new java.math.BigDecimal("7.2"), new java.math.BigDecimal("29.7"), 2, 2, 5, 120, 30,
+                List.of(new com.battery.device.simulator.BtsSimulatorStateStore.SimulatorPlanStep("充电", "cc", 60, 4.2),
+                        new com.battery.device.simulator.BtsSimulatorStateStore.SimulatorPlanStep("放电 <验证>", "dc", 90, 3.0)));
+        try (var simulator = new BtsDevelopmentSimulator(0, store(stored))) {
+            simulator.configureChannel(1, 1, configuration);
+            simulator.updateChannel(1, 1, false, DeviceWorkStatus.PAUSED);
+            simulator.setAllDevicesPoweredOn(false);
+            simulator.setSoftwareAccessible(false);
+        }
+        try (var simulator = new BtsDevelopmentSimulator(0, store(stored))) {
+            assertEquals(configuration, simulator.snapshot().devices().get(0).channels().get(0).configuration());
+            simulator.setSoftwareAccessible(true);
+            simulator.setAllDevicesPoweredOn(true);
+            simulator.updateChannel(1, 1, true, DeviceWorkStatus.WORKING);
+            var identity = simulator.discoverChannels().get(0).identity();
+            assertEquals(-3.123456, simulator.latestCabinet(identity).currentA());
+            assertEquals(8.125, simulator.latestCabinet(identity).voltageV());
+            assertEquals("放电 <验证>", simulator.testPlan(identity).rows().get(1).stepName());
+            assertEquals("进行中", simulator.testPlan(identity).rows().get(1).executionStatus());
+        }
+    }
+
+    @Test
+    void oldChannelStateReceivesDefaultConfigurationWithoutResettingIdentity()
+    {
+        var object = JSON.parseObject(JSON.toJSONString(state(7, "127.0.0.9")));
+        object.getJSONArray("devices").getJSONObject(0).getJSONArray("channels").getJSONObject(0).remove("configuration");
+        var restored = store(new AtomicReference<>(object.toJSONString())).loadOrInitialize(state(1, "127.0.0.2"));
+        assertEquals(7, restored.devices().get(0).deviceId());
+        assertEquals("127.0.0.9", restored.devices().get(0).ip());
+        assertEquals(1, restored.devices().get(0).channels().get(0).configuration().steps().size());
+    }
+
+    @Test
     void initializesOnlyWhenStateIsAbsentAndRestoresSavedState()
     {
         AtomicReference<Object> stored = new AtomicReference<>();

--
Gitblit v1.7.1