修改StorageVirtualRealityTrain;增加一个粗糙的Storage类生成工具

This commit is contained in:
joylink_zhangsai 2022-12-05 15:07:56 +08:00
parent ddaf91647a
commit e5aa725dca
21 changed files with 682 additions and 502 deletions

View File

@ -366,6 +366,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
itemMap.put(SimulationWorkParamVO.Item.DEFAULT_MEMBER, dispatcherOptional.get().getId());
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.trainingDesign(true)
.hasMemberManager(true)
.build();
@ -389,6 +390,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
itemMap.put(SimulationWorkParamVO.Item.DEFAULT_MEMBER, dispatcherOptional.get().getId());
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.isJoint(true)
.hasMemberManager(true)
.build();
@ -404,6 +406,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.hasExam(true)
.build();
return buildCreateVO(mapId, name, name, simType, null, domConfig);
@ -418,6 +421,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.hasTraining(true)
.hasMemberManager(true)
.build();
@ -433,6 +437,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.hasTraining(true)
.build();
return buildCreateVO(mapId, name, name, simType, null, domConfig);
@ -478,6 +483,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.singleMember(true)
.hasMemberManager(true)
.build();
@ -501,6 +507,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.singleMember(true)
.hasMemberManager(true)
.build();
@ -561,6 +568,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.singleMember(true)
.hasMemberManager(true)
.build();
@ -584,6 +592,7 @@ public class RtsMapFunctionServiceImpl implements RtsMapFunctionService {
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = SimulationWorkParamVO.DomConfigVO.builder()
.hasVoice(true)
.singleMember(true)
.hasMemberManager(true)
.build();

View File

@ -10,6 +10,7 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@ -27,6 +28,7 @@ public class MaService {
private OnboardAtpApiService onboardAtpApiService;
@Getter
@Setter
public static class Ma {
public static final int Safety_Margin = 1; // 安全余量单位m暂时没有计算紧急制动曲线暂时不用
public static final int EB_Trigger = 20; // 紧急制动触发点偏移量单位m

View File

@ -35,7 +35,6 @@ public class ResponderService {
for (Responder responder : responders) {
if (responder.isBetween(headPosition, headPositionNew)) { // 列车经过应答器
log.debug(String.format("列车[%s]经过应答器[%s]", train.getGroupNumber(), responder.debugStr()));
train.viaResponder(responder);
if (!train.isCommunicable() && train.isAtpOn() &&
(responder.isIB() || responder.isVB())) {
this.maService.calculateAndUpdateItcMa(simulation, train, responder);

View File

@ -87,10 +87,6 @@ public class Responder extends MapNamedElement {
return this.isVB() || this.isFB();
}
public void exchangeData(VirtualRealityTrain train) {
train.viaResponder(this);
}
public boolean isBetween(SectionPosition a, SectionPosition b) {
return this.position.isBetween(a, b);
}

View File

@ -378,25 +378,25 @@ public class StorageSimulationDataRepository {
if (Objects.nonNull(this.vrDoorList)) {
for (StorageVirtualRealityScreenDoor vrDoor : this.vrDoorList) {
VirtualRealityDevice vrDevice = repository.getVRByCode(vrDoor.getCode());
vrDoor.recover2Simulation(vrDevice, repository);
vrDoor.recover2Simulation(vrDevice, simulation, repository);
}
}
if (Objects.nonNull(this.vrSignalList)) {
for (StorageVirtualRealitySignal vrSignal : this.vrSignalList) {
VirtualRealityDevice vrDevice = repository.getVRByCode(vrSignal.getCode());
vrSignal.recover2Simulation(vrDevice, repository);
vrSignal.recover2Simulation(vrDevice, simulation, repository);
}
}
if (Objects.nonNull(this.vrSwitchList)) {
for (StorageVirtualRealitySwitch vrSwitch : this.vrSwitchList) {
VirtualRealityDevice vrDevice = repository.getVRByCode(vrSwitch.getCode());
vrSwitch.recover2Simulation(vrDevice, repository);
vrSwitch.recover2Simulation(vrDevice, simulation, repository);
}
}
if (Objects.nonNull(this.vrSectionList)) {
for (StorageVirtualRealitySection vrSection : this.vrSectionList) {
VirtualRealityDevice vrDevice = repository.getVRByCode(vrSection.getCode());
vrSection.recover2Simulation(vrDevice, repository);
vrSection.recover2Simulation(vrDevice, simulation, repository);
}
}
// 恢复服务-车次计划列表map
@ -428,7 +428,7 @@ public class StorageSimulationDataRepository {
if (Objects.nonNull(this.usedTrainList)) {
for (StorageVirtualRealityTrain train : this.usedTrainList) {
VirtualRealityDevice vrTrain = repository.getVRByCode(train.getGroupNumber());
train.recover2Simulation(vrTrain, repository);
train.recover2Simulation(vrTrain, simulation, repository);
repository.addOnlineTrain((VirtualRealityTrain) vrTrain);
}
}

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.data.storage.ato;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@ -23,7 +23,7 @@ public class StorageSpeedCurve {
this.speedCalculators = StorageSpeedCalculator.convertFromSpeedCalculatorList(speedCurve.getSpeedCalculators());
}
public SpeedCurve recover2Simulation(SimulationDataRepository repository) {
public SpeedCurve convert2SimulationObj(SimulationDataRepository repository) {
return new SpeedCurve(totalDistance,
StorageSpeedCalculator.convert2SpeedCalculatorList(speedCalculators));
}

View File

@ -1,6 +1,8 @@
package club.joylink.rtss.simulation.cbtc.data.storage.support;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Signal;
import club.joylink.rtss.vo.client.operation.DriveParamVO;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -9,7 +11,7 @@ import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class StorageDriveParam {
public class StorageDriveParamVO {
/**
* 限速值
*/
@ -41,7 +43,7 @@ public class StorageDriveParam {
private boolean releaseEB;
public StorageDriveParam(DriveParamVO param) {
public StorageDriveParamVO(DriveParamVO param) {
this.speedLimit = param.getSpeedLimit();
this.run = param.isRun();
this.targetDeviceCode = param.getTargetDeviceCode();
@ -53,4 +55,21 @@ public class StorageDriveParam {
this.throughSignalAspect = param.getThroughSignalAspect();
this.releaseEB = param.isReleaseEB();
}
public DriveParamVO convert2SimulationObj(SimulationDataRepository repository) {
DriveParamVO param = new DriveParamVO();
param.setSpeedLimit(speedLimit);
param.setRun(run);
param.setTargetDeviceCode(targetDeviceCode);
if (targetPosition != null) {
param.setTargetPosition(targetPosition.convert2SimulationObj(repository));
}
param.setThrough(through);
if (throughSignal != null) {
param.setThroughSignal(repository.getByCode(throughSignal, Signal.class));
}
param.setThroughSignalAspect(throughSignalAspect);
param.setReleaseEB(releaseEB);
return param;
}
}

View File

@ -0,0 +1,55 @@
package club.joylink.rtss.simulation.cbtc.data.storage.support;
import club.joylink.rtss.simulation.cbtc.ATP.ground.MaService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.storage.ato.StorageSpeedCurve;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import lombok.NonNull;
public class StorageMa {
private String trainCode;
private String deviceCode;
private MaService.MaType type;
private StorageSectionPosition eoaPosition;
private float distanceToEoa;
private StorageSpeedCurve ebTriggerCurve;
private StorageSpeedCurve atoStopCurve;
public StorageMa(@NonNull MaService.Ma ma) {
if (ma.getTrain() != null) {
this.trainCode = ma.getTrain().getCode();
}
if (ma.getDevice() != null) {
this.deviceCode = ma.getDevice().getCode();
}
this.type = ma.getType();
if (ma.getEoaPosition() != null) {
this.eoaPosition = new StorageSectionPosition(ma.getEoaPosition());
}
this.distanceToEoa = ma.getDistanceToEoa();
if (ma.getEbTriggerCurve() != null) {
this.ebTriggerCurve = new StorageSpeedCurve(ma.getEbTriggerCurve());
}
if (ma.getAtoStopCurve() != null) {
this.atoStopCurve = new StorageSpeedCurve(ma.getAtoStopCurve());
}
}
public MaService.Ma convert2SimulationObj(SimulationDataRepository repository) {
VirtualRealityTrain train = repository.getByCode(trainCode, VirtualRealityTrain.class);
MapNamedElement device = repository.getByCode(deviceCode, MapNamedElement.class);
MaService.Ma ma = new MaService.Ma(train, device, type);
if (eoaPosition != null) {
ma.setEoaPosition(eoaPosition.convert2SimulationObj(repository));
}
ma.setDistanceToEoa(distanceToEoa);
if (ebTriggerCurve != null) {
ma.setEbTriggerCurve(ebTriggerCurve.convert2SimulationObj(repository));
}
if (atoStopCurve != null) {
ma.setAtoStopCurve(atoStopCurve.convert2SimulationObj(repository));
}
return ma;
}
}

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.simulation.cbtc.data.storage.support;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
@ -8,6 +7,7 @@ import club.joylink.rtss.simulation.cbtc.data.storage.ato.StorageSpeedCurve;
import club.joylink.rtss.simulation.cbtc.data.support.MovementAuthority;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@ -17,7 +17,7 @@ import java.util.Objects;
@Getter
@Setter
@NoArgsConstructor
public class StorageMA {
public class StorageMovementAuthority {
/** 移动授权终点设备存储 */
private StorageEnd end;
@ -25,7 +25,7 @@ public class StorageMA {
/** 防护速度曲线 */
private StorageSpeedCurve protectSpeedCurve;
public StorageMA(MovementAuthority ma) {
public StorageMovementAuthority(MovementAuthority ma) {
if (ma.getEnd() != null) {
this.end = new StorageEnd(ma.getEnd());
}
@ -37,7 +37,7 @@ public class StorageMA {
public MovementAuthority convert2SimulationObj(SimulationDataRepository repository) {
SpeedCurve psc = null;
if (Objects.nonNull(this.protectSpeedCurve)) {
psc = this.protectSpeedCurve.recover2Simulation(repository);
psc = this.protectSpeedCurve.convert2SimulationObj(repository);
}
return new MovementAuthority(end.convert2SimulationObj(repository), psc);
}

View File

@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
public abstract class StorageControllableVrDevice<C> extends StorageVirtualRealityDeviceStatus {
public abstract class StorageControllableVrDevice<C> extends StorageVirtualRealityDevice {
/**
* 控制指令
*/

View File

@ -1,7 +1,8 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumDeserializer;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
@ -16,7 +17,7 @@ import java.util.Objects;
@Getter
@Setter
@NoArgsConstructor
public class StorageTrainDoor extends StorageControllableVrDevice<VirtualRealityTrain.Door.Operation> {
public class StorageDoor extends StorageControllableVrDevice<VirtualRealityTrain.Door.Operation> {
private String code;
@JsonSerialize(using = Boolean2NumSerializer.class)
@ -27,7 +28,7 @@ public class StorageTrainDoor extends StorageControllableVrDevice<VirtualReality
@JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean lock;
public StorageTrainDoor(VirtualRealityTrain.Door door) {
public StorageDoor(VirtualRealityTrain.Door door) {
this.code = door.getCode();
this.close = door.isClose();
this.lock = door.isLock();
@ -49,7 +50,21 @@ public class StorageTrainDoor extends StorageControllableVrDevice<VirtualReality
}
@Override
public void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository) {
public boolean convert(MapElement element) {
return false;
}
@Override
public void recover2Simulation(MapElement element, Simulation simulation, SimulationDataRepository repository) {
VirtualRealityTrain.Door door = (VirtualRealityTrain.Door) element;
if (Objects.nonNull(this.close)) {
door.setClose(close);
}
if (Objects.nonNull(this.lock)) {
door.setLock(lock);
}
if (this.getRemain() > 0) {
this.recoverTo(door);
}
}
}

View File

@ -0,0 +1,19 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.data.storage.device.StorageDevice;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public abstract class StorageVirtualRealityDevice extends StorageDevice {
private String code;
public StorageVirtualRealityDevice(VirtualRealityDevice device) {
super(device.getCode());
}
}

View File

@ -1,23 +0,0 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.vr.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public abstract class StorageVirtualRealityDeviceStatus {
private String code;
public StorageVirtualRealityDeviceStatus(VirtualRealityDevice device) {
this.code = device.getCode();
}
public abstract void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository);
}

View File

@ -1,7 +1,8 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumDeserializer;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
@ -92,7 +93,12 @@ public class StorageVirtualRealityScreenDoor extends StorageControllableVrDevice
}
@Override
public void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository) {
public boolean convert(MapElement element) {
return false;
}
@Override
public void recover2Simulation(MapElement vrDevice, Simulation simulation, SimulationDataRepository repository) {
VirtualRealityScreenDoor door = (VirtualRealityScreenDoor) vrDevice;
door.setClose(close != null ? close : true);
door.setOpen2End(open2End != null ? open2End : false);

View File

@ -1,12 +1,13 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumDeserializer;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@ -14,7 +15,7 @@ import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class StorageVirtualRealitySection extends StorageVirtualRealityDeviceStatus {
public class StorageVirtualRealitySection extends StorageVirtualRealityDevice {
/**
* 是否占用
@ -67,7 +68,12 @@ public class StorageVirtualRealitySection extends StorageVirtualRealityDeviceSta
}
@Override
public void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository) {
public boolean convert(MapElement element) {
return true;
}
@Override
public void recover2Simulation(MapElement vrDevice, Simulation simulation, SimulationDataRepository repository) {
VirtualRealitySectionAxleCounter s = (VirtualRealitySectionAxleCounter) vrDevice;
s.setOccupy(occupy != null ? occupy : false);
s.setPreReset(preReset != null ? preReset : false);

View File

@ -1,8 +1,9 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -43,7 +44,7 @@ public class StorageVirtualRealitySignal extends StorageControllableVrDevice<Sig
}
@Override
public void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository) {
public void recover2Simulation(MapElement vrDevice, Simulation simulation, SimulationDataRepository repository) {
VirtualRealitySignal signal = (VirtualRealitySignal) vrDevice;
if (this.aspect != null) {
signal.setAspect(this.aspect);
@ -53,4 +54,9 @@ public class StorageVirtualRealitySignal extends StorageControllableVrDevice<Sig
}
signal.setFault(fault);
}
@Override
public boolean convert(MapElement element) {
return false;
}
}

View File

@ -1,8 +1,9 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import lombok.Getter;
import lombok.NoArgsConstructor;
@ -46,7 +47,7 @@ public class StorageVirtualRealitySwitch extends StorageControllableVrDevice<Vir
}
@Override
public void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository) {
public void recover2Simulation(MapElement vrDevice, Simulation simulation, SimulationDataRepository repository) {
VirtualRealitySwitch s = (VirtualRealitySwitch) vrDevice;
if (this.p != null) {
s.setP(p);
@ -55,4 +56,9 @@ public class StorageVirtualRealitySwitch extends StorageControllableVrDevice<Vir
this.recoverTo(s);
}
}
@Override
public boolean convert(MapElement element) {
return false;
}
}

View File

@ -1,463 +1,310 @@
package club.joylink.rtss.simulation.cbtc.data.storage.vr;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.DriveMode;
import club.joylink.rtss.simulation.cbtc.constant.RunLevel;
import club.joylink.rtss.simulation.cbtc.constant.TrainTBControl;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Responder;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.map.Signal;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageDriveParam;
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageMA;
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageDriveParamVO;
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageMa;
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageMovementAuthority;
import club.joylink.rtss.simulation.cbtc.data.storage.support.StorageSectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vr.StandParkedTrainActivity;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityAudio;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.vo.client.operation.DriveParamVO;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.LinkedHashSet;
@Getter
@Setter
@NoArgsConstructor
public class StorageVirtualRealityTrain extends StorageVirtualRealityDeviceStatus {
/**
* 车组号
*/
public class StorageVirtualRealityTrain extends StorageVirtualRealityDevice {
private String groupNumber;
/**
* 列车运行级别
*/
private boolean noCommunicateDevice;
private boolean communication;
private RunLevel runLevel;
/**
* 驾驶模式
*/
private DriveMode driveMode;
/**
* 临时预选模式
*/
private VirtualRealityTrain.PreselectionMode tempPreselectionMode;
/**
* 预选模式
*/
private VirtualRealityTrain.PreselectionMode preselectionMode;
/**
* 服务号
*/
private PreselectionMode tempPreselectionMode;
private PreselectionMode preselectionMode;
private String serviceNumber;
/**
* 车次号
*/
private String tripNumber;
/**
* 目的地码
*/
private String destinationCode;
/**
* 下一站
*/
private String nextStationCode;
/**
* 即将到站
*/
private boolean beAbout2Arrive;
/**
* 下一目标区段code
*/
private String targetSectionCode;
/**
* 站台停靠时间
*/
private String targetCode;
private int parkTime;
/**
* 停站剩余时间,单位ms
*/
private int parkRemainTime;
/**
* 发车提示
*/
private String parkSectionCode;
private boolean departure;
/**
* 列车站台停靠
*/
private boolean parking;
/**
* 站台停靠列车动作
*/
private StandParkedTrainActivity standParkedTrainActivity;
private boolean nextParking;
/**
* 跳站信息
*/
private boolean jump;
/**
* 是否扣车
*/
private boolean hold;
/**
* 制动
*/
private boolean breaking;
/**
* 终点站
*/
private String terminalStationCode;
/**
* 车头位置
*/
private StorageSectionPosition headPosition;
/**
* 车尾位置
*/
private StorageSectionPosition tailPosition;
/**
* 是否向右行驶
*/
private boolean right;
/**
* 托管的目标位置
*/
private StorageSectionPosition robotTargetPosition;
/**
* 移动授权
*/
private StorageMA ma;
private StorageMovementAuthority ma;
private StorageMa ma2;
private int cbtcMaMissDuration;
private int itcMaMissDuration;
private VirtualRealityTrain.Handwheel gear;
/**
* 实际运行速度
*/
private Handwheel gear;
private float speed;
private float locationKM;
private float targetDistance;
private float atoSpeedMax;
/**
* ATO推荐速度
*/
private float atoSpeed;
/**
* ATP防护速度
*/
private float atpSpeed;
/**
* 限速
*/
private float speedLimit;
/**
* 是否信号EB
*/
private boolean signalEB;
/**
* 是否电路EB
*/
private boolean circuitEB;
/**
* 是否折返中
*/
private StandParkedTrainActivity standParkedTrainActivity;
private boolean nextParking;
private boolean jump;
private boolean hold;
private boolean trainHold;
private boolean dtro;
private boolean changeEnds;
private int changeEndsRemainTime;
/**
* ATO是否开启
*/
private boolean atoOn;
/**
* ATP是否可用
*/
private boolean atpOn;
private boolean priorityRouteSet;
/**
* 门1
*/
private StorageTrainDoor door1;
/**
* 门2
*/
private StorageTrainDoor door2;
/**
* 当前功率
*/
private float currentPower;
/**
* 牵引力,单位kN
* 公式 fk = 350 (0 <= v <= 36km/h)
* fk = 12900 / v (36 < v < 80km/h)
*/
private StorageDoor door1;
private StorageDoor door2;
private DoorMode doorMode;
private DoorSelection doorSelection;
private float fk;
/**
* 制动力,单位kN
*/
private float fb;
private TrainTBControl tbControl;
private float leverPosition;
private VirtualRealityTrain.Fault fault;
private Fault fault;
private boolean backUp;
/**
* 发车延迟时间
*/
private int delayTime;
private boolean powerOn;
private boolean pantograph1Up;
private boolean pantograph2Up;
private String linkTrainCode;
private RunType runType;
private boolean orderStop;
private boolean needDepartureCommand;
private boolean positioned;
private int runningTime;
private boolean released;
private LinkedHashSet<ConfirmationMessage> confirmationMessages;
private boolean atoCanOpen;
private String vrAudioCode;
private StorageDriveParamVO robotDriveParam;
/**
* 列车是否通电
*/
private boolean powerOn = true;
private boolean pantograph1Up = true;
private boolean pantograph2Up = true;
private String linkTrainGroupNumber;
// private Queue<Responder> lastTwoPassedResponders;
private List<String> lastTwoPassedResponders;
private StorageDriveParam driveParam;
private String parkSection;
public StorageVirtualRealityTrain(VirtualRealityTrain train) {
super(train);
this.groupNumber = train.getGroupNumber();
this.runLevel = train.getRunLevel();
this.driveMode = train.getDriveMode();
this.tempPreselectionMode = train.getTempPreselectionMode();
this.preselectionMode = train.getPreselectionMode();
this.serviceNumber = train.getServiceNumber();
this.tripNumber = train.getTripNumber();
this.destinationCode = train.getDestinationCode();
if (train.getNextStation() != null) {
this.nextStationCode = train.getNextStation().getCode();
}
if (Objects.nonNull(train.getTarget())) {
this.targetSectionCode = train.getTarget().getCode();
}
this.standParkedTrainActivity = train.getStandParkedTrainActivity();
this.nextParking = train.isNextParking();
this.beAbout2Arrive = train.isBeAbout2Arrive();
this.jump = train.isJump();
this.hold = train.isHold();
this.parkTime = train.getParkTime();
this.parkRemainTime = train.getParkRemainTime();
this.departure = train.isDeparture();
this.breaking = train.isBreaking();
if (train.getTerminalStation() != null) {
this.terminalStationCode = train.getTerminalStation().getCode();
}
if (train.getHeadPosition() != null) {
this.headPosition = new StorageSectionPosition(train.getHeadPosition());
}
this.right = train.isRight();
// if (train.getRobotTargetPosition() != null) {
// this.robotTargetPosition = new StorageSectionPosition(train.getRobotTargetPosition());
// }
if (train.getMa() != null) {
this.ma = new StorageMA(train.getMa());
}
this.cbtcMaMissDuration = train.getCbtcMaMissDuration();
this.gear = train.getGear();
this.speed = train.getSpeed();
this.targetDistance = train.getTargetDistance();
this.atoSpeedMax = train.getAtoSpeedMax();
this.atoSpeed = train.getAtoSpeed();
this.atpSpeed = train.getAtpSpeed();
// this.speedLimit = train.getNonNullSpeedLimit();
this.signalEB = train.isSignalEB();
this.circuitEB = train.isCircuitEB();
this.dtro = train.isDtro();
this.changeEnds = train.isChangeEnds();
this.changeEndsRemainTime = train.getChangeEndsRemainTime();
this.atoOn = train.isAtoOn();
this.atpOn = train.isAtpOn();
this.priorityRouteSet = train.isPriorityRouteSet();
this.door1 = new StorageTrainDoor(train.getDoor1());
this.door2 = new StorageTrainDoor(train.getDoor2());
this.fk = train.getFk();
this.fb = train.getFb();
this.tbControl = train.getTbControl();
this.leverPosition = train.getLeverPosition();
this.fault = train.getFault();
this.backUp = train.isBackUp();
this.delayTime = train.getDelayTime();
this.powerOn = train.isPowerOn();
this.pantograph1Up = train.isPantograph1Up();
this.pantograph2Up = train.isPantograph2Up();
if (train.getLinkTrain() != null) {
this.linkTrainGroupNumber = train.getLinkTrain().getGroupNumber();
}
// 20220721修改为保存应答器Code
this.lastTwoPassedResponders = train.getLastTwoPassedResponders().stream().map(Responder::getCode).collect(Collectors.toList());
this.driveParam = new StorageDriveParam(train.getRobotDriveParam());
if (train.getParkSection() != null) {
this.parkSection = train.getParkSection().getCode();
}
public StorageVirtualRealityTrain(VirtualRealityTrain virtualRealityTrain) {
super(virtualRealityTrain);
groupNumber = virtualRealityTrain.getGroupNumber();
}
public static StorageVirtualRealityTrain convert2Storage(VirtualRealityTrain vrTrain) {
return new StorageVirtualRealityTrain(vrTrain);
public static StorageVirtualRealityTrain convert2Storage(VirtualRealityTrain virtualRealityTrain) {
StorageVirtualRealityTrain storageVirtualRealityTrain = new StorageVirtualRealityTrain(virtualRealityTrain);
storageVirtualRealityTrain.setNoCommunicateDevice(virtualRealityTrain.isNoCommunicateDevice());
storageVirtualRealityTrain.setCommunication(virtualRealityTrain.isCommunication());
storageVirtualRealityTrain.setRunLevel(virtualRealityTrain.getRunLevel());
storageVirtualRealityTrain.setDriveMode(virtualRealityTrain.getDriveMode());
storageVirtualRealityTrain.setTempPreselectionMode(virtualRealityTrain.getTempPreselectionMode());
storageVirtualRealityTrain.setPreselectionMode(virtualRealityTrain.getPreselectionMode());
storageVirtualRealityTrain.setServiceNumber(virtualRealityTrain.getServiceNumber());
storageVirtualRealityTrain.setTripNumber(virtualRealityTrain.getTripNumber());
storageVirtualRealityTrain.setDestinationCode(virtualRealityTrain.getDestinationCode());
if (virtualRealityTrain.getNextStation() != null) {
storageVirtualRealityTrain.setNextStationCode(virtualRealityTrain.getNextStation().getCode());
}
storageVirtualRealityTrain.setBeAbout2Arrive(virtualRealityTrain.isBeAbout2Arrive());
if (virtualRealityTrain.getTarget() != null) {
storageVirtualRealityTrain.setTargetCode(virtualRealityTrain.getTarget().getCode());
}
storageVirtualRealityTrain.setParkTime(virtualRealityTrain.getParkTime());
storageVirtualRealityTrain.setParkRemainTime(virtualRealityTrain.getParkRemainTime());
if (virtualRealityTrain.getParkSection() != null) {
storageVirtualRealityTrain.setParkSectionCode(virtualRealityTrain.getParkSection().getCode());
}
storageVirtualRealityTrain.setDeparture(virtualRealityTrain.isDeparture());
storageVirtualRealityTrain.setBreaking(virtualRealityTrain.isBreaking());
if (virtualRealityTrain.getTerminalStation() != null) {
storageVirtualRealityTrain.setTerminalStationCode(virtualRealityTrain.getTerminalStation().getCode());
}
if (virtualRealityTrain.getHeadPosition() != null) {
storageVirtualRealityTrain.setHeadPosition(new StorageSectionPosition(virtualRealityTrain.getHeadPosition()));
}
if (virtualRealityTrain.getTailPosition() != null) {
storageVirtualRealityTrain.setTailPosition(new StorageSectionPosition(virtualRealityTrain.getTailPosition()));
}
storageVirtualRealityTrain.setRight(virtualRealityTrain.isRight());
if (virtualRealityTrain.getMa() != null) {
storageVirtualRealityTrain.setMa(new StorageMovementAuthority(virtualRealityTrain.getMa()));
}
if (virtualRealityTrain.getMa2() != null) {
storageVirtualRealityTrain.setMa2(new StorageMa(virtualRealityTrain.getMa2()));
}
storageVirtualRealityTrain.setCbtcMaMissDuration(virtualRealityTrain.getCbtcMaMissDuration());
storageVirtualRealityTrain.setGear(virtualRealityTrain.getGear());
storageVirtualRealityTrain.setSpeed(virtualRealityTrain.getSpeed());
storageVirtualRealityTrain.setLocationKM(virtualRealityTrain.getLocationKM());
storageVirtualRealityTrain.setTargetDistance(virtualRealityTrain.getTargetDistance());
storageVirtualRealityTrain.setAtoSpeedMax(virtualRealityTrain.getAtoSpeedMax());
storageVirtualRealityTrain.setAtoSpeed(virtualRealityTrain.getAtoSpeed());
storageVirtualRealityTrain.setAtpSpeed(virtualRealityTrain.getAtpSpeed());
storageVirtualRealityTrain.setSignalEB(virtualRealityTrain.isSignalEB());
storageVirtualRealityTrain.setCircuitEB(virtualRealityTrain.isCircuitEB());
storageVirtualRealityTrain.setStandParkedTrainActivity(virtualRealityTrain.getStandParkedTrainActivity());
storageVirtualRealityTrain.setNextParking(virtualRealityTrain.isNextParking());
storageVirtualRealityTrain.setJump(virtualRealityTrain.isJump());
storageVirtualRealityTrain.setHold(virtualRealityTrain.isHold());
storageVirtualRealityTrain.setTrainHold(virtualRealityTrain.isTrainHold());
storageVirtualRealityTrain.setDtro(virtualRealityTrain.isDtro());
storageVirtualRealityTrain.setChangeEnds(virtualRealityTrain.isChangeEnds());
storageVirtualRealityTrain.setChangeEndsRemainTime(virtualRealityTrain.getChangeEndsRemainTime());
storageVirtualRealityTrain.setAtoOn(virtualRealityTrain.isAtoOn());
storageVirtualRealityTrain.setAtpOn(virtualRealityTrain.isAtpOn());
storageVirtualRealityTrain.setPriorityRouteSet(virtualRealityTrain.isPriorityRouteSet());
if (virtualRealityTrain.getDoor1() != null) {
storageVirtualRealityTrain.setDoor1(new StorageDoor(virtualRealityTrain.getDoor1()));
}
if (virtualRealityTrain.getDoor2() != null) {
storageVirtualRealityTrain.setDoor2(new StorageDoor(virtualRealityTrain.getDoor2()));
}
storageVirtualRealityTrain.setDoorMode(virtualRealityTrain.getDoorMode());
storageVirtualRealityTrain.setDoorSelection(virtualRealityTrain.getDoorSelection());
storageVirtualRealityTrain.setFk(virtualRealityTrain.getFk());
storageVirtualRealityTrain.setFb(virtualRealityTrain.getFb());
storageVirtualRealityTrain.setTbControl(virtualRealityTrain.getTbControl());
storageVirtualRealityTrain.setLeverPosition(virtualRealityTrain.getLeverPosition());
storageVirtualRealityTrain.setFault(virtualRealityTrain.getFault());
storageVirtualRealityTrain.setBackUp(virtualRealityTrain.isBackUp());
storageVirtualRealityTrain.setDelayTime(virtualRealityTrain.getDelayTime());
storageVirtualRealityTrain.setPowerOn(virtualRealityTrain.isPowerOn());
storageVirtualRealityTrain.setPantograph1Up(virtualRealityTrain.isPantograph1Up());
storageVirtualRealityTrain.setPantograph2Up(virtualRealityTrain.isPantograph2Up());
if (virtualRealityTrain.getLinkTrain() != null) {
storageVirtualRealityTrain.setLinkTrainCode(virtualRealityTrain.getLinkTrain().getCode());
}
storageVirtualRealityTrain.setRunType(virtualRealityTrain.getRunType());
storageVirtualRealityTrain.setOrderStop(virtualRealityTrain.isOrderStop());
storageVirtualRealityTrain.setNeedDepartureCommand(virtualRealityTrain.isNeedDepartureCommand());
storageVirtualRealityTrain.setPositioned(virtualRealityTrain.isPositioned());
storageVirtualRealityTrain.setRunningTime(virtualRealityTrain.getRunningTime());
storageVirtualRealityTrain.setReleased(virtualRealityTrain.isReleased());
storageVirtualRealityTrain.setConfirmationMessages(virtualRealityTrain.getConfirmationMessages());
storageVirtualRealityTrain.setAtoCanOpen(virtualRealityTrain.isAtoCanOpen());
if (virtualRealityTrain.getVrAudio() != null) {
storageVirtualRealityTrain.setVrAudioCode(virtualRealityTrain.getVrAudio().getCode());
}
if (virtualRealityTrain.getRobotDriveParam() != null) {
storageVirtualRealityTrain.setRobotDriveParam(new StorageDriveParamVO(virtualRealityTrain.getRobotDriveParam()));
}
return storageVirtualRealityTrain;
}
@Override
public void recover2Simulation(VirtualRealityDevice vrDevice, SimulationDataRepository repository) {
VirtualRealityTrain train = (VirtualRealityTrain) vrDevice;
train.setRunLevel(runLevel);
train.setDriveMode(driveMode);
train.setTempPreselectionMode(tempPreselectionMode);
train.setPreselectionMode(preselectionMode);
train.setServiceNumber(serviceNumber);
train.setTripNumber(tripNumber);
train.setDestinationCode(destinationCode);
Section targetSection;
if (Objects.nonNull(this.targetSectionCode)) {
targetSection = repository.getByCode(this.targetSectionCode, Section.class);
train.setTarget(targetSection);
}
Station nextStation;
if (Objects.nonNull(this.nextStationCode)) {
nextStation = repository.getByCode(nextStationCode, Station.class);
train.setNextStation(nextStation);
}
train.setBeAbout2Arrive(beAbout2Arrive);
train.setNextParking(nextParking);
train.setStandParkedTrainActivity(this.standParkedTrainActivity);
train.setJump(jump);
train.setHold(hold);
train.setParkTime(parkTime);
train.setParkRemainTime(parkRemainTime);
train.setDeparture(departure);
train.setBreaking(breaking);
if (terminalStationCode != null) {
train.setTerminalStation(repository.getByCode(terminalStationCode, Station.class));
}
if (headPosition != null) {
train.setHeadPosition(headPosition.convert2SimulationObj(repository));
}
train.setRight(right);
if (robotTargetPosition != null) {
train.setRobotTargetPosition(robotTargetPosition.convert2SimulationObj(repository));
}
if (ma != null) {
train.setMa(ma.convert2SimulationObj(repository));
}
train.setCbtcMaMissDuration(cbtcMaMissDuration);
train.setGear(this.gear == null ? VirtualRealityTrain.Handwheel.ATO : this.gear);
train.setSpeed(speed);
train.setTargetDistance(targetDistance);
train.setAtoSpeedMax(atoSpeedMax);
train.setAtoSpeed(atoSpeed);
train.setAtpSpeed(atpSpeed);
train.setSpeedLimit(speedLimit);
train.setSignalEB(signalEB);
train.setCircuitEB(circuitEB);
train.setDtro(dtro);
train.setChangeEnds(changeEnds);
train.setChangeEndsRemainTime(changeEndsRemainTime);
train.setAtoOn(atoOn);
train.setAtpOn(atpOn);
train.setPriorityRouteSet(priorityRouteSet);
if (door1 != null) {
door1.recover2Simulation(train.getDoor1());
}
if (door2 != null) {
door2.recover2Simulation(train.getDoor2());
}
train.setFk(fk);
train.setFb(fb);
train.setTbControl(tbControl);
train.setLeverPosition(leverPosition);
train.setFault(this.fault);
train.setBackUp(backUp);
train.setDelayTime(delayTime);
train.setPowerOn(powerOn);
train.setPantograph1Up(pantograph1Up);
train.setPantograph2Up(pantograph2Up);
if (linkTrainGroupNumber != null) {
train.setLinkTrain(repository.getVRByCode(linkTrainGroupNumber, VirtualRealityTrain.class));
}
// 这里原本反序列化注释后续再做处理
if (!CollectionUtils.isEmpty(lastTwoPassedResponders)) {
// train.setLastTwoPassedResponders(lastTwoPassedResponders);
}
if (driveParam != null) {
train.setRobotDriveParam(convert2DriveParam(driveParam, repository));
}
if (parkSection != null) {
train.setParkSection(repository.getByCode(parkSection, Section.class));
}
public boolean convert(MapElement element) {
return true;
}
private DriveParamVO convert2DriveParam(StorageDriveParam storageDriveParam, SimulationDataRepository repository) {
DriveParamVO param = new DriveParamVO();
param.setSpeedLimit(storageDriveParam.getSpeedLimit());
param.setRun(storageDriveParam.isRun());
param.setTargetDeviceCode(storageDriveParam.getTargetDeviceCode());
if (storageDriveParam.getTargetPosition() != null) {
param.setTargetPosition(storageDriveParam.getTargetPosition().convert2SimulationObj(repository));
@Override
public void recover2Simulation(MapElement element, Simulation simulation, SimulationDataRepository repository) {
VirtualRealityTrain virtualRealityTrain = (VirtualRealityTrain) element;
virtualRealityTrain.setNoCommunicateDevice(noCommunicateDevice);
virtualRealityTrain.setCommunication(communication);
virtualRealityTrain.setRunLevel(runLevel);
virtualRealityTrain.setDriveMode(driveMode);
virtualRealityTrain.setTempPreselectionMode(tempPreselectionMode);
virtualRealityTrain.setPreselectionMode(preselectionMode);
virtualRealityTrain.setServiceNumber(serviceNumber);
virtualRealityTrain.setTripNumber(tripNumber);
virtualRealityTrain.setDestinationCode(destinationCode);
if (nextStationCode != null) {
virtualRealityTrain.setNextStation(repository.getByCode(nextStationCode, Station.class));
}
param.setThrough(storageDriveParam.getThrough());
if (storageDriveParam.getThroughSignal() != null) {
param.setThroughSignal(repository.getByCode(storageDriveParam.getThroughSignal(), Signal.class));
virtualRealityTrain.setBeAbout2Arrive(beAbout2Arrive);
if (targetCode != null) {
virtualRealityTrain.setTarget(repository.getByCode(targetCode, Section.class));
}
virtualRealityTrain.setParkTime(parkTime);
virtualRealityTrain.setParkRemainTime(parkRemainTime);
if (parkSectionCode != null) {
virtualRealityTrain.setParkSection(repository.getByCode(parkSectionCode, Section.class));
}
virtualRealityTrain.setDeparture(departure);
virtualRealityTrain.setBreaking(breaking);
if (terminalStationCode != null) {
virtualRealityTrain.setTerminalStation(repository.getByCode(terminalStationCode, Station.class));
}
if (headPosition != null) {
virtualRealityTrain.setHeadPosition(headPosition.convert2SimulationObj(repository));
}
if (tailPosition != null) {
virtualRealityTrain.setTailPosition(tailPosition.convert2SimulationObj(repository));
}
virtualRealityTrain.setRight(right);
if (ma != null) {
virtualRealityTrain.setMa(ma.convert2SimulationObj(repository));
}
if (ma2 != null) {
virtualRealityTrain.setMa2(ma2.convert2SimulationObj(repository));
}
virtualRealityTrain.setCbtcMaMissDuration(cbtcMaMissDuration);
virtualRealityTrain.setGear(gear);
virtualRealityTrain.setSpeed(speed);
virtualRealityTrain.setLocationKM(locationKM);
virtualRealityTrain.setTargetDistance(targetDistance);
virtualRealityTrain.setAtoSpeedMax(atoSpeedMax);
virtualRealityTrain.setAtoSpeed(atoSpeed);
virtualRealityTrain.setAtpSpeed(atpSpeed);
virtualRealityTrain.setSignalEB(signalEB);
virtualRealityTrain.setCircuitEB(circuitEB);
virtualRealityTrain.setStandParkedTrainActivity(standParkedTrainActivity);
virtualRealityTrain.setNextParking(nextParking);
virtualRealityTrain.setJump(jump);
virtualRealityTrain.setHold(hold);
virtualRealityTrain.setTrainHold(trainHold);
virtualRealityTrain.setDtro(dtro);
virtualRealityTrain.setChangeEnds(changeEnds);
virtualRealityTrain.setChangeEndsRemainTime(changeEndsRemainTime);
virtualRealityTrain.setAtoOn(atoOn);
virtualRealityTrain.setAtpOn(atpOn);
virtualRealityTrain.setPriorityRouteSet(priorityRouteSet);
if (door1 != null) {
door1.recover2Simulation(virtualRealityTrain.getDoor1());
}
if (door2 != null) {
door2.recover2Simulation(virtualRealityTrain.getDoor2());
}
virtualRealityTrain.setDoorMode(doorMode);
virtualRealityTrain.setDoorSelection(doorSelection);
virtualRealityTrain.setFk(fk);
virtualRealityTrain.setFb(fb);
virtualRealityTrain.setTbControl(tbControl);
virtualRealityTrain.setLeverPosition(leverPosition);
virtualRealityTrain.setFault(fault);
virtualRealityTrain.setBackUp(backUp);
virtualRealityTrain.setDelayTime(delayTime);
virtualRealityTrain.setPowerOn(powerOn);
virtualRealityTrain.setPantograph1Up(pantograph1Up);
virtualRealityTrain.setPantograph2Up(pantograph2Up);
if (linkTrainCode != null) {
virtualRealityTrain.setLinkTrain(repository.getByCode(linkTrainCode, VirtualRealityTrain.class));
}
virtualRealityTrain.setRunType(runType);
virtualRealityTrain.setOrderStop(orderStop);
virtualRealityTrain.setNeedDepartureCommand(needDepartureCommand);
virtualRealityTrain.setPositioned(positioned);
virtualRealityTrain.setRunningTime(runningTime);
virtualRealityTrain.setReleased(released);
virtualRealityTrain.setConfirmationMessages(confirmationMessages);
virtualRealityTrain.setAtoCanOpen(atoCanOpen);
if (vrAudioCode != null) {
virtualRealityTrain.setVrAudio(repository.getByCode(vrAudioCode, VirtualRealityAudio.class));
}
if (robotDriveParam != null) {
virtualRealityTrain.setRobotDriveParam(robotDriveParam.convert2SimulationObj(repository));
}
param.setThroughSignalAspect(storageDriveParam.getThroughSignalAspect());
param.setReleaseEB(storageDriveParam.isReleaseEB());
return param;
}
}

View File

@ -8,7 +8,6 @@ import club.joylink.rtss.simulation.cbtc.constant.TrainTBControl;
import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan;
import club.joylink.rtss.simulation.cbtc.data.support.FixedQueue;
import club.joylink.rtss.simulation.cbtc.data.support.MovementAuthority;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
@ -20,7 +19,10 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
/**
* 虚拟真实列车
@ -407,11 +409,6 @@ public class VirtualRealityTrain extends VirtualRealityDevice {
*/
private VirtualRealityTrain linkTrain;
/**
* 最近经过的两个应答器
*/
private Queue<Responder> lastTwoPassedResponders = new FixedQueue<>(Responders_Record);
/**
* 运行类型
*/
@ -446,7 +443,7 @@ public class VirtualRealityTrain extends VirtualRealityDevice {
/**
* 确认信息
*/
private final LinkedHashSet<ConfirmationMessage> confirmationMessages = new LinkedHashSet<>();
private LinkedHashSet<ConfirmationMessage> confirmationMessages = new LinkedHashSet<>();
/**
* ato可以开启
@ -469,22 +466,24 @@ public class VirtualRealityTrain extends VirtualRealityDevice {
public void setRunType(RunType runType) {
this.runType = runType;
switch (runType) {
case ENERGY_CONSERVATION:
this.atoSpeedMax = this.atpSpeedMax * 0.2f * 0.9f;
break;
case MIDDLE_TWO:
this.atoSpeedMax = this.atpSpeedMax * 0.4f * 0.9f;
break;
case MIDDLE_ONE:
this.atoSpeedMax = this.atpSpeedMax * 0.6f * 0.9f;
break;
case NORMAL:
this.atoSpeedMax = this.atpSpeedMax * 0.8f * 0.9f;
break;
case ACCELERATE:
this.atoSpeedMax = this.atpSpeedMax * 0.9f;
break;
if (runType != null) {
switch (runType) {
case ENERGY_CONSERVATION:
this.atoSpeedMax = this.atpSpeedMax * 0.2f * 0.9f;
break;
case MIDDLE_TWO:
this.atoSpeedMax = this.atpSpeedMax * 0.4f * 0.9f;
break;
case MIDDLE_ONE:
this.atoSpeedMax = this.atpSpeedMax * 0.6f * 0.9f;
break;
case NORMAL:
this.atoSpeedMax = this.atpSpeedMax * 0.8f * 0.9f;
break;
case ACCELERATE:
this.atoSpeedMax = this.atpSpeedMax * 0.9f;
break;
}
}
}
@ -578,7 +577,6 @@ public class VirtualRealityTrain extends VirtualRealityDevice {
this.pantograph1Up = true;
this.pantograph2Up = true;
this.linkTrain = null;
this.lastTwoPassedResponders = new FixedQueue<>(Responders_Record);
this.runType = null;
this.orderStop = false;
this.needDepartureCommand = false;
@ -1225,29 +1223,6 @@ public class VirtualRealityTrain extends VirtualRealityDevice {
}
}
public boolean passedResponder() {
return !lastTwoPassedResponders.isEmpty();
}
public void viaResponder(Responder responder) {
if (lastTwoPassedResponders.isEmpty()) {
lastTwoPassedResponders.offer(responder);
return;
}
lastTwoPassedResponders.remove(responder);
lastTwoPassedResponders.offer(responder);
if (!this.positioned && lastTwoPassedResponders.size() >= 2) {
this.positioned = true;
}
// if (lastTwoPassedResponders.stream().allMatch(Responder::isLocalizable)) {
// this.positioned = true;
// }
}
public void clearResponders() {
lastTwoPassedResponders.clear();
}
public boolean isCommunicable() {
Section section = headPosition.getSection();
return communication && section.anyZcWorking();

View File

@ -185,11 +185,11 @@ public class MetroSimulationWorkServiceImpl implements SimulationWorkService {
atsLogicLoop.addJobs(simulation);
simulationRobotService.addJobs(simulation);
vrTrainRunningService.addJobs(simulation);
ciLogic.addJobs(simulation);
vrDeviceLogicLoop.addJobs(simulation);
atsMessageCollectAndDispatcher.addJobs(simulation);
ciLogic.addJobs(simulation);
joylink3DMessageService.addJobs(simulation);
faultGenerator.addJobs(simulation);
atsMessageCollectAndDispatcher.addJobs(simulation);
}
@Override

View File

@ -0,0 +1,243 @@
package club.joylink.rtss.util;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.storage.device.StorageDevice;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class StorageGenerateUtil {
public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
generate(VirtualRealityTrain.class, "club.joylink.rtss.simulation.cbtc.data.storage.vr", "noCommunicateDevice");
}
/**
* 生成Storage类文件
*
* @param aClass 要生成文件的类
* @param packageName 生成的文件要放入的包
* @param startFieldName 从这个字段开始是要存的字段
*/
public static void generate(Class<?> aClass, String packageName, String startFieldName) {
String sourceClassName = aClass.getSimpleName();
String targetClassName = String.format("Storage%s", sourceClassName);
File file = new File(String.format("./src/main/java/%s/%s", packageName.replace(".", "/"), targetClassName + ".java"));
FileWriter fileWriter;
try {
fileWriter = new FileWriter(file);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
try {
Field[] declaredFields = aClass.getDeclaredFields();
List<Field> fieldList = new ArrayList<>(Arrays.asList(declaredFields));
for (Iterator<Field> iterator = fieldList.iterator(); iterator.hasNext(); ) { //删除所有不需要保存的字段
Field field = iterator.next();
if (field.getName().equals(startFieldName)) {
break;
}
iterator.remove();
}
List<String> importStrList = new ArrayList<>();
List<String> fieldStrList = new ArrayList<>();
List<String> convert2StorageMethodStrList = new ArrayList<>();
List<String> recover2SimulationMethodStrList = new ArrayList<>();
String lowercaseSourceClassName = lowercaseInitial(sourceClassName);
//convert2Storage方法开头
convert2StorageMethodStrList.add(String.format("public static %s convert2Storage(%s %s) {", targetClassName, sourceClassName, lowercaseSourceClassName));
String storageObjectName = lowercaseInitial(targetClassName);
convert2StorageMethodStrList.add(String.format("%s %s = new %s(%s);", targetClassName, storageObjectName, targetClassName, lowercaseSourceClassName));
//recover2Simulation方法开头
String element = "element";
String repository = "repository";
recover2SimulationMethodStrList.add("@Override");
recover2SimulationMethodStrList.add("public void recover2Simulation(MapElement element, Simulation simulation, SimulationDataRepository repository) {");
recover2SimulationMethodStrList.add(String.format("%s %s = (%s) %s;", sourceClassName, lowercaseSourceClassName, sourceClassName, element));
for (Field declaredField : fieldList) {
Class<?> fieldType = declaredField.getType();
String fieldClassSimpleName = fieldType.getSimpleName();
String sourceFieldName = declaredField.getName(); //源文件字段名
String uppercaseSourceFieldName = uppercaseInitial(sourceFieldName);
Type genericType = declaredField.getGenericType();
List<Class<Object>> genericClassList;
if (genericType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericType;
genericClassList = Stream.of(parameterizedType.getActualTypeArguments())
.map(ata -> {
Class<Object> cls = (Class<Object>) ata;
importStrList.add(String.format("import %s;", cls.getName()).replace("$", "."));
return cls;
}).collect(Collectors.toList());
} else {
genericClassList = null;
}
if (fieldType.isPrimitive()) { //基础类型
fieldStrList.add(String.format("private %s %s;", fieldClassSimpleName, sourceFieldName));
if (fieldType.equals(boolean.class)) {
convert2StorageMethodStrList.add(String.format("%s.set%s(%s.is%s());", storageObjectName, uppercaseSourceFieldName, lowercaseSourceClassName, uppercaseSourceFieldName));
} else {
convert2StorageMethodStrList.add(String.format("%s.set%s(%s.get%s());", storageObjectName, uppercaseSourceFieldName, lowercaseSourceClassName, uppercaseSourceFieldName));
}
recover2SimulationMethodStrList.add(String.format("%s.set%s(%s);", lowercaseSourceClassName, uppercaseSourceFieldName, sourceFieldName));
} else if (fieldType.isEnum()) { //枚举
importStrList.add(String.format("import %s;", fieldType.getName()).replace("$", "."));
fieldStrList.add(String.format("private %s %s;", fieldClassSimpleName, sourceFieldName));
convert2StorageMethodStrList.add(String.format("%s.set%s(%s.get%s());", storageObjectName, uppercaseSourceFieldName, lowercaseSourceClassName, uppercaseSourceFieldName));
recover2SimulationMethodStrList.add(String.format("%s.set%s(%s);", lowercaseSourceClassName, uppercaseSourceFieldName, sourceFieldName));
} else if (fieldType.getPackageName().startsWith("java.lang")) { //包装类
fieldStrList.add(String.format("private %s %s;", fieldClassSimpleName, sourceFieldName));
convert2StorageMethodStrList.add(String.format("%s.set%s(%s.get%s());", storageObjectName, uppercaseSourceFieldName, lowercaseSourceClassName, uppercaseSourceFieldName));
recover2SimulationMethodStrList.add(String.format("%s.set%s(%s);", lowercaseSourceClassName, uppercaseSourceFieldName, sourceFieldName));
} else if (fieldType.getPackageName().startsWith("club.joylink")){ //自定义类
importStrList.add(String.format("import %s;", fieldType.getName()).replace("$", "."));
if (MapElement.class.isAssignableFrom(fieldType)) { //地图元素
String targetFieldName = sourceFieldName + "Code"; //目标文件字段名
fieldStrList.add(String.format("private String %s;", targetFieldName));
convert2StorageMethodStrList.add(String.format("if (%s.get%s() != null) {", lowercaseSourceClassName, uppercaseInitial(sourceFieldName)));
convert2StorageMethodStrList.add(String.format("%s.set%s(%s.get%s().getCode());", storageObjectName,
uppercaseInitial(targetFieldName), lowercaseSourceClassName, uppercaseInitial(sourceFieldName)));
convert2StorageMethodStrList.add("}");
recover2SimulationMethodStrList.add(String.format("if (%s != null) {", targetFieldName));
recover2SimulationMethodStrList.add(String.format("%s.set%s(%s.getByCode(%s, %s));", lowercaseSourceClassName, uppercaseSourceFieldName, repository,
targetFieldName, fieldClassSimpleName + ".class"));
recover2SimulationMethodStrList.add("}");
} else {
String storageFieldClassName = String.format("Storage%s", fieldClassSimpleName);
try {
Class<?> storageField = Class.forName("club.joylink.rtss.simulation.cbtc.data.storage.support." + storageFieldClassName);
importStrList.add(String.format("import %s;", storageField.getName()));
fieldStrList.add(String.format("private %s %s;", storageFieldClassName, sourceFieldName));
convert2StorageMethodStrList.add(String.format("if (%s.get%s() != null) {", lowercaseSourceClassName, uppercaseSourceFieldName));
convert2StorageMethodStrList.add(String.format("%s.set%s(new %s(%s.get%s()));", storageObjectName, uppercaseSourceFieldName,
storageFieldClassName, lowercaseSourceClassName, uppercaseSourceFieldName));
convert2StorageMethodStrList.add("}");
recover2SimulationMethodStrList.add(String.format("if (%s != null) {", sourceFieldName));
recover2SimulationMethodStrList.add(String.format("%s.set%s(%s.convert2SimulationObj(%s));", lowercaseSourceClassName, uppercaseSourceFieldName,
sourceFieldName, repository));
recover2SimulationMethodStrList.add("}");
} catch (ClassNotFoundException e) {
System.out.printf("缺少%s%n", storageFieldClassName);
}
}
} else { //其它
importStrList.add(String.format("import %s;", fieldType.getName()).replace("$", "."));
if (CollectionUtils.isEmpty(genericClassList)) {
fieldStrList.add(String.format("private %s %s;", fieldClassSimpleName, sourceFieldName));
} else {
String genericClassSimpleNames = genericClassList.stream().map(Class::getSimpleName).collect(Collectors.joining(","));
fieldStrList.add(String.format("private %s<%s> %s;", fieldClassSimpleName, genericClassSimpleNames, sourceFieldName));
}
String uppercaseFieldName = uppercaseInitial(sourceFieldName);
convert2StorageMethodStrList.add(String.format("%s.set%s(%s.get%s());", storageObjectName, uppercaseFieldName, lowercaseSourceClassName, uppercaseFieldName));
recover2SimulationMethodStrList.add(String.format("%s.set%s(%s);", lowercaseSourceClassName, uppercaseSourceFieldName, sourceFieldName));
}
}
//package
writeLine(fileWriter, String.format("package %s;", packageName));
//import父类
writeLine(fileWriter, String.format("import %s;", StorageDevice.class.getName()));
//import注解
writeLine(fileWriter, String.format("import %s;", Getter.class.getName()));
writeLine(fileWriter, String.format("import %s;", Setter.class.getName()));
writeLine(fileWriter, String.format("import %s;", NoArgsConstructor.class.getName()));
//import recover2Simulation方法参数类型
writeLine(fileWriter, String.format("import %s;", MapElement.class.getName()));
writeLine(fileWriter, String.format("import %s;", Simulation.class.getName()));
writeLine(fileWriter, String.format("import %s;", SimulationDataRepository.class.getName()));
//import列表
importStrList.forEach(str -> writeLine(fileWriter, str));
//注解
writeLine(fileWriter, "@Getter");
writeLine(fileWriter, "@Setter");
writeLine(fileWriter, "@NoArgsConstructor");
//类声明
writeLine(fileWriter, String.format("public class %s extends StorageDevice {", targetClassName));
//字段
fieldStrList.forEach(str -> writeLine(fileWriter, str));
//构造器
writeLine(fileWriter, String.format("public %s(%s %s) {", targetClassName, sourceClassName, lowercaseSourceClassName));
writeLine(fileWriter, String.format("super(%s);", lowercaseSourceClassName));
writeLine(fileWriter, "}");
//convert2Storage方法
convert2StorageMethodStrList.forEach(str -> writeLine(fileWriter, str));
writeLine(fileWriter, String.format("return %s;", storageObjectName));
writeLine(fileWriter, "}");
//convert方法
writeLine(fileWriter, "@Override");
writeLine(fileWriter, "public boolean convert(MapElement element) {");
writeLine(fileWriter, "return true;");
writeLine(fileWriter, "}");
//recover2Simulation方法
recover2SimulationMethodStrList.forEach(str -> writeLine(fileWriter, str));
writeLine(fileWriter, "}");
//类结尾
writeLine(fileWriter, "}");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private static String lowercaseInitial(String s) {
String s1 = String.valueOf(s.charAt(0)).toLowerCase();
String s2 = s.substring(1);
return s1 + s2;
}
private static String uppercaseInitial(String s) {
String s1 = String.valueOf(s.charAt(0)).toUpperCase();
String s2 = s.substring(1);
return s1 + s2;
}
private static void writeLine(FileWriter writer, String text) {
try {
writer.write(String.format("%s\n", text));
} catch (IOException e) {
e.printStackTrace();
}
}
}