diff --git a/src/main/java/club/joylink/rtss/simulation/Simulation.java b/src/main/java/club/joylink/rtss/simulation/Simulation.java index 8ef139b2c..8592607eb 100644 --- a/src/main/java/club/joylink/rtss/simulation/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/Simulation.java @@ -102,7 +102,7 @@ public abstract class Simulation { if (typeName.equals(watchable.getClass().getTypeName())) { - watchable.register(watcher); + watchable.register(watcher, null); } }); } public void watch(Watchable watchable, Watcher watcher) { watchable.simulation = this; - watchable.register(watcher); + watchable.register(watcher, null); + } + + public void watchField(Watcher watcher, Watchable watchable, List fieldList) { + watchable.simulation = this; + watchable.register(watcher, fieldList); } public void saveOperation(Operation memberOperation) { diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationTriggerMessagePublisher.java b/src/main/java/club/joylink/rtss/simulation/SimulationTriggerMessagePublisher.java index c6080685c..4c3d719ed 100644 --- a/src/main/java/club/joylink/rtss/simulation/SimulationTriggerMessagePublisher.java +++ b/src/main/java/club/joylink/rtss/simulation/SimulationTriggerMessagePublisher.java @@ -23,7 +23,7 @@ public abstract class SimulationTriggerMessagePublisher extends SimulationMessag public abstract Object buildMessage(Watchable watchable); @Override - public void handleStateChange(Simulation simulation, Watchable watchable) { + public void handleFieldChange(Simulation simulation, Watchable watchable, String field, Object val) { List destinationList = this.getNeedBuildDestination(watchable); if (!destinationList.isEmpty()) { Object message = this.buildMessage(watchable); diff --git a/src/main/java/club/joylink/rtss/simulation/Watchable.java b/src/main/java/club/joylink/rtss/simulation/Watchable.java index 027c152b3..b9e23d182 100644 --- a/src/main/java/club/joylink/rtss/simulation/Watchable.java +++ b/src/main/java/club/joylink/rtss/simulation/Watchable.java @@ -6,16 +6,28 @@ import java.util.Objects; public abstract class Watchable { Simulation simulation; - List watcherList = new ArrayList<>(); + List watcherList = new ArrayList<>(); - public void register(Watcher watcher) { + public void register(Watcher watcher, List fieldList) { Objects.requireNonNull(watcher); - this.watcherList.add(watcher); + this.watcherList.add(new FieldWatcher(watcher, fieldList)); } - public void fireWatcher() { - for (Watcher watcher : this.watcherList) { - watcher.handleStateChange(simulation, this); + public void fireWatcher(String field, Object val) { + for (FieldWatcher fieldWatcher : this.watcherList) { + if (fieldWatcher.fieldList == null || fieldWatcher.fieldList.contains(field)) { + fieldWatcher.watcher.handleFieldChange(simulation, this, field, val); + } + } + } + + private class FieldWatcher{ + Watcher watcher; + List fieldList; + + public FieldWatcher(Watcher watcher, List fieldList) { + this.watcher = watcher; + this.fieldList = fieldList; } } } diff --git a/src/main/java/club/joylink/rtss/simulation/Watcher.java b/src/main/java/club/joylink/rtss/simulation/Watcher.java index fdbfc4ba9..8b4196463 100644 --- a/src/main/java/club/joylink/rtss/simulation/Watcher.java +++ b/src/main/java/club/joylink/rtss/simulation/Watcher.java @@ -1,5 +1,5 @@ package club.joylink.rtss.simulation; public interface Watcher { - void handleStateChange(Simulation simulation, W watchable); + void handleFieldChange(Simulation simulation, W watchable, String filed, Object val); } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainRouteService.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainRouteService.java index ce438683a..01c4280d4 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainRouteService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainRouteService.java @@ -8,6 +8,9 @@ import org.springframework.stereotype.Component; public class AtsTrainRouteService { public void triggerRouteForTrain(AtsRepository atsRepository, AtsTrain atsTrain) { + if (!atsRepository.getConfig().isArsOpen()) { // 列车进路触发服务是否开启 + return; + } if (atsTrain.isPlanTrain()) { // 计划车 this.triggerForPlanTrain(atsRepository, atsTrain); } else if (atsTrain.isHeadTrain()) { // 头码车 diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainTraceService.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainTraceService.java new file mode 100644 index 000000000..feffaf37c --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/AtsTrainTraceService.java @@ -0,0 +1,26 @@ +package club.joylink.rtss.simulation.rt.ATS; + +import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository; +import club.joylink.rtss.simulation.rt.ATS.bo.AtsTrain; +import org.springframework.stereotype.Component; + +/** + * ATS列车追踪服务 + */ +@Component +public class AtsTrainTraceService { + + public void traceTrain(AtsRepository atsRepository) { + for (AtsTrain atsTrain : atsRepository.getTrainMap().values()) { + if (atsTrain.isCtc()) { + continue; + } + String axcSectionId = atsTrain.getAxcSectionId(); + if (axcSectionId == null) { // 没有实际列车 + continue; + } + + } + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsConfig.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsConfig.java new file mode 100644 index 000000000..d9d37271e --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsConfig.java @@ -0,0 +1,9 @@ +package club.joylink.rtss.simulation.rt.ATS.bo; + +import lombok.Getter; + +@Getter +public class AtsConfig { + boolean arsOpen; + +} diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java index 862c9c549..a46b0ad8c 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepository.java @@ -4,8 +4,8 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.SimulationRepository; import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsRunPlan; -import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsStationPlan; import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsTripPlan; +import club.joylink.rtss.simulation.rt.RtSimulation; import lombok.Getter; import java.util.HashMap; @@ -15,6 +15,8 @@ import java.util.Map; public class AtsRepository extends SimulationRepository { public static final String NAME = "ATS"; + AtsConfig config; + AtsRunPlan runPlan; Map routeMap = new HashMap<>(); @@ -23,21 +25,27 @@ public class AtsRepository extends SimulationRepository { Map signalMap = new HashMap<>(); Map standMap = new HashMap<>(); Map stationMap = new HashMap<>(); - Map stationPlanMap = new HashMap<>(); Map switchMap = new HashMap<>(); Map trainMap = new HashMap<>(); - Map tripPlanMap = new HashMap<>(); Map unitPathMap = new HashMap<>(); public AtsRepository() { super(NAME); } + public static AtsRepository getInstanceFrom(RtSimulation simulation) { + return simulation.getRepository(NAME, AtsRepository.class); + } + @Override public void initState() { } + public void setRunPlan(AtsRunPlan atsRunPlan) { + this.runPlan = atsRunPlan; + } + public AtsRunPlan getRunPlan() { return runPlan; } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepositoryBuilder.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepositoryBuilder.java index f023bf1bf..e6084699c 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepositoryBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsRepositoryBuilder.java @@ -1,6 +1,7 @@ package club.joylink.rtss.simulation.rt.ATS.bo; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsRunPlanBuilder; import club.joylink.rtss.vo.map.*; import java.util.List; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java index 4d988b884..ec70c8d44 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSection.java @@ -28,7 +28,7 @@ public class AtsSection extends AtsDevice { if (this.occupy != occ) { this.occupy = occ; this.stateList.set(1, this.convert(this.occupy)); - this.fireWatcher(); + this.fireWatcher("occupy", this.occupy); return true; } return false; @@ -38,7 +38,7 @@ public class AtsSection extends AtsDevice { if (this.ctOccupy != ctOcc) { this.ctOccupy = ctOcc; this.stateList.set(2, this.convert(this.ctOccupy)); - this.fireWatcher(); + this.fireWatcher("ctOccupy", this.ctOccupy); return true; } return false; @@ -48,7 +48,7 @@ public class AtsSection extends AtsDevice { if (this.rl != rl) { this.rl = rl; this.stateList.set(3, this.convert(this.rl)); - this.fireWatcher(); + this.fireWatcher("rl", this.rl); return true; } return false; @@ -58,7 +58,7 @@ public class AtsSection extends AtsDevice { if (this.lr != lr) { this.lr = lr; this.stateList.set(4, this.convert(this.lr)); - this.fireWatcher(); + this.fireWatcher("lr", this.lr); return true; } return false; @@ -68,7 +68,7 @@ public class AtsSection extends AtsDevice { if (this.ol != ol) { this.ol = ol; this.stateList.set(5, this.convert(this.ol)); - this.fireWatcher(); + this.fireWatcher("ol", this.ol); return true; } return false; @@ -78,7 +78,7 @@ public class AtsSection extends AtsDevice { if (this.delayTime != delayTime) { this.delayTime = delayTime; this.stateList.set(6, this.delayTime); - this.fireWatcher(); + this.fireWatcher("delayTime", this.delayTime); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java index 9c0225e80..d87fc6924 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSignal.java @@ -34,7 +34,7 @@ public class AtsSignal extends AtsDevice { if (this.signalAspect != signalAspect) { this.signalAspect = signalAspect; this.stateList.set(1, this.signalAspect); - this.fireWatcher(); + this.fireWatcher("signalAspect", this.signalAspect); return true; } return false; @@ -44,7 +44,7 @@ public class AtsSignal extends AtsDevice { if (this.logic != logic) { this.logic = logic; this.stateList.set(2, this.convert(this.logic)); - this.fireWatcher(); + this.fireWatcher("logic", this.logic); return true; } return false; @@ -54,7 +54,7 @@ public class AtsSignal extends AtsDevice { if (this.forceLight != forceLight) { this.forceLight = forceLight; this.stateList.set(3, this.convert(this.forceLight)); - this.fireWatcher(); + this.fireWatcher("forceLight", this.forceLight); return true; } return false; @@ -64,7 +64,7 @@ public class AtsSignal extends AtsDevice { if (this.bl != bl) { this.bl = bl; this.stateList.set(4, this.convert(this.bl)); - this.fireWatcher(); + this.fireWatcher("bl", this.bl); return true; } return false; @@ -74,7 +74,7 @@ public class AtsSignal extends AtsDevice { if (this.rbl != rbl) { this.rbl = rbl; this.stateList.set(5, this.convert(this.rbl)); - this.fireWatcher(); + this.fireWatcher("rbl", this.rbl); return true; } return false; @@ -84,7 +84,7 @@ public class AtsSignal extends AtsDevice { if (this.level != level) { this.level = level; this.stateList.set(6, this.level); - this.fireWatcher(); + this.fireWatcher("level", this.level); return true; } return false; @@ -94,7 +94,7 @@ public class AtsSignal extends AtsDevice { if (!Objects.equals(this.lrId, lrId)) { this.lrId = lrId; this.stateList.set(7, this.lrId); - this.fireWatcher(); + this.fireWatcher("lrId", this.lrId); return true; } return false; @@ -104,7 +104,7 @@ public class AtsSignal extends AtsDevice { if (this.delayTime != delayTime) { this.delayTime = delayTime; this.stateList.set(8, this.delayTime); - this.fireWatcher(); + this.fireWatcher("delayTime", this.delayTime); return true; } return false; @@ -114,7 +114,7 @@ public class AtsSignal extends AtsDevice { if (this.guideTime != guideTime) { this.guideTime = guideTime; this.stateList.set(9, this.guideTime); - this.fireWatcher(); + this.fireWatcher("guideTime", this.guideTime); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java index 2e4c7b921..1d5c68050 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsSwitch.java @@ -30,7 +30,7 @@ public class AtsSwitch extends AtsDevice { if (this.position != position) { this.position = position; this.stateList.set(1, this.position); - this.fireWatcher(); + this.fireWatcher("position", this.position); return true; } return false; @@ -40,7 +40,7 @@ public class AtsSwitch extends AtsDevice { if (this.bl != bl) { this.bl = bl; this.stateList.set(2, this.convert(this.bl)); - this.fireWatcher(); + this.fireWatcher("bl", this.bl); return true; } return false; @@ -50,7 +50,7 @@ public class AtsSwitch extends AtsDevice { if (this.sl != sl) { this.sl = sl; this.stateList.set(3, this.convert(this.sl)); - this.fireWatcher(); + this.fireWatcher("sl", this.sl); return true; } return false; @@ -60,7 +60,7 @@ public class AtsSwitch extends AtsDevice { if (this.rl != rl) { this.rl = rl; this.stateList.set(4, this.convert(this.rl)); - this.fireWatcher(); + this.fireWatcher("rl", this.rl); return true; } return false; @@ -70,7 +70,7 @@ public class AtsSwitch extends AtsDevice { if (this.ol != ol) { this.ol = ol; this.stateList.set(5, this.convert(this.ol)); - this.fireWatcher(); + this.fireWatcher("ol", this.ol); return true; } return false; @@ -80,7 +80,7 @@ public class AtsSwitch extends AtsDevice { if (this.fl != fl) { this.fl = fl; this.stateList.set(6, this.convert(this.fl)); - this.fireWatcher(); + this.fireWatcher("fl", this.fl); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java index fd899b53c..97e82cdcc 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/AtsTrain.java @@ -19,9 +19,11 @@ public class AtsTrain extends AtsDevice { public static final int DIRECTION_N = 0; // 未知 public static final int DIRECTION_R = 1; // 右 public static final int DIRECTION_L = -1; // 左 + boolean ctc; // 是否连续通信列车 String sectionId; // 轨道区段(计轴区段或道岔区段) int offset; // 轨道区段偏移 - String logicSectionId; // 逻辑区段(逻辑区段或道岔计轴区段或岔心) + String axcSectionId; // 所在计轴id + String trainWindowId; // 所在车次窗id String sn;// 服务号/表号 String tn;// 车次号/圈数 String dn;// 目的地号 diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlan.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlan.java index e743ec963..677a71ffc 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlan.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlan.java @@ -3,9 +3,9 @@ package club.joylink.rtss.simulation.rt.ATS.bo.plan; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import lombok.Getter; +import java.time.LocalDateTime; import java.time.LocalTime; -import java.util.List; -import java.util.Map; +import java.util.*; @Getter public class AtsRunPlan { @@ -27,11 +27,17 @@ public class AtsRunPlan { */ Map> endTripMap; + public AtsRunPlan() { + this.serviceMap = new HashMap<>(); + this.tripPlanMap = new HashMap<>(); + this.endTripMap = new HashMap<>(); + } + public AtsTripPlan queryNextTripPlanOfPlan(AtsTripPlan atsTripPlan) { return this.queryNextTripPlanOfEnd(atsTripPlan.getEndSectionId(), atsTripPlan.getEndTime()); } - public AtsTripPlan queryNextTripPlanOfEnd(String endId, LocalTime time) { + public AtsTripPlan queryNextTripPlanOfEnd(String endId, LocalDateTime time) { List tripPlanList = this.endTripMap.get(endId); AtsTripPlan next = null; if (tripPlanList != null) { @@ -53,4 +59,32 @@ public class AtsRunPlan { } + public void save(AtsTripPlan atsTripPlan) { + String stNumber = atsTripPlan.getStNumber(); + BusinessExceptionAssertEnum.DATA_ERROR.assertNotTrue(this.tripPlanMap.containsKey(stNumber)); + this.tripPlanMap.put(stNumber, atsTripPlan); + + List tripPlanList = this.serviceMap.get(atsTripPlan.sn); + if (tripPlanList == null) { + tripPlanList = new ArrayList<>(); + this.serviceMap.put(atsTripPlan.sn, tripPlanList); + } + tripPlanList.add(atsTripPlan); + + List endPlanList = this.endTripMap.get(atsTripPlan.getStartSectionId()); + if (endPlanList == null) { + endPlanList = new ArrayList<>(); + this.endTripMap.put(atsTripPlan.getStartSectionId(), endPlanList); + } + endPlanList.add(atsTripPlan); + } + + public void sort() { + this.serviceMap.forEach((sn, list) -> { + list.sort(Comparator.comparing(AtsTripPlan::getStartTime)); + }); + this.endTripMap.forEach((stn, list) -> { + list.sort(Comparator.comparing(AtsTripPlan::getStartTime)); + }); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlanBuilder.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlanBuilder.java new file mode 100644 index 000000000..214794246 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsRunPlanBuilder.java @@ -0,0 +1,74 @@ +package club.joylink.rtss.simulation.rt.ATS.bo.plan; + +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.simulation.rt.repo.CommonRepository; +import club.joylink.rtss.vo.client.runplan.RunPlanTripTimeVO; +import club.joylink.rtss.vo.client.runplan.RunPlanTripVO; +import club.joylink.rtss.vo.client.runplan.RunPlanVO; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.List; + +public class AtsRunPlanBuilder { + + public static AtsRunPlan buildFrom(RunPlanVO runPlanVO, LocalDate date, CommonRepository commonRepo) { + AtsRunPlan atsRunPlan = new AtsRunPlan(); + List tripList = runPlanVO.getTripList(); + for (RunPlanTripVO tripVO : tripList) { + AtsTripPlan atsTripPlan = buildAtsTripPlan(tripVO, date, commonRepo); + atsRunPlan.save(atsTripPlan); + } + atsRunPlan.sort(); + return atsRunPlan; + } + + private static AtsTripPlan buildAtsTripPlan(RunPlanTripVO tripVO, LocalDate date, CommonRepository commonRepo) { + AtsTripPlan tripPlan = new AtsTripPlan(); + tripPlan.sn = tripVO.getServiceNumber(); + tripPlan.tn = tripVO.getTripNumber(); + tripPlan.dn = tripVO.getDestinationCode(); + tripPlan.in = tripVO.getIsInbound(); + tripPlan.out = tripVO.getIsOutbound(); + tripPlan.spare = tripVO.getIsBackUp(); + commonRepo.getSectionById(tripVO.getStartSectionCode()); + commonRepo.getSectionById(tripVO.getEndSectionCode()); + BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(tripVO.getStartTime()); + BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(tripVO.getEndTime()); + tripPlan.startSectionId = tripVO.getStartSectionCode(); + tripPlan.startTime = handleRunPlanDataTime(date, tripVO.getStartTime()); + tripPlan.endSectionId = tripVO.getEndSectionCode(); + tripPlan.endTime = handleRunPlanDataTime(date, tripVO.getEndTime()); + tripPlan.stationPlanList = buildStationPlanList(tripVO, date, commonRepo); + return tripPlan; + } + + private static ZoneOffset zoneOffset = ZoneOffset.ofHours(0); + + private static List buildStationPlanList(RunPlanTripVO tripVO, LocalDate date, CommonRepository commonRepo) { + List timeList = tripVO.getTimeList(); + List list = new ArrayList<>(); + for (RunPlanTripTimeVO tripTimeVO : timeList) { + commonRepo.getStationById(tripTimeVO.getStationCode()); + commonRepo.getSectionById(tripTimeVO.getSectionCode()); + AtsStationPlan atsStationPlan = new AtsStationPlan(); + atsStationPlan.stationId = tripTimeVO.getStationCode(); + atsStationPlan.sectionId = tripTimeVO.getSectionCode(); + BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(tripTimeVO.getArrivalTime()); + BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(tripTimeVO.getDepartureTime()); + atsStationPlan.arriveTime = handleRunPlanDataTime(date, tripTimeVO.getArrivalTime()); + atsStationPlan.leaveTime = handleRunPlanDataTime(date, tripTimeVO.getDepartureTime()); + atsStationPlan.parkTime = (int) (atsStationPlan.leaveTime.toEpochSecond(zoneOffset) - atsStationPlan.arriveTime.toEpochSecond(zoneOffset)); + list.add(atsStationPlan); + } + return list; + } + + private static LocalDateTime handleRunPlanDataTime(LocalDate date, LocalTime startTime) { + return date.atTime(startTime).plusHours(2); + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsStationPlan.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsStationPlan.java index 254ac1406..ade02574a 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsStationPlan.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsStationPlan.java @@ -2,13 +2,13 @@ package club.joylink.rtss.simulation.rt.ATS.bo.plan; import lombok.Getter; -import java.time.LocalTime; +import java.time.LocalDateTime; @Getter public class AtsStationPlan { String stationId; String sectionId; - LocalTime arriveTime;// 到站时间 - LocalTime leaveTime;// 出发时间 + LocalDateTime arriveTime;// 到站时间 + LocalDateTime leaveTime;// 出发时间 int parkTime;// 停靠时长 } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsTripPlan.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsTripPlan.java index fb0bd6700..28f7fff91 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsTripPlan.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/bo/plan/AtsTripPlan.java @@ -3,7 +3,7 @@ package club.joylink.rtss.simulation.rt.ATS.bo.plan; import lombok.Getter; import org.springframework.util.StringUtils; -import java.time.LocalTime; +import java.time.LocalDateTime; import java.util.List; @Getter @@ -14,16 +14,18 @@ public class AtsTripPlan { boolean in;// 回库 boolean out;// 出库 boolean spare;// 备用 - String startStationId; String startSectionId; - LocalTime startTime; - String endStationId; + LocalDateTime startTime; String endSectionId; - LocalTime endTime; + LocalDateTime endTime; List stationPlanList; boolean depart; // 是否已经发车 public static String buildSTNumber(String sn, String tn) { return String.format("%s%s", StringUtils.hasText(sn)?sn:"", StringUtils.hasText(tn)?tn:""); } + + public String getStNumber() { + return buildSTNumber(this.sn, this.tn); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSectionAtsWatcher.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSectionAtsWatcher.java index 4a770466b..66984c865 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSectionAtsWatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSectionAtsWatcher.java @@ -10,8 +10,9 @@ import org.springframework.stereotype.Component; @Component public class CilSectionAtsWatcher implements Watcher { + @Override - public void handleStateChange(Simulation simulation, CilSection watchable) { + public void handleFieldChange(Simulation simulation, CilSection watchable, String filed, Object val) { AtsRepository repository = (AtsRepository) simulation.getRepository(AtsRepository.NAME, AtsRepository.class); AtsMessagePublisher messagePublisher = (AtsMessagePublisher) simulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); AtsSection atsSection = repository.getSectionById(watchable.getId()); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSignalAtsWatcher.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSignalAtsWatcher.java index 8014f4694..7ab6e403b 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSignalAtsWatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSignalAtsWatcher.java @@ -11,7 +11,7 @@ import org.springframework.stereotype.Component; @Component public class CilSignalAtsWatcher implements Watcher { @Override - public void handleStateChange(Simulation simulation, CilSignal watchable) { + public void handleFieldChange(Simulation simulation, CilSignal watchable, String filed, Object val) { AtsRepository repository = (AtsRepository) simulation.getRepository(AtsRepository.NAME, AtsRepository.class); AtsMessagePublisher messagePublisher = (AtsMessagePublisher) simulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); AtsSignal atsSignal = repository.getSignalById(watchable.getId()); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSwitchAtsWatcher.java b/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSwitchAtsWatcher.java index bd764b8b9..3ffa7fea1 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSwitchAtsWatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/ATS/watcher/CilSwitchAtsWatcher.java @@ -11,7 +11,7 @@ import org.springframework.stereotype.Component; @Component public class CilSwitchAtsWatcher implements Watcher { @Override - public void handleStateChange(Simulation simulation, CilSwitch watchable) { + public void handleFieldChange(Simulation simulation, CilSwitch watchable, String filed, Object val) { AtsRepository repository = (AtsRepository) simulation.getRepository(AtsRepository.NAME, AtsRepository.class); AtsMessagePublisher messagePublisher = (AtsMessagePublisher) simulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class); AtsSwitch atsSwitch = repository.getSwitchById(watchable.getId()); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilRouteLogicService.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilRouteLogicService.java index 90f531474..6a0975bd6 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilRouteLogicService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilRouteLogicService.java @@ -7,6 +7,7 @@ import club.joylink.rtss.simulation.rt.SRD.bo.SrTrain; import club.joylink.rtss.simulation.rt.SRD.bo.SrdRepository; import club.joylink.rtss.simulation.rt.SRD.bo.TrackPosition; import club.joylink.rtss.simulation.rt.repo.*; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -17,6 +18,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +@Slf4j @Component public class CilRouteLogicService { @@ -44,7 +46,11 @@ public class CilRouteLogicService { .sorted(Comparator.comparing(commonRoute -> commonRoute.getPathElement().getReverseSwitchCount())) .findFirst().get(); if (!cilRepository.isSupervised(route.getId())) { - this.setRoute(rtSimulation, route.getId()); + try { + this.setRoute(rtSimulation, route.getId()); + } catch (Exception e) { + log.error("联锁自动触发进路失败:", e); + } } break; } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSection.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSection.java index 06d7e1975..dc931ed9e 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSection.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSection.java @@ -24,19 +24,18 @@ public class CilSection extends CilDevice { @Override public void init() { - axcOccupy = false; - routeId = null; - rl = false; - lr = false; - ol = false; - delayTime = 0; - this.fireWatcher(); + this.updateAxcOccupy(false); + this.updateRouteId(null); + this.updateRl(false); + this.updateLr(false); + this.updateOl(false); + this.updateDelayTime(0); } private boolean updateAxcOccupy(boolean axcOccupy) { if (this.axcOccupy != axcOccupy) { this.axcOccupy = axcOccupy; - this.fireWatcher(); + this.fireWatcher("axcOccupy", this.axcOccupy); return true; } return false; @@ -45,7 +44,7 @@ public class CilSection extends CilDevice { private boolean updateRouteId(String routeId) { if (!Objects.equals(this.routeId, routeId)) { this.routeId = routeId; - this.fireWatcher(); + this.fireWatcher("routeId", this.routeId); return true; } return false; @@ -54,7 +53,7 @@ public class CilSection extends CilDevice { private boolean updateRl(boolean rl) { if (this.rl != rl) { this.rl = rl; - this.fireWatcher(); + this.fireWatcher("rl", this.rl); return true; } return false; @@ -63,7 +62,7 @@ public class CilSection extends CilDevice { private boolean updateOl(boolean ol) { if (this.ol != ol) { this.ol = ol; - this.fireWatcher(); + this.fireWatcher("ol", this.ol); return true; } return false; @@ -72,7 +71,7 @@ public class CilSection extends CilDevice { private boolean updateLr(boolean lr) { if (this.lr != lr) { this.lr = lr; - this.fireWatcher(); + this.fireWatcher("lr", this.lr); return true; } return false; @@ -81,7 +80,7 @@ public class CilSection extends CilDevice { private boolean updateDelayTime(int delayTime) { if (this.delayTime != delayTime) { this.delayTime = delayTime; - this.fireWatcher(); + this.fireWatcher("delayTime", this.delayTime); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java index aac15e499..dc335460d 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java @@ -45,24 +45,23 @@ public class CilSignal extends CilDevice { @Override public void init() { - signalAspect = SrSignal.H; - logic = false; - forceLight = false; - bl = false; - rbl = false; - uta = false; - level = LEVEL_1; - fl = false; - routeId = null; - delayTime = 0; - guideTime = 0; - this.fireWatcher(); + this.updateSignalAspect(SrSignal.H); + this.updateLogic(false); + this.updateForceLight(false); + this.updateBl(false); + this.updateRbl(false); + this.updateUta(false); + this.updateLevel(LEVEL_1); + this.updateFl(false); + this.updateRouteId(null); + this.updateDelayTime(0); + this.updateGuideTime(0); } private boolean updateSignalAspect(int signalAspect) { if (this.signalAspect != signalAspect) { this.signalAspect = signalAspect; - this.fireWatcher(); + this.fireWatcher("signalAspect", this.signalAspect); return true; } return false; @@ -71,7 +70,7 @@ public class CilSignal extends CilDevice { private boolean updateLogic(boolean logic) { if (this.logic != logic) { this.logic = logic; - this.fireWatcher(); + this.fireWatcher("logic", this.logic); return true; } return false; @@ -80,7 +79,7 @@ public class CilSignal extends CilDevice { private boolean updateForceLight(boolean forceLight) { if (this.forceLight != forceLight) { this.forceLight = forceLight; - this.fireWatcher(); + this.fireWatcher("forceLight", this.forceLight); return true; } return false; @@ -89,7 +88,7 @@ public class CilSignal extends CilDevice { private boolean updateBl(boolean bl) { if (this.bl != bl) { this.bl = bl; - this.fireWatcher(); + this.fireWatcher("bl", this.bl); return true; } return false; @@ -98,7 +97,16 @@ public class CilSignal extends CilDevice { private boolean updateRbl(boolean rbl) { if (this.rbl != rbl) { this.rbl = rbl; - this.fireWatcher(); + this.fireWatcher("rbl", this.rbl); + return true; + } + return false; + } + + private boolean updateUta(boolean uta) { + if (this.uta != uta) { + this.uta = uta; + this.fireWatcher("uta", this.uta); return true; } return false; @@ -107,7 +115,7 @@ public class CilSignal extends CilDevice { private boolean updateFl(boolean fl) { if (this.fl != fl) { this.fl = fl; - this.fireWatcher(); + this.fireWatcher("fl", this.fl); return true; } return false; @@ -116,7 +124,7 @@ public class CilSignal extends CilDevice { private boolean updateLevel(int level) { if (this.level != level) { this.level = level; - this.fireWatcher(); + this.fireWatcher("level", this.level); return true; } return false; @@ -125,7 +133,7 @@ public class CilSignal extends CilDevice { private boolean updateRouteId(String routeId) { if (!Objects.equals(this.routeId, routeId)) { this.routeId = routeId; - this.fireWatcher(); + this.fireWatcher("routeId", this.routeId); return true; } return false; @@ -134,7 +142,7 @@ public class CilSignal extends CilDevice { private boolean updateDelayTime(int delayTime) { if (this.delayTime != delayTime) { this.delayTime = delayTime; - this.fireWatcher(); + this.fireWatcher("delayTime", this.delayTime); return true; } return false; @@ -143,7 +151,7 @@ public class CilSignal extends CilDevice { private boolean updateGuideTime(int guideTime) { if (this.guideTime != guideTime) { this.guideTime = guideTime; - this.fireWatcher(); + this.fireWatcher("guideTime", this.guideTime); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java index e8afd0319..db1dda5d7 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java @@ -33,22 +33,21 @@ public class CilSwitch extends CilDevice { @Override public void init() { - position = NORMAL; - routeUseToPosition = NONE; - bl = false; - sl = false; - this.routeId = null; - rl = false; - ol = false; - fl = false; - mgl = false; - this.fireWatcher(); + this.updatePosition(NORMAL); + this.updateRouteUseToPosition(NONE); + this.updateBl(false); + this.updateSl(false); + this.updateRouteId(null); + this.updateRl(false); + this.updateOl(false); + this.updateFl(false); + this.updateMgl(false); } private boolean updatePosition(int position) { if (this.position != position) { this.position = position; - this.fireWatcher(); + this.fireWatcher("position", this.position); return true; } return false; @@ -57,7 +56,7 @@ public class CilSwitch extends CilDevice { private boolean updateRouteUseToPosition(int routeUseToPosition) { if (this.routeUseToPosition != routeUseToPosition) { this.routeUseToPosition = routeUseToPosition; - this.fireWatcher(); + this.fireWatcher("routeUseToPosition", this.routeUseToPosition); return true; } return false; @@ -66,7 +65,7 @@ public class CilSwitch extends CilDevice { private boolean updateBl(boolean bl) { if (this.bl != bl) { this.bl = bl; - this.fireWatcher(); + this.fireWatcher("bl", this.bl); return true; } return false; @@ -75,7 +74,7 @@ public class CilSwitch extends CilDevice { private boolean updateSl(boolean sl) { if (this.sl != sl) { this.sl = sl; - this.fireWatcher(); + this.fireWatcher("sl", this.sl); return true; } return false; @@ -84,7 +83,7 @@ public class CilSwitch extends CilDevice { private boolean updateRouteId(String routeId) { if (!Objects.equals(this.routeId, routeId)) { this.routeId = routeId; - this.fireWatcher(); + this.fireWatcher("routeId", this.routeId); return true; } return false; @@ -93,7 +92,7 @@ public class CilSwitch extends CilDevice { private boolean updateRl(boolean rl) { if (this.rl != rl) { this.rl = rl; - this.fireWatcher(); + this.fireWatcher("rl", this.rl); return true; } return false; @@ -102,7 +101,7 @@ public class CilSwitch extends CilDevice { private boolean updateOl(boolean ol) { if (this.ol != ol) { this.ol = ol; - this.fireWatcher(); + this.fireWatcher("ol", this.ol); return true; } return false; @@ -111,7 +110,7 @@ public class CilSwitch extends CilDevice { private boolean updateFl(boolean fl) { if (this.fl != fl) { this.fl = fl; - this.fireWatcher(); + this.fireWatcher("fl", this.fl); return true; } return false; @@ -120,7 +119,7 @@ public class CilSwitch extends CilDevice { private boolean updateMgl(boolean mgl) { if (this.mgl != mgl) { this.mgl = mgl; - this.fireWatcher(); + this.fireWatcher("mgl", this.mgl); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrAxcCilWatcher.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrAxcCilWatcher.java index 2e4a7858e..08b4cc9e6 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrAxcCilWatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrAxcCilWatcher.java @@ -10,15 +10,8 @@ import org.springframework.stereotype.Component; public class SrAxcCilWatcher implements Watcher { @Override - public void handleStateChange(Simulation simulation, SrAXC watchable) { + public void handleFieldChange(Simulation simulation, SrAXC watchable, String filed, Object val) { CilSyncRepository cilSyncRepository = (CilSyncRepository) simulation.getRepository(CilSyncRepository.NAME, CilSyncRepository.class); cilSyncRepository.collectSrAXC(watchable); -// CilRepository cilRepository = (CilRepository) simulation.getRepository(CilRepository.NAME, CilRepository.class); -// CilSection cilSection = cilRepository.getSectionById(watchable.getId()); -// cilSection.applyAxcOccupyState(watchable.isOccupy()); -// List logicList = cilRepository.queryLogicListOfAxc(watchable.getId()); -// for (CilSection section : logicList) { -// section.applyAxcOccupyState(watchable.isOccupy()); -// } } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSignalCilWatcher.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSignalCilWatcher.java index fbfc45a83..1b65fff47 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSignalCilWatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSignalCilWatcher.java @@ -10,11 +10,8 @@ import org.springframework.stereotype.Component; public class SrSignalCilWatcher implements Watcher { @Override - public void handleStateChange(Simulation simulation, SrSignal watchable) { + public void handleFieldChange(Simulation simulation, SrSignal watchable, String filed, Object val) { CilSyncRepository cilSyncRepository = (CilSyncRepository) simulation.getRepository(CilSyncRepository.NAME, CilSyncRepository.class); cilSyncRepository.collectSrSignal(watchable); -// CilRepository cilRepository = (CilRepository) simulation.getRepository(CilRepository.NAME, CilRepository.class); -// CilSignal cilSignal = cilRepository.getSignalById(watchable.getId()); -// cilSignal.updateByDeviceState(watchable.getState()); } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSwitchCilWatcher.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSwitchCilWatcher.java index f94a60e0e..960eb4824 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSwitchCilWatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/watcher/SrSwitchCilWatcher.java @@ -10,11 +10,8 @@ import org.springframework.stereotype.Component; public class SrSwitchCilWatcher implements Watcher { @Override - public void handleStateChange(Simulation simulation, SrSwitch watchable) { + public void handleFieldChange(Simulation simulation, SrSwitch watchable, String filed, Object val) { CilSyncRepository cilSyncRepository = (CilSyncRepository) simulation.getRepository(CilSyncRepository.NAME, CilSyncRepository.class); cilSyncRepository.collectSrSwitch(watchable); -// CilRepository cilRepository = (CilRepository) simulation.getRepository(CilRepository.NAME, CilRepository.class); -// CilSwitch cilSwitch = cilRepository.getSwitchById(watchable.getId()); -// cilSwitch.applyPosition(watchable.getState()); } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java index 4b663c574..6f7869060 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/RtSimulationService.java @@ -3,9 +3,16 @@ package club.joylink.rtss.simulation.rt; import club.joylink.rtss.constants.MapPrdTypeEnum; import club.joylink.rtss.constants.Project; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; +import club.joylink.rtss.services.IDailyRunPlanService; +import club.joylink.rtss.services.ILoadPlanService; +import club.joylink.rtss.services.IRunPlanTemplateService; import club.joylink.rtss.services.MapService; import club.joylink.rtss.simulation.SimulationManager; +import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.rt.ATS.AtsLogicService; +import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository; +import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsRunPlan; +import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsRunPlanBuilder; import club.joylink.rtss.simulation.rt.CIL.CilLogicService; import club.joylink.rtss.simulation.rt.SRD.SrdLogicService; import club.joylink.rtss.simulation.rt.SRD.bo.SrTrain; @@ -17,10 +24,13 @@ import club.joylink.rtss.simulation.rt.repo.CommonRepository; import club.joylink.rtss.simulation.rt.repo.CommonStation; import club.joylink.rtss.simulation.rt.vo.RtSimulationInfoVO; import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.client.runplan.RunPlanLoadVO; +import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.map.MapVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.LocalDate; import java.util.Objects; @Component @@ -28,6 +38,12 @@ public class RtSimulationService { @Autowired private MapService mapService; @Autowired + private IDailyRunPlanService iDailyRunPlanService; + @Autowired + private ILoadPlanService iLoadPlanService; + @Autowired + private IRunPlanTemplateService iRunPlanTemplateService; + @Autowired private SimulationManager simulationManager; @Autowired private CommonRepoService commonRepoService; @@ -51,7 +67,8 @@ public class RtSimulationService { this.simulationManager.save(rtSimulation); try { rtSimulation.mapVO = mapVO; - this.loading(rtSimulation, mapVO); + this.loadingMap(rtSimulation, mapVO); + this.loadRunPlan(rtSimulation, this.queryUserRunPlan(accountVO.getId(), mapId)); this.initSimulationMember(rtSimulation); this.initCreatorPlayMember(rtSimulation, mapVO); } catch (Exception e) { @@ -68,6 +85,35 @@ public class RtSimulationService { return rtSimulation; } + private RunPlanVO queryUserRunPlan(Long mapId, Long userId) { + RunPlanLoadVO loadPlan = null; + LocalDate runPlanDate = SimulationConstants.getRunPlanDate(); + // 仿真运行计划的查询:先找用户的,如果不存在找通用的 + loadPlan = this.iLoadPlanService.findUserLoadPlan(userId, mapId, runPlanDate); + if (Objects.isNull(loadPlan)) { + loadPlan = this.iLoadPlanService.findCommonLoadPlanOfMap(mapId); + } + if (loadPlan != null) { + return this.iRunPlanTemplateService.getRunPlan(loadPlan.getTemplatePlanId()); + } + return null; + } + + public void loadRunPlan(String id, RunPlanVO runPlanVO) { + RtSimulation simulation = this.simulationManager.getById(id, RtSimulation.class); + this.loadRunPlan(simulation, runPlanVO); + } + + public void loadRunPlan(RtSimulation simulation, RunPlanVO runPlanVO) { + if (runPlanVO == null) { + return; + } + AtsRunPlan atsRunPlan = AtsRunPlanBuilder.buildFrom(runPlanVO, + simulation.getSystemTime().toLocalDate(), CommonRepository.getInstanceFrom(simulation)); + AtsRepository atsRepository = AtsRepository.getInstanceFrom(simulation); + atsRepository.setRunPlan(atsRunPlan); + } + private void initCreatorPlayMember(RtSimulation rtSimulation, MapVO mapVO) { // RtSimulationMember simulationMember = rtSimulation.querySimulationMemberById("2"); // List memberList = rtSimulation.querySimulationMembersOfRole(RtSimulationMember.Role.LOWS); @@ -106,7 +152,7 @@ public class RtSimulationService { /** * 加载相关数据 */ - private void loading(RtSimulation rtSimulation, MapVO mapVO) { + private void loadingMap(RtSimulation rtSimulation, MapVO mapVO) { this.commonRepoService.loading(rtSimulation, mapVO); SrdRepository srdRepository = this.srdLogicService.loading(rtSimulation, mapVO); this.cilLogicService.loading(rtSimulation, mapVO); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdLogicService.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdLogicService.java index f9e9f443d..1d8b6ff09 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdLogicService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdLogicService.java @@ -160,6 +160,7 @@ public class SrdLogicService { float speed = srTrain.getSpeed(); TlRepository tlRepository = TlRepository.getInstanceFrom((RtSimulation) repository.getSimulation()); TlTrain tlTrain = tlRepository.getTrainById(srTrain.getId()); + tlTrain.changeGear(); float f = tlTrain.calculateF(); float a = f / (srTrain.getMass() + srTrain.getLoadMass()); float cv = (speed + a * TRAIN_RUN_RATE / 1000); // 当前速度 diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdTrainService.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdTrainService.java index d4bd8cc2b..dfcea4f79 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdTrainService.java @@ -8,15 +8,31 @@ import club.joylink.rtss.simulation.rt.SRD.bo.SrdRepository; import club.joylink.rtss.simulation.rt.SRD.bo.TrackPosition; import club.joylink.rtss.simulation.rt.TL.bo.TlRepository; import club.joylink.rtss.simulation.rt.TL.bo.TlTrain; +import club.joylink.rtss.simulation.rt.repo.CommonRepository; +import club.joylink.rtss.simulation.rt.repo.CommonSection; +import club.joylink.rtss.simulation.rt.repo.CommonSignal; import org.springframework.stereotype.Component; +import java.util.List; + @Component public class SrdTrainService { public void loadTrain(RtSimulation simulation, String trainId, boolean right, String trackId) { - SrdRepository srdRepository = simulation.getRepository(SrdRepository.NAME, SrdRepository.class); + SrdRepository srdRepository = SrdRepository.getInstanceFrom(simulation); SrTrain train = srdRepository.getTrainById(trainId); SrTrack track = srdRepository.getTrackById(trackId); - TrackPosition trackPosition = new TrackPosition(track, 5000); + CommonRepository commonRepo = CommonRepository.getInstanceFrom(simulation); + CommonSection section = commonRepo.getSectionById(trackId); + CommonSignal signal = section.queryMoreDistanceSignalOf(right); + int loadOffset = 10000; // 10m + int offset = 0; + if (signal != null) { + offset = right ? signal.getOffset() - loadOffset : signal.getOffset() + loadOffset; + } + if (offset <= 0) { + offset = right ? track.getLen() - loadOffset : loadOffset; + } + TrackPosition trackPosition = new TrackPosition(track, offset); train.initPosition(trackPosition, right); } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrAXC.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrAXC.java index a18d6498d..d28c07dda 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrAXC.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrAXC.java @@ -24,7 +24,7 @@ public class SrAXC extends SrDevice { if (this.state != state) { this.state = state; this.stateList.set(1, this.state); - this.fireWatcher(); + this.fireWatcher("state", this.state); return true; } return false; @@ -47,9 +47,8 @@ public class SrAXC extends SrDevice { @Override public void initState() { - this.updateState(OFF); this.fault = null; - this.fireWatcher(); + this.updateState(OFF); } @Override diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrPSD.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrPSD.java index a7dbce11e..19f60fd4a 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrPSD.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrPSD.java @@ -41,7 +41,7 @@ public class SrPSD extends SrDevice { if (this.state != state) { this.state = state; this.stateList.set(1, this.state); - this.fireWatcher(); + this.fireWatcher("state", this.state); return true; } return false; @@ -51,7 +51,7 @@ public class SrPSD extends SrDevice { if (this.command != command) { this.command = (command); this.stateList.set(2, this.command); - this.fireWatcher(); + this.fireWatcher("command", this.command); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSignal.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSignal.java index 6ec424706..855488bf7 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSignal.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSignal.java @@ -47,7 +47,7 @@ public class SrSignal extends SrDevice { if (this.state != state) { this.state = state; this.stateList.set(1, this.state); - this.fireWatcher(); + this.fireWatcher("state", this.state); return true; } return false; @@ -56,7 +56,7 @@ public class SrSignal extends SrDevice { private boolean updateCommand(int command) { if (this.command != command) { this.command = (command); - this.fireWatcher(); + this.fireWatcher("command", this.command); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java index a6c5ce846..a244daf35 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java @@ -36,7 +36,7 @@ public class SrSwitch extends SrDevice { if (this.state != state) { this.state = state; this.stateList.set(1, this.state); - this.fireWatcher(); + this.fireWatcher("state", this.state); return true; } return false; @@ -46,7 +46,7 @@ public class SrSwitch extends SrDevice { if (this.command != command) { this.command = (command); this.stateList.set(2, this.command); - this.fireWatcher(); + this.fireWatcher("command", this.command); return true; } return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/TL/bo/TlTrain.java b/src/main/java/club/joylink/rtss/simulation/rt/TL/bo/TlTrain.java index 77ca19107..57e71f94d 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/TL/bo/TlTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/TL/bo/TlTrain.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.rt.TL.bo; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.rt.SRD.bo.SrTrain; import lombok.Getter; @@ -17,6 +18,7 @@ public class TlTrain extends TlDevice { */ float speed; int controlPosition;//司控器手柄位置 + boolean autoGear; // 是否自动挡 int gear; // 档位(-1~9,1挡为起步挡,2~9实际为1~8挡) int throttlePosition; // 油门杆位置(0~100) int changeOverSwitch; // 换向开关(-1, 0, 1, 2:手动) @@ -28,6 +30,7 @@ public class TlTrain extends TlDevice { public TlTrain(SrTrain train) { super(train.getId()); this.srTrain = train; + this.autoGear = true; // 大铁驾驶暂时默认自动挡 } /** @@ -147,90 +150,101 @@ public class TlTrain extends TlDevice { this.singleBreak, this.autoBreak); } + public void changeGear() { + if (this.isAutoGear()) { // 自动挡,根据油门和列车速度自动调整档位 +// int throttlePosition = this.throttlePosition; +// double speedMax = GearParam.G.vmax / 3.6; +// double ts = speedMax * throttlePosition / 100; // 油门最高速度 +// int tgear = this.calculateGearBySpeed((float) ts); // 油门对应档位 +// float speed = this.srTrain.getSpeed(); +// int sgear = this.calculateGearBySpeed(speed); +// int gear = Math.min(tgear, sgear); + this.updateGear(GearParam.G.gear); + } + } + + private int calculateGearBySpeed(float speed) { + for (GearParam param : GearParam.values()) { + float vc = param.vmax / 3.6f * 0.8f; + if (speed < vc) { + return param.gear; + } + } + return GearParam.G.gear; + } + + public static enum GearParam { +// GF1(-1, 3, 25, 1.89f, 1.64f), +// G0(0, 0, 0, 0, 0), +// G1(1, 3, 30, 1.89f, 1.64f), +// G2(2, 20, 56, 1.38f, 1.15f), +// G3(3, 32, 85, 0.92f, 0.73f), +// G4(4, 48, 118, 0.75f, 0.58f), +// G5(5, 62, 150, 0.57f, 0.42f), +// G6(6, 75, 190, 0.50f, 0.31f), +// G7(7, 95, 250, 0.41f, 0.29f), +// G8(8, 120, 300, 0.35f, 0.21f), +// G9(9, 150, 360, 0.26f, 0.16f), + G(1, 3, 360, 1.69f, 0.18f) + ; + + int gear; + float vmin; + float vmax; + float amax; + float amin; + + GearParam(int gear, float vmin, float vmax, float amax, float amin) { + this.gear = gear; + this.vmin = vmin; + this.vmax = vmax; + this.amax = amax; + this.amin = amin; + } + + public float getVminMps() { + return this.vmin / 3.6f; + } + + public float getVmaxMps() { + return this.vmax / 3.6f; + } + + public static GearParam getByGear(int gear) { + for (GearParam param : GearParam.values()) { + if (param.gear == gear) { + return param; + } + } + throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception("无效的档位"); + } + } + + public static void main(String[] args) { + for (int i = 0; i <= 100; i++) { + float fx = GearParam.G.vmin + i * i / 100f * (GearParam.G.vmax - GearParam.G.vmin) / 100f; + System.out.println(fx); + } + } + public float calculateF() { float f = 0; float speed = this.srTrain.getSpeed(); // 根据列车档位和油门计算牵引力或制动力 - float vmin = 0; - float vmax = 0; - float amin = 0; - float amax = 0; - switch (this.gear) { - case -1: // 倒车:3~7km/h; 1.89 ~ 1.64 m/s^2 - vmin = 3; - vmax = 7; - amax = 1.89f; - amin = 1.64f; - break; - case 0: // 空挡 - break; - case 1: // 起步挡:3~8km/h; 1.89 ~ 1.64 m/s^2 - vmin = 3; - vmax = 8; - amax = 1.89f; - amin = 1.64f; - break; - case 2: // 1挡:5~15km/h; 1.38 ~ 1.15 m/s^2 - vmin = 5; - vmax = 15; - amax = 1.38f; - amin = 1.15f; - break; - case 3: // 2挡:9~20km/h; 0.92 ~ 0.73 m/s^2 - vmin = 9; - vmax = 20; - amax = 0.92f; - amin = 0.73f; - break; - case 4: // 3挡:13~28km/h; 0.65 ~ 0.48 m/s^2 - vmin = 13; - vmax = 28; - amax = 0.65f; - amin = 0.48f; - break; - case 5: // 4挡:20~38km/h; 0.47 ~ 0.32 m/s^2 - vmin = 20; - vmax = 38; - amax = 0.47f; - amin = 0.32f; - break; - case 6: // 5挡:26~50km/h; 0.30 ~ 0.21 m/s^2 - vmin = 26; - vmax = 50; - amax = 0.30f; - amin = 0.21f; - break; - case 7: // 6挡:33~60km/h; 0.21 ~ 0.15 m/s^2 - vmin = 33; - vmax = 60; - amax = 0.21f; - amin = 0.15f; - break; - case 8: // 7挡:52~75km/h; 0.15 ~ 0.11 m/s^2 - vmin = 52; - vmax = 75; - amax = 0.15f; - amin = 0.11f; - break; - case 9: // 8挡:60~90km/h; 0.11 ~ 0.08 m/s^2 - vmin = 60; - vmax = 90; - amax = 0.11f; - amin = 0.08f; - break; - default: - throw new RuntimeException("无效的档位"); - } + GearParam param = GearParam.G; float fk = 0; float fb = 0; + int tp = this.throttlePosition; if (this.gear != 0 && this.changeOverState != 0) { // 非空挡 - float vs = (float) ((vmin + (Float.valueOf(vmax - vmin) * this.throttlePosition / 100)) / 3.6); + float vs = (param.vmin + (((param.vmax - param.vmin) / 100f) * (tp * tp / 100f))) / 3.6f; if (speed > vs) { - fb += this.calculateAccOf(speed - vs) * this.srTrain.getTotalMass(); + fb += this.calculateAccOf(speed - vs) * this.srTrain.getMass(); } else { - fk = (float) ((amin + ((vs - vmin) / (vmax - vmin) * (amax - amin))) * this.srTrain.getTotalMass()); + fk = ((param.amin + ((vs - speed) / (param.getVmaxMps() - param.getVminMps()) * (param.amax - param.amin))) * this.srTrain.getMass()); } } + // 摩擦阻力 + fb += 0.034 * this.srTrain.getTotalMass(); // 根据制动阀计算制动力 fb += this.calculateFb(); // 计算合力 @@ -254,7 +268,7 @@ public class TlTrain extends TlDevice { * @return */ private float calculateAccOf(float v) { - return v / 20; + return v / 60; } private float calculateFriction(float speed, float mass) { diff --git a/src/main/java/club/joylink/rtss/simulation/rt/TrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/rt/TrainLoadService.java index 7ed97a9a7..017917c2f 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/TrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/TrainLoadService.java @@ -24,7 +24,7 @@ public class TrainLoadService { } private List queryLoadTrips(RtSimulation rtSimulation, LocalDateTime dateTime) { - LocalTime time = dateTime.toLocalTime(); + LocalDateTime time = dateTime; AtsRepository atsRepository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class); AtsRunPlan runPlan = atsRepository.getRunPlan(); List loadTripList = new ArrayList<>(); @@ -57,7 +57,7 @@ public class TrainLoadService { LocalDateTime systemTime = rtSimulation.convertToSystemTime(dateTime); List loadTripList = this.queryLoadTrips(rtSimulation, systemTime); loadTripList.sort(Comparator.comparing(AtsTripPlan::getStartTime)); // 按时间排序 - LocalTime time = systemTime.toLocalTime(); + LocalDateTime time = systemTime; for (AtsTripPlan tripPlan : loadTripList) { if (!time.isAfter(tripPlan.getEndTime())) {// 在车次计划中 List stationPlanList = tripPlan.getStationPlanList(); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java b/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java index c9ecf9417..c49b3ac1e 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java @@ -84,4 +84,10 @@ public class CommonRepository extends SimulationRepository { public List querySignalsByDirection(boolean right) { return this.signalMap.values().stream().filter(cs -> cs.isRight() == right).collect(Collectors.toList()); } + + public CommonStation getStationById(String id) { + CommonStation commonStation = this.stationMap.get(id); + BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(commonStation, String.format("不存在id为[%s]的车站", id)); + return commonStation; + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonSection.java b/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonSection.java index db2e8b69a..c4dd60992 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonSection.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonSection.java @@ -4,6 +4,7 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import lombok.Getter; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -96,6 +97,17 @@ public class CommonSection extends CommonDevice { .collect(Collectors.toList()); } + public CommonSignal queryMoreDistanceSignalOf(boolean right) { + List list = this.getSignalOf(right); + if (list.size() == 1) { + return list.get(0); + } else if (list.size() > 1) { + list.sort(Comparator.comparing(signal -> right ? signal.getOffset() : this.getLen() - signal.getOffset())); + return list.get(list.size() - 1); + } + return null; + } + public enum Type { /** 一般计轴区段 */ NAx,