【进路列表筛选】

This commit is contained in:
weizhihong 2022-11-30 14:48:24 +08:00
parent 9871e37f81
commit 27a4dbd5b2
2 changed files with 26 additions and 8 deletions

View File

@ -6,6 +6,8 @@ import lombok.Getter;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@Getter
@ -20,9 +22,17 @@ public enum MapDeviceRule {
return List.of();
}
Station station = stationList.get(0);
// 获取本站的5个进路信息
Predicate<Route.Type> predicate = (type) -> {
if (Simulation.Type.RAILWAY.equals(simulation.getBuildParams().getWorkParamVO().getType())) {
return Objects.equals(type, Route.Type.DEPARTURE) || Objects.equals(type, Route.Type.RECEIVING)
|| Objects.equals(type, Route.Type.PASS);
}
return true;
};
// 获取本站的2个进路信息
return simulation.getRepository().getRouteList().stream()
.filter(r -> station.equals(r.getInterlockStation())).limit(5).collect(Collectors.toList());
.filter(r -> predicate.test(r.getType()) && station.equals(r.getStart().getStation()))
.limit(2).collect(Collectors.toList());
}
},
SWITCH_LIST("道岔列表") {
@ -35,7 +45,7 @@ public enum MapDeviceRule {
}
Station station = stationList.get(0);
return simulation.getRepository().getSwitchList().stream()
.filter(s -> station.equals(s.getDeviceStation())).limit(5).collect(Collectors.toList());
.filter(s -> station.equals(s.getDeviceStation())).limit(2).collect(Collectors.toList());
}
},
SIGNAL_LIST("信号机列表") {
@ -48,7 +58,7 @@ public enum MapDeviceRule {
}
Station station = stationList.get(0);
return simulation.getRepository().getSignalList().stream()
.filter(s -> station.equals(s.getDeviceStation())).limit(5).collect(Collectors.toList());
.filter(s -> station.equals(s.getDeviceStation())).limit(2).collect(Collectors.toList());
}
},
SIGNAL_BUTTON_LIST("有按钮的信号机列表") {
@ -62,7 +72,7 @@ public enum MapDeviceRule {
Station station = stationList.get(0);
return simulation.getRepository().getSignalList().stream()
.filter(s -> station.equals(s.getDeviceStation()) && Signal.SignalType.RECEIVING.equals(s.getType()))
.limit(5).collect(Collectors.toList());
.limit(2).collect(Collectors.toList());
}
};

View File

@ -88,11 +88,15 @@ public class Training2Rule {
this.name = rule.getName();
this.description = rule.getDescription();
this.type = Training2.Type.valueOf(rule.getType());
this.locationRule = MapLocationRule.valueOf(rule.getLocationRule());
if (StringUtils.hasText(rule.getLocationRule())) {
this.locationRule = MapLocationRule.valueOf(rule.getLocationRule());
}
if (StringUtils.hasText(rule.getLabels())) {
this.labels = JsonUtils.readCollection(rule.getLabels(), List.class, String.class);
}
this.sceneRule = BgSceneStatusRule.valueOf(rule.getSceneRule());
if (StringUtils.hasText(rule.getSceneRule())) {
this.sceneRule = BgSceneStatusRule.valueOf(rule.getSceneRule());
}
if (StringUtils.hasText(rule.getSteps())) {
this.steps = JsonUtils.readCollection(rule.getSteps(), List.class, StepRule.class);
}
@ -120,7 +124,11 @@ public class Training2Rule {
// 实训类型
copyTraining2.setType(type.name());
// 实训标签
copyTraining2.setLabelJson(JsonUtils.writeValueAsString(labels));
if (labels != null) {
copyTraining2.setLabelJson(JsonUtils.writeValueAsString(labels));
} else {
copyTraining2.setLabelJson("[]");
}
// 背景设置
if (sceneRule != null) {
copyTraining2.setBgSceneJson(sceneRule.doHandle(simulation, mapElement));