diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java index fa6d2e5cb..983176afa 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java @@ -4,10 +4,7 @@ import club.joylink.rtss.services.training2.Training2RuleService; import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -24,15 +21,21 @@ public class TrainingRuleController { /** - * 根据地图生成 - * @param groupId - * @return + * 根据仿真生成 */ @PostMapping("{groupId}/generate") public List generateTraining(@PathVariable String groupId){ return training2RuleService.generateTrainingByRule(groupId); } + /** + * 根据地图与功能生成 + */ + @PostMapping("{mapId}/function/{functionId}") + public List generateTrainingByMapIdAndFunId(@PathVariable Long mapId, @PathVariable Long functionId) { + return training2RuleService.generateTrainingByMapIdAndFunId(mapId, functionId); + } + @PostMapping("{groupId}/test") public void test(@PathVariable String groupId){ training2RuleService.test(groupId); diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java index 4752ced6b..54a95fe9c 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java @@ -98,6 +98,17 @@ public class Training2RuleService { return Arrays.asList("生成完成!"); } + /** + * + * @param mapId + * @param functionId + * @return + */ + public List generateTrainingByMapIdAndFunId(Long mapId, Long functionId) { + String groupId = simulationService.querySimulationByMapIdAndMapFunction(mapId, functionId); + return generateTrainingByRule(groupId); + } + public void test(String groupId) { Simulation simulation = simulationManager.getById(groupId , Simulation.class); Switch aSwitch = simulation.getRepository().getByCode("W32728", Switch.class); 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 a9f560a63..f3d064fdd 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 @@ -263,11 +263,9 @@ public enum BgSceneStatusRule { @Override public String doHandle(Simulation simulation, MapElement mapElement) { Signal signal = (Signal) mapElement; - List fltRouteList = signal.getRouteList().stream().filter(Route::isFlt).collect(Collectors.toList()); - fltRouteList.forEach(route -> { - openRouteDirect(simulation, route); - route.setFleetMode(true); - }); + Route route = signal.getRouteList().get(0); + openRouteDirect(simulation, route); + route.setFleetMode(true); return getBgScene(simulation); } }, 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 124113fb8..c90c187d1 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 @@ -22,9 +22,8 @@ public enum MapDeviceRule { List stationList = simulation.getBuildParams().getMap().getGraphDataNew().getStationList() .stream().filter(s -> s.isVisible() && s.isCentralized() && s.isCiStation() && !s.isDepot()) .sorted(Comparator.comparing(MapStationNewVO::getSn)) - .map(MapStationNewVO::getCode) - .map(code -> simulation.getRepository().getByCode(code, Station.class)) - .collect(Collectors.toList()); + .map(MapStationNewVO::getCode).map(code -> simulation.getRepository().getByCode(code, Station.class)) + .filter(Station::isInterlock).collect(Collectors.toList()); return generateRandomElement(stationList, NUMBER); } }, @@ -38,7 +37,7 @@ public enum MapDeviceRule { Station firstStation = stationList.get(0); Station lastStation = stationList.get(stationList.size() - 1); List standList = simulation.getRepository().getStandList().stream().filter(stand -> { - if (stand.getStation() != null && stand.getStation().isDepot()) + if (stand.getStation() != null && (stand.getStation().isDepot() || !stand.getStation().isInterlock())) return false; // 去除第一个与最后一个站的站台 if (firstStation.equals(stand.getStation()) || lastStation.equals(stand.getStation())) { @@ -47,7 +46,6 @@ public enum MapDeviceRule { if (!stand.isVisible() || !stand.hasDoor() || stand.isSmall()) { // 特殊站台 return false; } - return true; }).sorted(Comparator.comparingInt(stand -> stand.getStation().getSn())).collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(standList, NUMBER); @@ -63,7 +61,7 @@ public enum MapDeviceRule { Station firstStation = stationList.get(0); Station lastStation = stationList.get(stationList.size() - 1); List standList = simulation.getRepository().getStandList().stream().filter(stand -> { - if (stand.getStation() != null && stand.getStation().isDepot()) + if (stand.getStation() != null && (stand.getStation().isDepot() || !stand.getStation().isInterlock())) return false; // 去除第一个与最后一个站的站台 if (firstStation.equals(stand.getStation()) || lastStation.equals(stand.getStation())) { @@ -88,10 +86,12 @@ public enum MapDeviceRule { if (route.getStart() == null || route.getStart().isVirtual()) { return false; } - if (route.getStart().getStation()!= null && route.getStart().getStation().isDepot()) { + if (route.getStart().getStation() != null + && (route.getStart().getStation().isDepot() || !route.getStart().getStation().isInterlock())) { return false; } - if (route.getStart().getDeviceStation()!= null && route.getStart().getDeviceStation().isDepot()) { + if (route.getStart().getDeviceStation() != null + && (route.getStart().getDeviceStation().isDepot() || !route.getStart().getDeviceStation().isInterlock())) { return false; } if (route.getSectionList().size() < 2) { @@ -122,6 +122,9 @@ public enum MapDeviceRule { .filter(aSwitch -> { if (aSwitch.getDeviceStation() != null && aSwitch.getDeviceStation().isDepot()) return false; + if (!aSwitch.getDeviceStation().isInterlock()) { + return false; + } if (aSwitch.isSingleLock()) { return false; } @@ -137,7 +140,7 @@ public enum MapDeviceRule { .filter(aSwitch -> { if (aSwitch.getDeviceStation() != null && aSwitch.getDeviceStation().isDepot()) return false; - if (!aSwitch.getDeviceStation().isHasControlMode()) { + if (!aSwitch.getDeviceStation().isHasControlMode() || !aSwitch.getDeviceStation().isInterlock()) { return false; } if (aSwitch.isSingleLock()) { @@ -169,14 +172,20 @@ public enum MapDeviceRule { if (route.getStart().getStation() != null && route.getStart().getStation().isDepot()) { return false; } + if (route.getStart().getStation() != null && !route.getStart().getStation().isInterlock()) { + return false; + } if (route.getStart().getDeviceStation() != null && route.getStart().getDeviceStation().isDepot()) { return false; } - if (route.isArs() || route.isGuide()) { + if (route.getStart().getDeviceStation() != null && !route.getStart().getDeviceStation().isInterlock()) { + return false; + } + if ((!route.isArs()) || route.isGuide()) { return false; } return true; - }).map(route -> route.getStart()).distinct().collect(Collectors.toList()); + }).map(Route::getStart).distinct().collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(signalList, NUMBER); } }, @@ -214,7 +223,16 @@ public enum MapDeviceRule { public List filterMapDeviceList(Simulation simulation) { //找到所有有控制模式的车站 List stationList = simulation.getRepository().getStationList().stream() - .filter(Station::isHasControlMode).collect(Collectors.toList()); + .filter(s -> s.isHasControlMode() && s.isInterlock()).collect(Collectors.toList()); + return MapDeviceRule.generateRandomElement(stationList, NUMBER); + } + }, + INTERLOCK_STATION_LIST("联锁车站列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + //找到所有有控制模式的车站 + List stationList = simulation.getRepository().getStationList().stream() + .filter(Station::isInterlock).collect(Collectors.toList()); return MapDeviceRule.generateRandomElement(stationList, NUMBER); } } @@ -262,6 +280,9 @@ public enum MapDeviceRule { if (deviceStation != null && deviceStation.isDepot()) { return false; } + if (deviceStation != null && !deviceStation.isInterlock()) { + return false; + } Section axleCounterSection = section.findAxleCounterSection(); if (axleCounterSection != null) { Station axleDeviceStation = axleCounterSection.getDeviceStation();