diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java index be795e831..0f2ab0f70 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java @@ -127,37 +127,6 @@ public class ATSMessageCollectAndDispatcher { return totalList; } - public void collectDeviceStatusAndSend(Simulation simulation, List deviceList) { - if (!CollectionUtils.isEmpty(deviceList)) { - List filterList = new ArrayList<>(); - SimulationDataRepository repository = simulation.getRepository(); - deviceList.forEach(device -> { - DeviceStatus deviceStatus = repository.findStatusByCode(device.getCode()); - if (Objects.isNull(deviceStatus)) { - deviceStatus = buildDeviceStatus(device); - if (Objects.nonNull(deviceStatus)) { - repository.addDeviceInfo(deviceStatus); - filterList.add(deviceStatus); - } - } else { - DeviceStatusVO statusVO = buildDeviceStatusVO(device); - if (deviceStatus.compareAndChange(device, statusVO)) { - filterList.add(statusVO); - } - } - }); - // 构建并发送设备状态消息 - if (CollectionUtils.isEmpty(filterList)) { - return; - } - SocketMessageVO deviceStatusMessage = - SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus, - simulation.getId(), filterList); - Set sessions = simulation.getSimulationUserIds(); - stompMessageService.sendToUser(sessions, deviceStatusMessage); - } - } - private DeviceStatus buildDeviceStatus(MapElement device) { DeviceStatus status = null; switch (device.getDeviceType()) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java index df7f36f18..62475ba31 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java @@ -97,6 +97,10 @@ public class SimulationUserWsListener { handleSubscribeSimulationMain(simulation, simulationUser); break; } + case DeviceStatus: { + handleSubscribeSimulationDeviceStatus(simulation, userId); + break; + } case SandBox: { applicationContext.publishEvent(new SandboxUserConnectEvent(userId, subscribeTopic.getId(destination), this)); break; @@ -114,6 +118,12 @@ public class SimulationUserWsListener { ctcLogicLoop.sendMessageWhenSubscribeCtc(simulation, userId); break; } +// case Room: +// break; +// case Wgu3d: +// break; +// case YJDDZH_TRAIN_POSITION: +// break; } } @@ -123,14 +133,6 @@ public class SimulationUserWsListener { private void handleSubscribeSimulationMain(club.joylink.rtss.simulation.cbtc.Simulation simulation, SimulationUser simulationUser) { String group = simulation.getId(); String userId = simulationUser.getId(); - // 将当前所有设备状态同步给用户 - List statusList = simulation.getRepository().getAllStatusList(); - if (!CollectionUtils.isEmpty(statusList)) { - SocketMessageVO allStatusMessage = - SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus, - group, statusList); - this.stompMessageService.sendToUser(userId, allStatusMessage); - } // 将当前所有列车实际运行数据同步给用户 List realRunRecordList = simulation.getRepository().getRealRunRecordList(); if (!CollectionUtils.isEmpty(realRunRecordList)) { @@ -159,6 +161,17 @@ public class SimulationUserWsListener { this.stompMessageService.sendToUser(userId, message); } + private void handleSubscribeSimulationDeviceStatus(club.joylink.rtss.simulation.cbtc.Simulation simulation, String userId) { + // 将当前所有设备状态同步给用户 + List statusList = simulation.getRepository().getAllStatusList(); + if (!CollectionUtils.isEmpty(statusList)) { + SocketMessageVO allStatusMessage = + SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus, + simulation.getId(), statusList); + this.stompMessageService.sendToUser(userId, allStatusMessage); + } + } + @Async("nsExecutor") @EventListener public void handle(SimulationUserUnsubscribeEvent event) {