From 1428cf38f517153b8923d1d0bda79cc7b6d12020 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 2 Dec 2022 18:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E7=A7=8D=E7=B1=BB=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vo/training2/rule/BgSceneStatusRule.java | 142 ++++++++++++++++++ .../rtss/vo/training2/rule/MapDeviceRule.java | 34 ++++- .../vo/training2/rule/MapElementRule.java | 2 + .../rtss/vo/training2/rule/MemberRule.java | 2 +- .../rtss/vo/training2/rule/OperationRule.java | 2 +- .../vo/training2/rule/PropertyValueRule.java | 17 ++- .../rtss/vo/training2/rule/ValuableRule.java | 2 +- 7 files changed, 189 insertions(+), 12 deletions(-) diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java index da1d2d6ab..41126b663 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/BgSceneStatusRule.java @@ -1,13 +1,19 @@ package club.joylink.rtss.vo.training2.rule; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.constant.RunLevel; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication; +import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.storage.StorageSimulation; +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.VirtualRealitySignal; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.util.JsonUtils; import lombok.Getter; import org.springframework.util.CollectionUtils; @@ -133,6 +139,69 @@ public enum BgSceneStatusRule { return getBgScene(simulation); } }, + /** + * 信号机重开背景 + */ + SIGNAL_REOPEN_BG_SCENE("信号机重开背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Signal signal = (Signal) mapElement; + Route route = signal.getRouteList().get(0); + openRouteDirect(simulation, route); + VirtualRealitySignal vrSignal = signal.getVirtualSignal(); + signal.setForbidden(true); + signal.setAspect(signal.getDefaultAspect()); + vrSignal.setAspect(signal.getDefaultAspect()); + return getBgScene(simulation); + } + }, + /** + * 信号机关灯背景 + */ + SIGNAL_CLOSE_BG_SCENE("信号机关灯背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Signal signal = (Signal) mapElement; + Route route = signal.getRouteList().get(0); + openRouteDirect(simulation, route); + return getBgScene(simulation); + } + }, + /** + * 信号机引导背景 + */ + SIGNAL_GUIDE_BG_SCENE("信号机引导背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Signal signal = (Signal) mapElement; + // 开放进路 + Route route = signal.getRouteList().get(0); + openRouteDirect(simulation, route); + // 关闭信号机 + VirtualRealitySignal vrSignal = signal.getVirtualSignal(); + signal.setForbidden(true); + signal.setAspect(signal.getDefaultAspect()); + vrSignal.setAspect(signal.getDefaultAspect()); + // 添加信号机 + VirtualRealityTrain train = (VirtualRealityTrain) simulation.getRepository().getVrDeviceMap().values().stream() + .filter(o -> o instanceof VirtualRealityTrain).findFirst().get(); + Section section = route.getStart().getSection(); + trainOnline(simulation, train, section, route.isRight()); + return getBgScene(simulation); + } + }, + /** + * 进路交自动控背景 + */ + SIGNAL_ROUTE_AUTO_SET_BG_SCENE("进路交自动控背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Signal signal = (Signal) mapElement; + Route route = signal.getRouteList().get(0); + route.setAtsControl(false); + return getBgScene(simulation); + } + }, /** * 区段区故解背景 */ @@ -144,6 +213,65 @@ public enum BgSceneStatusRule { return getBgScene(simulation); } }, + /** + * 区段故障解锁背景 + */ + SECTION_FAULT_UNLOCK_BG_SCENE("区段故障解锁背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Section section = (Section) mapElement; + section.setRouteLock(true); + section.setLockRight(true); + if(!CollectionUtils.isEmpty(section.getLogicList())) { + section.getLogicList().forEach(s -> { + s.setRouteLock(true); + s.setLockRight(true); + }); + } + return getBgScene(simulation); + } + }, + /** + * 区段激活背景 + */ + SECTION_ACTIVE_BG_SCENE("区段激活背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Section section = (Section) mapElement; + Section axleSection = section; + if (Objects.nonNull(section.getParent())) { + axleSection = section.getParent(); + } + axleSection.setCutOff(true); + for (Section logic : axleSection.getLogicList()) { + logic.setCutOff(true); + } + return null; + } + }, + /** + * 区段取消限速背景 + */ + SECTION_CANCEL_LIMIT_SPEED_BG_SCENE("区段取消限速背景") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Section section = (Section) mapElement; + section.setSpeedUpLimit(5); + return null; + } + }, + SECTION_CONFIRM_AXIS_VALID_BG_SCENE("") { + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Section section = (Section) mapElement; + if (Objects.nonNull(section.getParent())) { + section.getParent().judgeAsNctOccupied(simulation); + } else { + section.judgeAsNctOccupied(simulation); + } + return null; + } + }, /** * 车站上电解锁 */ @@ -321,4 +449,18 @@ public enum BgSceneStatusRule { } } } + + /** + * 列车上线 + */ + private static void trainOnline(Simulation simulation, VirtualRealityTrain train, Section section, boolean right) { + //重叠检测 + SectionPosition headPosition = new SectionPosition(section, section.getStopPointByDirection(right)); + train.initManualTrain(headPosition, right); + SimulationDataRepository repository = simulation.getRepository(); + TrainInfo trainInfo = TrainInfo.constructManualTrain(train); + trainInfo.tracking(train); + repository.addOnlineTrain(train); + repository.addTrainInfo(trainInfo); + } } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java index e832b27de..bf57eaeaf 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java @@ -2,6 +2,7 @@ package club.joylink.rtss.vo.training2.rule; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.map.*; +import club.joylink.rtss.vo.map.graph.MapStationNewVO; import lombok.Getter; import org.springframework.util.CollectionUtils; @@ -21,8 +22,9 @@ public enum MapDeviceRule { if (!isMETRO) { return List.of(); } - List routeList = simulation.getRepository().getRouteList().stream() - .filter(r -> Signal.SignalType.PROTECTION.equals(r.getStart().getType())).collect(Collectors.toList()); + List signalList = METRO_DEPARTURE_SIGNAL_LIST.filterMapDeviceList(simulation); + List routeList = new ArrayList<>(); + signalList.forEach(s -> routeList.addAll(s.getRouteList())); return generateRandomElement(routeList, 2); } }, @@ -41,7 +43,10 @@ public enum MapDeviceRule { STATION_LIST("车站列表") { @Override public List filterMapDeviceList(Simulation simulation) { - List stationList = simulation.getRepository().getStationList(); + List stationList = simulation.getBuildParams().getMap().getGraphDataNew().getStationList() + .stream().filter(s -> s.isVisible() && s.isCentralized() && s.isCiStation()).map(MapStationNewVO::getCode) + .map(code -> simulation.getRepository().getByCode(code, Station.class)) + .collect(Collectors.toList()); return generateRandomElement(stationList, 1); } }, @@ -59,6 +64,14 @@ public enum MapDeviceRule { return generateRandomElement(signalList, 2); } }, + METRO_DEPARTURE_SIGNAL_LIST("地铁信号机列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List signalList = simulation.getRepository().getStandList().stream().map(s -> s.getSection().getSignalToRight()) + .filter(s -> s != null && !CollectionUtils.isEmpty(s.getRouteList())).collect(Collectors.toList()); + return generateRandomElement(signalList, 2); + } + }, RAILWAY_DEPARTURE_SIGNAL_LIST("大铁发车信号机列表") { @Override public List filterMapDeviceList(Simulation simulation) { @@ -70,8 +83,11 @@ public enum MapDeviceRule { SECTION_LIST("普通区段列表") { @Override public List
filterMapDeviceList(Simulation simulation) { - List
sectionList = simulation.getRepository().getSectionList().stream() - .filter(s -> s.getParent() == null).collect(Collectors.toList()); + List signalList = simulation.getRepository().getStandList().stream().map(s -> s.getSection().getSignalToRight()) + .filter(s -> s != null && !CollectionUtils.isEmpty(s.getRouteList())).collect(Collectors.toList()); + signalList = generateRandomElement(signalList, 2); + List
sectionList = new ArrayList<>(100); + signalList.forEach(s -> s.getRouteList().forEach(r -> sectionList.addAll(r.getSectionList()))); return generateRandomElement(sectionList, 2); } }, @@ -82,6 +98,14 @@ public enum MapDeviceRule { .filter(Section::isSwitchTrack).collect(Collectors.toList()); return generateRandomElement(sectionList, 2); } + }, + SECTION_ROUTE_LIST("") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + List signalList = simulation.getRepository().getStandList().stream() + .map(s -> s.getSection().getSignalToRight()).filter(s -> s != null && !CollectionUtils.isEmpty(s.getRouteList())).collect(Collectors.toList()); + return null; + } } ; diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapElementRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapElementRule.java index f72ec64ba..95e6811c6 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapElementRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapElementRule.java @@ -34,6 +34,8 @@ public abstract class MapElementRule { return (Station) mapElement; } else if (mapElement instanceof Switch) { return ((Switch) mapElement).getDeviceStation(); + } else if (mapElement instanceof Section) { + return ((Section) mapElement).getDeviceStation(); } throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error); } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java index ef6996a6e..c521d8633 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java @@ -40,7 +40,7 @@ public class MemberRule { /** * 所属设备编码 */ - String code = deviceCodeRule.resolve(simulation, mapElement); + String code = String.valueOf(deviceCodeRule.resolve(simulation, mapElement)); List resultMemberList = memberList.stream().filter(member -> member.getDevice() != null && member.getDevice().getCode().equals(code)).collect(Collectors.toList()); if (CollectionUtils.isEmpty(resultMemberList)) { diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java index 93728e914..d8db2166f 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java @@ -97,7 +97,7 @@ public abstract class OperationRule { Operation2VO.ClientOperation2VO operation2 = new Operation2VO.ClientOperation2VO(); operation2.setId(this.getId()); if (PropertyValueRule.match(deviceCode)) { // 设备规则编码设置 - operation2.setDeviceCode(PropertyValueRule.valueOf(deviceCode).resolve(simulation, mapElement)); + operation2.setDeviceCode(String.valueOf(PropertyValueRule.valueOf(deviceCode).resolve(simulation, mapElement))); } else { operation2.setDeviceCode(""); } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java index 53a6728c8..d123ca852 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java @@ -112,7 +112,16 @@ public enum PropertyValueRule { } return buttonVO.getCode(); } - }; + }, + SIGNAL_FIRST_ROUTE_CODE_LIST("信号机关联的第一条进路编码列表") { + @Override + public Object resolve(Simulation simulation, Object mapElement) { + Signal signal = (Signal) mapElement; + Route route = signal.getRouteList().get(0); + return List.of(route.getCode()); + } + } + ; private final String description; @@ -122,7 +131,7 @@ public enum PropertyValueRule { this.description = description; } - public abstract String resolve(Simulation simulation, Object mapElement); + public abstract Object resolve(Simulation simulation, Object mapElement); public static boolean match(String ruleValue) { return Arrays.stream(PropertyValueRule.values()).anyMatch(r -> r.name().equals(ruleValue)); @@ -142,11 +151,11 @@ public enum PropertyValueRule { } String result = contentFormat; String propertyEnum; - String propertyValue; + Object propertyValue; for (String property : propertySet) { propertyEnum = property.replaceAll("[\\{\\}]", ""); propertyValue = PropertyValueRule.valueOf(propertyEnum).resolve(simulation, mapElement); - result = result.replace(property, propertyValue); + result = result.replace(property, String.valueOf(propertyValue)); } return result; } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/ValuableRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/ValuableRule.java index fb2c17d4f..b9a49fb38 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/ValuableRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/ValuableRule.java @@ -35,7 +35,7 @@ public abstract class ValuableRule { public StatusValueVO convert2BO(Simulation simulation, Object mapElement) { StatusValueVO valuable = JsonUtils.read(JsonUtils.writeValueAsString(this.getValuableVO()), StatusValueVO.class); if (elementCodeRule != null) { - valuable.setElementCode(elementCodeRule.resolve(simulation, mapElement)); + valuable.setElementCode(String.valueOf(elementCodeRule.resolve(simulation, mapElement))); } return valuable; }