diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java index c65031b3d..6cff0948a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/CtcRepository.java @@ -16,6 +16,7 @@ import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import lombok.Getter; import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; @@ -285,10 +286,15 @@ public class CtcRepository { return routeSequence.getLine(tripNumber, departure); } - public RouteSequence.Line getRouteSequenceLine(String stationCode, String tripNumber, String routeCode) { + public RouteSequence.Line findRouteSequenceLine(String stationCode, String tripNumber, String routeCode) { RouteSequence routeSequence = routeSequenceMap.get(stationCode); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(routeSequence); - return routeSequence.getLine(tripNumber, routeCode); + return routeSequence.findLine(tripNumber, routeCode); + } + + public RouteSequence.Line getRouteSequenceLine(String stationCode, String tripNumber, String routeCode) { + RouteSequence.Line line = findRouteSequenceLine(stationCode, tripNumber, routeCode); + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(line); + return line; } public synchronized void addDispatchCommand(RailDispatchCommand command) { @@ -337,4 +343,24 @@ public class CtcRepository { } return tickets; } + + /** + * 查询计划早于这个时间的进路序列 + */ + public List findRouteSequenceLineThatLessThan(String stationCode, LocalTime planTime) { + RouteSequence routeSequence = routeSequenceMap.get(stationCode); + if (routeSequence == null) + return new ArrayList<>(); + return routeSequence.getLines().stream() + .filter(line -> line.getPlanTime().isBefore(planTime)) + .collect(Collectors.toList()); + } + + public RouteSequence getRouteSequence(String stationCode) { + return routeSequenceMap.get(stationCode); + } + + public TrackView getTrackView(String stationCode) { + return trackViewMap.get(stationCode); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/RouteSequence.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/RouteSequence.java index b32fd746a..3021f38a5 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/RouteSequence.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/data/RouteSequence.java @@ -122,8 +122,16 @@ public class RouteSequence { return l; } + public Line findLine(String tripNumber, String routeCode) { + List lines = tripLineMap.get(tripNumber); + if (CollectionUtils.isEmpty(lines)) + return null; + return lines.stream().filter(line -> Objects.equals(routeCode, line.getRoute().getCode())) + .findAny().orElse(null); + } + /** - * 获取进路序列中的一行(进路应该对每个车次只会办一次 + * 获取进路序列中的一行 */ public Line getLine(String tripNumber, String routeCode) { List lines = tripLineMap.get(tripNumber); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/operation/RailCtcOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/operation/RailCtcOperateHandler.java index 5947fbafa..c88cc9428 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/operation/RailCtcOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/operation/RailCtcOperateHandler.java @@ -104,8 +104,8 @@ public class RailCtcOperateHandler { * @param duration 办理调车进路时可以输入时间 */ @OperateHandlerMapping(type = Operation.Type.CTC_SET_ROUTE) - public void setRoute(Simulation simulation, String routeCode, String tripNumber, Boolean force, Integer duration) { - ctcService.setRoute(simulation, routeCode, tripNumber, force, duration); + public List setRoute(Simulation simulation, String routeCode, String tripNumber, Boolean force, Integer duration) { + return ctcService.setRoute(simulation, routeCode, tripNumber, force, duration); } /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/service/CTCService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/service/CTCService.java index 24af6416e..0124776ad 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/service/CTCService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/service/CTCService.java @@ -1,18 +1,25 @@ package club.joylink.rtss.simulation.cbtc.CTC.service; +import club.joylink.rtss.exception.BaseException; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.CI.CiApiService; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; import club.joylink.rtss.simulation.cbtc.CTC.data.RouteSequence; +import club.joylink.rtss.simulation.cbtc.CTC.data.TrackView; import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.data.map.Route; -import club.joylink.rtss.simulation.cbtc.data.map.Station; +import club.joylink.rtss.simulation.cbtc.data.map.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import java.time.LocalTime; import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.stream.Collectors; @Component public class CTCService { @@ -132,14 +139,59 @@ public class CTCService { line.setAutoTrigger(trigger); } - public String setRoute(Simulation simulation, String routeCode, String tripNumber, Boolean force, Integer duration) { -// if (StringUtils.hasText(tripNumber) && !Objects.equals(true, force)) { -// // CTC卡控功能 -// } + public List setRoute(Simulation simulation, String routeCode, String tripNumber, Boolean force, Integer duration) { + Route route = simulation.getRepository().getByCode(routeCode, Route.class); + Station station = route.getStart().getStation(); + if (station == null) + station = route.getStart().getDeviceStation(); + + List conflictInfo = new ArrayList<>(); + CtcRepository ctcRepository = simulation.getCtcRepository(); + if (StringUtils.hasText(tripNumber) && !Objects.equals(true, force)) { //列车进路防错办 + RouteSequence.Line line = ctcRepository.findRouteSequenceLine(station.getCode(), tripNumber, routeCode); + if (line == null) + conflictInfo.add(String.format("车次[%s]的进路序列中不包含[name:%s]进路", tripNumber, route.getName())); + } + if (duration != null && !Objects.equals(true, force)) { //调车进路防错办 + Set
sections = new HashSet<>(route.getSectionList()); + Map switchMap = new HashMap<>(); + List switchList = route.getSwitchList(); + if (!CollectionUtils.isEmpty(switchList)) { + switchMap = switchList.stream().collect(Collectors.toMap(SwitchElement::getASwitch, Function.identity())); + } + LocalTime endTime = simulation.getCorrectSystemTime().plusSeconds(duration).toLocalTime(); + List lines = ctcRepository.findRouteSequenceLineThatLessThan(station.getCode(), endTime); + out: + for (RouteSequence.Line line : lines) { + Route lineRoute = line.getRoute(); + if (lineRoute == null) + continue; + for (Section section : lineRoute.getSectionList()) { + if (sections.contains(section)) { + conflictInfo.add(String.format("所选进路[name:%s]与车次[%s]的[name:%s]进路冲突", + route.getName(), line.getTripNumber(), lineRoute.getName())); + continue out; + } + } + List sl = lineRoute.getSwitchList(); + if (!CollectionUtils.isEmpty(sl)) { + for (SwitchElement element : sl) { + SwitchElement e = switchMap.get(element.getASwitch()); + if (e != null && !element.equals(e)) { + conflictInfo.add(String.format("所选进路[name:%s]与车次[%s]的[name:%s]进路冲突", + route.getName(), line.getTripNumber(), lineRoute.getName())); + continue out; + } + } + } + } + } + if (!conflictInfo.isEmpty()) + return conflictInfo; + Route.CheckFailMessage checkFailMessage = ciApiService.settingRoute(simulation, routeCode); if (checkFailMessage != null) throw BusinessExceptionAssertEnum.OPERATION_FAIL.exception(checkFailMessage.debugStr()); - Route route = simulation.getRepository().getByCode(routeCode, Route.class); route.setTripNumber(tripNumber); return null; }