diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/Joylink3DMessageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/communication/Joylink3DMessageService.java index 8701af624..05b2990b2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/Joylink3DMessageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/communication/Joylink3DMessageService.java @@ -13,7 +13,6 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.event.*; -import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.vo.client.SocketMessageVO; import club.joylink.rtss.vo.client.WebSocketMessageType; @@ -38,9 +37,6 @@ public class Joylink3DMessageService { @Autowired private StompMessageService stompMessageService; - @Autowired - private MemberManager memberManager; - @Autowired private GroupSimulationService groupSimulationService; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/message/websocket/SimulationSubscribeManager.java b/src/main/java/club/joylink/rtss/simulation/cbtc/message/websocket/SimulationSubscribeManager.java index b0437c488..c084f3fa2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/message/websocket/SimulationSubscribeManager.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/message/websocket/SimulationSubscribeManager.java @@ -144,7 +144,7 @@ public class SimulationSubscribeManager { } subscribeInfos.removeAll(removeList); return set.stream() - .filter(dest -> this.containsSubDestination(dest) ? false : true) + .filter(dest -> !this.containsSubDestination(dest)) .collect(Collectors.toList()); } @@ -162,7 +162,7 @@ public class SimulationSubscribeManager { .map(subscribeInfo -> subscribeInfo.destination) .collect(Collectors.toSet()) .stream() - .filter(dest -> this.containsSubDestination(dest) ? false : true) + .filter(dest -> !this.containsSubDestination(dest)) .collect(Collectors.toList()); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/PassengerFlowSimulateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/PassengerFlowSimulateService.java index 27c19f1df..e42c2a681 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/PassengerFlowSimulateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/PassengerFlowSimulateService.java @@ -114,9 +114,31 @@ public class PassengerFlowSimulateService { // 发送初始化数据 this.sendStandPassengerFlowData(simulation, standPassengerFlowMap); this.sendTrainPassengerFlowData(simulation, trainPassengerFlowMap); + // 发送列车pis数据 + this.sendTrainInitPisData(simulation, trainPassengerFlowMap); log.debug(String.format("客流初始化成功")); } + private void sendTrainInitPisData(Simulation simulation, Map trainPassengerFlowMap) { + List> trainPisList = new ArrayList<>(); + for (TrainPassengerFlow tpf : trainPassengerFlowMap.values()) { + VirtualRealityTrain train = tpf.getTrain(); + Map pisInfo = new HashMap<>(); + pisInfo.put("code", train.getGroupNumber()); + pisInfo.put("nextStation", train.getNextStation() != null ? train.getNextStation().getCode() : null); + pisInfo.put("endStation", train.getTerminalStation() != null ? train.getTerminalStation().getCode() : null); + trainPisList.add(pisInfo); + } + if (!trainPisList.isEmpty()) { + Set users = simulation.getSimulationUserIds(); + String json = JsonUtils.writeValueNullableFieldAsString(trainPisList); + SocketMessageVO message = SocketMessageFactory.build( + WebSocketMessageType.TRAIN_PIS, + simulation.getGroup(), json); + this.stompMessageService.sendToUser(users, message); + } + } + private void sendTrainPassengerFlowData(Simulation simulation, Map trainPassengerFlowMap) { List> trainPFNumList = new ArrayList<>(); for (TrainPassengerFlow flow : trainPassengerFlowMap.values()) { @@ -162,6 +184,8 @@ public class PassengerFlowSimulateService { } this.sendStandPassengerFlowData(simulation, passengerFlowSimulationData.getStandPassengerFlowMap()); this.sendTrainPassengerFlowData(simulation, passengerFlowSimulationData.getTrainPassengerFlowMap()); + // 发生列车pis数据 + this.sendTrainInitPisData(simulation, passengerFlowSimulationData.getTrainPassengerFlowMap()); } private Map loadTrainPassengerFlow(Simulation simulation, PassengerFlowData passengerFlowData) { @@ -289,6 +313,7 @@ public class PassengerFlowSimulateService { SimulationDataRepository repository = simulation.getRepository(); List allTrainPassengerFlows = passengerFlowSimulationData.getAllTrainPassengerFlow(); PassengerFlowData passengerFlowData = passengerFlowSimulationData.getPassengerFlowData(); + Set users = simulation.getSimulationUserIds(); for (TrainPassengerFlow trainPassengerFlow : allTrainPassengerFlows) { VirtualRealityTrain train = trainPassengerFlow.getTrain(); TrainInfo trainInfo = repository.findSupervisedTrainByGroup(train.getGroupNumber()); @@ -328,14 +353,46 @@ public class PassengerFlowSimulateService { sendData.put("out", tripStationPassengerFlowData.getDown()); trainPassengerFlow.startBoarding(station, tripStationPassengerFlowData); - Set users = simulation.getSimulationUserIds(); String json = JsonUtils.writeValueNullableFieldAsString(sendData); SocketMessageVO message = SocketMessageFactory.build( WebSocketMessageType.TRAIN_PFI_BL, simulation.getGroup(), json); this.stompMessageService.sendToUser(users, message); } + }); + } + @Async("nsExecutor") + @Scheduled(fixedRate = 5000) + public void trainPis() { + passengerFlowSimulationDataMap.forEach((group, passengerFlowSimulationData) -> { + Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group); + SimulationDataRepository repository = simulation.getRepository(); + List allTrainPassengerFlows = passengerFlowSimulationData.getAllTrainPassengerFlow(); + List> trainPisList = new ArrayList<>(); + for (TrainPassengerFlow trainPassengerFlow : allTrainPassengerFlows) { + VirtualRealityTrain train = trainPassengerFlow.getTrain(); + TrainInfo trainInfo = repository.findSupervisedTrainByGroup(train.getGroupNumber()); + if (Objects.isNull(trainInfo) || !trainInfo.isPlanTrain() || !trainInfo.isParking()) { + continue; + } + if (train.isStandReadyStart()) { + Map pisInfo = new HashMap<>(); + pisInfo.put("code", train.getGroupNumber()); + pisInfo.put("nextStation", train.getNextStation() != null ? train.getNextStation().getCode() : null); + pisInfo.put("endStation", train.getTerminalStation() != null ? train.getTerminalStation().getCode() : null); + trainPisList.add(pisInfo); + } + } + if (trainPisList.isEmpty()) { + return; + } + Set users = simulation.getSimulationUserIds(); + String json = JsonUtils.writeValueNullableFieldAsString(trainPisList); + SocketMessageVO message = SocketMessageFactory.build( + WebSocketMessageType.TRAIN_PIS, + simulation.getGroup(), json); + this.stompMessageService.sendToUser(users, message); }); } diff --git a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java index 8cfcad4f3..9b7e931af 100644 --- a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java +++ b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java @@ -164,6 +164,8 @@ public enum WebSocketMessageType { TRAIN_PFI_NUM, /** 列车客流乘降人数信息 */ TRAIN_PFI_BL, + /** 列车位置信息 */ + TRAIN_PIS, /** 车站客流当前人数信息 */ STATION_PFI_NUM, // ------------客流消息end------------ diff --git a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java index c93d10c98..65bff510c 100644 --- a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java +++ b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java @@ -131,6 +131,7 @@ public class SocketMessageFactory { case STAND_PFI: case TRAIN_PFI_NUM: case TRAIN_PFI_BL: + case TRAIN_PIS: case PFV: case SJL3D_TrainStatus: { topicList.add(String.format(WebSocketSubscribeTopic.Sandbox3D, group));