package com.ruoyi.device.simulator;
|
|
import java.math.BigDecimal;
|
import java.time.Instant;
|
import java.util.List;
|
import com.ruoyi.device.model.DeviceWorkStatus;
|
|
/** 持久化开发模拟器配置;实现必须在返回前确认写入成功。 */
|
public interface BtsSimulatorStateStore
|
{
|
int CURRENT_VERSION = 1;
|
|
/** 读取已有状态;仅在状态不存在时原子写入并返回默认状态。 */
|
SimulatorState loadOrInitialize(SimulatorState defaultState);
|
|
/** 完整保存下一版模拟器状态。 */
|
void save(SimulatorState state);
|
|
/** 读取短期保留的最近请求。 */
|
List<RecentRequest> loadRecentRequests();
|
|
/** 保存短期保留的最近请求。 */
|
void saveRecentRequests(List<RecentRequest> requests);
|
|
/** 人工重置主状态和最近请求。 */
|
void reset(SimulatorState defaultState);
|
|
record SimulatorState(int version, List<DeviceState> devices, List<CollectorState> collectors,
|
int nextDeviceId, int nextCollectorId, List<ChannelTombstone> tombstones)
|
{
|
public SimulatorState
|
{
|
if (version != CURRENT_VERSION)
|
throw new IllegalStateException("Unsupported BTS simulator state version: " + version);
|
devices = List.copyOf(devices);
|
collectors = List.copyOf(collectors);
|
tombstones = List.copyOf(tombstones);
|
}
|
}
|
|
record DeviceState(int deviceId, String ip, boolean online, List<ChannelState> channels)
|
{
|
public DeviceState { channels = List.copyOf(channels); }
|
}
|
|
record CollectorState(int collectorId, String deviceCode, String ip, String mac, String name,
|
String manufacturer, String model, int channelCount, boolean online, int sampleIntervalMs,
|
long nextSequence, Instant lastSampledAt, List<CollectorChannelState> channels,
|
List<CollectorMeasurementRecord> history, CollectorHistoryFaults historyFaults)
|
{
|
public CollectorState
|
{
|
channels = List.copyOf(channels);
|
history = List.copyOf(history);
|
historyFaults = historyFaults == null ? CollectorHistoryFaults.none() : historyFaults;
|
}
|
|
/** 兼容只包含发现配置的旧模拟状态;Redis 读取边界会补齐采样合同。 */
|
public CollectorState(int collectorId, String deviceCode, String ip, String mac, String name,
|
String manufacturer, String model, int channelCount, boolean online)
|
{
|
this(collectorId, deviceCode, ip, mac, name, manufacturer, model, channelCount, online,
|
DevelopmentCollectorSimulation.DEFAULT_SAMPLE_INTERVAL_MS, 1L, null,
|
DevelopmentCollectorSimulation.defaultChannels(channelCount), List.of(),
|
CollectorHistoryFaults.none());
|
}
|
}
|
|
record CollectorChannelState(String channelCode, List<CollectorMetricState> metrics)
|
{
|
public CollectorChannelState { metrics = List.copyOf(metrics); }
|
}
|
|
record CollectorMetricState(String metricCode, BigDecimal value, String unit) { }
|
|
record CollectorMeasurementRecord(String adapterCode, String collectorCode, String channelCode,
|
long sequenceId, Instant deviceTime, String deviceTimeRaw, Instant serverReceivedAt,
|
String metricCode, BigDecimal value, String unit) { }
|
|
record CollectorHistoryFaults(List<Long> missingSequences, Long duplicateSequence,
|
Long conflictingSequence, boolean outOfOrder)
|
{
|
public CollectorHistoryFaults
|
{
|
missingSequences = missingSequences == null ? List.of() : List.copyOf(missingSequences);
|
}
|
|
public static CollectorHistoryFaults none()
|
{
|
return new CollectorHistoryFaults(List.of(), null, null, false);
|
}
|
}
|
|
record ChannelState(int channelId, boolean online, DeviceWorkStatus workStatus) { }
|
|
record ChannelTombstone(int deviceId, String ip, int channelId, int remainingDiscoveries) { }
|
|
record RecentRequest(Instant receivedAt, String command, String request) { }
|
}
|