| | |
| | | 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); |
| | |
| | | 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); |
| | | } |
| | | } |