Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
commit
ced64ef381
@ -46,7 +46,7 @@ public interface RunPlanRoutingDAO {
|
||||
"AND user_id IS NULL " +
|
||||
"</if> " +
|
||||
"<if test=\"userId != null\">\n" +
|
||||
"AND (user_id IS NULL OR user_id = #{userId})\n" +
|
||||
"AND user_id = #{userId}\n" +
|
||||
"</if> " +
|
||||
"AND section_data = #{sectionData} " +
|
||||
"</script>")
|
||||
|
@ -30,6 +30,9 @@ public class DraftMapCiDataGeneratorImpl implements DraftMapCiDataGenerator {
|
||||
@Autowired
|
||||
private DraftMapService draftMapService;
|
||||
|
||||
@Autowired
|
||||
private RoutingGenerator routingGenerator;
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public CiGenerateResultVO generate(Long mapId) {
|
||||
@ -93,7 +96,7 @@ public class DraftMapCiDataGeneratorImpl implements DraftMapCiDataGenerator {
|
||||
/**
|
||||
* 唯一编码生成器
|
||||
*/
|
||||
private class CodeGenerator {
|
||||
public static class CodeGenerator {
|
||||
private AtomicInteger sn;
|
||||
private String prefix;
|
||||
|
||||
@ -300,7 +303,7 @@ public class DraftMapCiDataGeneratorImpl implements DraftMapCiDataGenerator {
|
||||
}
|
||||
|
||||
// 生成交路数据
|
||||
List<MapRoutingDataVO> generateRoutingList = this.generateRoutings(deviceMap, generatedRouteList, autoSignalList, errorList);
|
||||
List<MapRoutingDataVO> generateRoutingList = this.routingGenerator.generateAllRouting(deviceMap, errorList);
|
||||
|
||||
//站间运行等级生成
|
||||
List<MapStationRunLevelVO> generatedStationRunLevelList = new ArrayList<>();
|
||||
@ -624,600 +627,6 @@ public class DraftMapCiDataGeneratorImpl implements DraftMapCiDataGenerator {
|
||||
return nearly;
|
||||
}
|
||||
|
||||
private List<MapRoutingDataVO> generateRoutings(Map<String, MapElement> deviceMap, List<Route> generatedRouteList, List<AutoSignal> autoSignalList, List<String> errorList) {
|
||||
// 数据准备:车站,和车站下的折返轨/转换轨列表
|
||||
List<Station> stationList = deviceMap.values().stream()
|
||||
.filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.STATION))
|
||||
.map(mapElement -> ((Station) mapElement))
|
||||
.collect(Collectors.toList());
|
||||
Map<String, List<Section>> stationSectionMap = new HashMap<>();
|
||||
deviceMap.values().stream()
|
||||
.filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.SECTION))
|
||||
.map(mapElement -> ((Section) mapElement))
|
||||
.filter(section -> section.isTurnBackTrack() || section.isTransferTrack())
|
||||
.forEach(section -> {
|
||||
List<Section> sectionList = stationSectionMap.get(section.getStation().getCode());
|
||||
if (Objects.isNull(sectionList)) {
|
||||
sectionList = new ArrayList<>();
|
||||
stationSectionMap.put(section.getStation().getCode(), sectionList);
|
||||
}
|
||||
sectionList.add(section);
|
||||
});
|
||||
CodeGenerator routingCodeGenerator = new CodeGenerator("Routing");
|
||||
List<MapRoutingDataVO> generatedRoutingList = new ArrayList<>();
|
||||
List<List<String>> generatedStationList = new ArrayList<>();
|
||||
// 遍历车站查询有配置生成交路的
|
||||
for (Station station : stationList) {
|
||||
List<String> routingStationList = station.getRoutingStationList();
|
||||
if (CollectionUtils.isEmpty(routingStationList)) {
|
||||
continue;
|
||||
}
|
||||
List<Section> sectionList = stationSectionMap.get(station.getCode());
|
||||
if (CollectionUtils.isEmpty(sectionList)) {
|
||||
log.warn(String.format("车站[%s(%s)]没有折返轨和转换轨", station.getName(), station.getCode()));
|
||||
continue;
|
||||
}
|
||||
// 配置存在
|
||||
for (String stationCode : routingStationList) {
|
||||
// 是否生成过校验
|
||||
boolean generated = false;
|
||||
for (List<String> list : generatedStationList) {
|
||||
if (list.contains(station.getCode()) && list.contains(stationCode)) {
|
||||
generated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (generated) {
|
||||
// 已经生成过,跳过
|
||||
continue;
|
||||
} else {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add(station.getCode());
|
||||
list.add(stationCode);
|
||||
generatedStationList.add(list);
|
||||
}
|
||||
// 未生成过,生成
|
||||
Station routingStation = (Station) deviceMap.get(stationCode);
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(routingStation);
|
||||
List<Section> otherSectionList = stationSectionMap.get(routingStation.getCode());
|
||||
if (CollectionUtils.isEmpty(otherSectionList)) {
|
||||
log.warn(String.format("车站[%s(%s)]没有折返轨和转换轨", routingStation.getName(), routingStation.getCode()));
|
||||
continue;
|
||||
}
|
||||
boolean right = station.getSn() < routingStation.getSn();
|
||||
for (Section a : sectionList) {
|
||||
for (Section b : otherSectionList) {
|
||||
Routing routing = this.generateRouting(a, b, right, stationList);
|
||||
if (Objects.nonNull(routing)) {
|
||||
generatedRoutingList.add(this.buildRoutingData(routingCodeGenerator.next(), routing));
|
||||
}
|
||||
Routing reverseRouting = this.generateRouting(b, a, !right, stationList);
|
||||
if (Objects.nonNull(reverseRouting)) {
|
||||
generatedRoutingList.add(this.buildRoutingData(routingCodeGenerator.next(), reverseRouting));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return generatedRoutingList;
|
||||
}
|
||||
|
||||
private MapRoutingDataVO buildRoutingData(String code, Routing routing) {
|
||||
MapRoutingDataVO vo = MapRoutingDataVO.from(routing);
|
||||
vo.setCode(code);
|
||||
return vo;
|
||||
}
|
||||
|
||||
private Routing generateRouting(Section start, Section end, boolean right, List<Station> stationList) {
|
||||
// 从起始区段开始找停站路径
|
||||
List<Section> paths = new ArrayList<>();
|
||||
List<List<Section>> pathsList = new ArrayList<>();
|
||||
paths.add(start);
|
||||
getRoutingPathOf(start, end, right, stationList, paths, pathsList);
|
||||
String name = String.format("%s(%s)-%s(%s)",
|
||||
start.getStation().getName(), start.getName(),
|
||||
end.getStation().getName(), end.getName());
|
||||
if (pathsList.size() > 0) {
|
||||
if (pathsList.size() > 1) {
|
||||
log.warn(String.format("从[%s]的交路找到超过一个路径", name));
|
||||
for (int i = 0; i < pathsList.size(); i++) {
|
||||
log.info(String.format("从[%s]的交路%s:[%s]",
|
||||
name, i+1, this.buildRoutingPathString(pathsList.get(i))));
|
||||
}
|
||||
} else {
|
||||
// 找到,构建
|
||||
log.info(String.format("从[%s]的交路找到:[%s]",
|
||||
name, this.buildRoutingPathString(pathsList.get(0))));
|
||||
}
|
||||
String destinationCode = end.getDestinationCode();
|
||||
Routing routing = new Routing(name, destinationCode);
|
||||
routing.setStartStation(start.getStation());
|
||||
routing.setStartSection(start);
|
||||
routing.setEndStation(end.getStation());
|
||||
routing.setEndSection(end);
|
||||
routing.setRight(right);
|
||||
routing.setViaSectionList(pathsList.get(0));
|
||||
return routing;
|
||||
} else {
|
||||
// 未找到
|
||||
log.warn(String.format("从[%s]的交路未找到", name));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String buildRoutingPathString(List<Section> sections) {
|
||||
return String.join(",", sections.stream()
|
||||
.map(section -> String.format("%s(%s)", section.getStation().getName(), section.getName()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private void getRoutingPathOf(Section start, Section end, boolean right,
|
||||
List<Station> stationList, List<Section> paths, List<List<Section>> pathsList) {
|
||||
Section lastSection = paths.get(paths.size() - 1);
|
||||
List<Section> nstdList = new ArrayList<>(); // 指定方向的正常站台轨
|
||||
if (paths.size() == 1) {
|
||||
if (Math.abs(start.getStation().getSn() - end.getStation().getSn()) == 1) {
|
||||
if (this.canArriveNearby(start, end, right)) {
|
||||
// 相邻车站,起始是转换轨且终点是正常站台轨或特殊站台(无正常站台轨且不是停车场的车站)
|
||||
// if ((start.isTransferTrack() && (end.isNormalStandTrack() || end.getStation().isNoDepotAndNoNormalStand()))
|
||||
// || ((start.isNormalStandTrack() || start.getStation().isNoDepotAndNoNormalStand()) && end.isTransferTrack())) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(start.isTransferTrack()){
|
||||
if(end.isNormalStandTrack() || end.getStation().isNoDepotAndNoNormalStand()){
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
Signal signal = start.querySignalOnDirectionConsiderSectionType(right);
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
if(nstdList.size()==0){
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
if(nstdList.size()==1){
|
||||
if (!this.canArriveNearby(nstdList.get(0), end, right)){
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(end.isTransferTrack()){
|
||||
if(start.isNormalStandTrack() || start.getStation().isNoDepotAndNoNormalStand()){
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
Signal signal = start.querySignalOnDirectionConsiderSectionType(right);
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
if(nstdList.size()==0){
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
if(nstdList.size()==1){
|
||||
if (!this.canArriveNearby(nstdList.get(0), end, right)){
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // 相邻站,不能到达的直接返回
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 起始查询
|
||||
if(CollectionUtils.isEmpty(nstdList)){
|
||||
Signal signal = start.querySignalOnDirectionConsiderSectionType(right);
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
}
|
||||
if (CollectionUtils.isEmpty(nstdList)) {
|
||||
// 未找到,如果是折返轨/转换轨,反向尝试
|
||||
if ((start.isTurnBackTrack() || start.isTransferTrack()) && !start.isNormalStandTrack()) {
|
||||
Signal signal = start.getSignalOf(!right);
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (Objects.equals(lastSection.getStation(), end.getStation())) {
|
||||
// 找到终点相同车站,判断并收尾
|
||||
if (Objects.equals(lastSection, end)) { // 相同,找到,结束
|
||||
pathsList.add(paths);
|
||||
} else {
|
||||
if (end.isLeftLine() || end.isRightLine()) {
|
||||
// 如果是左行线或右行线,对应方向可到达,则找到返回
|
||||
if (canArriveNearby(lastSection, end, right)) {
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
}
|
||||
} else {
|
||||
// 否则只要可到达,则找到返回
|
||||
if (canArriveNearby(lastSection, end)) {
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (Math.abs(lastSection.getStation().getSn() - end.getStation().getSn()) == 1) {
|
||||
// 相邻车站,判断是否可以收尾
|
||||
if (!end.isNormalStandTrack() && (end.isTurnBackTrack() || end.isTransferTrack())) {
|
||||
if (canArriveNearby(lastSection, end)) {
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
} else if (lastSection.isNormalStandTrack() &&
|
||||
end.isNormalStandTrack() && end.isTurnBackTrack() &&
|
||||
!Objects.equals(end.getStandList().get(0).isRight(), right)) { // 站前折返
|
||||
if (canArriveOppositeStandTrack(lastSection, end, right)) {
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 如果终点是折返轨,判断是否可以收尾
|
||||
if (!end.isNormalStandTrack() && end.isTurnBackTrack() && this.canArriveNearby(lastSection, end, right)) {
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 找指定方向的站台轨
|
||||
Signal signal = lastSection.getSignalOf(right);
|
||||
if (signal == null) {
|
||||
this.queryNormalStandTracksOnDirectionFromSection(lastSection, right, nstdList);
|
||||
} else {
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
}
|
||||
// 站前折返情况处理
|
||||
if (!CollectionUtils.isEmpty(nstdList) &&
|
||||
end.isNormalStandTrack() &&
|
||||
!nstdList.contains(end) &&
|
||||
Objects.equals(nstdList.get(0).getStation(), end.getStation())) {
|
||||
if (this.canArriveOppositeStandTrack(lastSection, end, right)) {
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(nstdList)) {
|
||||
// 找到正常站台轨
|
||||
for (Section section : nstdList) {
|
||||
// 判断找到的站台轨区段是否是此方向上一个车站后的车站,且是紧接着的站台区段,否则抛弃
|
||||
if (this.isContainOtherNormalStation(lastSection, section, stationList)) {
|
||||
continue;
|
||||
}
|
||||
// if (lastSection.isNormalStandTrack() &&
|
||||
// this.isAfter(right, lastSection.getStation(), section.getStation())) {
|
||||
// }
|
||||
List<Section> clonePaths = new ArrayList<>(paths);
|
||||
clonePaths.add(section);
|
||||
this.getRoutingPathOf(start, end, right, stationList, clonePaths, pathsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void queryNormalStandTracksOnDirectionFromSection(Section lastSection, boolean right, List<Section> nstdList) {
|
||||
Signal signal = lastSection.getSignalOf(right);
|
||||
if (signal != null) {
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
} else {
|
||||
Section nextSection = lastSection.getSectionOf(right);
|
||||
if (nextSection.isNormalStandTrack() && nextSection.getStandList().get(0).isRight() == right) {
|
||||
nstdList.add(nextSection);
|
||||
return;
|
||||
} else {
|
||||
this.queryNormalStandTracksOnDirectionFromSection(nextSection, right, nstdList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canArriveOppositeStandTrack(Section start, Section end, boolean right) {
|
||||
Signal signal = start.getSignalOf(right);
|
||||
List<Section> nstdList = new ArrayList<>();
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signal, !right, nstdList);
|
||||
if (nstdList.contains(end)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isContainOtherNormalStation(Section startSection, Section endSection, List<Station> stationList) {
|
||||
int min = Math.min(startSection.getStation().getSn(), endSection.getStation().getSn());
|
||||
int max = Math.max(startSection.getStation().getSn(), endSection.getStation().getSn());
|
||||
int di = Math.abs(max - min);
|
||||
if (di > 1) { // 间隔大于1,判断中间车站是否停车场/非正常车站
|
||||
boolean jump = false;
|
||||
for (Station station : stationList) {
|
||||
if (station.getSn() > min && station.getSn() < max) {
|
||||
if (!(station.isDepot() || station.isNoDepotAndNoNormalStand())) {
|
||||
jump = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return jump;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以到达
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
private boolean canArriveNearby(Section start, Section end) {
|
||||
List<Section> ftList = new ArrayList<>();
|
||||
this.queryNearbyFunctionTracks(start, ftList);
|
||||
if (ftList.contains(end)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以到达
|
||||
* @param start
|
||||
* @param end
|
||||
* @param right
|
||||
* @return
|
||||
*/
|
||||
private boolean canArriveNearby(Section start, Section end, boolean right) {
|
||||
Signal signal = start.getSignalOf(right);
|
||||
List<Section> ftList = new ArrayList<>();
|
||||
this.queryTurnBackTracksOnDirection(signal, right, ftList);
|
||||
this.queryTransferTracksOnDirection(signal, right, ftList);
|
||||
if (ftList.contains(end)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否和指定运行方向一致
|
||||
* @param right
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
private boolean isAfter(boolean right, Station start, Station end) {
|
||||
if (right) {
|
||||
return start.getSn() <= end.getSn();
|
||||
} else {
|
||||
return start.getSn() >= end.getSn();
|
||||
}
|
||||
}
|
||||
|
||||
private void queryNearbyFunctionTracks(Section section, List<Section> ftList) {
|
||||
Signal rightSignal = section.getSignalOf(true);
|
||||
this.queryTurnBackTracksOnDirection(rightSignal, true, ftList);
|
||||
this.queryTransferTracksOnDirection(rightSignal, true, ftList);
|
||||
Signal leftSignal = section.getSignalOf(false);
|
||||
this.queryTurnBackTracksOnDirection(leftSignal, false, ftList);
|
||||
this.queryTransferTracksOnDirection(leftSignal, false, ftList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定方向的转换轨
|
||||
* @param signal
|
||||
* @param right
|
||||
* @param ftList
|
||||
*/
|
||||
private void queryTransferTracksOnDirection(Signal signal, boolean right, List<Section> ftList) {
|
||||
if (Objects.isNull(signal)) {
|
||||
return;
|
||||
}
|
||||
List<Route> routeList = signal.getRouteList();
|
||||
if (!CollectionUtils.isEmpty(routeList)) {
|
||||
// 根据信号机的进路查询
|
||||
Set<Signal> signals = new HashSet<>();
|
||||
for (Route route : routeList) {
|
||||
boolean find = false;
|
||||
for (Section section : route.getSectionList()) {
|
||||
if (section.isTransferTrack()) {
|
||||
find = true;
|
||||
if (!ftList.contains(section)) {
|
||||
ftList.add(section);
|
||||
}
|
||||
break;
|
||||
} else if (section.isNormalStandTrack()) {
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find) {
|
||||
continue;
|
||||
} else {
|
||||
signals.add(route.getDestination());
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(signals)) {
|
||||
for (Signal end : signals) {
|
||||
this.queryTransferTracksOnDirection(end, right, ftList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 循着自动信号后面的区段查询
|
||||
AutoSignal autoSignal = signal.getAutoSignal();
|
||||
if (Objects.nonNull(autoSignal)) {
|
||||
List<Section> sectionList = autoSignal.getSectionList();
|
||||
for (Section section : sectionList) {
|
||||
if (section.isTransferTrack()) {
|
||||
if (!ftList.contains(section)) {
|
||||
ftList.add(section);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (section.isNormalStandTrack()) {
|
||||
break;
|
||||
}
|
||||
Signal signalOf = section.getSignalOf(right);
|
||||
if (Objects.nonNull(signalOf)) {
|
||||
this.queryTransferTracksOnDirection(signalOf, right, ftList);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询附近的折返轨
|
||||
* @param signal
|
||||
* @param right
|
||||
* @param ftList
|
||||
*/
|
||||
private void queryTurnBackTracksOnDirection(Signal signal, boolean right, List<Section> ftList) {
|
||||
if (Objects.isNull(signal)) {
|
||||
return;
|
||||
}
|
||||
List<Route> routeList = signal.getRouteList();
|
||||
if (!CollectionUtils.isEmpty(routeList)) {
|
||||
// 根据信号机的进路查询
|
||||
Set<Signal> signals = new HashSet<>();
|
||||
for (Route route : routeList) {
|
||||
boolean find = false;
|
||||
for (Section section : route.getSectionList()) {
|
||||
if (section.isTurnBackTrack() && !section.isNormalStandTrack()) {
|
||||
find = true;
|
||||
if (!ftList.contains(section)) {
|
||||
ftList.add(section);
|
||||
}
|
||||
break;
|
||||
} else if (section.isNormalStandTrack() || section.isTransferTrack()) {
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (find) {
|
||||
continue;
|
||||
} else {
|
||||
signals.add(route.getDestination());
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(signals)) {
|
||||
for (Signal end : signals) {
|
||||
this.queryTurnBackTracksOnDirection(end, right, ftList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 循着自动信号后面的区段查询
|
||||
AutoSignal autoSignal = signal.getAutoSignal();
|
||||
if (Objects.nonNull(autoSignal)) {
|
||||
List<Section> sectionList = autoSignal.getSectionList();
|
||||
for (Section section : sectionList) {
|
||||
if (section.isTurnBackTrack()) {
|
||||
if (!ftList.contains(section)) {
|
||||
ftList.add(section);
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (section.isNormalStandTrack() || section.isTransferTrack()) {
|
||||
break;
|
||||
}
|
||||
Signal signalOf = section.getSignalOf(right);
|
||||
if (Objects.nonNull(signalOf)) {
|
||||
this.queryTurnBackTracksOnDirection(signalOf, right, ftList);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定方向的正常站台轨
|
||||
* @param signal 起始信号机和方向
|
||||
* @param standRight 指定站台方向
|
||||
* @param nstdList
|
||||
* @return
|
||||
*/
|
||||
private void queryNormalStandTracksOnDirectionFromSignal(Signal signal, boolean standRight, List<Section> nstdList) {
|
||||
if (Objects.isNull(signal)) {
|
||||
return;
|
||||
}
|
||||
boolean right = signal.isRight();
|
||||
List<Route> routeList = signal.getRouteList();
|
||||
if (!CollectionUtils.isEmpty(routeList)) {
|
||||
// 根据信号机的进路查询
|
||||
Set<Signal> signals = new HashSet<>();
|
||||
for (Route route : routeList) {
|
||||
boolean containOppositeStandTrack = false;
|
||||
boolean contains = false;
|
||||
for (Section section : route.getSectionList()) {
|
||||
if (section.isNormalStandTrack()) {
|
||||
if (!Objects.equals(section.getStandList().get(0).isRight(), standRight)) {
|
||||
containOppositeStandTrack = true;
|
||||
} else {
|
||||
contains = true;
|
||||
nstdList.add(section);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (containOppositeStandTrack) {
|
||||
continue;
|
||||
}
|
||||
if (contains) {
|
||||
continue;
|
||||
} else {
|
||||
signals.add(route.getDestination());
|
||||
}
|
||||
// Section lastRouteSection = route.getLastRouteSection();
|
||||
// if (lastRouteSection.isNormalStandTrack()) {
|
||||
// if (Objects.equals(lastRouteSection.getStandList().get(0).isRight(), standRight)) {
|
||||
// if (!nstdList.contains(lastRouteSection)) {
|
||||
// nstdList.add(lastRouteSection);
|
||||
// }
|
||||
// }
|
||||
// continue;
|
||||
// } else {
|
||||
// signals.add(route.getDestination());
|
||||
// }
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(signals)) {
|
||||
for (Signal end : signals) {
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(end, standRight, nstdList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 循着自动信号后面的区段查询
|
||||
AutoSignal autoSignal = signal.getAutoSignal();
|
||||
if (Objects.nonNull(autoSignal)) {
|
||||
List<Section> sectionList = autoSignal.getSectionList();
|
||||
for (Section section : sectionList) {
|
||||
if (section.isNormalStandTrack()) {
|
||||
if (Objects.equals(section.getStandList().get(0).isRight(), standRight)) {
|
||||
if (!nstdList.contains(section)) {
|
||||
nstdList.add(section);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
Signal signalOf = section.getSignalOf(right);
|
||||
if (Objects.nonNull(signalOf)) {
|
||||
this.queryNormalStandTracksOnDirectionFromSignal(signalOf, standRight, nstdList);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据信号机配置,删除不需要的基本进路
|
||||
* @param signalList
|
||||
|
@ -0,0 +1,820 @@
|
||||
package club.joylink.rtss.services.draftData;
|
||||
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.*;
|
||||
import club.joylink.rtss.vo.client.map.newmap.MapRoutingDataVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RoutingGenerator {
|
||||
|
||||
public List<MapRoutingDataVO> generateAllRouting(Map<String, MapElement> deviceMap, List<String> errorList) {
|
||||
// 数据准备:车站,和车站下的折返轨/转换轨列表
|
||||
List<Station> stationList = deviceMap.values().stream()
|
||||
.filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.STATION))
|
||||
.map(mapElement -> ((Station) mapElement))
|
||||
.sorted(Comparator.comparing(Station::getKmPostVal))
|
||||
.collect(Collectors.toList());
|
||||
// 车站折返轨、转换轨map
|
||||
Map<String, List<Section>> stationSectionMap = new HashMap<>();
|
||||
deviceMap.values().stream()
|
||||
.filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.SECTION))
|
||||
.map(mapElement -> ((Section) mapElement))
|
||||
.filter(section -> section.isTurnBackTrack() || section.isTransferTrack())
|
||||
.forEach(section -> {
|
||||
List<Section> sectionList = stationSectionMap.get(section.getStation().getCode());
|
||||
if (Objects.isNull(sectionList)) {
|
||||
sectionList = new ArrayList<>();
|
||||
stationSectionMap.put(section.getStation().getCode(), sectionList);
|
||||
}
|
||||
sectionList.add(section);
|
||||
});
|
||||
// 构建正常站台和转换轨左向和右向能到达的临近车站的站台轨、折返轨、转换轨
|
||||
Map<String, Set<Section>> standTrackAdjoinMap = this.buildNormalStandTrackAdjoinSections(deviceMap);
|
||||
DraftMapCiDataGeneratorImpl.CodeGenerator routingCodeGenerator = new DraftMapCiDataGeneratorImpl.CodeGenerator("Routing");
|
||||
List<MapRoutingDataVO> routingList = new ArrayList<>();
|
||||
// Map<String, String> generatedStationsList = new HashMap<>();
|
||||
// 遍历车站列表,开始生成
|
||||
for (Station station : stationList) {
|
||||
List<Section> sectionList = stationSectionMap.get(station.getCode());
|
||||
if (CollectionUtils.isEmpty(sectionList)) {
|
||||
log.info(String.format("车站[%s(%s)]没有折返轨和转换轨,不生成交路", station.getName(), station.getCode()));
|
||||
continue;
|
||||
}
|
||||
for (int i = stationList.size() - 1; i >= 0; i--) {
|
||||
Station otherStation = stationList.get(i);
|
||||
if (Objects.equals(otherStation, station)) {
|
||||
break;
|
||||
}
|
||||
List<Section> otherSectionList = stationSectionMap.get(otherStation.getCode());
|
||||
if (CollectionUtils.isEmpty(otherSectionList)) {
|
||||
log.info(String.format("车站[%s(%s)]没有折返轨和转换轨,不生成交路", station.getName(), station.getCode()));
|
||||
continue;
|
||||
}
|
||||
for (Section a : sectionList) {
|
||||
for (Section b : otherSectionList) {
|
||||
Routing routing = this.generateRouting2(a, b, true, stationList, standTrackAdjoinMap);
|
||||
if (Objects.nonNull(routing)) {
|
||||
routingList.add(this.buildRoutingData(routingCodeGenerator.next(), routing));
|
||||
}
|
||||
Routing reverseRouting = this.generateRouting2(b, a, false, stationList, standTrackAdjoinMap);
|
||||
if (Objects.nonNull(reverseRouting)) {
|
||||
routingList.add(this.buildRoutingData(routingCodeGenerator.next(), reverseRouting));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return routingList;
|
||||
}
|
||||
|
||||
private Map<String, Set<Section>> buildNormalStandTrackAdjoinSections(Map<String, MapElement> deviceMap) {
|
||||
List<Section> standTrackList = deviceMap.values().stream()
|
||||
.filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.SECTION))
|
||||
.map(mapElement -> ((Section) mapElement))
|
||||
.filter(section -> section.isNormalStandTrack() || section.isTransferTrack() || section.isTurnBackTrack())
|
||||
.collect(Collectors.toList());
|
||||
Map<String, Set<Section>> sectionDirectionSectionsMap = new HashMap<>();
|
||||
for (Section section : standTrackList) {
|
||||
Set<Section> rightDirectionList = new HashSet<>();
|
||||
sectionDirectionSectionsMap.put(this.buildSectionDirectionKey(section, true), rightDirectionList);
|
||||
this.queryAdjoinSections(section, true, rightDirectionList);
|
||||
Set<Section> leftDirectionList = new HashSet<>();
|
||||
sectionDirectionSectionsMap.put(this.buildSectionDirectionKey(section, false), leftDirectionList);
|
||||
this.queryAdjoinSections(section, false, leftDirectionList);
|
||||
System.out.println(String.format("区段[%s][右向]邻接区段为[%s],[左向]邻接区段为[%s]",
|
||||
section.debugStr(),
|
||||
String.join(",",rightDirectionList.stream().map(Section::debugStr).collect(Collectors.toList())),
|
||||
String.join(",", leftDirectionList.stream().map(Section::debugStr).collect(Collectors.toList()))));
|
||||
}
|
||||
return sectionDirectionSectionsMap;
|
||||
}
|
||||
|
||||
private String buildSectionDirectionKey(Section section, boolean right) {
|
||||
return String.format("%s-%s", section.getCode(), right?"R":"L");
|
||||
}
|
||||
|
||||
private void queryAdjoinSections(Section section, boolean right, Set<Section> rightDirectionList) {
|
||||
Signal signal = section.getSignalOf(right);
|
||||
if (signal == null) {
|
||||
Section base = section;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Section next = base.getSectionOf(right);
|
||||
if (next == null) { // 可能到尽头了
|
||||
return;
|
||||
}
|
||||
if (this.checkAdjoinSectionAndAdd(next, rightDirectionList)) {
|
||||
return;
|
||||
}
|
||||
signal = next.getSignalOf(right);
|
||||
if (signal != null) {
|
||||
break;
|
||||
}
|
||||
base = next;
|
||||
}
|
||||
}
|
||||
if (signal == null) {
|
||||
return;
|
||||
}
|
||||
this.queryAdjoinSections(signal, rightDirectionList);
|
||||
}
|
||||
|
||||
private void queryAdjoinSections(Signal signal, Set<Section> rightDirectionList) {
|
||||
boolean right = signal.isRight();
|
||||
List<Route> routeList = signal.getRouteList();
|
||||
if (CollectionUtils.isEmpty(routeList)) { // 没有进路,找自动信号
|
||||
AutoSignal autoSignal = signal.getAutoSignal();
|
||||
if (autoSignal == null) {
|
||||
return;
|
||||
}
|
||||
List<Section> sectionList = autoSignal.getSectionList();
|
||||
for (Section temp : sectionList) {
|
||||
if (this.checkAdjoinSectionAndAdd(temp, rightDirectionList)) {
|
||||
return;
|
||||
}
|
||||
signal = temp.getSignalOf(right);
|
||||
if (signal != null) {
|
||||
this.queryAdjoinSections(signal, rightDirectionList);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Set<Signal> queryList = new HashSet<>();
|
||||
for (Route route : routeList) {
|
||||
if (route.isAtp() || route.isGuide()) {
|
||||
continue;
|
||||
}
|
||||
List<Section> sectionList = route.getSectionList();
|
||||
boolean finish = false;
|
||||
for (Section section : sectionList) {
|
||||
if (this.checkAdjoinSectionAndAdd(section, rightDirectionList)) {
|
||||
finish = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!finish) {
|
||||
queryList.add(route.getDestination());
|
||||
}
|
||||
}
|
||||
for (Signal next : queryList) {
|
||||
this.queryAdjoinSections(next, rightDirectionList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAdjoinSectionAndAdd(Section temp, Set<Section> rightDirectionList) {
|
||||
if (temp.isStandTrack() || temp.isTransferTrack()) {
|
||||
rightDirectionList.add(temp);
|
||||
return true;
|
||||
} else if (temp.isTurnBackTrack()) {
|
||||
rightDirectionList.add(temp);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private Routing generateRouting2(Section start, Section end, boolean right, List<Station> stationList, Map<String, Set<Section>> standTrackAdjoinMap) {
|
||||
// 从起始区段开始找停站路径
|
||||
List<Section> paths = new ArrayList<>();
|
||||
List<List<Section>> pathsList = new ArrayList<>();
|
||||
paths.add(start);
|
||||
getRoutingPath2(start, end, right, stationList, standTrackAdjoinMap, paths, pathsList);
|
||||
String name = String.format("%s(%s)-%s(%s)",
|
||||
start.getStation().getName(), start.getName(),
|
||||
end.getStation().getName(), end.getName());
|
||||
if (pathsList.size() > 0) {
|
||||
if (pathsList.size() > 1) {
|
||||
log.warn(String.format("从[%s]的交路找到超过一个路径", name));
|
||||
for (int i = 0; i < pathsList.size(); i++) {
|
||||
log.info(String.format("从[%s]的交路%s:[%s]",
|
||||
name, i+1, this.buildRoutingPathString(pathsList.get(i))));
|
||||
}
|
||||
} else {
|
||||
// 找到,构建
|
||||
log.info(String.format("从[%s]的交路找到:[%s]",
|
||||
name, this.buildRoutingPathString(pathsList.get(0))));
|
||||
}
|
||||
String destinationCode = end.getDestinationCode();
|
||||
Routing routing = new Routing(name, destinationCode);
|
||||
routing.setStartStation(start.getStation());
|
||||
routing.setStartSection(start);
|
||||
routing.setEndStation(end.getStation());
|
||||
routing.setEndSection(end);
|
||||
routing.setRight(right);
|
||||
routing.setViaSectionList(pathsList.get(0));
|
||||
return routing;
|
||||
} else {
|
||||
// 未找到
|
||||
log.warn(String.format("从[%s]的交路未找到", name));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void getRoutingPath2(Section start, Section end, boolean right,
|
||||
List<Station> stationList, Map<String, Set<Section>> standTrackAdjoinMap,
|
||||
List<Section> paths, List<List<Section>> pathsList) {
|
||||
Section last = paths.get(paths.size() - 1);
|
||||
Set<Section> sectionSet = standTrackAdjoinMap.get(this.buildSectionDirectionKey(last, right));
|
||||
if (sectionSet == null) {
|
||||
return;
|
||||
}
|
||||
if (sectionSet.contains(end)) {
|
||||
// 找到,结束
|
||||
paths.add(end);
|
||||
pathsList.add(paths);
|
||||
return;
|
||||
} else {
|
||||
for (Section section : sectionSet) {
|
||||
if (section.isNormalStandTrack() && section.getStandList().get(0).isRight() == right) {
|
||||
ArrayList<Section> clone = new ArrayList<>(paths);
|
||||
clone.add(section);
|
||||
this.getRoutingPath2(start, end, right, stationList, standTrackAdjoinMap, clone, pathsList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// public List<MapRoutingDataVO> generateRoutings(Map<String, MapElement> deviceMap, List<String> errorList) {
|
||||
// // 数据准备:车站,和车站下的折返轨/转换轨列表
|
||||
// List<Station> stationList = deviceMap.values().stream()
|
||||
// .filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.STATION))
|
||||
// .map(mapElement -> ((Station) mapElement))
|
||||
// .sorted(Comparator.comparing(Station::getSn))
|
||||
// .collect(Collectors.toList());
|
||||
// Map<String, List<Section>> stationSectionMap = new HashMap<>();
|
||||
// deviceMap.values().stream()
|
||||
// .filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.SECTION))
|
||||
// .map(mapElement -> ((Section) mapElement))
|
||||
// .filter(section -> section.isTurnBackTrack() || section.isTransferTrack())
|
||||
// .forEach(section -> {
|
||||
// List<Section> sectionList = stationSectionMap.get(section.getStation().getCode());
|
||||
// if (Objects.isNull(sectionList)) {
|
||||
// sectionList = new ArrayList<>();
|
||||
// stationSectionMap.put(section.getStation().getCode(), sectionList);
|
||||
// }
|
||||
// sectionList.add(section);
|
||||
// });
|
||||
// DraftMapCiDataGeneratorImpl.CodeGenerator routingCodeGenerator = new DraftMapCiDataGeneratorImpl.CodeGenerator("Routing");
|
||||
// List<MapRoutingDataVO> generatedRoutingList = new ArrayList<>();
|
||||
// List<List<String>> generatedStationList = new ArrayList<>();
|
||||
// // 遍历车站查询有配置生成交路的
|
||||
// for (Station station : stationList) {
|
||||
// List<String> routingStationList = station.getRoutingStationList();
|
||||
// if (CollectionUtils.isEmpty(routingStationList)) {
|
||||
// continue;
|
||||
// }
|
||||
// List<Section> sectionList = stationSectionMap.get(station.getCode());
|
||||
// if (CollectionUtils.isEmpty(sectionList)) {
|
||||
// log.warn(String.format("车站[%s(%s)]没有折返轨和转换轨", station.getName(), station.getCode()));
|
||||
// continue;
|
||||
// }
|
||||
// // 配置存在
|
||||
// for (String stationCode : routingStationList) {
|
||||
// // 是否生成过校验
|
||||
// boolean generated = false;
|
||||
// for (List<String> list : generatedStationList) {
|
||||
// if (list.contains(station.getCode()) && list.contains(stationCode)) {
|
||||
// generated = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (generated) {
|
||||
// // 已经生成过,跳过
|
||||
// continue;
|
||||
// } else {
|
||||
// List<String> list = new ArrayList<>();
|
||||
// list.add(station.getCode());
|
||||
// list.add(stationCode);
|
||||
// generatedStationList.add(list);
|
||||
// }
|
||||
// // 未生成过,生成
|
||||
// Station routingStation = (Station) deviceMap.get(stationCode);
|
||||
// BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(routingStation);
|
||||
// List<Section> otherSectionList = stationSectionMap.get(routingStation.getCode());
|
||||
// if (CollectionUtils.isEmpty(otherSectionList)) {
|
||||
// log.warn(String.format("车站[%s(%s)]没有折返轨和转换轨", routingStation.getName(), routingStation.getCode()));
|
||||
// continue;
|
||||
// }
|
||||
// boolean right = station.getSn() < routingStation.getSn();
|
||||
// for (Section a : sectionList) {
|
||||
// for (Section b : otherSectionList) {
|
||||
// Routing routing = this.generateRouting(a, b, right, stationList);
|
||||
// if (Objects.nonNull(routing)) {
|
||||
// generatedRoutingList.add(this.buildRoutingData(routingCodeGenerator.next(), routing));
|
||||
// }
|
||||
// Routing reverseRouting = this.generateRouting(b, a, !right, stationList);
|
||||
// if (Objects.nonNull(reverseRouting)) {
|
||||
// generatedRoutingList.add(this.buildRoutingData(routingCodeGenerator.next(), reverseRouting));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return generatedRoutingList;
|
||||
// }
|
||||
|
||||
private MapRoutingDataVO buildRoutingData(String code, Routing routing) {
|
||||
MapRoutingDataVO vo = MapRoutingDataVO.from(routing);
|
||||
vo.setCode(code);
|
||||
return vo;
|
||||
}
|
||||
//
|
||||
// public Routing generateRouting(Section start, Section end, boolean right, List<Station> stationList) {
|
||||
// // 从起始区段开始找停站路径
|
||||
// List<Section> paths = new ArrayList<>();
|
||||
// List<List<Section>> pathsList = new ArrayList<>();
|
||||
// paths.add(start);
|
||||
// getRoutingPathOf(start, end, right, stationList, paths, pathsList);
|
||||
// String name = String.format("%s(%s)-%s(%s)",
|
||||
// start.getStation().getName(), start.getName(),
|
||||
// end.getStation().getName(), end.getName());
|
||||
// if (pathsList.size() > 0) {
|
||||
// if (pathsList.size() > 1) {
|
||||
// log.warn(String.format("从[%s]的交路找到超过一个路径", name));
|
||||
// for (int i = 0; i < pathsList.size(); i++) {
|
||||
// log.info(String.format("从[%s]的交路%s:[%s]",
|
||||
// name, i+1, this.buildRoutingPathString(pathsList.get(i))));
|
||||
// }
|
||||
// } else {
|
||||
// // 找到,构建
|
||||
// log.info(String.format("从[%s]的交路找到:[%s]",
|
||||
// name, this.buildRoutingPathString(pathsList.get(0))));
|
||||
// }
|
||||
// String destinationCode = end.getDestinationCode();
|
||||
// Routing routing = new Routing(name, destinationCode);
|
||||
// routing.setStartStation(start.getStation());
|
||||
// routing.setStartSection(start);
|
||||
// routing.setEndStation(end.getStation());
|
||||
// routing.setEndSection(end);
|
||||
// routing.setRight(right);
|
||||
// routing.setViaSectionList(pathsList.get(0));
|
||||
// return routing;
|
||||
// } else {
|
||||
// // 未找到
|
||||
// log.warn(String.format("从[%s]的交路未找到", name));
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private void getRoutingPathOf(Section start, Section end, boolean right,
|
||||
// List<Station> stationList, List<Section> paths, List<List<Section>> pathsList) {
|
||||
// Section lastSection = paths.get(paths.size() - 1);
|
||||
// List<Section> nstdList = new ArrayList<>(); // 指定方向的正常站台轨
|
||||
// if (paths.size() == 1) {
|
||||
// if (Math.abs(start.getStation().getSn() - end.getStation().getSn()) == 1) {
|
||||
// if (this.canArriveNearby(start, end, right)) {
|
||||
// // 相邻车站,起始是转换轨且终点是正常站台轨或特殊站台(无正常站台轨且不是停车场的车站)
|
||||
//// if ((start.isTransferTrack() && (end.isNormalStandTrack() || end.getStation().isNoDepotAndNoNormalStand()))
|
||||
//// || ((start.isNormalStandTrack() || start.getStation().isNoDepotAndNoNormalStand()) && end.isTransferTrack())) {
|
||||
//// paths.add(end);
|
||||
//// pathsList.add(paths);
|
||||
//// return;
|
||||
//// }
|
||||
//
|
||||
// if(start.isTransferTrack()){
|
||||
// if(end.isNormalStandTrack() || end.getStation().isNoDepotAndNoNormalStand()){
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// Signal signal = start.querySignalOnDirectionConsiderSectionType(right);
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
// if(nstdList.size()==0){
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// if(nstdList.size()==1){
|
||||
// if (!this.canArriveNearby(nstdList.get(0), end, right)){
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if(end.isTransferTrack()){
|
||||
// if(start.isNormalStandTrack() || start.getStation().isNoDepotAndNoNormalStand()){
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// Signal signal = start.querySignalOnDirectionConsiderSectionType(right);
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
// if(nstdList.size()==0){
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// if(nstdList.size()==1){
|
||||
// if (!this.canArriveNearby(nstdList.get(0), end, right)){
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// } else { // 相邻站,不能到达的直接返回
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// // 起始查询
|
||||
// if(CollectionUtils.isEmpty(nstdList)){
|
||||
// Signal signal = start.querySignalOnDirectionConsiderSectionType(right);
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
// }
|
||||
// if (CollectionUtils.isEmpty(nstdList)) {
|
||||
// // 未找到,如果是折返轨/转换轨,反向尝试
|
||||
// if ((start.isTurnBackTrack() || start.isTransferTrack()) && !start.isNormalStandTrack()) {
|
||||
// Signal signal = start.getSignalOf(!right);
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (Objects.equals(lastSection.getStation(), end.getStation())) {
|
||||
// // 找到终点相同车站,判断并收尾
|
||||
// if (Objects.equals(lastSection, end)) { // 相同,找到,结束
|
||||
// pathsList.add(paths);
|
||||
// } else {
|
||||
// if (end.isLeftLine() || end.isRightLine()) {
|
||||
// // 如果是左行线或右行线,对应方向可到达,则找到返回
|
||||
// if (canArriveNearby(lastSection, end, right)) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// }
|
||||
// } else {
|
||||
// // 否则只要可到达,则找到返回
|
||||
// if (canArriveNearby(lastSection, end)) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return;
|
||||
// } else if (Math.abs(lastSection.getStation().getSn() - end.getStation().getSn()) == 1) {
|
||||
// // 相邻车站,判断是否可以收尾
|
||||
// if (!end.isNormalStandTrack() && (end.isTurnBackTrack() || end.isTransferTrack())) {
|
||||
// if (canArriveNearby(lastSection, end)) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// } else if (lastSection.isNormalStandTrack() &&
|
||||
// end.isNormalStandTrack() && end.isTurnBackTrack() &&
|
||||
// !Objects.equals(end.getStandList().get(0).isRight(), right)) { // 站前折返
|
||||
// if (canArriveOppositeStandTrack(lastSection, end, right)) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // 如果终点是折返轨,判断是否可以收尾
|
||||
// if (!end.isNormalStandTrack() && end.isTurnBackTrack() && this.canArriveNearby(lastSection, end, right)) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// // 找指定方向的站台轨
|
||||
// Signal signal = lastSection.getSignalOf(right);
|
||||
// if (signal == null) {
|
||||
// this.queryNormalStandTracksOnDirectionFromSection(lastSection, right, nstdList);
|
||||
// } else {
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
// }
|
||||
// // 站前折返情况处理
|
||||
// if (!CollectionUtils.isEmpty(nstdList) &&
|
||||
// end.isNormalStandTrack() &&
|
||||
// !nstdList.contains(end) &&
|
||||
// Objects.equals(nstdList.get(0).getStation(), end.getStation())) {
|
||||
// if (this.canArriveOppositeStandTrack(lastSection, end, right)) {
|
||||
// paths.add(end);
|
||||
// pathsList.add(paths);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (!CollectionUtils.isEmpty(nstdList)) {
|
||||
// // 找到正常站台轨
|
||||
// for (Section section : nstdList) {
|
||||
// // 判断找到的站台轨区段是否是此方向上一个车站后的车站,且是紧接着的站台区段,否则抛弃
|
||||
// if (this.isContainOtherNormalStation(lastSection, section, stationList)) {
|
||||
// continue;
|
||||
// }
|
||||
//// if (lastSection.isNormalStandTrack() &&
|
||||
//// this.isAfter(right, lastSection.getStation(), section.getStation())) {
|
||||
//// }
|
||||
// List<Section> clonePaths = new ArrayList<>(paths);
|
||||
// clonePaths.add(section);
|
||||
// this.getRoutingPathOf(start, end, right, stationList, clonePaths, pathsList);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
////////
|
||||
//////// /**
|
||||
//////// * 是否可以到达
|
||||
//////// * @param start
|
||||
//////// * @param end
|
||||
//////// * @param right
|
||||
//////// * @return
|
||||
//////// */
|
||||
//////// private boolean canArriveNearby(Section start, Section end, boolean right) {
|
||||
//////// Signal signal = start.getSignalOf(right);
|
||||
//////// List<Section> ftList = new ArrayList<>();
|
||||
//////// this.queryTurnBackTracksOnDirection(signal, right, ftList);
|
||||
//////// this.queryTransferTracksOnDirection(signal, right, ftList);
|
||||
//////// if (ftList.contains(end)) {
|
||||
//////// return true;
|
||||
//////// }
|
||||
//////// return false;
|
||||
//////// }
|
||||
////////
|
||||
//////// /**
|
||||
//////// * 是否可以到达
|
||||
//////// * @param start
|
||||
//////// * @param end
|
||||
//////// * @return
|
||||
//////// */
|
||||
//////// private boolean canArriveNearby(Section start, Section end) {
|
||||
//////// List<Section> ftList = new ArrayList<>();
|
||||
//////// this.queryNearbyFunctionTracks(start, ftList);
|
||||
//////// if (ftList.contains(end)) {
|
||||
//////// return true;
|
||||
//////// }
|
||||
//////// return false;
|
||||
//////// }
|
||||
//////
|
||||
////// private void queryNearbyFunctionTracks(Section section, List<Section> ftList) {
|
||||
////// Signal rightSignal = section.getSignalOf(true);
|
||||
////// this.queryTurnBackTracksOnDirection(rightSignal, true, ftList);
|
||||
////// this.queryTransferTracksOnDirection(rightSignal, true, ftList);
|
||||
////// Signal leftSignal = section.getSignalOf(false);
|
||||
////// this.queryTurnBackTracksOnDirection(leftSignal, false, ftList);
|
||||
////// this.queryTransferTracksOnDirection(leftSignal, false, ftList);
|
||||
////// }
|
||||
////
|
||||
//// /**
|
||||
//// * 查询附近的折返轨
|
||||
//// * @param signal
|
||||
//// * @param right
|
||||
//// * @param ftList
|
||||
//// */
|
||||
//// private void queryTurnBackTracksOnDirection(Signal signal, boolean right, List<Section> ftList) {
|
||||
//// if (Objects.isNull(signal)) {
|
||||
//// return;
|
||||
//// }
|
||||
//// List<Route> routeList = signal.getRouteList();
|
||||
//// if (!CollectionUtils.isEmpty(routeList)) {
|
||||
//// // 根据信号机的进路查询
|
||||
//// Set<Signal> signals = new HashSet<>();
|
||||
//// for (Route route : routeList) {
|
||||
//// boolean find = false;
|
||||
//// for (Section section : route.getSectionList()) {
|
||||
//// if (section.isTurnBackTrack() && !section.isNormalStandTrack()) {
|
||||
//// find = true;
|
||||
//// if (!ftList.contains(section)) {
|
||||
//// ftList.add(section);
|
||||
//// }
|
||||
//// break;
|
||||
//// } else if (section.isNormalStandTrack() || section.isTransferTrack()) {
|
||||
//// find = true;
|
||||
//// break;
|
||||
//// }
|
||||
//// }
|
||||
//// if (find) {
|
||||
//// continue;
|
||||
//// } else {
|
||||
//// signals.add(route.getDestination());
|
||||
//// }
|
||||
//// }
|
||||
//// if (!CollectionUtils.isEmpty(signals)) {
|
||||
//// for (Signal end : signals) {
|
||||
//// this.queryTurnBackTracksOnDirection(end, right, ftList);
|
||||
//// }
|
||||
//// }
|
||||
//// } else {
|
||||
//// // 循着自动信号后面的区段查询
|
||||
//// AutoSignal autoSignal = signal.getAutoSignal();
|
||||
//// if (Objects.nonNull(autoSignal)) {
|
||||
//// List<Section> sectionList = autoSignal.getSectionList();
|
||||
//// for (Section section : sectionList) {
|
||||
//// if (section.isTurnBackTrack()) {
|
||||
//// if (!ftList.contains(section)) {
|
||||
//// ftList.add(section);
|
||||
//// }
|
||||
//// break;
|
||||
//// } else {
|
||||
//// if (section.isNormalStandTrack() || section.isTransferTrack()) {
|
||||
//// break;
|
||||
//// }
|
||||
//// Signal signalOf = section.getSignalOf(right);
|
||||
//// if (Objects.nonNull(signalOf)) {
|
||||
//// this.queryTurnBackTracksOnDirection(signalOf, right, ftList);
|
||||
//// break;
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// /**
|
||||
//// * 查询指定方向的转换轨
|
||||
//// * @param signal
|
||||
//// * @param right
|
||||
//// * @param ftList
|
||||
//// */
|
||||
//// private void queryTransferTracksOnDirection(Signal signal, boolean right, List<Section> ftList) {
|
||||
//// if (Objects.isNull(signal)) {
|
||||
//// return;
|
||||
//// }
|
||||
//// List<Route> routeList = signal.getRouteList();
|
||||
//// if (!CollectionUtils.isEmpty(routeList)) {
|
||||
//// // 根据信号机的进路查询
|
||||
//// Set<Signal> signals = new HashSet<>();
|
||||
//// for (Route route : routeList) {
|
||||
//// boolean find = false;
|
||||
//// for (Section section : route.getSectionList()) {
|
||||
//// if (section.isTransferTrack()) {
|
||||
//// find = true;
|
||||
//// if (!ftList.contains(section)) {
|
||||
//// ftList.add(section);
|
||||
//// }
|
||||
//// break;
|
||||
//// } else if (section.isNormalStandTrack()) {
|
||||
//// find = true;
|
||||
//// break;
|
||||
//// }
|
||||
//// }
|
||||
//// if (find) {
|
||||
//// continue;
|
||||
//// } else {
|
||||
//// signals.add(route.getDestination());
|
||||
//// }
|
||||
//// }
|
||||
//// if (!CollectionUtils.isEmpty(signals)) {
|
||||
//// for (Signal end : signals) {
|
||||
//// this.queryTransferTracksOnDirection(end, right, ftList);
|
||||
//// }
|
||||
//// }
|
||||
//// } else {
|
||||
//// // 循着自动信号后面的区段查询
|
||||
//// AutoSignal autoSignal = signal.getAutoSignal();
|
||||
//// if (Objects.nonNull(autoSignal)) {
|
||||
//// List<Section> sectionList = autoSignal.getSectionList();
|
||||
//// for (Section section : sectionList) {
|
||||
//// if (section.isTransferTrack()) {
|
||||
//// if (!ftList.contains(section)) {
|
||||
//// ftList.add(section);
|
||||
//// }
|
||||
//// break;
|
||||
//// } else {
|
||||
//// if (section.isNormalStandTrack()) {
|
||||
//// break;
|
||||
//// }
|
||||
//// Signal signalOf = section.getSignalOf(right);
|
||||
//// if (Objects.nonNull(signalOf)) {
|
||||
//// this.queryTransferTracksOnDirection(signalOf, right, ftList);
|
||||
//// break;
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
//
|
||||
// /**
|
||||
// * 查询指定方向的正常站台轨
|
||||
// * @param signal 起始信号机和方向
|
||||
// * @param standRight 指定站台方向
|
||||
// * @param nstdList
|
||||
// * @return
|
||||
// */
|
||||
// private void queryNormalStandTracksOnDirectionFromSignal(Signal signal, boolean standRight, List<Section> nstdList) {
|
||||
// if (Objects.isNull(signal)) {
|
||||
// return;
|
||||
// }
|
||||
// boolean right = signal.isRight();
|
||||
// List<Route> routeList = signal.getRouteList();
|
||||
// if (!CollectionUtils.isEmpty(routeList)) {
|
||||
// // 根据信号机的进路查询
|
||||
// Set<Signal> signals = new HashSet<>();
|
||||
// for (Route route : routeList) {
|
||||
// boolean containOppositeStandTrack = false;
|
||||
// boolean contains = false;
|
||||
// for (Section section : route.getSectionList()) {
|
||||
// if (section.isNormalStandTrack()) {
|
||||
// if (!Objects.equals(section.getStandList().get(0).isRight(), standRight)) {
|
||||
// containOppositeStandTrack = true;
|
||||
// } else {
|
||||
// contains = true;
|
||||
// nstdList.add(section);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (containOppositeStandTrack) {
|
||||
// continue;
|
||||
// }
|
||||
// if (contains) {
|
||||
// continue;
|
||||
// } else {
|
||||
// signals.add(route.getDestination());
|
||||
// }
|
||||
//// Section lastRouteSection = route.getLastRouteSection();
|
||||
//// if (lastRouteSection.isNormalStandTrack()) {
|
||||
//// if (Objects.equals(lastRouteSection.getStandList().get(0).isRight(), standRight)) {
|
||||
//// if (!nstdList.contains(lastRouteSection)) {
|
||||
//// nstdList.add(lastRouteSection);
|
||||
//// }
|
||||
//// }
|
||||
//// continue;
|
||||
//// } else {
|
||||
//// signals.add(route.getDestination());
|
||||
//// }
|
||||
// }
|
||||
// if (!CollectionUtils.isEmpty(signals)) {
|
||||
// for (Signal end : signals) {
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(end, standRight, nstdList);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// // 循着自动信号后面的区段查询
|
||||
// AutoSignal autoSignal = signal.getAutoSignal();
|
||||
// if (Objects.nonNull(autoSignal)) {
|
||||
// List<Section> sectionList = autoSignal.getSectionList();
|
||||
// for (Section section : sectionList) {
|
||||
// if (section.isNormalStandTrack()) {
|
||||
// if (Objects.equals(section.getStandList().get(0).isRight(), standRight)) {
|
||||
// if (!nstdList.contains(section)) {
|
||||
// nstdList.add(section);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// } else {
|
||||
// Signal signalOf = section.getSignalOf(right);
|
||||
// if (Objects.nonNull(signalOf)) {
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signalOf, standRight, nstdList);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private boolean canArriveOppositeStandTrack(Section start, Section end, boolean right) {
|
||||
// Signal signal = start.getSignalOf(right);
|
||||
// List<Section> nstdList = new ArrayList<>();
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, !right, nstdList);
|
||||
// if (nstdList.contains(end)) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private void queryNormalStandTracksOnDirectionFromSection(Section lastSection, boolean right, List<Section> nstdList) {
|
||||
// Signal signal = lastSection.getSignalOf(right);
|
||||
// if (signal != null) {
|
||||
// this.queryNormalStandTracksOnDirectionFromSignal(signal, right, nstdList);
|
||||
// } else {
|
||||
// Section nextSection = lastSection.getSectionOf(right);
|
||||
// BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(nextSection);// 找到道岔区段,都没有找到信号机,数据有问题
|
||||
// if (nextSection.isNormalStandTrack() && nextSection.getStandList().get(0).isRight() == right) {
|
||||
// nstdList.add(nextSection);
|
||||
// return;
|
||||
// } else {
|
||||
// this.queryNormalStandTracksOnDirectionFromSection(nextSection, right, nstdList);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private boolean isContainOtherNormalStation(Section startSection, Section endSection, List<Station> stationList) {
|
||||
// int min = Math.min(startSection.getStation().getSn(), endSection.getStation().getSn());
|
||||
// int max = Math.max(startSection.getStation().getSn(), endSection.getStation().getSn());
|
||||
// int di = Math.abs(max - min);
|
||||
// if (di > 1) { // 间隔大于1,判断中间车站是否停车场/非正常车站
|
||||
// boolean jump = false;
|
||||
// for (Station station : stationList) {
|
||||
// if (station.getSn() > min && station.getSn() < max) {
|
||||
// if (!(station.isDepot() || station.isNoDepotAndNoNormalStand())) {
|
||||
// jump = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return jump;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
private String buildRoutingPathString(List<Section> sections) {
|
||||
return String.join(",", sections.stream()
|
||||
.map(section -> String.format("%s(%s)", section.getStation().getName(), section.getName()))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
}
|
@ -234,6 +234,7 @@ public class RunPlanRoutingService implements IRunPlanRoutingService {
|
||||
RunPlanRouting routing = getRunPlanRoutingData(routingId);
|
||||
if(Objects.equals(routing.getSectionData(),JsonUtils.writeValueAsString(routingVO.getParkSectionCodeList()))){
|
||||
runPlanRoutingDAO.updateByPrimaryKey(newRouting);
|
||||
return;
|
||||
}
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(routingDataExist(routingVO), "交路数据重复");
|
||||
runPlanRoutingDAO.updateByPrimaryKeyWithBLOBs(newRouting);
|
||||
|
@ -458,6 +458,8 @@ public class MapDeviceBuilder {
|
||||
}
|
||||
}
|
||||
});
|
||||
// 区段是否站台轨、转换轨检查
|
||||
checkSectionFunctionType(elementMap, errMsgList);
|
||||
// 信号机
|
||||
buildSignal(graphData, elementMap, deviceMap, errMsgList);
|
||||
|
||||
@ -744,6 +746,21 @@ public class MapDeviceBuilder {
|
||||
buildResponderDataRef(graphData, elementMap, errMsgList, mapDataBuildResult.getSectionRespondersMap());
|
||||
}
|
||||
|
||||
private static void checkSectionFunctionType(Map<String, MapElement> deviceMap, List<String> errMsgList) {
|
||||
List<Section> sectionList = deviceMap.values().stream()
|
||||
.filter(mapElement -> mapElement.getDeviceType().equals(MapElement.DeviceType.SECTION))
|
||||
.map(mapElement -> ((Section) mapElement))
|
||||
.collect(Collectors.toList());
|
||||
for (Section section : sectionList) {
|
||||
if (section.isStandTrack() && !section.isNormalStandTrack()) {
|
||||
errMsgList.add(String.format("区段[%s]不是正常站台的站台轨,却设置了站台轨属性", section.debugStr()));
|
||||
}
|
||||
if (section.isTransferTrack() && (section.getStation() == null || !section.getStation().isDepot())) {
|
||||
errMsgList.add(String.format("区段[%s]所属车站不是车辆段/停车场车站,却设置了转换轨属性", section.debugStr()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建区段数据
|
||||
*/
|
||||
@ -1047,7 +1064,6 @@ public class MapDeviceBuilder {
|
||||
station.setInterlock(stationVO.isCiStation());
|
||||
station.setHasControlMode(stationVO.isCreateControlMode());
|
||||
station.setDepot(stationVO.isDepot());
|
||||
station.setRoutingStationList(stationVO.getRoutingStationList());
|
||||
station.setTurnBack(stationVO.isReentry());
|
||||
station.setSmallRouting(stationVO.isSmallRouting());
|
||||
if (station.isDepot() && station.isTurnBack()) {
|
||||
|
@ -83,11 +83,6 @@ public class Station extends MayOutOfOrderDevice {
|
||||
*/
|
||||
private List<Section> transferList;
|
||||
|
||||
/**
|
||||
* 生成交路的车站列表
|
||||
*/
|
||||
private List<String> routingStationList;
|
||||
|
||||
/**
|
||||
* 是否折返站
|
||||
*/
|
||||
|
@ -80,10 +80,10 @@ public class MapRouteNewVO {
|
||||
@ApiModelProperty(value = "是否折返进路", required = true)
|
||||
private boolean turnBack;
|
||||
|
||||
/** 是否引导进路 */
|
||||
/** 是否atp进路 */
|
||||
private boolean atp;
|
||||
|
||||
/** 是否引导进路 */
|
||||
/** 是否联锁进路 */
|
||||
private boolean ground;
|
||||
|
||||
/** 是否引导进路 */
|
||||
|
@ -164,9 +164,6 @@ public class MapStationNewVO {
|
||||
*/
|
||||
private boolean depot;
|
||||
|
||||
/** 生成交路的车站列表 */
|
||||
private List<String> routingStationList;
|
||||
|
||||
/**
|
||||
* 是否折返站
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user