diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java index 45977f600..5de2d6afe 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.cbtc.CTC; +import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainLoadService; import club.joylink.rtss.simulation.cbtc.CTC.data.*; import club.joylink.rtss.simulation.cbtc.CTC.data.vo.*; import club.joylink.rtss.simulation.cbtc.CTC.service.CTCService; @@ -41,10 +42,15 @@ public class CTCLogicLoop { @Autowired private CtcDispatchCommandService ctcDispatchCommandService; + @Autowired + private AtsTrainLoadService atsTrainLoadService; + public void run(Simulation simulation) { updateRunPlanLog(simulation); routeSequenceTrigger(simulation); trackViewUpdate(simulation); + // 加载已签收行车日志, + loadSignRunPlanTrain(simulation); } public void sendMessage(Simulation simulation) { @@ -300,7 +306,7 @@ public class CTCLogicLoop { sendCtcMessage(simulation.getId(), allList, WebSocketMessageType.SIMULATION_RAILWAY_RUN_PLAN_SEND, simulation.getSimulationUserIds()); } } - + /** * 运行计划发送变化事件 */ @@ -379,4 +385,30 @@ public class CTCLogicLoop { stompMessageService.sendToUser(userIds, messageVO); } } + + + /** + * 加载已签收至占线板上的列车 + * + * @param simulation 仿真信息 + */ + private void loadSignRunPlanTrain(Simulation simulation) { + simulation.getCtcRepository().getAllRunPlanList().stream() + .filter(r -> !r.isLoad() && r.isStartRunPlan() && r.isSign()) + .forEach(r -> { + simulation.getCtcRepository().addRunPlanTrain(r); + r.setLoad(true); // 已上线 + }); + + // 列车上线 + simulation.getCtcRepository().getRunPlanTrainMap().forEach((k, v) -> { + if (v.getTrackSection().isFree() && !v.getTrainList().isEmpty()) { + CtcTrainQueue.RunPlanTrain train = v.getTrainList().poll(); + String tripNumber = train.getTripNumber(); + int lastNum = tripNumber.charAt(tripNumber.length() - 1) - 48; + atsTrainLoadService.loadTripNumberTrain(simulation, tripNumber, k, lastNum % 2 == 0); + } + }); + + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java index f025e60fc..8d1d141a8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java @@ -101,6 +101,11 @@ public class CtcRepository { * 是否需要发送计划消息 */ private Boolean runPlanSendOut; + + /** + * 运行计划列车集合 + */ + private final Map runPlanTrainMap = new ConcurrentHashMap<>(); /******************************************* 以上为车站终端数据:车站为单位 *******************************************/ /** @@ -434,4 +439,23 @@ public class CtcRepository { trackView.addReceivingLine(routeSequenceLine); } } + + /** + * 增加列车至轨道队列 + * + * @param runPlanLog 运行计划日志 + */ + public void addRunPlanTrain(CtcStationRunPlanLog runPlanLog) { + CtcStationRunPlanLog.RunPlanItem departItem = runPlanLog.getDepartRunPlan(); + if (departItem.getTrackSection() != null) { + String sectionCode = departItem.getTrackSection().getCode(); + CtcTrainQueue trainQueue = this.runPlanTrainMap.get(sectionCode); + if (trainQueue == null) { + trainQueue = new CtcTrainQueue(); + trainQueue.setTrackSection(departItem.getTrackSection()); + } + trainQueue.addTrain(runPlanLog); + this.runPlanTrainMap.put(sectionCode, trainQueue); + } + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcStationRunPlanLog.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcStationRunPlanLog.java index b735fb79a..a26901181 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcStationRunPlanLog.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcStationRunPlanLog.java @@ -154,6 +154,16 @@ public class CtcStationRunPlanLog { */ private int status; + /** + * 是否已加载至轨道 + */ + private boolean load; + + /** + * 是否签收至占线板 + */ + private boolean sign; + public CtcStationRunPlanLog(CtcRunPlanParam paramInfo) { this.planParam = paramInfo; this.code = paramInfo.getRunPlanCode(); @@ -309,10 +319,11 @@ public class CtcStationRunPlanLog { } /** - * 清空变化状态 + * 签收后,清空变化状态 */ public void clearChange() { this.changeType = null; + this.sign = true; } /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcTrainQueue.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcTrainQueue.java new file mode 100644 index 000000000..9e420bbf3 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcTrainQueue.java @@ -0,0 +1,79 @@ +package club.joylink.rtss.simulation.cbtc.CTC.data; + +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.PriorityQueue; +import java.util.Queue; + +/** + * Ctc运行计划的列车 + */ +@Data +public class CtcTrainQueue { + /** + * 需要加车轨道 + */ + private Section trackSection; + + /** + * 计划列车队列 + */ + private Queue trainList = new PriorityQueue<>((t1, t2) -> t1.getPlanTime().isBefore(t2.getPlanTime()) ? -1 : 1); + + @Data + public static class RunPlanTrain { + private CtcStationRunPlanLog runPlanLog; + + private String tripNumber; + + private LocalDateTime planTime; + + private Section trackSection; + + public RunPlanTrain(CtcStationRunPlanLog runPlanLog) { + this.runPlanLog = runPlanLog; + this.tripNumber = runPlanLog.getDepartRunPlan().getTripNumber(); + this.planTime = runPlanLog.getDepartRunPlan().getPlanTime(); + this.trackSection = runPlanLog.getDepartRunPlan().getTrackSection(); + } + } + + /** + * 是否已经上线 + * + * @return 不存在已上线 + */ + public boolean isExistOnline(String tripNumber) { + return trainList.stream().anyMatch(t -> tripNumber.equals(t.getTripNumber())); + } + + /** + * 移除已签收未上线的列车 + * + * @param tripNumber 车次 + * @return 是否移除成功 + */ + public boolean removeTrain(String tripNumber) { + if (isExistOnline(tripNumber)) { + RunPlanTrain train = trainList.stream().filter(t -> tripNumber.equals(t.getTripNumber())) + .findFirst().orElseGet(null); + if (train != null) { + this.trainList.remove(train); + return true; + } + } + return false; + } + + /** + * 将列车添加至队列 + * + * @param runPlanLog 运行计划日志 + */ + public void addTrain(CtcStationRunPlanLog runPlanLog) { + RunPlanTrain runPlanTrain = new RunPlanTrain(runPlanLog); + this.trainList.add(runPlanTrain); + } +}