大铁CTC股道视图恢复中

This commit is contained in:
joylink_zhangsai 2022-06-15 16:24:46 +08:00
parent f653eff7f3
commit e9d834c533
7 changed files with 245 additions and 87 deletions

View File

@ -5,9 +5,7 @@ import club.joylink.rtss.simulation.cbtc.CI.CiApiService;
import club.joylink.rtss.simulation.cbtc.CTC.data.*;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
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.map.*;
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.VirtualRealityTrain;
@ -63,14 +61,19 @@ public class CTCLogicLoop {
LocalDateTime correctSystemTime = simulation.getCorrectSystemTime();
for (RouteSequence routeSequence : simulation.getCtcRepository().getRouteSequenceMap().values()) {
for (RouteSequence.Line line : routeSequence.getLines()) {
if (line.isAutoTrigger()) {
if (line.getRoute() != null && correctSystemTime.toLocalTime().isAfter(line.getPlanTime())) {
Route route = line.getRoute();
if (!line.isTriggered()) {
if (route != null) {
if (route.isLock()) {
line.setTriggered(true);
} else if (line.isAutoTrigger() && correctSystemTime.toLocalTime().isAfter(line.getPlanTime())) {
ciApiService.settingRoute(simulation, line.getRouteCode());
}
}
}
}
}
}
/**
* 更新行车日志状态
@ -112,19 +115,33 @@ public class CTCLogicLoop {
map.put("trackView", vo);
list.add(map);
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), list);
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
private void sendTrackViewMessage(Simulation simulation) {
// CtcRepository ctcRepository = simulation.getCtcRepository();
// for (CtcStationRunPlanLog runPlan : ctcRepository.getAllRunPlanList()) {
// CtcStationRunPlanLog.RunPlanItem arriveRunPlan = runPlan.getArriveRunPlan();
// if (arriveRunPlan != null) {
// RouteSequence.Line routeSequenceLine = ctcRepository.getRouteSequenceLine(runPlan.getStation().getCode(), arriveRunPlan.getTripNumber(), false);
//
// }
// }
List<Map<String, Object>> list = new ArrayList<>();
CtcRepository ctcRepository = simulation.getCtcRepository();
for (RouteSequence routeSequence : ctcRepository.getRouteSequenceMap().values()) {
TrackViewVO trackViewVO = new TrackViewVO(routeSequence.getStationCode());
Map<String, Object> map = new HashMap<>();
map.put("stationCode", routeSequence.getStationCode());
map.put("trackView", trackViewVO);
for (RouteSequence.Line line : routeSequence.getLines()) {
if (line.isDeparture()) {
trackViewVO.addDepartureLine(line);
} else {
trackViewVO.addReceivingLine(line);
}
}
Station station = routeSequence.getStation();
Map<String, Boolean> sectionOccupiedMap = station.getAllStandList().stream().map(Stand::getSection)
.collect(Collectors.toMap(MapElement::getCode, Section::isOccupied));
trackViewVO.getSectionOccupiedMap().putAll(sectionOccupiedMap);
list.add(map);
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
private void sendAllRouteSequenceMessage(Simulation simulation) {
@ -136,7 +153,7 @@ public class CTCLogicLoop {
map.put("routeSequence", vo);
list.add(map);
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), list);
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
@ -169,7 +186,7 @@ public class CTCLogicLoop {
}
}
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcRouteSequenceMessage(simulation.getId(), list);
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}

View File

@ -17,12 +17,10 @@ public class CTCService {
@Autowired
private CTCLogicLoop ctcLogicLoop;
public void runPlanItemUpdate(Simulation simulation, Station station, CtcStationRunPlanLog.RunPlanItem item, boolean departure) {
CtcRepository ctcRepository = simulation.getCtcRepository();
ctcRepository.deleteRouteSequenceLine(station.getCode(), item);
RouteSequence.Line line = RouteSequence.buildLine(item, departure);
ctcRepository.addRouteSequenceLine(station.getCode(), line);
RouteSequence.Line routeSequenceLine = ctcRepository.getRouteSequenceLine(station.getCode(), item.getTripNumber(), departure);
routeSequenceLine.updateRoute();
}
/**

View File

@ -77,6 +77,7 @@ public class CtcRepository {
public void reset() {
routeSequenceMap.clear();
routeSequenceVOMap.clear();
trackViewVOMap.clear();
// 编辑区清空
this.simulationRunPlanEditAreaMap.clear();
// 仿真运行数据直接清空
@ -205,4 +206,8 @@ public class CtcRepository {
RouteSequence routeSequence = routeSequenceMap.get(stationCode);
routeSequence.addLine(line);
}
public TrackViewVO getTrackViewVO(String stationCode) {
return trackViewVOMap.computeIfAbsent(stationCode, k -> new TrackViewVO());
}
}

View File

@ -98,7 +98,7 @@ public class RouteSequence {
}
int id = idGenerator.getAndIncrement();
LocalTime planTime = item.getPlanTime().minusMinutes(9);
return new Line(String.valueOf(id), item, false, departure, planTime, planTime, route);
return new Line(String.valueOf(id), item, departure, planTime, planTime, route);
}
public Line findLine(String id) {
@ -189,10 +189,32 @@ public class RouteSequence {
private LocalTime planTime;
private Route route;
/**
* 进路是否已经触发过
*/
@Setter
private boolean triggered;
public Line(String id, CtcStationRunPlanLog.RunPlanItem item, boolean departure, LocalTime startTime, LocalTime planTime, Route route) {
this.id = id;
this.item = item;
this.departure = departure;
this.startTime = startTime;
this.planTime = planTime;
this.route = route;
}
public String getTripNumber() {
return this.item.getTripNumber();
}
public boolean isSetting() {
if (route != null) {
return route.isSetting();
}
return false;
}
public Section getTrack() {
return this.item.getTrackSection();
}
@ -206,6 +228,15 @@ public class RouteSequence {
}
}
public String getTrackCode() {
Section track = getTrack();
if (track == null) {
return null;
} else {
return track.getCode();
}
}
private boolean isRight() {
return this.item.isRight();
}
@ -213,5 +244,36 @@ public class RouteSequence {
public String getRouteCode() {
return route == null ? null : route.getCode();
}
public void updateRoute() {
boolean right = isRight();
Signal startSignal;
Signal endSignal;
Route route = null;
Section trackSection = getTrack();
if (trackSection != null) {
if (departure) { //发车
startSignal = trackSection.getSignalOf(right); //股道的同向信号机作为发车进路的起始信号机
if (startSignal == null || !startSignal.isShunting2()) //没有出站信号机的股道不生成进路序列
startSignal = null;
endSignal = item.getStationDirection().getSignal();
} else { //接车
startSignal = item.getStationDirection().getSignal();
Signal tempEndSignal = trackSection.getSignalOf(!right);
if (tempEndSignal == null || !tempEndSignal.isShunting2())
endSignal = null;
else
endSignal = tempEndSignal; //股道的反向信号机作为接车进路终点信号机
}
if (startSignal != null && endSignal != null) {
route = startSignal.getRouteList().stream()
.filter(r -> Objects.equals(r.getDestination(), endSignal))
.findAny().orElse(null);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(route,
String.format("车次[%s]的[%s]进路找不到", item.getTripNumber(), departure ? "发车" : "接车"));
this.route = route;
}
}
}
}
}

