From 6ffb3c037b9c6b67c7137227e73fce4a47b0abe3 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 19 Dec 2022 10:10:08 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=8E=A7=E5=88=B6=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E7=BB=93=E6=9E=9C=E6=B6=88=E6=81=AF=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATS/service/AtsStationService.java | 26 +- .../cbtc/data/vo/ControlTransferResultVO.java | 46 ++ .../vo/training2/rule/BgSceneStatusRule.java | 39 +- .../rtss/vo/training2/rule/MapDeviceRule.java | 453 +++++++++++++++--- .../vo/training2/rule/MapElementRule.java | 55 ++- .../vo/training2/rule/MapLocationRule.java | 3 +- 6 files changed, 506 insertions(+), 116 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ControlTransferResultVO.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java index fc4451130..648fb90d3 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java @@ -11,6 +11,7 @@ import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.status.StationStatus; import club.joylink.rtss.simulation.cbtc.data.support.StationTurnBackStrategyOption; import club.joylink.rtss.simulation.cbtc.data.vo.ControlTransferReplyVO; +import club.joylink.rtss.simulation.cbtc.data.vo.ControlTransferResultVO; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; @@ -185,24 +186,20 @@ public class AtsStationService { if (CollectionUtils.isEmpty(replyVOList)) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "回复结果列表不能为空"); } - Map resultMap = null; - SimulationMember applicant = null; + List resultVOList = new ArrayList<>(replyVOList.size()); for (ControlTransferReplyVO reply : replyVOList) { Station station = simulation.getRepository().getByCode(reply.getStationCode(), Station.class); if (station.isControlTransferApplying()) { if (reply.isAgree()) { station.setControlMode(controlMode); } - resultMap = new HashMap<>(); - applicant = station.getApplicant(); - resultMap.put("stationCode", station.getCode()); - resultMap.put("applicantId", applicant.getId()); - resultMap.put("apply2TheControlMode", station.getApply2TheControlMode()); - resultMap.put("status", reply.isAgree()); + resultVOList.add(new ControlTransferResultVO(station, reply.isAgree())); station.cancelControlTransferApplication(); - sendHandlerMessage(simulation, applicant, resultMap); } } + if (!CollectionUtils.isEmpty(resultVOList)) { + resultVOList.forEach(vo -> sendHandlerMessage(simulation.getId(), vo)); + } } /** @@ -567,13 +564,12 @@ public class AtsStationService { /** * 发送车站转换结果 * - * @param simulation 仿真 - * @param applicant 申请者 - * @param data 转换结果 + * @param group 仿真 + * @param vo 转换结果 */ - private void sendHandlerMessage(Simulation simulation, SimulationMember applicant, Map data) { + private void sendHandlerMessage(String group, ControlTransferResultVO vo) { SocketMessageVO> messageVO = - SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Transfer_Result, simulation.getId(), data); - stompMessageService.sendToUser(Set.of(applicant.getUserId()), messageVO); + SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Transfer_Result, group, vo.getData()); + stompMessageService.sendToUser(Set.of(vo.getUserId()), messageVO); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ControlTransferResultVO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ControlTransferResultVO.java new file mode 100644 index 000000000..6898982c9 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/ControlTransferResultVO.java @@ -0,0 +1,46 @@ +package club.joylink.rtss.simulation.cbtc.data.vo; + +import club.joylink.rtss.simulation.cbtc.data.map.Station; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.HashMap; +import java.util.Map; + +/** + * 控制权转换结果信息 + */ +@Getter +@Setter +@NoArgsConstructor +public class ControlTransferResultVO { + + private String stationCode; + + private String applicantId; + + private String userId; + + private Station.ControlMode apply2TheControlMode; + + private boolean status; + + public ControlTransferResultVO(Station station, boolean agree) { + this.status = agree; + this.stationCode = station.getCode(); + this.applicantId = station.getApplicantId(); + this.userId = station.getApplicant().getUserId(); + this.apply2TheControlMode = station.getApply2TheControlMode(); + } + + public Map getData() { + Map resultMap = new HashMap<>(); + resultMap.put("stationCode", stationCode); + resultMap.put("applicantId", applicantId); + resultMap.put("apply2TheControlMode", apply2TheControlMode); + resultMap.put("status", status); + return resultMap; + } +} 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 e54da6935..7c972812c 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 @@ -83,7 +83,6 @@ public enum BgSceneStatusRule { return getBgScene(simulation); } }, - SWITCH_NP_NB_BG_SCENE("宁波道岔定位背景") { @Override public String doHandle(Simulation simulation, MapElement mapElement) { @@ -214,7 +213,12 @@ public enum BgSceneStatusRule { @Override public String doHandle(Simulation simulation, MapElement mapElement) { Signal signal = (Signal) mapElement; - Route route = signal.getRouteList().get(0); + Route route = signal.getRouteList().stream() + .filter(r -> r.getSwitchList().stream().allMatch(switchElement -> switchElement.isNormal())) + .findFirst().orElse(null); + if (route == null) { + throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error); + } openRouteDirect(simulation, route); return getBgScene(simulation); } @@ -295,6 +299,21 @@ public enum BgSceneStatusRule { return getBgScene(simulation); } }, + SIGNAL_HUMAN_RELEASE_BG_SCENE("信号机总人解背景"){ + @Override + public String doHandle(Simulation simulation, MapElement mapElement) { + Signal signal = (Signal) mapElement; + Route route = signal.getRouteList().get(0); + openRouteDirect(simulation, route); + closeSignalDirectly(route.getStart()); + // 添加信号机 + 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); + } + }, /** * 区段区故解背景 */ @@ -716,4 +735,20 @@ public enum BgSceneStatusRule { repository.addOnlineTrain(train); repository.addTrainInfo(trainInfo); } + + /** + * 直接关灯(默认逻辑点灯) + */ + private static void closeSignalDirectly(Signal signal) { + VirtualRealitySignal virtualSignal = signal.getVirtualSignal(); + signal.changeLightType(true); + SignalAspect defaultAspect = virtualSignal.getModel().getDefaultAspect(); + if (signal.isLogicLight()) { + virtualSignal.control(SignalAspect.No); + } else { + virtualSignal.control(defaultAspect); + } + virtualSignal.finish(); + signal.setAspect(defaultAspect); + } } 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 9b44df51a..54a00b0e7 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 @@ -1,5 +1,6 @@ package club.joylink.rtss.vo.training2.rule; +import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; @@ -123,6 +124,23 @@ public enum MapDeviceRule { return MapDeviceRule.generateRandomElement(standList, NUMBER); } }, + STAND_NO_DEPOT_LIST("非停车场站台列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List standList = simulation.getRepository().getStandList().stream().filter(stand -> { + if (stand.getStation() != null && stand.getStation().isDepot()) + return false; + if (!stand.isVisible() || !stand.hasDoor() || stand.isSmall()) { // 特殊站台 + return false; + } + if (!stand.getStation().isHasControlMode()) { + return false; + } + return true; + }).sorted(Comparator.comparingInt(stand -> stand.getStation().getSn())).collect(Collectors.toList()); + return MapDeviceRule.generateRandomElement(standList, NUMBER); + } + }, ROUTE_LIST("进路列表") { @Override public List filterMapDeviceList(Simulation simulation) { @@ -158,25 +176,6 @@ public enum MapDeviceRule { return generateRandomElement(routeList, NUMBER); } }, - ROUTE_ATP_LIST("ATP进路列表") { - @Override - public List filterMapDeviceList(Simulation simulation) { - List routeList = simulation.getRepository().getRouteList().stream().filter(route -> { - if (route.getStart() == null || route.getStart().isVirtual()) { - return false; - } - // 获取集中站的信息 - if (route.getInterlockStation() == null || !route.getInterlockStation().isCentralized()) { - return false; - } - if (!route.isAtp()) { - return false; - } - return true; - }).collect(Collectors.toList()); - return generateRandomElement(routeList, NUMBER); - } - }, ROUTE_FIRST_STATION_LIST("获取第一个站进路列表") { @Override public List filterMapDeviceList(Simulation simulation) { @@ -220,24 +219,6 @@ public enum MapDeviceRule { return generateRandomElement(switchList, 1); } }, - SWITCH_ATP_LIST("集中站道岔列表") { - @Override - public List filterMapDeviceList(Simulation simulation) { - List switchList = simulation.getRepository().getSwitchList().stream() - .filter(aSwitch -> { - if (aSwitch.getDeviceStation() != null && aSwitch.getDeviceStation().isDepot()) - return false; - if (!aSwitch.getDeviceStation().isCentralized()) { - return false; - } - if (aSwitch.isSingleLock()) { - return false; - } - return true; - }).collect(Collectors.toList()); - return generateRandomElement(switchList, 1); - } - }, CONTROL_STATION_SWITCH_LIST("控制模式车站的道岔列表") { @Override public List filterMapDeviceList(Simulation simulation) { @@ -309,24 +290,6 @@ public enum MapDeviceRule { return MapDeviceRule.generateRandomElement(signalList, NUMBER); } }, - SIGNAL_ATP_LIST("集中站信号机列表") { - @Override - public List filterMapDeviceList(Simulation simulation) { - List signalList = simulation.getRepository().getSignalList().stream().filter(signal -> { - if (signal.getDeviceStation() == null) { - return false; - } - if (!signal.getDeviceStation().isCentralized()) { - return false; - } - if (signal.getRouteList().isEmpty()) { - return false; - } - return true; - }).collect(Collectors.toList()); - return generateRandomElement(signalList, NUMBER); - } - }, SIGNAL_FIRST_STATION_LIST("获取第一个站信号机列表") { @Override public List filterMapDeviceList(Simulation simulation) { @@ -349,20 +312,6 @@ public enum MapDeviceRule { return generateRandomElement(sectionList, 1); } }, - SECTION_LOGIC_LIST("逻辑区段列表") { - @Override - public List
filterMapDeviceList(Simulation simulation) { - List
sectionList = querySectionListByFunction(simulation, Section::isLogicSection); - return generateRandomElement(sectionList, NUMBER); - } - }, - SECTION_PHYSICAL_LIST("物理区段列表") { - @Override - public List
filterMapDeviceList(Simulation simulation) { - List
sectionList = querySectionListByFunction(simulation, Section::isAxleCounterSection); - return generateRandomElement(sectionList, NUMBER); - } - }, SECTION_AXLE_COUNTER_LIST("道岔计轴区段列表") { @Override public List
filterMapDeviceList(Simulation simulation) { @@ -426,6 +375,226 @@ public enum MapDeviceRule { .filter(Station::isInterlock).collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(stationList, NUMBER); } + }, + + /**************************************** 车站列表 *********************************************/ + STATION_NORMAL_LIST("车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalStationList(simulation, null), NUMBER); + } + }, + STATION_CONTROL_LIST("控制模式车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + //找到所有有控制模式的车站 + List stationList = queryNormalStationList(simulation, s -> s.isHasControlMode() && s.isInterlock()); + return MapDeviceRule.generateRandomElement(stationList, NUMBER); + } + }, + STATION_INTERLOCK_LIST("联锁车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List stationList = queryNormalStationList(simulation, Station::isInterlock); + return MapDeviceRule.generateRandomElement(stationList, NUMBER); + } + }, + STATION_TURN_BACK_LIST("折返车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List stationList = queryNormalStationList(simulation, Station::isTurnBack); + return generateRandomElement(stationList, NUMBER); + } + }, + STATION_CENTRALIZED_LIST("集中车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List stationList = queryNormalStationList(simulation, Station::isCentralized); + return generateRandomElement(stationList, NUMBER); + } + }, + STATION_INTERLOCK_CENTRALIZED_LIST("联锁集中车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List stationList = queryNormalStationList(simulation, s -> s.isInterlock() && s.isCentralized()); + return generateRandomElement(stationList, NUMBER); + } + }, + /**************************************** 站台列表 *********************************************/ + STAND_NORMAL_LIST("站台列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return MapDeviceRule.generateRandomElement(queryNormalStandList(simulation, null), NUMBER); + } + }, + STAND_CONTROL_LIST("控制模式车站站台列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List standList = queryNormalStandList(simulation, + stand -> stand.getStation().isHasControlMode() && stand.getStation().isInterlock()); + return MapDeviceRule.generateRandomElement(standList, NUMBER); + } + }, + STAND_CENTRALIZED_LIST("集中车站站台列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List standList = queryNormalStandList(simulation, stand -> stand.getStation().isCentralized()); + return MapDeviceRule.generateRandomElement(standList, NUMBER); + } + }, + STAND_INTERLOCK_CENTRALIZED_LIST("联锁集中车站站台列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + List standList = queryNormalStandList(simulation, + stand -> stand.getStation().isCentralized() && stand.getStation().isInterlock()); + return MapDeviceRule.generateRandomElement(standList, NUMBER); + } + }, + /**************************************** 区段列表 *********************************************/ + SECTION_NORMAL_LIST("区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + List
sectionList = queryNormalSectionList(simulation, section -> { + // 普通区段排除道岔区段 + if (section.isSwitchTrack() || section.isSwitchAxleCounterSection() || section.isLogicSection() || section.isCross()) { + return false; + } + return true; + }); + return generateRandomElement(sectionList, 1); + } + }, + SECTION_LOGIC_LIST("逻辑区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return generateRandomElement(querySectionListByFunction(simulation, Section::isLogicSection), NUMBER); + } + }, + SECTION_PHYSICAL_LIST("物理区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return generateRandomElement(querySectionListByFunction(simulation, Section::isAxleCounterSection), NUMBER); + } + }, + SECTION_SWITCH_TRACK_LIST("道岔物理区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return generateRandomElement(querySectionListByFunction(simulation, Section::isSwitchTrack), NUMBER); + } + }, + SECTION_SWITCH_AXLE_TRACK_LIST("道岔计轴区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return generateRandomElement(querySectionListByFunction(simulation,s -> s.isAxleCounter() && !s.isSwitchAxleCounterSection()), NUMBER); + } + }, + SECTION_CROSS_LIST("岔心区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return generateRandomElement(querySectionListByFunction(simulation, Section::isCross), NUMBER); + } + }, + SECTION_STAND_TRACK_LIST("站台轨区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return MapDeviceRule.generateRandomElement(querySectionListByFunction(simulation, Section::isStandTrack), NUMBER); + } + }, + SECTION_STAND_TURN_BACK_TRACK_LIST("折返站台轨区段列表") { + @Override + public List
filterMapDeviceList(Simulation simulation) { + return MapDeviceRule.generateRandomElement( + querySectionListByFunction(simulation, s -> s.isStandTrack() && s.isTurnBackTrack()), NUMBER); + } + }, + /**************************************** 信号机列表 *********************************************/ + SIGNAL_NORMAL_LIST("信号机列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSignalList(simulation, signal -> { + // 获取存在全部定位的进路信号机 + boolean isExistNormalRoute = signal.getRouteList().stream().allMatch(route -> { + if (route.getSwitchList().stream().allMatch(switchElement -> !switchElement.isNormal())) { + return false; + } + return true; + }); + if (!isExistNormalRoute) { + return false; + } + return Signal.SignalType.DEPARTURE.equals(signal.getType()) || Signal.SignalType.PROTECTION.equals(signal.getType()); + }), NUMBER); + } + }, + SIGNAL_CI_LIST("联锁自动信号机列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSignalList(simulation, signal -> { + if (signal.getRouteList().stream().noneMatch(Route::isArs)) { + return false; + } + if (signal.getRouteList().stream().noneMatch(Route::isFlt)) { + return false; + } + return signal.getStation().isInterlock(); + }), NUMBER); + } + }, + SIGNAL_GUIDE_LIST("引导信号机列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSignalList(simulation, signal -> signal.getRouteList().stream().anyMatch(Route::isGuide)), NUMBER); + } + }, + SIGNAL_ATP_LIST("集中站信号机列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSignalList(simulation, signal -> signal.getStation().isCentralized()), NUMBER); + } + }, + /**************************************** 道岔列表 *********************************************/ + SWITCH_NORMAL_LIST("道岔列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSwitchList(simulation, s -> !s.isSingleLock()), NUMBER); + } + }, + SWITCH_ATP_LIST("集中站道岔列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSwitchList(simulation, s -> s.getDeviceStation().isCentralized()), NUMBER); + } + }, + SWITCH_CONTROL_LIST("控制模式车站道岔列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSwitchList(simulation, s -> s.getDeviceStation().isHasControlMode()), NUMBER); + } + }, + /**************************************** 进路列表 *********************************************/ + ROUTE_NORMAL_LIST("进路列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return MapDeviceRule.generateRandomElement(queryNormalRouteList(simulation, route -> { + return !route.isTurnBack() && !route.isGuide() && !route.isPassRoute() && !route.isLongShuntingRoute(); + }), NUMBER); + } + }, + ROUTE_ATP_LIST("ATP进路列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalRouteList(simulation, route ->{ + return route.getInterlockStation().isCentralized() && route.isAtp() && !route.isGuide(); + }), NUMBER); + } + }, + ROUTE_GUIDE_LIST("引导进路列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalRouteList(simulation, route -> { + return route.getStart().isCallOn() && route.isGuide(); + }), NUMBER); + } } ; @@ -500,4 +669,150 @@ public enum MapDeviceRule { return true; }).collect(Collectors.toList()); } + + /** + * 筛选普通车站列表 + * @param simulation 仿真 + * @param filterFun 筛选条件 + * @return 车站列表 + */ + private static List queryNormalStationList(Simulation simulation, Function filterFun) { + return simulation.getRepository().getStationList().stream() + .filter(station -> { + if (station.isDepot()) { + return false; + } + if (filterFun != null) { + return filterFun.apply(station); + } + return true; + }).sorted(Comparator.comparingInt(Station::getSn)).collect(Collectors.toList()); + } + + /** + * 筛选普通站台列表 + * @param simulation 仿真 + * @param filterFun 筛选条件 + * @return 站台列表 + */ + private static List queryNormalStandList(Simulation simulation, Function filterFun) { + return simulation.getRepository().getStandList().stream() + .filter(stand -> { + if (stand.getStation() == null || stand.getStation().isDepot()) { + return false; + } + if (!stand.isVisible() || !stand.hasDoor() || stand.isSmall()) { // 特殊站台 + return false; + } + if (filterFun != null) { + return filterFun.apply(stand); + } + return true; + }).sorted(Comparator.comparingInt(s -> s.getStation().getSn())).collect(Collectors.toList()); + } + + /** + * 筛选普通区段列表 + * @param simulation 仿真 + * @param filterFun 筛选条件 + * @return 区段列表 + */ + private static List
queryNormalSectionList(Simulation simulation, Function filterFun) { + return simulation.getRepository().getSectionList().stream().filter(section -> { + Station deviceStation = section.getDeviceStation(); + if (deviceStation != null && deviceStation.isDepot()) { + return false; + } + Section axleCounterSection = section.findAxleCounterSection(); + if (axleCounterSection != null) { + Station axleDeviceStation = axleCounterSection.getDeviceStation(); + if (axleDeviceStation != null && axleDeviceStation.isDepot()) { + return false; + } + } + if(StringUtils.isEmpty(section.getName())) { + return false; + } + if (filterFun != null) { + if (section.getParent() != null && section.getParent().isCross()) { + return false; + } + return filterFun.apply(section); + } + return true; + }).sorted(Comparator.comparingInt(s -> s.getDeviceStation().getSn())).collect(Collectors.toList()); + } + + /** + * 筛选普通信号机列表 + * @param simulation 仿真 + * @param filterFun 过滤条件 + * @return 信号机列表 + */ + private static List queryNormalSignalList(Simulation simulation, Function filterFun) { + return simulation.getRepository().getSignalList().stream().filter(signal -> { + if (signal.isVirtual()) { + return false; + } + if (signal.getStation() == null || signal.getStation().isDepot()) { + return false; + } + if (CollectionUtils.isEmpty(signal.getRouteList())) { + return false; + } + if (filterFun != null) { + return filterFun.apply(signal); + } + return true; + }).sorted(Comparator.comparingInt(s -> s.getStation().getSn())).collect(Collectors.toList()); + } + + /** + * 筛选普通道岔列表 + * @param simulation 仿真 + * @param filterFun 过滤条件 + * @return 道岔列表 + */ + private static List queryNormalSwitchList(Simulation simulation, Function filterFun) { + return simulation.getRepository().getSwitchList().stream().filter(aSwitch -> { + if (aSwitch.getDeviceStation() != null && aSwitch.getDeviceStation().isDepot()) { + return false; + } + if (filterFun != null) { + return filterFun.apply(aSwitch); + } + return true; + }).sorted(Comparator.comparingInt(s -> s.getDeviceStation().getSn())).collect(Collectors.toList()); + } + + /** + * 筛选普通进路列表 + * @param simulation 仿真 + * @param filterFun 过滤条件 + * @return 进路列表 + */ + private static List queryNormalRouteList(Simulation simulation, Function filterFun) { + return simulation.getRepository().getRouteList().stream().filter(route -> { + if (route.getInterlockStation().isDepot()) { // 停车场进路排除 + return false; + } + if (route.getStart() == null || route.getDestination() == null) { + return false; + } + if (route.getStart().isVirtual()) { + return false; + } + if (route.getStart().getStation() == null || route.getStart().getStation().isDepot()) { + return false; + } + // 排除道岔默认单锁的进路 + if (route.getSwitchList().stream().anyMatch(switchElement -> !switchElement.isNormal())) { + return false; + } + if (filterFun != null) { + return filterFun.apply(route); + } + return true; + }).sorted(Comparator.comparingInt(r -> r.getInterlockStation().getSn())).collect(Collectors.toList()); + } } 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 3d450e119..bd8614b93 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 @@ -16,22 +16,23 @@ public abstract class MapElementRule { * @return 车站信息 */ public static Station queryStation(Object mapElement) { - if (mapElement instanceof Route) { - return ((Route) mapElement).getInterlockStation(); - } else if (mapElement instanceof Signal) { - return ((Signal) mapElement).getDeviceStation(); - } else if (mapElement instanceof Station) { + if (mapElement instanceof Station) { return (Station) mapElement; - } else if (mapElement instanceof Switch) { - return ((Switch) mapElement).getDeviceStation(); + } else if (mapElement instanceof Stand) { + return ((Stand) mapElement).getStation(); } else if (mapElement instanceof Section) { Section section = (Section) mapElement; if (section.getStation() != null) { return section.getStation(); + } else if (section.getDeviceStation() != null) { + return section.getDeviceStation(); } - return section.getDeviceStation(); - } else if (mapElement instanceof Stand) { - return ((Stand) mapElement).getDeviceStation(); + } else if (mapElement instanceof Signal) { + return ((Signal) mapElement).getStation(); + } else if (mapElement instanceof Switch) { + return ((Switch) mapElement).getDeviceStation(); + } else if (mapElement instanceof Route) { + return ((Route) mapElement).getInterlockStation(); } throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error); } @@ -43,33 +44,31 @@ public abstract class MapElementRule { */ public static Signal querySignal(Object mapElement) { if (mapElement instanceof Route) { - Route route = (Route) mapElement; - return route.getStart(); + return ((Route) mapElement).getStart(); } else if (mapElement instanceof Signal) { return (Signal) mapElement; } else if (mapElement instanceof Section) { - Section section = (Section) mapElement; - boolean flag = true; - do { - if (section.getSignalToLeft() != null) { - return section.getSignalToLeft(); - } else if (section.getSignalToRight() != null) { - return section.getSignalToRight(); - } - if (section.getParent() != null) { - section = section.getParent(); - } else { - flag = false; - } - } while (flag); + return querySectionSignal((Section) mapElement); } else if (mapElement instanceof Stand) { - Section section = ((Stand) mapElement).getSection(); + return querySectionSignal(((Stand) mapElement).getSection()); + } + throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error); + } + + private static Signal querySectionSignal(Section section) { + boolean flag = true; + do { if (section.getSignalToLeft() != null) { return section.getSignalToLeft(); } else if (section.getSignalToRight() != null) { return section.getSignalToRight(); } - } + if (section.getParent() != null) { + section = section.getParent(); + } else { + flag = false; + } + } while (flag); throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error); } } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapLocationRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapLocationRule.java index 4bccbf946..1a8a0710d 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapLocationRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapLocationRule.java @@ -77,8 +77,7 @@ public enum MapLocationRule { SWITCH_MAP_LOCATION("使用道岔定位") { @Override public String doHandle(Simulation simulation, MapElement mapElement) { - Switch aSwitch = (Switch) mapElement; - return MapLocationRule.SECTION_MAP_LOCATION.doHandle(simulation, aSwitch.getA()); + return MapLocationRule.SECTION_MAP_LOCATION.doHandle(simulation, ((Switch) mapElement).getA()); } } ;