Merge remote-tracking branch 'origin/test' into dev

This commit is contained in:
joylink_zhangsai 2021-06-03 16:15:18 +08:00
commit 7bba9fb3fa
3 changed files with 39 additions and 30 deletions

View File

@ -241,45 +241,42 @@ public class AtsTrainService {
break;
}
case OTHER:
// Set<List<Section>> pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, right, stop);
// if (CollectionUtils.isEmpty(pathSet)) {
// pathSet = CalculateService.querySectionPaths2Destination(headSection, destinationSection, !right, stop);
// }
// BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(pathSet,
// String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
// //从找到的路径中筛选出最短路径
// List<Section> path = null;
// if (pathSet.size() == 1) {
// path = pathSet.stream().findAny().get();
// } else if (pathSet.size() > 1) {
// Optional<List<Section>> pathOptional = pathSet.stream()
// .min(Comparator.comparingDouble(availablePath -> availablePath.stream().mapToDouble(Section::getLen).sum()));
// path = pathOptional.get();
// }
// BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(path,
// String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
// supervisedTrain.setHeadPath(path);
Routing selectRouting = null;
Section fromSection = headSection;
List<Routing> routings = repository.queryRoutingByDestCode(destinationCode);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertCollectionNotEmpty(routings,
String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode()));
// Map<Boolean, List<Section>> map = new HashMap<>();
for (Routing routing : routings) {
if (routing.containsSection(headSection)) {
selectRouting = routing;
} else {
List<Section> allSections = routing.getAllSections();
for (int i = allSections.size() - 1; i >= 0; i--) {
Section section = allSections.get(i);
if (headSection.isTurnBackTrack()) { //是折返轨不限制方向
if (routing.containsSection(headSection)) {
selectRouting = routing;
}
for (Section section : routing.getAllSections()) {
List<RoutePath> routePaths = repository.queryRoutePathsByEndAndContainsSection(section, headSection);
if (!CollectionUtils.isEmpty(routePaths)) {
fromSection = section;
selectRouting = routing;
break;
if (routePaths.stream().anyMatch(routePath -> routePath.isRight() == routing.isRight())) {
fromSection = section;
selectRouting = routing;
}
}
}
} else { //不是折返轨必须和列车同向
if (routing.isRight() == right) {
if (routing.containsSection(headSection)) {
selectRouting = routing;
} else {
for (Section section : routing.getAllSections()) {
List<RoutePath> routePaths = repository.queryRoutePathsByEndAndContainsSection(section, headSection);
if (routePaths.stream().anyMatch(routePath -> routePath.isRight() == right)) {
fromSection = section;
selectRouting = routing;
}
}
}
}
}
if (selectRouting != null) {
break;
}
}
BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(selectRouting,

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 交路从一个车站的可折返区段到另一个车站的可折返区段,途经的所有可停车区段列表
@ -69,6 +70,6 @@ public class Routing {
}
list.add(endSection);
}
return list;
return list.stream().distinct().collect(Collectors.toList());
}
}

View File

@ -426,4 +426,15 @@ public class RoutePath {
list.add(end);
return list;
}
public boolean isReverse() {
Section section = sectionList.get(0);
if (section.isRightLine()) {
return !this.isRight();
}
if (section.isLeftLine()) {
return this.isRight();
}
return false;
}
}