【增加实训背景种类】

This commit is contained in:
weizhihong 2022-12-02 18:14:50 +08:00
parent cb12f654a2
commit 1428cf38f5
7 changed files with 189 additions and 12 deletions

View File

@ -1,13 +1,19 @@
package club.joylink.rtss.vo.training2.rule; package club.joylink.rtss.vo.training2.rule;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.RunLevel;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication; import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.storage.StorageSimulation; import club.joylink.rtss.simulation.cbtc.data.storage.StorageSimulation;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import lombok.Getter; import lombok.Getter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -133,6 +139,69 @@ public enum BgSceneStatusRule {
return getBgScene(simulation); return getBgScene(simulation);
} }
}, },
/**
* 信号机重开背景
*/
SIGNAL_REOPEN_BG_SCENE("信号机重开背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Signal signal = (Signal) mapElement;
Route route = signal.getRouteList().get(0);
openRouteDirect(simulation, route);
VirtualRealitySignal vrSignal = signal.getVirtualSignal();
signal.setForbidden(true);
signal.setAspect(signal.getDefaultAspect());
vrSignal.setAspect(signal.getDefaultAspect());
return getBgScene(simulation);
}
},
/**
* 信号机关灯背景
*/
SIGNAL_CLOSE_BG_SCENE("信号机关灯背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Signal signal = (Signal) mapElement;
Route route = signal.getRouteList().get(0);
openRouteDirect(simulation, route);
return getBgScene(simulation);
}
},
/**
* 信号机引导背景
*/
SIGNAL_GUIDE_BG_SCENE("信号机引导背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Signal signal = (Signal) mapElement;
// 开放进路
Route route = signal.getRouteList().get(0);
openRouteDirect(simulation, route);
// 关闭信号机
VirtualRealitySignal vrSignal = signal.getVirtualSignal();
signal.setForbidden(true);
signal.setAspect(signal.getDefaultAspect());
vrSignal.setAspect(signal.getDefaultAspect());
// 添加信号机
VirtualRealityTrain train = (VirtualRealityTrain) simulation.getRepository().getVrDeviceMap().values().stream()
.filter(o -> o instanceof VirtualRealityTrain).findFirst().get();
Section section = route.getStart().getSection();
trainOnline(simulation, train, section, route.isRight());
return getBgScene(simulation);
}
},
/**
* 进路交自动控背景
*/
SIGNAL_ROUTE_AUTO_SET_BG_SCENE("进路交自动控背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Signal signal = (Signal) mapElement;
Route route = signal.getRouteList().get(0);
route.setAtsControl(false);
return getBgScene(simulation);
}
},
/** /**
* 区段区故解背景 * 区段区故解背景
*/ */
@ -144,6 +213,65 @@ public enum BgSceneStatusRule {
return getBgScene(simulation); return getBgScene(simulation);
} }
}, },
/**
* 区段故障解锁背景
*/
SECTION_FAULT_UNLOCK_BG_SCENE("区段故障解锁背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Section section = (Section) mapElement;
section.setRouteLock(true);
section.setLockRight(true);
if(!CollectionUtils.isEmpty(section.getLogicList())) {
section.getLogicList().forEach(s -> {
s.setRouteLock(true);
s.setLockRight(true);
});
}
return getBgScene(simulation);
}
},
/**
* 区段激活背景
*/
SECTION_ACTIVE_BG_SCENE("区段激活背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Section section = (Section) mapElement;
Section axleSection = section;
if (Objects.nonNull(section.getParent())) {
axleSection = section.getParent();
}
axleSection.setCutOff(true);
for (Section logic : axleSection.getLogicList()) {
logic.setCutOff(true);
}
return null;
}
},
/**
* 区段取消限速背景
*/
SECTION_CANCEL_LIMIT_SPEED_BG_SCENE("区段取消限速背景") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Section section = (Section) mapElement;
section.setSpeedUpLimit(5);
return null;
}
},
SECTION_CONFIRM_AXIS_VALID_BG_SCENE("") {
@Override
public String doHandle(Simulation simulation, MapElement mapElement) {
Section section = (Section) mapElement;
if (Objects.nonNull(section.getParent())) {
section.getParent().judgeAsNctOccupied(simulation);
} else {
section.judgeAsNctOccupied(simulation);
}
return null;
}
},
/** /**
* 车站上电解锁 * 车站上电解锁
*/ */
@ -321,4 +449,18 @@ public enum BgSceneStatusRule {
} }
} }
} }
/**
* 列车上线
*/
private static void trainOnline(Simulation simulation, VirtualRealityTrain train, Section section, boolean right) {
//重叠检测
SectionPosition headPosition = new SectionPosition(section, section.getStopPointByDirection(right));
train.initManualTrain(headPosition, right);
SimulationDataRepository repository = simulation.getRepository();
TrainInfo trainInfo = TrainInfo.constructManualTrain(train);
trainInfo.tracking(train);
repository.addOnlineTrain(train);
repository.addTrainInfo(trainInfo);
}
} }

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.vo.training2.rule;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.vo.map.graph.MapStationNewVO;
import lombok.Getter; import lombok.Getter;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -21,8 +22,9 @@ public enum MapDeviceRule {
if (!isMETRO) { if (!isMETRO) {
return List.of(); return List.of();
} }
List<Route> routeList = simulation.getRepository().getRouteList().stream() List<Signal> signalList = METRO_DEPARTURE_SIGNAL_LIST.filterMapDeviceList(simulation);
.filter(r -> Signal.SignalType.PROTECTION.equals(r.getStart().getType())).collect(Collectors.toList()); List<Route> routeList = new ArrayList<>();
signalList.forEach(s -> routeList.addAll(s.getRouteList()));
return generateRandomElement(routeList, 2); return generateRandomElement(routeList, 2);
} }
}, },
@ -41,7 +43,10 @@ public enum MapDeviceRule {
STATION_LIST("车站列表") { STATION_LIST("车站列表") {
@Override @Override
public List<Station> filterMapDeviceList(Simulation simulation) { public List<Station> filterMapDeviceList(Simulation simulation) {
List<Station> stationList = simulation.getRepository().getStationList(); List<Station> stationList = simulation.getBuildParams().getMap().getGraphDataNew().getStationList()
.stream().filter(s -> s.isVisible() && s.isCentralized() && s.isCiStation()).map(MapStationNewVO::getCode)
.map(code -> simulation.getRepository().getByCode(code, Station.class))
.collect(Collectors.toList());
return generateRandomElement(stationList, 1); return generateRandomElement(stationList, 1);
} }
}, },
@ -59,6 +64,14 @@ public enum MapDeviceRule {
return generateRandomElement(signalList, 2); return generateRandomElement(signalList, 2);
} }
}, },
METRO_DEPARTURE_SIGNAL_LIST("地铁信号机列表") {
@Override
public List<Signal> filterMapDeviceList(Simulation simulation) {
List<Signal> signalList = simulation.getRepository().getStandList().stream().map(s -> s.getSection().getSignalToRight())
.filter(s -> s != null && !CollectionUtils.isEmpty(s.getRouteList())).collect(Collectors.toList());
return generateRandomElement(signalList, 2);
}
},
RAILWAY_DEPARTURE_SIGNAL_LIST("大铁发车信号机列表") { RAILWAY_DEPARTURE_SIGNAL_LIST("大铁发车信号机列表") {
@Override @Override
public List<Signal> filterMapDeviceList(Simulation simulation) { public List<Signal> filterMapDeviceList(Simulation simulation) {
@ -70,8 +83,11 @@ public enum MapDeviceRule {
SECTION_LIST("普通区段列表") { SECTION_LIST("普通区段列表") {
@Override @Override
public List<Section> filterMapDeviceList(Simulation simulation) { public List<Section> filterMapDeviceList(Simulation simulation) {
List<Section> sectionList = simulation.getRepository().getSectionList().stream() List<Signal> signalList = simulation.getRepository().getStandList().stream().map(s -> s.getSection().getSignalToRight())
.filter(s -> s.getParent() == null).collect(Collectors.toList()); .filter(s -> s != null && !CollectionUtils.isEmpty(s.getRouteList())).collect(Collectors.toList());
signalList = generateRandomElement(signalList, 2);
List<Section> sectionList = new ArrayList<>(100);
signalList.forEach(s -> s.getRouteList().forEach(r -> sectionList.addAll(r.getSectionList())));
return generateRandomElement(sectionList, 2); return generateRandomElement(sectionList, 2);
} }
}, },
@ -82,6 +98,14 @@ public enum MapDeviceRule {
.filter(Section::isSwitchTrack).collect(Collectors.toList()); .filter(Section::isSwitchTrack).collect(Collectors.toList());
return generateRandomElement(sectionList, 2); return generateRandomElement(sectionList, 2);
} }
},
SECTION_ROUTE_LIST("") {
@Override
public List<Section> filterMapDeviceList(Simulation simulation) {
List<Signal> signalList = simulation.getRepository().getStandList().stream()
.map(s -> s.getSection().getSignalToRight()).filter(s -> s != null && !CollectionUtils.isEmpty(s.getRouteList())).collect(Collectors.toList());
return null;
}
} }
; ;

View File

@ -34,6 +34,8 @@ public abstract class MapElementRule {
return (Station) mapElement; return (Station) mapElement;
} else if (mapElement instanceof Switch) { } else if (mapElement instanceof Switch) {
return ((Switch) mapElement).getDeviceStation(); return ((Switch) mapElement).getDeviceStation();
} else if (mapElement instanceof Section) {
return ((Section) mapElement).getDeviceStation();
} }
throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error); throw new SimulationException(SimulationExceptionType.Simulation_Map_Data_Error);
} }

