From 7254a0235693cfffce26bc1cad1ae18543e393f8 Mon Sep 17 00:00:00 2001 From: Jade Date: Mon, 6 Dec 2021 16:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=A6=E8=BE=86=E6=AE=B5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/TrainOperateHandler.java | 2 +- .../cbtc/ATS/service/AtsTrainLoadService.java | 7 +- .../cbtc/SimulationLifeCycleServiceImpl.java | 22 ++--- .../cbtc/build/SchedulingBuilder.java | 4 +- .../cbtc/constant/SimulationConstants.java | 3 + .../cbtc/constant/SimulationModule.java | 2 + .../cbtc/data/SimulationDataRepository.java | 6 +- .../cbtc/depot/DepotLoadService.java | 45 ---------- .../simulation/cbtc/depot/DepotService.java | 86 +++++++++++++++++++ 9 files changed, 113 insertions(+), 64 deletions(-) delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java index f64706942..5f517df23 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/TrainOperateHandler.java @@ -50,7 +50,7 @@ public class TrainOperateHandler { SimulationDataRepository repository = simulation.getRepository(); List onlineTrainList = repository.getOnlineTrainList(); VirtualRealityTrain train = repository - .getTrain(serviceNumber, tripNumber); + .getTrain(simulation, serviceNumber, tripNumber); for (VirtualRealityTrain online : onlineTrainList) { if (Objects.equals(train, online)) { throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java index 3f4287d5c..4c0dac1d1 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java @@ -510,7 +510,10 @@ public class AtsTrainLoadService { SimulationDataRepository repository = simulation.getRepository(); for (VirtualRealityTrain train : loadedList) { // 构建监控列车信息 - TrainInfo trainInfo = new TrainInfo(train.getGroupNumber()); + TrainInfo trainInfo = simulation.getRepository().getTrainInfoMap().get(train.getGroupNumber()); + if (trainInfo == null) { + trainInfo = new TrainInfo(train.getGroupNumber()); + } TripPlan tripPlan = repository.getTripPlan(train.getServiceNumber(), train.getTripNumber()); trainInfo.init(tripPlan, repository.getConfig()); List stationPlanList = tripPlan.getPlanList(); @@ -739,7 +742,7 @@ public class AtsTrainLoadService { break; } TripPlan tripPlan = trainLoadParam2.getTripPlan(); - VirtualRealityTrain train = repository.getTrain(tripPlan.getServiceNumber(), tripPlan.getTripNumber()); + VirtualRealityTrain train = repository.getTrain(simulation, tripPlan.getServiceNumber(), tripPlan.getTripNumber()); if (loadedTrainList.contains(train)) { throw new SimulationException(SimulationExceptionType.System_Fault, String.format("加载计划[%s|%s|%s]和[%s|%s|%s]使用列车重复", diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java index ee4c3b8ed..7b9d41db2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java @@ -14,15 +14,18 @@ import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder; import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO; import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; -import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; -import club.joylink.rtss.simulation.cbtc.depot.DepotLoadService; +import club.joylink.rtss.simulation.cbtc.depot.DepotService; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager; import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop; import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService; -import club.joylink.rtss.simulation.cbtc.event.*; +import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationErrorEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationPauseEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationResumeEvent; +import club.joylink.rtss.simulation.cbtc.event.SimulationRunPlanReloadEvent; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.fault.FaultGenerator; @@ -31,10 +34,6 @@ import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPLogicLoop; import club.joylink.rtss.simulation.cbtc.onboard.TrainTargetUpdateService; import club.joylink.rtss.simulation.cbtc.robot.RobotLogicLoop; import club.joylink.rtss.simulation.rt.iscs.IscsStatusPublisher; -import club.joylink.rtss.util.JsonUtils; -import club.joylink.rtss.vo.client.ibp.IbpData; -import club.joylink.rtss.vo.client.ibp.IbpQueryVO; -import club.joylink.rtss.vo.client.ibp.IbpVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import lombok.extern.slf4j.Slf4j; @@ -112,7 +111,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic private IbpService ibpService; @Autowired - private DepotLoadService depotLoadService; + private DepotService depotService; @Override public Simulation create(SimulationBuildParams params, String group) { @@ -126,7 +125,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic simulation.addMessagePublisher(new IscsStatusPublisher(simulation)); // 初始化设备状态 this.deviceStatusService.init(simulation); - depotLoadService.loadDepotTrain(simulation); + depotService.loadDepotTrain(simulation); // 初始化成员 this.memberManager.init(simulation); // 初始化语音指令 @@ -141,6 +140,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic private void addJobs(Simulation simulation) { atsLogicLoop.addJobs(simulation); atpLogicLoop.addJobs(simulation); + depotService.addJobs(simulation); trainTargetUpdateService.addJobs(simulation); vrTrainRunningService.addJobs(simulation); this.ciLogic.addJobs(simulation); @@ -220,7 +220,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic // } // 初始化设备状态 this.deviceStatusService.init(simulation); - depotLoadService.loadDepotTrain(simulation); + depotService.loadDepotTrain(simulation); // Map oldMemberMap = simulation.getMemberMap(); // Simulation build = SimulationBuilder.build(simulation.getBuildParams()); // simulation.resetFrom(build); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java index 14e25b6ee..434e3015e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/SchedulingBuilder.java @@ -78,9 +78,7 @@ public class SchedulingBuilder { SchedulingTrainPlan schedulingTrainPlan = schedulingPlanList.get(i); String serviceNumber = schedulingTrainPlan.getOutDepotTrip().getServiceNumber(); VirtualRealityTrain train = serverTrainMap.get(serviceNumber); - if (Objects.nonNull(train)) { - schedulingTrainPlan.setGroupNumber(train.getGroupNumber()); - } else { + if (Objects.isNull(train)) { train = trainQueue.poll(); serverTrainMap.put(serviceNumber, train); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java index b51987081..c7d5a4a77 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java @@ -105,6 +105,9 @@ public interface SimulationConstants { */ int ROUTE_SETTING_TIMEOUT = 20; + /** 停车场/车辆段循环逻辑频率(单位ms) */ + int DEPOT_LOOP_RATE = 1000; + /** * 获取仿真运行计划日期(运营日) * @return diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java index ebd81a5bd..fc438e63d 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java @@ -43,6 +43,8 @@ public enum SimulationModule { DRIVE_POSITION(SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE), /** 剧本演出模块 */ SCRIPT(SimulationConstants.SCRIPT_LOOP_RATE), + /** 停车场/车辆段模块 */ + DEPOT(SimulationConstants.DEPOT_LOOP_RATE), /** 故障模块 */ FAULT(SimulationConstants.FAULT_GENERATE_RATE), diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java index 395769321..a9f26251b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java @@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.data; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; +import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.communication.vo.TrainHmiDisplay; import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; @@ -586,12 +587,13 @@ public class SimulationDataRepository { return this.serviceTripsMap.get(serviceNumber); } - public VirtualRealityTrain getTrain(String serviceNumber, String tripNumber) { + public VirtualRealityTrain getTrain(Simulation simulation, String serviceNumber, String tripNumber) { VirtualRealityTrain train = this.queryTrain(serviceNumber, tripNumber); if (Objects.isNull(train)) { throw new SimulationException(SimulationExceptionType.System_Fault, String.format("服务车次[%s|%s]找不到派班的列车", serviceNumber, tripNumber)); - } else if (this.usedTrainMap.containsKey(train.getGroupNumber())) { + } else if (!simulation.getRepository().getConfig().isHandleDepot() + && this.usedTrainMap.containsKey(train.getGroupNumber())) { throw new SimulationException(SimulationExceptionType.System_Fault, String.format("列车[%s]已经被使用", train.getGroupNumber())); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java deleted file mode 100644 index 80b7d4990..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotLoadService.java +++ /dev/null @@ -1,45 +0,0 @@ -package club.joylink.rtss.simulation.cbtc.depot; - -import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.data.map.Section; -import club.joylink.rtss.simulation.cbtc.data.map.Station; -import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; -import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; -import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; -import org.springframework.stereotype.Component; - -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -@Component -public class DepotLoadService { - - public void loadDepotTrain(Simulation simulation) { - if (!simulation.getRepository().getConfig().isHandleDepot()) { - return; - } - Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); - simulation.getRepository().getAllVrTrain().stream() - .collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation)) - .forEach((station, trainList) -> { - List
sections = parkingTracksMap.get(station); - // 先加载内侧的停车轨 - sections.sort(Comparator.comparing(section -> - Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection()))); - boolean right = sections.get(sections.size() - 1).getLeftSection() == null; - for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) { - VirtualRealityTrain train = trainList.get(i); - Section section = sections.get(i); - train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right); - train.parkingAt(section); - TrainInfo trainInfo = TrainInfo.constructManualTrain(train); - trainInfo.tracking(train); - simulation.getRepository().addOnlineTrain(train); - simulation.getRepository().addTrainInfo(trainInfo); - } - }); - } -} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java new file mode 100644 index 000000000..b4c9afa26 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/depot/DepotService.java @@ -0,0 +1,86 @@ +package club.joylink.rtss.simulation.cbtc.depot; + +import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; +import club.joylink.rtss.simulation.cbtc.GroupSimulationService; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.command.CommandBO; +import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; +import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; +import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; +import club.joylink.rtss.simulation.cbtc.data.map.Route; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.map.Station; +import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; +import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; +import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; +import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +@Component +public class DepotService { + + @Autowired + private CiRouteService ciRouteService; + + @Autowired + private GroupSimulationService groupSimulationService; + + public void loadDepotTrain(Simulation simulation) { + if (!simulation.getRepository().getConfig().isHandleDepot()) { + return; + } + Map> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); + simulation.getRepository().getAllVrTrain().stream() + .collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation)) + .forEach((station, trainList) -> { + List
sections = parkingTracksMap.get(station); + // 先加载内侧的停车轨 + sections.sort(Comparator.comparing(section -> + Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection()))); + boolean right = sections.get(sections.size() - 1).getLeftSection() == null; + for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) { + VirtualRealityTrain train = trainList.get(i); + Section section = sections.get(i); + train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right); + train.parkingAt(section); + train.initAsRM(); + TrainInfo trainInfo = TrainInfo.constructManualTrain(train); + trainInfo.tracking(train); + simulation.getRepository().addOnlineTrain(train); + simulation.getRepository().addTrainInfo(trainInfo); + } + }); + } + + public void addJobs(Simulation simulation) { + simulation.addJob(SimulationModule.DEPOT.name(), () -> this.run(simulation), SimulationConstants.DEPOT_LOOP_RATE); + } + + private void run(Simulation simulation) { + SchedulingTrainPlan schedulingTrainPlan = simulation.getRepository().getSchedulingTrainPlanList().get(0); + LocalDateTime systemTime = simulation.getSystemTime(); + if (!schedulingTrainPlan.getOutDepotTrip().getStartTime().plusMinutes(20).isAfter(systemTime.toLocalTime())) { + return; + } + String groupNumber = schedulingTrainPlan.getGroupNumber(); + VirtualRealityTrain train = simulation.getRepository().getVRByCode(groupNumber, VirtualRealityTrain.class); + List routePaths = simulation.getRepository().queryRoutePathsByStart(train.getHeadPosition().getSection()); + RoutePath routePath = routePaths.get(0); + for (Route route : routePath.getRouteList()) { + ciRouteService.setRoute(simulation, route); + } + CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Drive_To, schedulingTrainPlan.getDriverCode(), null); + List memberList = simulation.getSimulationMembersByDevice(train); + groupSimulationService.command(simulation, commandInitiateVO, memberList.get(0)); + } +}