| | |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator.StateSnapshot; |
| | | import com.ruoyi.device.discovery.DeviceDiscoveryCandidateStore; |
| | | import com.ruoyi.device.model.DeviceWorkStatus; |
| | | |
| | | /** 本机临时 BTS 模拟器控制 API。 */ |
| | |
| | | public class BtsDevelopmentSimulatorController |
| | | { |
| | | private final BtsDevelopmentSimulator simulator; |
| | | private final DeviceDiscoveryCandidateStore candidateStore; |
| | | |
| | | public BtsDevelopmentSimulatorController(BtsDevelopmentSimulator simulator) |
| | | public BtsDevelopmentSimulatorController(BtsDevelopmentSimulator simulator, |
| | | DeviceDiscoveryCandidateStore candidateStore) |
| | | { |
| | | this.simulator = simulator; |
| | | this.candidateStore = candidateStore; |
| | | } |
| | | |
| | | /** 返回临时控制页;匿名放行后仍由本机拦截器限制来源。 */ |
| | |
| | | @GetMapping("/dev/bts-simulator/state") |
| | | public StateSnapshot state() |
| | | { |
| | | return simulator.snapshot(); |
| | | } |
| | | |
| | | /** 人工清空长期状态并恢复一台默认检测柜和采集器。 */ |
| | | @PostMapping("/dev/bts-simulator/reset") |
| | | public StateSnapshot reset() |
| | | { |
| | | simulator.reset(); |
| | | candidateStore.removeAdapter(BtsDevelopmentSimulator.ADAPTER_CODE); |
| | | return simulator.snapshot(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** 添加一台与检测柜分开配置的虚拟采集器。 */ |
| | | @PostMapping("/dev/bts-simulator/collectors") |
| | | public StateSnapshot createCollector(@RequestBody CreateCollectorCommand command) |
| | | { |
| | | try |
| | | { |
| | | simulator.addCollector(command.ip(), command.channelCount()); |
| | | return simulator.snapshot(); |
| | | } |
| | | catch (IllegalArgumentException exception) |
| | | { |
| | | throw badRequest(exception); |
| | | } |
| | | } |
| | | |
| | | /** 修改虚拟采集器的地址、通道数和在线状态。 */ |
| | | @PutMapping("/dev/bts-simulator/collectors/{collectorId}") |
| | | public StateSnapshot updateCollector(@PathVariable int collectorId, |
| | | @RequestBody CollectorStateCommand command) |
| | | { |
| | | try |
| | | { |
| | | simulator.updateCollector(collectorId, command.ip(), command.channelCount(), command.online()); |
| | | return simulator.snapshot(); |
| | | } |
| | | catch (IllegalArgumentException exception) |
| | | { |
| | | throw badRequest(exception); |
| | | } |
| | | } |
| | | |
| | | /** 删除指定虚拟采集器。 */ |
| | | @DeleteMapping("/dev/bts-simulator/collectors/{collectorId}") |
| | | public StateSnapshot deleteCollector(@PathVariable int collectorId) |
| | | { |
| | | try |
| | | { |
| | | simulator.deleteCollector(collectorId); |
| | | return simulator.snapshot(); |
| | | } |
| | | catch (IllegalArgumentException exception) |
| | | { |
| | | throw badRequest(exception); |
| | | } |
| | | } |
| | | |
| | | /** 修改指定虚拟设备通道的在线和工作状态。 */ |
| | | @PutMapping("/dev/bts-simulator/devices/{deviceId}/channels/{channelId}") |
| | | public StateSnapshot updateChannel(@PathVariable int deviceId, @PathVariable int channelId, |
| | |
| | | public record DeviceStateCommand(String ip, int channelCount, boolean online) { } |
| | | |
| | | public record ChannelStateCommand(boolean online, DeviceWorkStatus workStatus) { } |
| | | |
| | | public record CreateCollectorCommand(String ip, int channelCount) { } |
| | | |
| | | public record CollectorStateCommand(String ip, int channelCount, boolean online) { } |
| | | } |