View File

@ -40,7 +40,7 @@ public class MemberRule {
/** /**
* 所属设备编码 * 所属设备编码
*/ */
String code = deviceCodeRule.resolve(simulation, mapElement); String code = String.valueOf(deviceCodeRule.resolve(simulation, mapElement));
List<SimulationMember> resultMemberList = memberList.stream().filter(member -> member.getDevice() != null List<SimulationMember> resultMemberList = memberList.stream().filter(member -> member.getDevice() != null
&& member.getDevice().getCode().equals(code)).collect(Collectors.toList()); && member.getDevice().getCode().equals(code)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(resultMemberList)) { if (CollectionUtils.isEmpty(resultMemberList)) {

View File

@ -97,7 +97,7 @@ public abstract class OperationRule {
Operation2VO.ClientOperation2VO operation2 = new Operation2VO.ClientOperation2VO(); Operation2VO.ClientOperation2VO operation2 = new Operation2VO.ClientOperation2VO();
operation2.setId(this.getId()); operation2.setId(this.getId());
if (PropertyValueRule.match(deviceCode)) { // 设备规则编码设置 if (PropertyValueRule.match(deviceCode)) { // 设备规则编码设置
operation2.setDeviceCode(PropertyValueRule.valueOf(deviceCode).resolve(simulation, mapElement)); operation2.setDeviceCode(String.valueOf(PropertyValueRule.valueOf(deviceCode).resolve(simulation, mapElement)));
} else { } else {
operation2.setDeviceCode(""); operation2.setDeviceCode("");
} }

View File

@ -112,7 +112,16 @@ public enum PropertyValueRule {
} }
return buttonVO.getCode(); return buttonVO.getCode();
} }
}; },
SIGNAL_FIRST_ROUTE_CODE_LIST("信号机关联的第一条进路编码列表") {
@Override
public Object resolve(Simulation simulation, Object mapElement) {
Signal signal = (Signal) mapElement;
Route route = signal.getRouteList().get(0);
return List.of(route.getCode());
}
}
;
private final String description; private final String description;
@ -122,7 +131,7 @@ public enum PropertyValueRule {
this.description = description; this.description = description;
} }
public abstract String resolve(Simulation simulation, Object mapElement); public abstract Object resolve(Simulation simulation, Object mapElement);
public static boolean match(String ruleValue) { public static boolean match(String ruleValue) {
return Arrays.stream(PropertyValueRule.values()).anyMatch(r -> r.name().equals(ruleValue)); return Arrays.stream(PropertyValueRule.values()).anyMatch(r -> r.name().equals(ruleValue));
@ -142,11 +151,11 @@ public enum PropertyValueRule {
} }
String result = contentFormat; String result = contentFormat;
String propertyEnum; String propertyEnum;
String propertyValue; Object propertyValue;
for (String property : propertySet) { for (String property : propertySet) {
propertyEnum = property.replaceAll("[\\{\\}]", ""); propertyEnum = property.replaceAll("[\\{\\}]", "");
propertyValue = PropertyValueRule.valueOf(propertyEnum).resolve(simulation, mapElement); propertyValue = PropertyValueRule.valueOf(propertyEnum).resolve(simulation, mapElement);
result = result.replace(property, propertyValue); result = result.replace(property, String.valueOf(propertyValue));
} }
return result; return result;
} }

View File

@ -35,7 +35,7 @@ public abstract class ValuableRule {
public StatusValueVO convert2BO(Simulation simulation, Object mapElement) { public StatusValueVO convert2BO(Simulation simulation, Object mapElement) {
StatusValueVO valuable = JsonUtils.read(JsonUtils.writeValueAsString(this.getValuableVO()), StatusValueVO.class); StatusValueVO valuable = JsonUtils.read(JsonUtils.writeValueAsString(this.getValuableVO()), StatusValueVO.class);
if (elementCodeRule != null) { if (elementCodeRule != null) {
valuable.setElementCode(elementCodeRule.resolve(simulation, mapElement)); valuable.setElementCode(String.valueOf(elementCodeRule.resolve(simulation, mapElement)));
} }
return valuable; return valuable;
} }