diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index 49d997e21..4ae420a2a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -28,10 +28,7 @@ import org.springframework.util.StringUtils; import java.time.LocalTime; import java.time.temporal.ChronoUnit; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -302,13 +299,24 @@ public class AtsTrainService { break; } } - BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(selectRouting, - String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode())); - List
sections = selectRouting.getSectionsFrom(fromSection); - if (!sections.get(0).equals(headSection)) { - sections.add(0, headSection); + if (selectRouting != null) { + List
sections = selectRouting.getSectionsFrom(fromSection); + if (!sections.get(0).equals(headSection)) { + sections.add(0, headSection); + } + supervisedTrain.setHctPath(new SectionRunPath(sections, selectRouting.isRight())); + } else { + List routePaths = repository.queryRoutePathsByEndAndContainsSection(destinationSection, headSection); + BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(routePaths, + String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode())); + RoutePath routePath = routePaths.stream() + .min(Comparator.comparingDouble(RoutePath::getReverseSwitchQuantity)) + .get(); + List
sections = routePath.getSectionList().stream() + .filter(Section::isSpecialSection) + .collect(Collectors.toList()); + supervisedTrain.setHctPath(new SectionRunPath(sections, routePath.isRight())); } - supervisedTrain.setHctPath(new SectionRunPath(sections, selectRouting.isRight())); break; default: throw new SimulationException(SimulationExceptionType.System_Fault, String.format("无法识别的目的地码类型[%s]", destinationCodeDefinition.getType()));