【将CTC所有消息发送移到CTCLogicLoop】

【增加调度台、邻站消息发送类型】
This commit is contained in:
weizhihong 2022-06-14 10:47:24 +08:00
parent 8ef0eafd69
commit 99678ccc1d
4 changed files with 155 additions and 54 deletions

View File

@ -10,14 +10,11 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.util.RandomGenerator; import club.joylink.rtss.util.RandomGenerator;
import club.joylink.rtss.vo.client.WebSocketMessageType;
import club.joylink.rtss.vo.client.ctc.CtcRunPlanVO;
import club.joylink.rtss.websocket.StompMessageService; import club.joylink.rtss.websocket.StompMessageService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.time.LocalTime; import java.time.LocalTime;
@ -92,7 +89,7 @@ public class CtcStationRunPlanLogService {
runPlanLogList.add(changeRunPlanLog); runPlanLogList.add(changeRunPlanLog);
} }
}); });
sendRunPlanChangeMessage(simulation, runPlanLogList); ctcLogicLoop.sendRunPlanChangeMessage(simulation, runPlanLogList, simulation.getSimulationUserIds());
} }
/** /**
@ -120,8 +117,7 @@ public class CtcStationRunPlanLogService {
} }
}); });
// 发送消息 // 发送消息
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), runPlanLogList, ctcLogicLoop.sendCtcManageChangeMessage(simulation, runPlanLogList, simulation.getSimulationUserIds());
WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_CHANGE, simulation.getSimulationUserIds());
} }
/** /**
@ -142,8 +138,7 @@ public class CtcStationRunPlanLogService {
}, (p) -> p)); }, (p) -> p));
simulation.getCtcRepository().getSimulationRunPlanEditAreaMap().put(stationCode, planParamMap); simulation.getCtcRepository().getSimulationRunPlanEditAreaMap().put(stationCode, planParamMap);
// 发送消息 // 发送消息
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), runPlanParamList, ctcLogicLoop.sendCtcManageCoverMessage(simulation, runPlanParamList, simulation.getSimulationUserIds());
WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_COVER, simulation.getSimulationUserIds());
} }
/** /**
@ -158,8 +153,7 @@ public class CtcStationRunPlanLogService {
.getSimulationRunPlanEditAreaMap().getOrDefault(stationCode, new ConcurrentHashMap<>()); .getSimulationRunPlanEditAreaMap().getOrDefault(stationCode, new ConcurrentHashMap<>());
tripNumberList.forEach(tripNumber -> stationRunLogTripNumberMap.remove(tripNumber)); tripNumberList.forEach(tripNumber -> stationRunLogTripNumberMap.remove(tripNumber));
// 发送消息 // 发送消息
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), tripNumberList, ctcLogicLoop.sendCtcManageRemoveMessage(simulation, tripNumberList, simulation.getSimulationUserIds());
WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_REMOVE, simulation.getSimulationUserIds());
} }
/** /**
@ -180,7 +174,7 @@ public class CtcStationRunPlanLogService {
simulation.getCtcRepository().addRunPlanToSimulationMap(runPlanLog); simulation.getCtcRepository().addRunPlanToSimulationMap(runPlanLog);
runPlanLogList.add(runPlanLog); runPlanLogList.add(runPlanLog);
}); });
coverRunPlanMessage(simulation, runPlanLogList); ctcLogicLoop.coverRunPlanMessage(simulation, runPlanLogList, simulation.getSimulationUserIds());
} }
/** /**
@ -236,7 +230,7 @@ public class CtcStationRunPlanLogService {
} }
} }
if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) {
sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds());
} }
} }
} }
@ -273,7 +267,7 @@ public class CtcStationRunPlanLogService {
} }
} }
if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) {
sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds());
} }
} }
@ -307,7 +301,7 @@ public class CtcStationRunPlanLogService {
} }
} }
if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) {
sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds());
} }
} }
@ -344,7 +338,7 @@ public class CtcStationRunPlanLogService {
} }
} }
if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) {
sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds());
} }
} }
@ -362,7 +356,7 @@ public class CtcStationRunPlanLogService {
CtcStationRunPlanLog changeRunPlanLog = new CtcStationRunPlanLog(); CtcStationRunPlanLog changeRunPlanLog = new CtcStationRunPlanLog();
changeRunPlanLog.setCode(runPlanCode); changeRunPlanLog.setCode(runPlanCode);
changeRunPlanLog.setDelete(Boolean.TRUE); changeRunPlanLog.setDelete(Boolean.TRUE);
sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds());
} }
} }
@ -567,30 +561,4 @@ public class CtcStationRunPlanLogService {
} }
return runPlanParam; return runPlanParam;
} }
/**
* websocket消息发送事件
*
* @param simulation 仿真实体
* @param ctcStationRunPlanLogList 信息变更的实体列表
*/
private void sendRunPlanChangeMessage(Simulation simulation, List<CtcStationRunPlanLog> ctcStationRunPlanLogList) {
if (!CollectionUtils.isEmpty(ctcStationRunPlanLogList)) {
// CTC运行日志发消息
List<CtcRunPlanVO> messageList = ctcStationRunPlanLogList.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog))
.collect(Collectors.toList());
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), messageList
, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_CHANGE, simulation.getSimulationUserIds());
}
}
private void coverRunPlanMessage(Simulation simulation, List<CtcStationRunPlanLog> ctcStationRunPlanLogList) {
if (!CollectionUtils.isEmpty(ctcStationRunPlanLogList)) {
// CTC运行日志发消息
List<CtcRunPlanVO> messageList = ctcStationRunPlanLogList.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog))
.collect(Collectors.toList());
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), messageList
, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_COVER, simulation.getSimulationUserIds());
}
}
} }

