| | |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.server.ResponseStatusException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator; |
| | | import com.ruoyi.device.bts.BtsDevelopmentSimulator.StateSnapshot; |
| | |
| | | { |
| | | private final BtsDevelopmentSimulator simulator; |
| | | private final DeviceDiscoveryCandidateStore candidateStore; |
| | | private final com.ruoyi.config.DevelopmentCollectorStatusSynchronizer statusSynchronizer; |
| | | |
| | | @Autowired |
| | | public BtsDevelopmentSimulatorController(BtsDevelopmentSimulator simulator, |
| | | DeviceDiscoveryCandidateStore candidateStore) |
| | | DeviceDiscoveryCandidateStore candidateStore, |
| | | com.ruoyi.config.DevelopmentCollectorStatusSynchronizer statusSynchronizer) |
| | | { |
| | | this.simulator = simulator; |
| | | this.candidateStore = candidateStore; |
| | | this.statusSynchronizer = statusSynchronizer; |
| | | } |
| | | |
| | | /** 保留独立模拟器测试和工具调用的构造入口,不触发数据库同步。 */ |
| | | public BtsDevelopmentSimulatorController(BtsDevelopmentSimulator simulator, |
| | | DeviceDiscoveryCandidateStore candidateStore) |
| | | { |
| | | this(simulator, candidateStore, null); |
| | | } |
| | | |
| | | /** 返回临时控制页;匿名放行后仍由本机拦截器限制来源。 */ |
| | |
| | | if (command == null || command.poweredOn() == null) |
| | | throw badRequest(new IllegalArgumentException("poweredOn must be true or false")); |
| | | simulator.setAllDevicesPoweredOn(command.poweredOn()); |
| | | synchronizeOnlineStatusIfConfigured(); |
| | | return simulator.snapshot(); |
| | | } |
| | | |
| | |
| | | try |
| | | { |
| | | simulator.updateCollector(collectorId, command.ip(), command.channelCount(), command.online()); |
| | | synchronizeOnlineStatusIfConfigured(); |
| | | return simulator.snapshot(); |
| | | } |
| | | catch (IllegalArgumentException exception) |
| | |
| | | return new ResponseStatusException(HttpStatus.BAD_REQUEST, exception.getMessage(), exception); |
| | | } |
| | | |
| | | private void synchronizeOnlineStatusIfConfigured() |
| | | { |
| | | if (statusSynchronizer != null) statusSynchronizer.synchronizeOnlineStatus(); |
| | | } |
| | | |
| | | public record CreateDeviceCommand(String ip, int channelCount, String model) |
| | | { |
| | | public CreateDeviceCommand(String ip, int channelCount) |