修改股道视图数据发送bug

This commit is contained in:
joylink_zhangsai 2022-07-08 16:34:54 +08:00
parent f8a67b7182
commit 1d968dabc5
11 changed files with 202 additions and 100 deletions

View File

@ -1,10 +1,7 @@
package club.joylink.rtss.simulation.cbtc.CTC;
import club.joylink.rtss.simulation.cbtc.CTC.data.*;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.CtcStationRunPlanLogVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.RailDispatchCommandVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.RouteSequenceVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.TrackViewVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.*;
import club.joylink.rtss.simulation.cbtc.CTC.service.CTCService;
import club.joylink.rtss.simulation.cbtc.CTC.service.CtcDispatchCommandService;
import club.joylink.rtss.simulation.cbtc.Simulation;
@ -63,11 +60,29 @@ public class CTCLogicLoop {
}
public void sendMessageWhenSubscribeCtc(Simulation simulation, String userId) {
sendAllTrackViewMessage(simulation, userId);
sendAllRouteSequenceMessage(simulation, userId);
sendAllBusyBoardMessage(simulation, userId);
sendUnreadDispatchCommand(simulation, userId);
}
private void sendAllBusyBoardMessage(Simulation simulation, String userId) {
CtcRepository ctcRepository = simulation.getCtcRepository();
List<BusyBoardVO> list = new ArrayList<>();
Map<String, TrackViewVO> trackViewVOMap = ctcRepository.getTrackViewVOMap();
Map<String, RouteSequenceVO> routeSequenceVOMap = ctcRepository.getRouteSequenceVOMap();
HashSet<String> stationCodes = new HashSet<>(trackViewVOMap.keySet());
stationCodes.addAll(routeSequenceVOMap.keySet());
for (String stationCode : stationCodes) {
TrackViewVO trackViewVO = trackViewVOMap.get(stationCode);
RouteSequenceVO routeSequenceVO = routeSequenceVOMap.get(stationCode);
BusyBoardVO busyBoardVO = new BusyBoardVO(stationCode, routeSequenceVO, trackViewVO);
list.add(busyBoardVO);
}
SocketMessageVO<List<BusyBoardVO>> message
= SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(userId, message);
}
/**
* 发送该成员所属受令方的未读的调度命令
*/
@ -206,21 +221,8 @@ public class CTCLogicLoop {
}
}
private void sendAllTrackViewMessage(Simulation simulation, String userId) {
CtcRepository ctcRepository = simulation.getCtcRepository();
List<Map<String, Object>> list = new ArrayList<>();
for (TrackViewVO vo : ctcRepository.getTrackViewVOMap().values()) {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", vo.getStationCode());
map.put("trackView", vo);
list.add(map);
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(userId, message);
}
private void sendTrackViewMessage(Simulation simulation) {
List<Map<String, Object>> list = new ArrayList<>();
List<BusyBoardVO> list = new ArrayList<>();
CtcRepository ctcRepository = simulation.getCtcRepository();
Map<String, TrackView> trackViewMap = ctcRepository.getTrackViewMap();
Map<String, TrackViewVO> trackViewVOMap = ctcRepository.getTrackViewVOMap();
@ -237,27 +239,15 @@ public class CTCLogicLoop {
changedViewVO = trackViewVO.updateAndReturnChanged(trackView);
}
if (changedViewVO != null) {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", stationCode);
map.put("trackView", changedViewVO);
list.add(map);
BusyBoardVO busyBoardVO = new BusyBoardVO(stationCode, null, changedViewVO);
list.add(busyBoardVO);
}
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
private void sendAllRouteSequenceMessage(Simulation simulation, String userId) {
CtcRepository ctcRepository = simulation.getCtcRepository();
List<Map<String, Object>> list = new ArrayList<>();
for (RouteSequenceVO vo : ctcRepository.getRouteSequenceVOMap().values()) {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", vo.getStationCode());
map.put("routeSequence", vo);
list.add(map);
if (!CollectionUtils.isEmpty(list)) {
SocketMessageVO<List<BusyBoardVO>> message
= SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(userId, message);
}
/**
@ -267,30 +257,29 @@ public class CTCLogicLoop {
CtcRepository ctcRepository = simulation.getCtcRepository();
Map<String, RouteSequence> routeSequenceMap = ctcRepository.getRouteSequenceMap();
Map<String, RouteSequenceVO> routeSequenceVOMap = ctcRepository.getRouteSequenceVOMap();
List<Map<String, Object>> list = new ArrayList<>();
List<BusyBoardVO> list = new ArrayList<>();
if (CollectionUtils.isEmpty(routeSequenceVOMap)) {
for (RouteSequence routeSequence : routeSequenceMap.values()) {
RouteSequenceVO routeSequenceVO = new RouteSequenceVO(routeSequence);
routeSequenceVOMap.put(routeSequenceVO.getStationCode(), routeSequenceVO);
Map<String, Object> map = new HashMap<>();
map.put("stationCode", routeSequenceVO.getStationCode());
map.put("routeSequence", routeSequenceVO);
list.add(map);
BusyBoardVO busyBoardVO = new BusyBoardVO(routeSequenceVO.getStationCode(), routeSequenceVO, null);
list.add(busyBoardVO);
}
} else {
for (RouteSequence routeSequence : routeSequenceMap.values()) {
RouteSequenceVO vo = routeSequenceVOMap.get(routeSequence.getStationCode());
RouteSequenceVO changed = vo.updateAndReturnChanged(routeSequence);
if (changed != null) {
Map<String, Object> map = new HashMap<>();
map.put("stationCode", vo.getStationCode());
map.put("routeSequence", changed);
list.add(map);
BusyBoardVO busyBoardVO = new BusyBoardVO(vo.getStationCode(), changed, null);
list.add(busyBoardVO);
}
}
}
SocketMessageVO<Object> message = SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
if (!CollectionUtils.isEmpty(list)) {
SocketMessageVO<List<BusyBoardVO>> message
= SocketMessageFactory.buildCtcBusyBoardMessage(simulation.getId(), list);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
}
public void addJobs(Simulation simulation) {
@ -300,8 +289,6 @@ public class CTCLogicLoop {
/**
* 行车区段运行计划下发
*
* @param simulation 仿真
*/
public void sendZoneRunPlanSend(Simulation simulation) {
List<CtcEffectRepository.CtcStageRunPlanRepository.CtcStageRunPlanVO> allList = simulation.getCtcRepository().getCtcEffectRepository().getChangeStageRunPlan();

View File

@ -1,5 +0,0 @@
package club.joylink.rtss.simulation.cbtc.CTC.data;
public class BusyBoard {
}

View File

@ -158,7 +158,7 @@ public class CtcRepository {
/**
* 构建占线板股道视图数据
*/
private void buildTrackViewData(Simulation simulation) {
public void buildTrackViewData(Simulation simulation) {
for (Station station : simulation.getRepository().getStationList()) {
trackViewMap.put(station.getCode(), new TrackView(station));
}
@ -391,4 +391,14 @@ public class CtcRepository {
.exception(String.format("[id:%s]的票据不存在", ticketId)));
}
public void updateTrackView(String stationCode, String oldTrackCode, String oldTripNumber, RouteSequence.Line routeSequenceLine) {
TrackView trackView = getTrackView(stationCode);
trackView.remove(oldTrackCode, oldTripNumber, routeSequenceLine);
if (routeSequenceLine.isDeparture()) {
trackView.addDepartureLine(routeSequenceLine);
} else {
trackView.addReceivingLine(routeSequenceLine);
}
}
}

View File

@ -201,6 +201,16 @@ public class RouteSequence {
private final String id;
private CtcStationRunPlanLog.RunPlanItem item;
/**
* 车次号
*/
private String tripNumber;
/**
* 股道
*/
private Section track;
/**
* 是自触
*/
@ -229,6 +239,8 @@ public class RouteSequence {
Line(String id, CtcStationRunPlanLog.RunPlanItem item, boolean departure, LocalTime startTime, LocalTime planTime, Route route) {
this.id = id;
this.item = item;
this.track = item == null ? null : item.getTrackSection();
this.tripNumber = item == null ? null : item.getTripNumber();
this.departure = departure;
this.startTime = startTime;
this.planTime = planTime;
@ -243,14 +255,6 @@ public class RouteSequence {
return departure ? "-->" + item.getStation().getName() : item.getStation().getName() + "-->";
}
public String getTripNumber() {
return this.item.getTripNumber();
}
public Section getTrack() {
return this.item.getTrackSection();
}
public String getTrackName() {
Section track = getTrack();
if (track == null) {
@ -277,7 +281,21 @@ public class RouteSequence {
return route == null ? null : route.getCode();
}
public void updateRoute() {
public void update() {
updateTripNumber();
updateTrack();
updateRoute();
}
private void updateTripNumber() {
this.tripNumber = item == null ? null : item.getTripNumber();
}
private void updateTrack() {
this.track = item == null ? null : item.getTrackSection();
}
private void updateRoute() {
boolean right = isRight();
Signal startSignal;
Signal endSignal;

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.simulation.cbtc.CTC.data;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.map.Stand;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
@ -75,6 +76,14 @@ public class TrackView {
}
}
public void remove(String trackCode, String tripNumber, RouteSequence.Line routeSequenceLine) {
Map<String, Line> tnLineMap = this.trackLineMap.get(trackCode);
if (tnLineMap != null) {
Line line = tnLineMap.get(tripNumber);
line.remove(routeSequenceLine);
}
}
@Getter
@Setter
public static class Line {
@ -274,6 +283,14 @@ public class TrackView {
return "图定终到";
return departureRoute.getItem().getPlanTimeStr();
}
public void remove(RouteSequence.Line routeSequenceLine) {
if (Objects.equals(routeSequenceLine, this.receivingRoute)) {
receivingRoute = null;
} else if (Objects.equals(routeSequenceLine, this.departureRoute)) {
departureRoute = null;
}
}
}
public enum Process {

View File

@ -0,0 +1,21 @@
package club.joylink.rtss.simulation.cbtc.CTC.data.vo;
import lombok.Getter;
/**
* 占线板消息
*/
@Getter
public class BusyBoardVO {
private String stationCode;
private RouteSequenceVO routeSequence;
private TrackViewVO trackView;
public BusyBoardVO(String stationCode, RouteSequenceVO routeSequence, TrackViewVO trackView) {
this.stationCode = stationCode;
this.routeSequence = routeSequence;
this.trackView = trackView;
}
}

View File

@ -27,6 +27,8 @@ public class RouteSequenceVO {
@JsonIgnore
private final Map<String, LineVO> idLineMap;
private Set<String> deletedLineIds;
public RouteSequenceVO() {
lines = new ArrayList<>();
idLineMap = new HashMap<>();
@ -50,17 +52,26 @@ public class RouteSequenceVO {
this.idLineMap.put(line.getId(), line);
}
private void removeLines(Set<String> ids) {
for (String id : ids) {
idLineMap.remove(id);
}
lines.removeIf(lineVO -> ids.contains(lineVO.getTripNumber()));
}
public RouteSequenceVO updateAndReturnChanged(RouteSequence routeSequence) {
RouteSequenceVO routeSequenceVO = new RouteSequenceVO();
RouteSequenceVO changedRsVO = new RouteSequenceVO();
boolean change = false;
if (!Objects.equals(readOnly, routeSequence.isReadOnly())) {
change = true;
readOnly = routeSequence.isReadOnly();
routeSequenceVO.setReadOnly(readOnly);
changedRsVO.setReadOnly(readOnly);
}
List<LineVO> lines = routeSequenceVO.getLines();
List<LineVO> lineVOS = changedRsVO.getLines();
Set<String> deletedLineIds = new HashSet<>(this.idLineMap.keySet());
changedRsVO.setDeletedLineIds(deletedLineIds);
for (RouteSequence.Line line : routeSequence.getLines()) {
// TODO: 2022/6/14 需要考虑修改股道之后对应的进路序列删除的逻辑
deletedLineIds.remove(line.getId());
if (line.getRoute() == null) {
continue;
}
@ -69,16 +80,20 @@ public class RouteSequenceVO {
change = true;
vo = new LineVO(line);
addLine(vo);
lines.add(vo);
lineVOS.add(vo);
} else {
LineVO changed = vo.updateAndReturnChanged(line);
if (changed != null) {
change = true;
lines.add(changed);
lineVOS.add(changed);
}
}
}
return change ? routeSequenceVO : null;
if (!deletedLineIds.isEmpty()) {
removeLines(deletedLineIds);
change = true;
}
return change ? changedRsVO : null;
}
@Getter

View File

@ -18,7 +18,11 @@ public class TrackViewVO {
private Map<String, Map<String, LineVO>> trackLineMap;
/** 被删除的数据 */
/**
* 被删除的数据
* k - trackCode
* v - tripNumber
*/
private Map<String, Set<String>> deletedMap;
public TrackViewVO(TrackView view) {
@ -59,8 +63,8 @@ public class TrackViewVO {
public TrackViewVO updateAndReturnChanged(TrackView view) {
boolean change = false;
TrackViewVO viewVO = new TrackViewVO();
viewVO.setStationCode(view.getStationCode());
TrackViewVO changedViewVO = new TrackViewVO();
changedViewVO.setStationCode(view.getStationCode());
//股道占用
for (Section section : view.getSections()) {
@ -68,7 +72,7 @@ public class TrackViewVO {
if (!Objects.equals(sectionOccupiedMap.get(section.getCode()), occupied)) {
change = true;
sectionOccupiedMap.put(section.getCode(), occupied);
viewVO.addSectionOccupied(section.getCode(), occupied);
changedViewVO.addSectionOccupied(section.getCode(), occupied);
}
}
//分行数据
@ -82,29 +86,35 @@ public class TrackViewVO {
LineVO lineVO = lineVOMap.get(line.getTripNumber());
if (lineVO == null) { //没有这条记录
change = true;
viewVO.addLine(trackCode, new LineVO(line));
LineVO vo = new LineVO(line);
addLine(trackCode, vo);
changedViewVO.addLine(trackCode, vo);
} else { //有这条记录
deletedTripNumbers.remove(line.getTripNumber());
LineVO changedLineVO = lineVO.updateAndReturnChanged(line);
if (changedLineVO != null) {
change = true;
viewVO.addLine(trackCode, changedLineVO);
changedViewVO.addLine(trackCode, changedLineVO);
}
}
}
if (!deletedTripNumbers.isEmpty()) {
change = true;
viewVO.addDeletedLine(trackCode, deletedTripNumbers);
changedViewVO.addDeletedLine(trackCode, deletedTripNumbers);
for (String deletedTripNumber : deletedTripNumbers) {
lineVOMap.remove(deletedTripNumber);
}
}
}
if (!deletedTrackCodes.isEmpty()) {
change = true;
for (String trackCode : deletedTrackCodes) {
viewVO.addDeletedLine(trackCode, trackLineMap.get(trackCode).keySet());
changedViewVO.addDeletedLine(trackCode, trackLineMap.get(trackCode).keySet());
trackLineMap.remove(trackCode);
}
}
return change ? viewVO : null;
return change ? changedViewVO : null;
}
@Getter

View File

@ -7,6 +7,7 @@ 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.TrackView;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.data.map.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -29,28 +30,46 @@ public class CTCService {
* 创建了新的运行计划item
*/
public void runPlanItemCreate(Simulation simulation, Station station, CtcStationRunPlanLog.RunPlanItem item, boolean departure) {
CtcRepository ctcRepository = simulation.getCtcRepository();
//进路序列
RouteSequence routeSequence = ctcRepository.getRouteSequence(station.getCode());
AtomicInteger idGenerator = ctcRepository.getRouteSequenceIdGenerator();
RouteSequence.Line line = RouteSequence.buildLine(item, departure, idGenerator);
routeSequence.addLine(line);
//股道视图
TrackView trackView = ctcRepository.getTrackView(station.getCode());
if (departure) {
trackView.addDepartureLine(line);
} else {
trackView.addReceivingLine(line);
}
regenerateRouteSequenceAndTrackView(simulation);
// CtcRepository ctcRepository = simulation.getCtcRepository();
// //进路序列
// RouteSequence routeSequence = ctcRepository.getRouteSequence(station.getCode());
// AtomicInteger idGenerator = ctcRepository.getRouteSequenceIdGenerator();
// RouteSequence.Line line = RouteSequence.buildLine(item, departure, idGenerator);
// routeSequence.addLine(line);
// //股道视图
// TrackView trackView = ctcRepository.getTrackView(station.getCode());
// if (departure) {
// trackView.addDepartureLine(line);
// } else {
// trackView.addReceivingLine(line);
// }
}
/**
* 运行计划item更新了
*/
public void runPlanItemUpdate(Simulation simulation, Station station, CtcStationRunPlanLog.RunPlanItem item, boolean departure) {
regenerateRouteSequenceAndTrackView(simulation);
// CtcRepository ctcRepository = simulation.getCtcRepository();
// RouteSequence.Line routeSequenceLine = ctcRepository.getRouteSequenceLine(station.getCode(), item.getTripNumber(), departure);
//
// String oldTc = routeSequenceLine.getTrackCode();
// String oldTn = routeSequenceLine.getTripNumber();
//
// routeSequenceLine.update();
//
// ctcRepository.updateTrackView(station.getCode(), oldTc, oldTn, routeSequenceLine);
}
/**
* 重新生成进路序列和股道视图
* 该方法应该在车务终端发送阶段计划之后调用
*/
public void regenerateRouteSequenceAndTrackView(Simulation simulation) {
SimulationBuilder.generateRouteSequence(simulation);
CtcRepository ctcRepository = simulation.getCtcRepository();
RouteSequence.Line routeSequenceLine = ctcRepository.getRouteSequenceLine(station.getCode(), item.getTripNumber(), departure);
routeSequenceLine.updateRoute();
ctcRepository.buildTrackViewData(simulation);
}
/**

View File

@ -3,6 +3,7 @@ package club.joylink.rtss.vo.client.factory;
import club.joylink.rtss.constants.BusinessConsts.WebSocketSubscribeTopic;
import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog;
import club.joylink.rtss.simulation.cbtc.CTC.data.Ticket;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.BusyBoardVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.CtcStationRunPlanLogVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.RailDispatchCommandVO;
import club.joylink.rtss.simulation.cbtc.Simulation;
@ -415,9 +416,9 @@ public class SocketMessageFactory {
/**
* CTC进路序列消息
*/
public static SocketMessageVO<Object> buildCtcBusyBoardMessage(String simulationId,
Object message) {
return build(WebSocketMessageType.Simulation_RailCtcStatus, simulationId, message);
public static SocketMessageVO<List<BusyBoardVO>> buildCtcBusyBoardMessage(String simulationId,
List<BusyBoardVO> body) {
return build(WebSocketMessageType.Simulation_RailCtcStatus, simulationId, body);
}
/**

View File

@ -15,4 +15,13 @@ public class WebSocketMessage<T, B> {
this.type = type;
this.body = body;
}
public enum Type {
/** 所有数据 */
ALL,
/** 更新数据 */
UPDATE,
/** 清除数据 */
CLEAR,
}
}