增加进路序列根据行车日志的变更而变更的方法

This commit is contained in:
joylink_zhangsai 2022-06-14 17:07:38 +08:00
parent cfd8454328
commit 82a99ff099
7 changed files with 149 additions and 61 deletions

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.ATS.service.runplan;
import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.CtcRunPlanParam; import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.CtcRunPlanParam;
import club.joylink.rtss.simulation.cbtc.CTC.CTCLogicLoop; import club.joylink.rtss.simulation.cbtc.CTC.CTCLogicLoop;
import club.joylink.rtss.simulation.cbtc.CTC.CTCService;
import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog;
import club.joylink.rtss.simulation.cbtc.CTC.data.RouteSequence; import club.joylink.rtss.simulation.cbtc.CTC.data.RouteSequence;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
@ -36,6 +37,9 @@ public class CtcStationRunPlanLogService {
@Autowired @Autowired
private CTCLogicLoop ctcLogicLoop; private CTCLogicLoop ctcLogicLoop;
@Autowired
private CTCService ctcService;
/** /**
* 批量修改运行计划 * 批量修改运行计划
* *
@ -232,6 +236,7 @@ public class CtcStationRunPlanLogService {
ctcStationRunPlanLog.getArriveRunPlan().setTrackSection(arriveSection); ctcStationRunPlanLog.getArriveRunPlan().setTrackSection(arriveSection);
changeRunPlanLog.setArriveRunPlan(new CtcStationRunPlanLog.RunPlanItem()); changeRunPlanLog.setArriveRunPlan(new CtcStationRunPlanLog.RunPlanItem());
changeRunPlanLog.getArriveRunPlan().setTrackSection(arriveSection); changeRunPlanLog.getArriveRunPlan().setTrackSection(arriveSection);
ctcService.runPlanItemUpdate(simulation, ctcStationRunPlanLog.getStation(), changeRunPlanLog.getArriveRunPlan(), false);
} }
} }
if (!StringUtils.isEmpty(departSectionCode)) { if (!StringUtils.isEmpty(departSectionCode)) {
@ -241,6 +246,7 @@ public class CtcStationRunPlanLogService {
ctcStationRunPlanLog.getDepartRunPlan().setTrackSection(departSection); ctcStationRunPlanLog.getDepartRunPlan().setTrackSection(departSection);
changeRunPlanLog.setDepartRunPlan(new CtcStationRunPlanLog.RunPlanItem()); changeRunPlanLog.setDepartRunPlan(new CtcStationRunPlanLog.RunPlanItem());
changeRunPlanLog.getDepartRunPlan().setTrackSection(departSection); changeRunPlanLog.getDepartRunPlan().setTrackSection(departSection);
ctcService.runPlanItemUpdate(simulation, ctcStationRunPlanLog.getStation(), changeRunPlanLog.getArriveRunPlan(), true);
} }
} }
if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) {

View File

@ -18,10 +18,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
@ -55,12 +52,14 @@ public class CTCLogicLoop {
private void sendAllRouteSequenceMessage(Simulation simulation) { private void sendAllRouteSequenceMessage(Simulation simulation) {
CtcRepository ctcRepository = simulation.getCtcRepository(); CtcRepository ctcRepository = simulation.getCtcRepository();
Map<String, Object> map = new HashMap<>(); List<Map<String, Object>> list = new ArrayList<>();
for (RouteSequenceVO vo : ctcRepository.getRouteSequenceVOMap().values()) { for (RouteSequenceVO vo : ctcRepository.getRouteSequenceVOMap().values()) {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", vo.getStationCode()); map.put("stationCode", vo.getStationCode());
map.put("routeSequence", vo); map.put("routeSequence", vo);
list.add(map);
} }
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), map); SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -71,23 +70,29 @@ public class CTCLogicLoop {
CtcRepository ctcRepository = simulation.getCtcRepository(); CtcRepository ctcRepository = simulation.getCtcRepository();
Map<String, RouteSequence> routeSequenceMap = ctcRepository.getRouteSequenceMap(); Map<String, RouteSequence> routeSequenceMap = ctcRepository.getRouteSequenceMap();
Map<String, RouteSequenceVO> routeSequenceVOMap = ctcRepository.getRouteSequenceVOMap(); Map<String, RouteSequenceVO> routeSequenceVOMap = ctcRepository.getRouteSequenceVOMap();
Map<String, Object> map = new HashMap<>(); List<Map<String, Object>> list = new ArrayList<>();
if (CollectionUtils.isEmpty(routeSequenceVOMap)) { if (CollectionUtils.isEmpty(routeSequenceVOMap)) {
for (RouteSequence routeSequence : routeSequenceMap.values()) { for (RouteSequence routeSequence : routeSequenceMap.values()) {
RouteSequenceVO routeSequenceVO = new RouteSequenceVO(routeSequence); RouteSequenceVO routeSequenceVO = new RouteSequenceVO(routeSequence);
routeSequenceVOMap.put(routeSequenceVO.getStationCode(), routeSequenceVO); routeSequenceVOMap.put(routeSequenceVO.getStationCode(), routeSequenceVO);
Map<String, Object> map = new HashMap<>();
map.put("stationCode", routeSequenceVO.getStationCode()); map.put("stationCode", routeSequenceVO.getStationCode());
map.put("routeSequence", routeSequenceVO); map.put("routeSequence", routeSequenceVO);
list.add(map);
} }
} else { } else {
for (RouteSequenceVO vo : routeSequenceVOMap.values()) { for (RouteSequence routeSequence : routeSequenceMap.values()) {
RouteSequence routeSequence = routeSequenceMap.get(vo.getStationCode()); RouteSequenceVO vo = routeSequenceVOMap.get(routeSequence.getStationCode());
Map<String, Object> changed = vo.updateAndReturnChanged(routeSequence); Map<String, Object> changed = vo.updateAndReturnChanged(routeSequence);
if (changed != null) {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", vo.getStationCode()); map.put("stationCode", vo.getStationCode());
map.put("routeSequence", changed); map.put("routeSequence", changed);
list.add(map);
} }
} }
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), map); }
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }

View File

@ -16,31 +16,11 @@ import java.util.Map;
@Component @Component
public class CTCService { public class CTCService {
public void generateRouteSequence(Simulation simulation) { public void runPlanItemUpdate(Simulation simulation, Station station, CtcStationRunPlanLog.RunPlanItem item, boolean departure) {
SimulationDataRepository repository = simulation.getRepository();
CtcRepository ctcRepository = simulation.getCtcRepository(); CtcRepository ctcRepository = simulation.getCtcRepository();
Map<String, List<RouteSequence.Line>> stationLineMap = new HashMap<>(); ctcRepository.deleteRouteSequenceLine(station.getCode(), item);
for (Station station : repository.getStationList()) { RouteSequence.Line line = RouteSequence.buildLine(item, departure);
stationLineMap.put(station.getCode(), new ArrayList<>()); ctcRepository.addRouteSequenceLine(station.getCode(), line);
}
for (CtcStationRunPlanLog plan : ctcRepository.getAllRunPlanList()) {
List<RouteSequence.Line> lines = stationLineMap.get(plan.getStation().getCode());
CtcStationRunPlanLog.RunPlanItem arriveRunPlan = plan.getArriveRunPlan();
if (arriveRunPlan != null) {
RouteSequence.Line line = RouteSequence.buildLine(arriveRunPlan, false);
lines.add(line);
}
CtcStationRunPlanLog.RunPlanItem departRunPlan = plan.getDepartRunPlan();
if (departRunPlan != null) {
RouteSequence.Line line = RouteSequence.buildLine(departRunPlan, true);
lines.add(line);
}
}
Map<String, RouteSequence> routeSequenceMap = ctcRepository.getRouteSequenceMap();
for (Station station : repository.getStationList()) {
RouteSequence routeSequence = new RouteSequence(station, stationLineMap.get(station.getCode()));
routeSequenceMap.put(station.getCode(), routeSequence);
}
} }
/** /**

View File

@ -15,7 +15,7 @@ import java.util.stream.Collectors;
@Getter @Getter
public class CtcRepository { public class CtcRepository {
/** /**
* 进路序列 * 车站-进路序列每个车站都应该有
* k - stationCode * k - stationCode
*/ */
private final Map<String, RouteSequence> routeSequenceMap = new HashMap<>(); private final Map<String, RouteSequence> routeSequenceMap = new HashMap<>();
@ -65,6 +65,20 @@ public class CtcRepository {
*/ */
private final Map<String, Map<String, CtcRunPlanParam>> simulationRunPlanEffectAreaMap = new ConcurrentHashMap<>(); private final Map<String, Map<String, CtcRunPlanParam>> simulationRunPlanEffectAreaMap = new ConcurrentHashMap<>();
public void reset() {
// 编辑区清空
this.simulationRunPlanEditAreaMap.clear();
// 仿真运行数据直接清空
this.simulationRunPlanMap.clear();
this.allRunPlanList.clear();
// 重置原始数据
this.originRunPlanMap.values().forEach(runPlanMap -> runPlanMap.values().forEach(runPlan -> {
runPlan.reset();
this.allRunPlanList.add(runPlan);
}));
}
/** /**
* 添加至仿真中的行车计划 * 添加至仿真中的行车计划
* *
@ -168,17 +182,15 @@ public class CtcRepository {
return routeSequence.getLine(tripNumber, routeCode); return routeSequence.getLine(tripNumber, routeCode);
} }
public void reset() { public void deleteRouteSequenceLine(String stationCode, CtcStationRunPlanLog.RunPlanItem item) {
// 编辑区清空 RouteSequence routeSequence = routeSequenceMap.get(stationCode);
this.simulationRunPlanEditAreaMap.clear(); if (routeSequence == null)
// 仿真运行数据直接清空 return;
this.simulationRunPlanMap.clear(); routeSequence.deleteLines(item);
this.allRunPlanList.clear(); }
// 重置原始数据
this.originRunPlanMap.values().forEach(runPlanMap -> runPlanMap.values().forEach(runPlan -> { public void addRouteSequenceLine(String stationCode, RouteSequence.Line line) {
runPlan.reset(); RouteSequence routeSequence = routeSequenceMap.get(stationCode);
this.allRunPlanList.add(runPlan); routeSequence.addLine(line);
}));
// generateRouteSequence();
} }
} }

View File

@ -8,11 +8,10 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.springframework.util.CollectionUtils;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.List; import java.util.*;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -60,8 +59,13 @@ public class RouteSequence {
return 1; return 1;
}); });
this.lines = lines; this.lines = lines;
if (!CollectionUtils.isEmpty(lines)) {
this.tripLineMap = lines.stream().collect(Collectors.groupingBy(Line::getTripNumber)); this.tripLineMap = lines.stream().collect(Collectors.groupingBy(Line::getTripNumber));
this.idLineMap = lines.stream().collect(Collectors.toMap(Line::getId, Function.identity())); this.idLineMap = lines.stream().collect(Collectors.toMap(Line::getId, Function.identity()));
} else {
this.tripLineMap = new HashMap<>();
this.idLineMap = new HashMap<>();
}
} }
public static Line buildLine(CtcStationRunPlanLog.RunPlanItem item, boolean departure) { public static Line buildLine(CtcStationRunPlanLog.RunPlanItem item, boolean departure) {
@ -130,6 +134,37 @@ public class RouteSequence {
return station == null ? null : station.getCode(); return station == null ? null : station.getCode();
} }
public void deleteLines(CtcStationRunPlanLog.RunPlanItem item) {
Iterator<Line> iterator = lines.iterator();
while (iterator.hasNext()) {
Line line = iterator.next();
if (Objects.equals(line.getItem(), item)) {
iterator.remove();
tripLineMap.remove(line.getTripNumber());
idLineMap.remove(line.getId());
}
}
}
public void addLine(Line line) {
idLineMap.put(line.getId(), line);
List<Line> list = tripLineMap.computeIfAbsent(line.getTripNumber(), k -> new ArrayList<>());
for (int i = 0, listSize = list.size(); i < listSize; i++) {
Line l = list.get(i);
if (l.getPlanTime().isAfter(line.getPlanTime())) {
list.add(i, line);
break;
}
}
for (int i = 0, linesSize = lines.size(); i < linesSize; i++) {
Line l = lines.get(i);
if (l.getPlanTime().isAfter(line.getPlanTime())) {
list.add(i, line);
break;
}
}
}
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public static class Line { public static class Line {

View File

@ -22,10 +22,10 @@ public class RouteSequenceVO {
*/ */
private boolean readOnly; private boolean readOnly;
private List<LineVO> lines; private final List<LineVO> lines;
@JsonIgnore @JsonIgnore
private Map<String, LineVO> idLineMap; private final Map<String, LineVO> idLineMap;
public RouteSequenceVO(RouteSequence routeSequence) { public RouteSequenceVO(RouteSequence routeSequence) {
this.stationCode = routeSequence.getStationCode(); this.stationCode = routeSequence.getStationCode();
@ -34,17 +34,35 @@ public class RouteSequenceVO {
this.idLineMap = lines.stream().collect(Collectors.toMap(LineVO::getId, Function.identity())); this.idLineMap = lines.stream().collect(Collectors.toMap(LineVO::getId, Function.identity()));
} }
private LineVO findLine(String id) {
return idLineMap.get(id);
}
private void addLine(LineVO line) {
this.lines.add(line);
this.idLineMap.put(line.getId(), line);
}
public Map<String, Object> updateAndReturnChanged(RouteSequence routeSequence) { public Map<String, Object> updateAndReturnChanged(RouteSequence routeSequence) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
if (!Objects.equals(readOnly, routeSequence.isReadOnly())) { if (!Objects.equals(readOnly, routeSequence.isReadOnly())) {
readOnly = routeSequence.isReadOnly(); readOnly = routeSequence.isReadOnly();
map.put("readOnly", readOnly); map.put("readOnly", readOnly);
} }
List<Map<String, Object>> lines = this.lines.stream() List<Object> properties = new ArrayList<>();
.map(vo -> vo.updateAndReturnChanged(routeSequence.getLine(vo.getId()))) for (RouteSequence.Line line : routeSequence.getLines()) {
.collect(Collectors.toList()); LineVO vo = findLine(line.getId());
if (!CollectionUtils.isEmpty(lines)) { if (vo == null) {
map.put("lines", lines); vo = new LineVO(line);
addLine(vo);
properties.add(vo);
} else {
Map<String, Object> changed = vo.updateAndReturnChanged(line);
properties.add(changed);
}
}
if (!CollectionUtils.isEmpty(properties)) {
map.put("lines", properties);
} }
if (!CollectionUtils.isEmpty(map)) { if (!CollectionUtils.isEmpty(map)) {
return map; return map;

View File

@ -2,7 +2,9 @@ package club.joylink.rtss.simulation.cbtc.build;
import club.joylink.rtss.entity.Ibp; import club.joylink.rtss.entity.Ibp;
import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.CtcRunPlanParam; import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.CtcRunPlanParam;
import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository;
import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog;
import club.joylink.rtss.simulation.cbtc.CTC.data.RouteSequence;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
@ -97,10 +99,40 @@ public class SimulationBuilder {
// CTC行车日志数据结构构建 // CTC行车日志数据结构构建
if (simulation.getRepository().getConfig().isHasCTC()) { if (simulation.getRepository().getConfig().isHasCTC()) {
buildCtcStationRunPlanLog(simulation, simulation.getRepository().getServiceTripsMap()); buildCtcStationRunPlanLog(simulation, simulation.getRepository().getServiceTripsMap());
generateRouteSequence(simulation);
} }
return simulation; return simulation;
} }
private static void generateRouteSequence(Simulation simulation) {
SimulationDataRepository repository = simulation.getRepository();
CtcRepository ctcRepository = simulation.getCtcRepository();
Map<String, List<RouteSequence.Line>> stationLineMap = new HashMap<>();
for (Station station : repository.getStationList()) {
stationLineMap.put(station.getCode(), new ArrayList<>());
}
for (CtcStationRunPlanLog plan : ctcRepository.getAllRunPlanList()) {
List<RouteSequence.Line> lines = stationLineMap.get(plan.getStation().getCode());
CtcStationRunPlanLog.RunPlanItem arriveRunPlan = plan.getArriveRunPlan();
if (arriveRunPlan != null) {
RouteSequence.Line line = RouteSequence.buildLine(arriveRunPlan, false);
if (line != null)
lines.add(line);
}
CtcStationRunPlanLog.RunPlanItem departRunPlan = plan.getDepartRunPlan();
if (departRunPlan != null) {
RouteSequence.Line line = RouteSequence.buildLine(departRunPlan, true);
if (line != null)
lines.add(line);
}
}
Map<String, RouteSequence> routeSequenceMap = ctcRepository.getRouteSequenceMap();
for (Station station : repository.getStationList()) {
RouteSequence routeSequence = new RouteSequence(station, stationLineMap.get(station.getCode()));
routeSequenceMap.put(station.getCode(), routeSequence);
}
}
private static void loadIscsResources(Simulation simulation, List<IscsSystemResourcesVO> iscsSystemResourceList) { private static void loadIscsResources(Simulation simulation, List<IscsSystemResourcesVO> iscsSystemResourceList) {
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository(); SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
iscsRepository.addSystemResources(iscsSystemResourceList); iscsRepository.addSystemResources(iscsSystemResourceList);