View File

@ -97,6 +97,11 @@ public class RouteSequenceVO {
*/
private boolean autoTrigger;
/**
* 是否发车
*/
private boolean departure;
// /**
// * 方向
// */
@ -117,14 +122,30 @@ public class RouteSequenceVO {
*/
private String routeCode;
/**
* 状态0/1/2分别代表等待正在触发触发完成
*/
private String status;
private static final String WAIT = "0";
private static final String SETTING = "1";
private static final String TRIGGERED = "2";
public LineVO(RouteSequence.Line line) {
id = line.getId();
tripNumber = line.getTripNumber();
trackName = line.getTrackName();
autoTrigger = line.isAutoTrigger();
departure = line.isDeparture();
startTime = line.getStartTime();
planTime = line.getPlanTime();
routeCode = line.getRouteCode();
if (line.isTriggered()) {
status = TRIGGERED;
} else if (line.isSetting()) {
status = SETTING;
} else {
status = WAIT;
}
}
/**
@ -144,6 +165,10 @@ public class RouteSequenceVO {
autoTrigger = line.isAutoTrigger();
map.put("autoTrigger", autoTrigger);
}
if (!Objects.equals(departure, line.isDeparture())) {
departure = line.isDeparture();
map.put("departure", departure);
}
if (!Objects.equals(startTime, line.getStartTime())) {
startTime = line.getStartTime();
map.put("startTime", startTime);
@ -156,8 +181,17 @@ public class RouteSequenceVO {
routeCode = line.getRouteCode();
map.put("routeCode", line.getRouteCode());
}
if (line.isTriggered()) {
status = TRIGGERED;
} else if (line.isSetting()) {
status = SETTING;
} else {
status = WAIT;
}
if (!CollectionUtils.isEmpty(map)) {
map.put("id", id);
map.put("status", status);
return map;
}
return null;

View File

@ -5,32 +5,54 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 股道视图
* 注意里面看起来没有被调用的方法不要删用于序列化
*/
@Getter
@Setter
@NoArgsConstructor
public class TrackViewVO {
private String stationCode;
private final Map<String, TrackInfo> sectionAndTrackInfo = new HashMap<>();
private final Map<String, Boolean> sectionOccupiedMap = new HashMap<>();
private final Map<String, List<Line>> trackLineMap = new HashMap<>();
public TrackViewVO(String stationCode) {
this.stationCode = stationCode;
}
public void addLine(Line line) {
String trackCode = line.getTrackCode();
List<Line> lines = trackLineMap.computeIfAbsent(trackCode, k -> new ArrayList<>());
lines.add(line);
}
public TrackViewVO.Line findLine(String trackCode, String tripNumber) {
List<Line> lines = trackLineMap.get(trackCode);
if (CollectionUtils.isEmpty(lines))
return null;
return lines.stream()
.filter(line -> Objects.equals(line.getTripNumber(), tripNumber))
.findAny().orElse(null);
}
public void addReceivingLine(RouteSequence.Line receivingRoute) {
Section track = receivingRoute.getTrack();
if (track == null)
return;
TrackInfo trackInfo = sectionAndTrackInfo.computeIfAbsent(track.getCode(), k -> new TrackInfo(track));
Line trackViewLine = trackInfo.findLine(receivingRoute.getTripNumber());
if (trackViewLine == null) {
Line line = Line.buildReceivingLine(receivingRoute);
trackInfo.addLine(line);
Line line = findLine(track.getCode(), receivingRoute.getTripNumber());
if (line != null) {
line.setReceivingRoute(receivingRoute);
} else {
trackViewLine.setReceivingRoute(receivingRoute);
Line newLine = Line.buildReceivingLine(receivingRoute);
addLine(newLine);
}
}
@ -38,57 +60,57 @@ public class TrackViewVO {
Section track = departureRoute.getTrack();
if (track == null)
return;
TrackInfo trackInfo = sectionAndTrackInfo.computeIfAbsent(track.getCode(), k -> new TrackInfo(track));
Line trackViewLine = trackInfo.findLine(departureRoute.getTripNumber());
if (trackViewLine == null) {
Line line = Line.buildDepartureLine(departureRoute);
trackInfo.addLine(line);
Line line = findLine(track.getCode(), departureRoute.getTripNumber());
if (line != null) {
line.setDepartureRoute(departureRoute);
} else {
trackViewLine.setDepartureRoute(departureRoute);
Line newLine = Line.buildDepartureLine(departureRoute);
addLine(newLine);
}
}
public static class TrackInfo {
@JsonIgnore
private Section track;
private final List<Line> lines = new ArrayList<>();
@JsonIgnore
private final Map<String, Line> tripLineMap = new HashMap<>();
public TrackInfo(Section track) {
this.track = track;
}
public boolean isOccupied() {
return this.track.isOccupied();
}
public Line findLine(String tripNumber) {
return tripLineMap.get(tripNumber);
}
public void addLine(Line line) {
lines.add(line);
tripLineMap.put(line.getTripNumber(), line);
}
}
// @Getter
// public static class TrackInfo {
// @JsonIgnore
// private Section track;
//
// private final List<Line> lines = new ArrayList<>();
//
// @JsonIgnore
// private final Map<String, Line> tripLineMap = new HashMap<>();
//
// public TrackInfo(Section track) {
// this.track = track;
// }
//
// public boolean isOccupied() {
// return this.track.isOccupied();
// }
//
// public Line findLine(String tripNumber) {
// return tripLineMap.get(tripNumber);
// }
//
// public void addLine(Line line) {
// lines.add(line);
// tripLineMap.put(line.getTripNumber(), line);
// }
// }
@Getter
@Setter
public static class Line {
private String tripNumber;
private String trainType;
private String trainDistanceInfo;
// private String tripNumber;
//
// private String trainType;
//
// private String trainDistanceInfo;
// private Process process;
// private boolean receivingNotice;
private boolean receivingRouteLock;
// private boolean receivingRouteLock;
@JsonIgnore
private RouteSequence.Line receivingRoute;
@ -97,7 +119,7 @@ public class TrackViewVO {
// private boolean departureNotice;
private boolean departureRouteLock;
// private boolean departureRouteLock;
@JsonIgnore
private RouteSequence.Line departureRoute;
@ -114,36 +136,56 @@ public class TrackViewVO {
public static Line buildReceivingLine(RouteSequence.Line receivingRoute) {
Line line = new Line();
line.setTripNumber(receivingRoute.getTripNumber());
line.setReceivingRoute(receivingRoute);
return line;
}
public static Line buildDepartureLine(RouteSequence.Line departureRoute) {
Line line = new Line();
line.setTripNumber(departureRoute.getTripNumber());
line.setDepartureRoute(departureRoute);
return line;
}
public void updateRouteLock() {
if (!receivingRouteLock) {
if (receivingRoute != null && receivingRoute.getRoute().isLock()) {
receivingRouteLock = true;
public String getTripNumber() {
if (receivingRoute != null) {
return receivingRoute.getTripNumber();
}
if (departureRoute != null) {
return departureRoute.getTripNumber();
}
if (!departureRouteLock) {
if (departureRoute != null && departureRoute.getRoute().isLock()) {
departureRouteLock = true;
return null;
}
public boolean isReceivingRouteLock() {
if (receivingRoute != null) {
return receivingRoute.isTriggered();
}
return false;
}
public boolean isDepartureRouteLock() {
if (departureRoute != null) {
return departureRoute.isTriggered();
}
return false;
}
@JsonIgnore
public String getTrackCode() {
if (receivingRoute != null) {
return receivingRoute.getTrackCode();
}
if (departureRoute != null) {
return departureRoute.getTrackCode();
}
return null;
}
public Process getProcess() {
if (isDeparture()) {
return Process.FINISH;
}
if (departureRouteLock) {
if (isDepartureRouteLock()) {
return Process.DEPARTURE;
}
if (isDepartureNotice()) {
@ -152,7 +194,7 @@ public class TrackViewVO {
if (isArrive()) {
return Process.DEPARTURE_BLOCK;
}
if (receivingRouteLock) {
if (isReceivingRouteLock()) {
return Process.ARRIVE;
}
if (isReceivingNotice()) {

View File

@ -415,7 +415,7 @@ public class SocketMessageFactory {
/**
* CTC进路序列消息
*/
public static SocketMessageVO<Object> buildCtcRouteSequenceMessage(String simulationId,
public static SocketMessageVO<Object> buildCtcBusyBoardMessage(String simulationId,
Object message) {
return build(WebSocketMessageType.Simulation_RailCtcStatus, simulationId, message);
}