设置头码车路径寻找逻辑修改

This commit is contained in:
joylink_zhangsai 2021-08-05 09:51:35 +08:00
parent 3d712e6486
commit 8e58d6ba89

View File

@ -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()));
if (selectRouting != null) {
List<Section> sections = selectRouting.getSectionsFrom(fromSection);
if (!sections.get(0).equals(headSection)) {
sections.add(0, headSection);
}
supervisedTrain.setHctPath(new SectionRunPath(sections, selectRouting.isRight()));
} else {
List<RoutePath> 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<Section> sections = routePath.getSectionList().stream()
.filter(Section::isSpecialSection)
.collect(Collectors.toList());
supervisedTrain.setHctPath(new SectionRunPath(sections, routePath.isRight()));
}
break;
default:
throw new SimulationException(SimulationExceptionType.System_Fault, String.format("无法识别的目的地码类型[%s]", destinationCodeDefinition.getType()));