From e379a0a95f2f75e7cdb0ae4fc4a735072f32a694 Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Tue, 8 Nov 2022 10:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AE=A2=E9=98=85=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=8A=B6=E6=80=81=E6=97=B6=E5=8F=91=E9=80=81=E6=89=80?= =?UTF-8?q?=E6=9C=89=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ATS/ATSMessageCollectAndDispatcher.java | 31 ------------------- .../message/SimulationUserWsListener.java | 29 ++++++++++++----- 2 files changed, 21 insertions(+), 39 deletions(-) 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) {