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

This commit is contained in:
joylink_zhangsai 2023-11-13 09:26:06 +08:00
commit f98dee79a0
1 changed files with 32 additions and 29 deletions

View File

@ -16,36 +16,39 @@ import java.util.Optional;
/**
* 车辆折返
*/
public class TurnBackService implements CalculateDiagram{
public class TurnBackService implements CalculateDiagram {
@Override
public Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation){
if(trainInfo.isTurnBack()/* && Objects.equals(trainInfo.getTurnBackStatus(),TrainInfo.EXIT)*/){
if(StringUtils.equalsAny(trainInfo.getTurnBackStatus(),TrainInfo.TO,TrainInfo.STOP)){
//列车开向折返轨或停留在折返轨
StationDiagram sd = new StationDiagram(train);
sd.setShowTrainDiagram(false);
return Optional.of(sd);
}else if(Objects.equals(trainInfo.getTurnBackStatus(),TrainInfo.EXIT)){
//列车离开折返轨
StationDiagram sd = new StationDiagram(train,0F,true);
sd.setStartStation(train.getNextStation());
Station nextStopStation = diagramStation.findNext(train.getNextStation(),train.isRight());
sd.setEndStation(nextStopStation);
sd.setTurnBack(true);
return Optional.of(sd);
}else{
//列车正在准备折返
Station lastStation = diagramStation.findLastNotDepotStation(train.isRight());
Station preStation = diagramStation.findPre(lastStation,train.isRight());
StationDiagram sd = new StationDiagram(train,1F,true);
sd.setStartStation(preStation);
sd.setEndStation(lastStation);
sd.setTurnBack(true);
return Optional.of(sd);
}
@Override
public Optional<StationDiagram> calculate(Simulation simulation, TrainInfo trainInfo, VirtualRealityTrain train, SortDiagramStation diagramStation) {
if (trainInfo.isTurnBack()/* && Objects.equals(trainInfo.getTurnBackStatus(),TrainInfo.EXIT)*/) {
if (StringUtils.equalsAny(trainInfo.getTurnBackStatus(), TrainInfo.TO, TrainInfo.STOP)) {
//列车开向折返轨或停留在折返轨
StationDiagram sd = new StationDiagram(train);
sd.setShowTrainDiagram(false);
return Optional.of(sd);
} else if (Objects.equals(trainInfo.getTurnBackStatus(), TrainInfo.EXIT)) {
//列车离开折返轨
if (Objects.isNull(train.getNextStation())) {
return Optional.empty();
}
return Optional.empty();
StationDiagram sd = new StationDiagram(train, 0F, true);
sd.setStartStation(train.getNextStation());
Station nextStopStation = diagramStation.findNext(train.getNextStation(), train.isRight());
sd.setEndStation(nextStopStation);
sd.setTurnBack(true);
return Optional.of(sd);
} else {
//列车正在准备折返
Station lastStation = diagramStation.findLastNotDepotStation(train.isRight());
Station preStation = diagramStation.findPre(lastStation, train.isRight());
StationDiagram sd = new StationDiagram(train, 1F, true);
sd.setStartStation(preStation);
sd.setEndStation(lastStation);
sd.setTurnBack(true);
return Optional.of(sd);
}
}
return Optional.empty();
}
}