diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java index 4cbf3f7a7..2ed668069 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java @@ -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 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()); } }; diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/Training2Rule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/Training2Rule.java index 28c8dd188..021f92a05 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/Training2Rule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/Training2Rule.java @@ -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));