View File

@ -1,11 +1,14 @@
package club.joylink.rtss.simulation.cbtc.CTC; package club.joylink.rtss.simulation.cbtc.CTC;
import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.CtcRunPlanParam;
import club.joylink.rtss.simulation.cbtc.ATS.service.ars.AtsRouteSelectService; import club.joylink.rtss.simulation.cbtc.ATS.service.ars.AtsRouteSelectService;
import club.joylink.rtss.simulation.cbtc.CI.CiApiService; import club.joylink.rtss.simulation.cbtc.CI.CiApiService;
import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository;
import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.vo.client.SocketMessageVO; import club.joylink.rtss.vo.client.SocketMessageVO;
import club.joylink.rtss.vo.client.WebSocketMessageType; import club.joylink.rtss.vo.client.WebSocketMessageType;
import club.joylink.rtss.vo.client.ctc.CtcRunPlanVO;
import club.joylink.rtss.vo.client.factory.SocketMessageFactory; import club.joylink.rtss.vo.client.factory.SocketMessageFactory;
import club.joylink.rtss.websocket.StompMessageService; import club.joylink.rtss.websocket.StompMessageService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -15,6 +18,7 @@ import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
@Component @Component
public class CTCLogicLoop { public class CTCLogicLoop {
@ -58,18 +62,139 @@ public class CTCLogicLoop {
simulation.addFixedRateJob(MESSAGE_NAME, () -> this.sendMessage(simulation), MESSAGE_RATE); simulation.addFixedRateJob(MESSAGE_NAME, () -> this.sendMessage(simulation), MESSAGE_RATE);
} }
/**
* 发送CTC初始变化
*
* @param simulation 仿真实体
* @param messageList 消息列表
* @param userIds 用户ID
*/
public void sendRunPlanInitMessage(Simulation simulation, List<CtcRunPlanVO> messageList, Set<String> userIds) {
if (!CollectionUtils.isEmpty(messageList)) {
sendCtcMessage(simulation.getId(), messageList, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_INIT, userIds);
}
}
/**
* websocket消息发送变化事件
*
* @param simulation 仿真实体
* @param messageInfo 信息变更的实体列表
*/
public void sendRunPlanChangeMessage(Simulation simulation, List<CtcStationRunPlanLog> messageInfo, Set<String> userIds) {
if (!CollectionUtils.isEmpty(messageInfo)) {
// CTC运行日志发消息
List<CtcRunPlanVO> messageList = messageInfo.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog))
.collect(Collectors.toList());
sendCtcMessage(simulation.getId(), messageList, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_CHANGE, userIds);
}
}
/**
* websocket消息发送覆盖事件
*
* @param simulation 仿真实体
* @param messageInfo 信息变更的实体列表
*/
public void coverRunPlanMessage(Simulation simulation, List<CtcStationRunPlanLog> messageInfo, Set<String> userIds) {
if (!CollectionUtils.isEmpty(messageInfo)) {
// CTC运行日志发消息
List<CtcRunPlanVO> messageList = messageInfo.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog))
.collect(Collectors.toList());
sendCtcMessage(simulation.getId(), messageList, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_COVER, userIds);
}
}
/**
* @param simulation
* @param messageInfo
* @param userIds
*/
public void initCtcManageMessage(Simulation simulation, List<CtcRunPlanParam> messageInfo, Set<String> userIds) {
if (!CollectionUtils.isEmpty(messageInfo)) {
sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_INIT, userIds);
}
}
/**
* 发送管理端信息变更消息
*
* @param simulation 仿真ID
* @param messageInfo 消息
* @param userIds 用户ID
*/
public void sendCtcManageChangeMessage(Simulation simulation, List<CtcRunPlanParam> messageInfo, Set<String> userIds) {
if (messageInfo != null && !messageInfo.isEmpty()) {
sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_CHANGE, userIds);
}
}
/**
* 发送管理端信息覆盖消息
*
* @param simulation 仿真ID
* @param messageInfo 消息
* @param userIds 用户ID
*/
public void sendCtcManageCoverMessage(Simulation simulation, List<CtcRunPlanParam> messageInfo, Set<String> userIds) {
if (messageInfo != null && !messageInfo.isEmpty()) {
sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_COVER, userIds);
}
}
/**
* 发送管理端信息删除消息
*
* @param simulation 仿真ID
* @param messageInfo 消息
* @param userIds 用户ID
*/
public void sendCtcManageRemoveMessage(Simulation simulation, List<String> messageInfo, Set<String> userIds) {
if (messageInfo != null && !messageInfo.isEmpty()) {
sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_REMOVE, userIds);
}
}
/**
* 发送调度台消息
*
* @param simulationId 仿真ID
* @param messageInfo 消息
* @param userIds 用户ID
* @param <T> 消息类型
*/
public <T> void sendCtcDispatcherMessage(String simulationId, T messageInfo, Set<String> userIds) {
if (messageInfo != null) {
sendCtcMessage(simulationId, messageInfo, WebSocketMessageType.SIMULATION_CTC_DISPATCHER_MESSAGE, userIds);
}
}
/**
* CTC邻站消息
*
* @param simulationId 仿真ID
* @param messageInfo 消息
* @param userIds 用户ID
* @param <T> 消息类型
*/
public <T> void sendCtcAdjacentStationMessage(String simulationId, T messageInfo, Set<String> userIds) {
if (messageInfo != null) {
sendCtcMessage(simulationId, messageInfo, WebSocketMessageType.SIMULATION_CTC_ADJACENT_STATION_MESSAGE, userIds);
}
}
/** /**
* 发送CTC运行计划消息 * 发送CTC运行计划消息
* *
* @param simulationId 仿真ID * @param simulationId 仿真ID
* @param messageInfoList 运行计划列表 * @param messageInfo 运行计划列表
* @param type 消息类型 * @param type 消息类型
* @param userIds 用户ID * @param userIds 用户ID
*/ */
public <T> void sendCtcRunPlanMessage(String simulationId, List<T> messageInfoList, WebSocketMessageType type, Set<String> userIds) { public <T> void sendCtcMessage(String simulationId, T messageInfo, WebSocketMessageType type, Set<String> userIds) {
if (!CollectionUtils.isEmpty(messageInfoList)) { if (messageInfo != null) {
SocketMessageVO<List<T>> message = SocketMessageFactory.build(type, simulationId, messageInfoList); SocketMessageVO<T> messageVO = SocketMessageFactory.build(type, simulationId, messageInfo);
stompMessageService.sendToUser(userIds, message); stompMessageService.sendToUser(userIds, messageVO);
} }
} }
} }

