From b985e6140e7f395ead7dc55e41e6b16d97f9f02b Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期日, 30 八月 2026 14:44:30 +0800
Subject: [PATCH] 简化开发模拟器历史数据管理

---
 ruoyi-admin/src/main/java/com/ruoyi/config/RedisBtsSimulatorStateStore.java |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/config/RedisBtsSimulatorStateStore.java b/ruoyi-admin/src/main/java/com/ruoyi/config/RedisBtsSimulatorStateStore.java
index f151ea6..796c15e 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/config/RedisBtsSimulatorStateStore.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/config/RedisBtsSimulatorStateStore.java
@@ -47,6 +47,29 @@
         return restoreState(stored);
     }
 
+    @Override
+    public SimulatorState resetHistoryForDemoStartup(SimulatorState state)
+    {
+        pendingEmbeddedHistory = List.of();
+        Set<Object> historyKeys = redisTemplate.opsForSet().members(HISTORY_KEYS_KEY);
+        if (historyKeys != null && !historyKeys.isEmpty()) redisTemplate.delete(historyKeys);
+        redisTemplate.delete(HISTORY_KEYS_KEY);
+
+        List<com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorState> collectors = state.collectors()
+                .stream()
+                .map(collector -> new com.ruoyi.device.simulator.BtsSimulatorStateStore.CollectorState(
+                        collector.collectorId(), collector.deviceCode(), collector.ip(), collector.mac(),
+                        collector.name(), collector.manufacturer(), collector.model(), collector.channelCount(),
+                        collector.online(), collector.sampleIntervalMs(), 1L,
+                        null, collector.channels(), List.of(), 0L,
+                        collector.historyFaults()))
+                .toList();
+        SimulatorState reset = new SimulatorState(state.version(), state.devices(), collectors,
+                state.nextDeviceId(), state.nextCollectorId(), state.tombstones());
+        redisTemplate.opsForValue().set(STATE_KEY, JSON.toJSONString(reset));
+        return reset;
+    }
+
     private SimulatorState restoreState(Object stored)
     {
         ParsedSimulatorState parsed = parseState(stored);
@@ -88,6 +111,7 @@
                         List<Object> records = new ArrayList<>(
                                 append.records().stream().map(JSON::toJSONString).toList());
                         typed.opsForList().rightPushAll(historyKey, records);
+                        typed.opsForList().trim(historyKey, -MAX_HISTORY_RECORDS, -1);
                         typed.opsForSet().add(HISTORY_KEYS_KEY, historyKey);
                     }
                 }

--
Gitblit v1.7.1