From 6f6a323d8de80fcfcd07069f5a81c91ca0fbe0e8 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 20 Jan 2021 15:23:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=B5=81=E5=88=97=E8=BD=A6=E5=88=B0?= =?UTF-8?q?=E7=AB=99=E4=B8=8A=E8=BD=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PassengerFlowSimulateService.java | 96 ++++++++++++------- .../passenger/data/StandPassengerFlow.java | 10 ++ .../passenger/data/TrainPassengerFlow.java | 10 ++ 3 files changed, 84 insertions(+), 32 deletions(-) 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 93b0f90ba..eb0b523f6 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 @@ -288,45 +288,48 @@ public class PassengerFlowSimulateService { Map sendData = new HashMap<>(); Stand stand = standPassengerFlow.getStand(); StandTimePassengerFlowData flowData = standTimePassengerFlowDataMap.get(stand.getCode()); - int add = flowData.getNum() - standPassengerFlow.getPassengerQuantity(); + int add = flowData.getNum() - standPassengerFlow.getLastLoad(); if (add < 0) { - log.warn(String.format("站台[%s]时间[%s]到站人数计算小于0,站台本身数量[%s],下一时间数量[%s]", - stand.debugStr(), systemTimeStr, - standPassengerFlow.getPassengerQuantity(), flowData.getNum())); - add = 0; + // 列车拉走了站台上的人 + add = flowData.getNum(); } sendData.put("standCode", stand.getCode()); sendData.put("num", flowData.getNum()); sendData.put("to", add); sendDataList.add(sendData); -// standPassengerFlow.passengerEnter(add); - standPassengerFlow.updateRemain(flowData.getNum()); + standPassengerFlow.passengerEnter(add); + standPassengerFlow.reload(flowData.getNum()); } - Set users = simulation.getSimulationUserIds(); - String json = JsonUtils.writeValueNullableFieldAsString(sendDataList); - SocketMessageVO message = SocketMessageFactory.build( - WebSocketMessageType.STAND_PFI, - simulation.getGroup(), json); - this.stompMessageService.sendToUser(users, message); - //发给二维 - Map standPassengerFlowMap = passengerFlowSimulationData.getStandPassengerFlowMap(); - PassengerFlowMessage2TD message2TD = new PassengerFlowMessage2TD(systemTime); - List data = message2TD.getData(); - for (Station station : simulation.getRepository().getStationList()) { - int stationPassengerQuantity = station.getAllStandList().stream() - .filter(stand -> standPassengerFlowMap.get(stand.getCode()) != null) - .mapToInt(stand -> standPassengerFlowMap.get(stand.getCode()).getPassengerQuantity()) - .sum(); - data.add(message2TD.new PassengerFlowMessageData2TD(station.getCode(), stationPassengerQuantity)); - } - SocketMessageVO sendMessage = - SocketMessageFactory.buildPassengerFlowMessage2TD(simulation.getGroup(), message2TD); - stompMessageService.sendToUser(users, sendMessage); - passengerFlowSimulationData.getHistoryPassengerMessage2TD().add(message2TD); + sendStandPassengerToUser(simulation, systemTime, passengerFlowSimulationData, sendDataList); } }); } + private void sendStandPassengerToUser(Simulation simulation, LocalDateTime systemTime, + PassengerFlowSimulationData passengerFlowSimulationData, List> sendDataList) { + Set users = simulation.getSimulationUserIds(); + String json = JsonUtils.writeValueNullableFieldAsString(sendDataList); + SocketMessageVO message = SocketMessageFactory.build( + WebSocketMessageType.STAND_PFI, + simulation.getGroup(), json); + this.stompMessageService.sendToUser(users, message); + //发给二维 + Map standPassengerFlowMap = passengerFlowSimulationData.getStandPassengerFlowMap(); + PassengerFlowMessage2TD message2TD = new PassengerFlowMessage2TD(systemTime); + List data = message2TD.getData(); + for (Station station : simulation.getRepository().getStationList()) { + int stationPassengerQuantity = station.getAllStandList().stream() + .filter(stand -> standPassengerFlowMap.get(stand.getCode()) != null) + .mapToInt(stand -> standPassengerFlowMap.get(stand.getCode()).getPassengerQuantity()) + .sum(); + data.add(message2TD.new PassengerFlowMessageData2TD(station.getCode(), stationPassengerQuantity)); + } + SocketMessageVO sendMessage = + SocketMessageFactory.buildPassengerFlowMessage2TD(simulation.getGroup(), message2TD); + stompMessageService.sendToUser(users, sendMessage); + passengerFlowSimulationData.getHistoryPassengerMessage2TD().add(message2TD); + } + @Async("nsExecutor") @Scheduled(fixedRate = 500) public void trainPassengerFlowSimulate() { @@ -336,6 +339,7 @@ public class PassengerFlowSimulateService { List allTrainPassengerFlows = passengerFlowSimulationData.getAllTrainPassengerFlow(); PassengerFlowData passengerFlowData = passengerFlowSimulationData.getPassengerFlowData(); Set users = simulation.getSimulationUserIds(); + LocalDateTime systemTime = simulation.getCorrectSystemTime(); for (TrainPassengerFlow trainPassengerFlow : allTrainPassengerFlows) { VirtualRealityTrain train = trainPassengerFlow.getTrain(); TrainInfo trainInfo = repository.findSupervisedTrainByGroup(train.getGroupNumber()); @@ -350,6 +354,7 @@ public class PassengerFlowSimulateService { } if (train.isStandReadyStart()) { trainPassengerFlow.endBoarding(); + continue; } if (!train.isStandBoarding()) { continue; @@ -366,20 +371,47 @@ public class PassengerFlowSimulateService { log.debug(String.format("车站[%s]列车车次[%s]客流数据不存在,不更新", station.debugStr(), tripPlan.debugStr())); continue; } - if (Objects.equals(trainPassengerFlow.getStation(), station)) { // 已经处理过 + Stand stand = station.getStandOf(train.isRight()).get(0); + StandPassengerFlow standPassengerFlow = passengerFlowSimulationData.getStandPassengerFlowMap().get(stand.getCode()); + if (standPassengerFlow.getPassengerQuantity() == 0 && Objects.nonNull(trainPassengerFlow.getStation())) { + // 已下过车且车站没人等车 continue; } + // 列车最大容量1500 + int in = Math.min(1500 - trainPassengerFlow.getPassengerQuantity(), standPassengerFlow.getPassengerQuantity()); Map sendData = new HashMap<>(); sendData.put("code", train.getGroupNumber()); - sendData.put("in", tripStationPassengerFlowData.getUp()); - sendData.put("out", tripStationPassengerFlowData.getDown()); - trainPassengerFlow.startBoarding(station, tripStationPassengerFlowData); + sendData.put("in", in); + if (Objects.isNull(trainPassengerFlow.getStation())) { + if (train.getTerminalStation().equals(station)) { + if (trainPassengerFlow.getPassengerQuantity() > tripStationPassengerFlowData.getDown()) { + log.warn("列车[{}]到达终点站,车上乘客人数[{}]多余下车人数[{}]", train.getGroupNumber(), + trainPassengerFlow.getPassengerQuantity(), tripStationPassengerFlowData.getDown()); + } + // 全部下车 + sendData.put("out", trainPassengerFlow.getPassengerQuantity()); + trainPassengerFlow.startOutboard(station, trainPassengerFlow.getPassengerQuantity()); + } else { + sendData.put("out", tripStationPassengerFlowData.getDown()); + trainPassengerFlow.startOutboard(station, tripStationPassengerFlowData.getDown()); + } + } else { + sendData.put("out", 0); + } + trainPassengerFlow.startBoarding(station, in); String json = JsonUtils.writeValueNullableFieldAsString(sendData); SocketMessageVO message = SocketMessageFactory.build( WebSocketMessageType.TRAIN_PFI_BL, simulation.getGroup(), json); this.stompMessageService.sendToUser(users, message); + // 发送站台数据变更 + Map sendStandData = new HashMap<>(); + sendStandData.put("standCode", stand.getCode()); + sendStandData.put("num", standPassengerFlow.getPassengerQuantity() - in); + sendStandData.put("to", 0); + standPassengerFlow.passengerGetTrain(in); + sendStandPassengerToUser(simulation, systemTime, passengerFlowSimulationData, Collections.singletonList(sendStandData)); } }); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/StandPassengerFlow.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/StandPassengerFlow.java index a5ee6e321..24ed4ad83 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/StandPassengerFlow.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/StandPassengerFlow.java @@ -13,6 +13,8 @@ public class StandPassengerFlow { private Stand stand; + private int lastLoad; + private int passengerQuantity; public StandPassengerFlow(Stand stand) { @@ -27,6 +29,14 @@ public class StandPassengerFlow { this.passengerQuantity += add; } + public void passengerGetTrain(int num) { + this.passengerQuantity -= num; + } + + public void reload(int num) { + this.lastLoad = num; + } + public void updateRemain(int num) { this.passengerQuantity = num; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/TrainPassengerFlow.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/TrainPassengerFlow.java index 0dde2aeb4..ea7ae0173 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/TrainPassengerFlow.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/data/TrainPassengerFlow.java @@ -26,6 +26,16 @@ public class TrainPassengerFlow { this.passengerQuantity = remain; } + public void startOutboard(Station station, int num) { + this.station = station; + this.passengerQuantity -= num; + } + + public void startBoarding(Station station, int num) { + this.station = station; + this.passengerQuantity += num; + } + public void startBoarding(Station station, TripStationPassengerFlowData tripStationPassengerFlowData) { this.station = station; this.passengerQuantity = tripStationPassengerFlowData.getRemain();