View File

@ -115,8 +115,7 @@ public class SimulationUserWsListener {
List<CtcRunPlanVO> messageList = simulation.getCtcRepository().getAllRunPlanList().stream() List<CtcRunPlanVO> messageList = simulation.getCtcRepository().getAllRunPlanList().stream()
.map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog)) .map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog))
.collect(Collectors.toList()); .collect(Collectors.toList());
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), messageList ctcLogicLoop.sendRunPlanInitMessage(simulation, messageList, Stream.of(userId).collect(Collectors.toSet()));
, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_INIT, Stream.of(userId).collect(Collectors.toSet()));
ctcLogicLoop.sendAllMessage(simulation); ctcLogicLoop.sendAllMessage(simulation);
break; break;
} }
@ -124,8 +123,7 @@ public class SimulationUserWsListener {
// CTC管理端编辑区发送消息 // CTC管理端编辑区发送消息
List<CtcRunPlanParam> allList = new ArrayList<>(); List<CtcRunPlanParam> allList = new ArrayList<>();
simulation.getCtcRepository().getSimulationRunPlanEditAreaMap().forEach((k, v) -> allList.addAll(v.values())); simulation.getCtcRepository().getSimulationRunPlanEditAreaMap().forEach((k, v) -> allList.addAll(v.values()));
ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), allList ctcLogicLoop.initCtcManageMessage(simulation, allList, Stream.of(userId).collect(Collectors.toSet()));
, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_INIT, Stream.of(userId).collect(Collectors.toSet()));
break; break;
} }
} }

View File

@ -367,6 +367,16 @@ public enum WebSocketMessageType {
*/ */
SIMULATION_CTC_RUN_PLAN_COVER, SIMULATION_CTC_RUN_PLAN_COVER,
/**
* CTC调度台消息类型
*/
SIMULATION_CTC_DISPATCHER_MESSAGE,
/**
* CTC邻站消息
*/
SIMULATION_CTC_ADJACENT_STATION_MESSAGE,
/** /**
* 仿真CTC管理端 * 仿真CTC管理端
*/ */