【实训背景列车反序列化逻辑修改】
This commit is contained in:
parent
6385e89ce4
commit
e32288027b
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.data.storage;
|
package club.joylink.rtss.simulation.cbtc.data.storage;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.ATP.ground.MaService;
|
||||||
import club.joylink.rtss.simulation.cbtc.CI.data.StationDirection;
|
import club.joylink.rtss.simulation.cbtc.CI.data.StationDirection;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import club.joylink.rtss.simulation.cbtc.build.RunPlanBuilder;
|
import club.joylink.rtss.simulation.cbtc.build.RunPlanBuilder;
|
||||||
@ -14,14 +15,16 @@ import club.joylink.rtss.simulation.cbtc.data.storage.vo.StorageTrainInfo;
|
|||||||
import club.joylink.rtss.simulation.cbtc.data.storage.vr.*;
|
import club.joylink.rtss.simulation.cbtc.data.storage.vr.*;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
|
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.vr.*;
|
import club.joylink.rtss.simulation.cbtc.data.vr.*;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.function.Consumer;
|
||||||
import java.util.Objects;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -426,11 +429,46 @@ public class StorageSimulationDataRepository {
|
|||||||
}
|
}
|
||||||
// 使用中的列车恢复
|
// 使用中的列车恢复
|
||||||
if (Objects.nonNull(this.usedTrainList)) {
|
if (Objects.nonNull(this.usedTrainList)) {
|
||||||
for (StorageVirtualRealityTrain train : this.usedTrainList) {
|
// 已经序列化的列车
|
||||||
|
List<String> alreadyRecoverTrainCode = new ArrayList<>(this.usedTrainList.size());
|
||||||
|
// 反序列化
|
||||||
|
Consumer<StorageVirtualRealityTrain> trainRecoverConsumer = train -> {
|
||||||
VirtualRealityDevice vrTrain = repository.getVRByCode(train.getGroupNumber());
|
VirtualRealityDevice vrTrain = repository.getVRByCode(train.getGroupNumber());
|
||||||
train.recover2Simulation(vrTrain, simulation, repository);
|
train.recover2Simulation(vrTrain, simulation, repository);
|
||||||
repository.addOnlineTrain((VirtualRealityTrain) vrTrain);
|
repository.addOnlineTrain((VirtualRealityTrain) vrTrain);
|
||||||
|
alreadyRecoverTrainCode.add(train.getCode());
|
||||||
|
};
|
||||||
|
// 前方列车类型的列车
|
||||||
|
Queue<StorageVirtualRealityTrain> trainsQueue = new LinkedList<>();
|
||||||
|
// 序列化不是前方列车类型的列车
|
||||||
|
for (StorageVirtualRealityTrain train : this.usedTrainList) {
|
||||||
|
if (train.getMa2() != null && MaService.MaType.Front_Train.equals(train.getMa2().getType())) {
|
||||||
|
trainsQueue.add(train);
|
||||||
|
} else {
|
||||||
|
trainRecoverConsumer.accept(train);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// 循环次数,防止死循环
|
||||||
|
int loopTimes = 0;
|
||||||
|
// 序列化前方列车类型的列车
|
||||||
|
while (!trainsQueue.isEmpty()) {
|
||||||
|
StorageVirtualRealityTrain train = trainsQueue.poll();
|
||||||
|
if (alreadyRecoverTrainCode.contains(train.getMa2().getDeviceCode())) { // 依赖列车已序列化
|
||||||
|
trainRecoverConsumer.accept(train);
|
||||||
|
loopTimes = 0;
|
||||||
|
} else if (loopTimes == 0) {
|
||||||
|
trainsQueue.add(train);
|
||||||
|
loopTimes ++;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 循环超过一次,打印错误信息
|
||||||
|
if (loopTimes > 0) {
|
||||||
|
String trainCode = trainsQueue.stream().map(StorageVirtualRealityTrain::getCode).collect(Collectors.joining(","));
|
||||||
|
throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error,String.format("问题列车【%s】", trainCode));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// 有状态的进路恢复
|
// 有状态的进路恢复
|
||||||
if (!CollectionUtils.isEmpty(this.settingRouteList)) {
|
if (!CollectionUtils.isEmpty(this.settingRouteList)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user