【实训加载时人员初始化】

This commit is contained in:
weizhihong 2023-11-27 16:47:31 +08:00
parent 300804dccc
commit a73c568b7f
6 changed files with 799 additions and 647 deletions

View File

@ -30,6 +30,7 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.member.MemberManager;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.member.SimulationMemberPO;
import club.joylink.rtss.simulation.cbtc.script.ScriptBO;
import club.joylink.rtss.simulation.cbtc.training2.Operation2;
import club.joylink.rtss.simulation.cbtc.training2.Operation2.SimCommand2;
@ -565,8 +566,9 @@ public class Training2Service {
Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
loadTrainingPre(simulation);
// 重置仿真状态
// groupSimulationService.planOver(group);
simulationService.reset(group);
// 初始化实训人员
initTrainingMember(simulation, draftTraining2);
// 场景的时候加载最后背景
String bgSceneJson = StringUtils.isEmpty(draftTraining2.getFinalScenesJson())
? draftTraining2.getBgSceneJson() : draftTraining2.getFinalScenesJson();
@ -650,6 +652,8 @@ public class Training2Service {
private void loadTraining(Simulation simulation, DraftTraining2WithBLOBs draftTraining2,
LoginUserInfoVO loginUserInfoVO) {
loadTrainingPre(simulation);
// 初始化实训人员
initTrainingMember(simulation, draftTraining2);
// 没有背景不做加载加载的时候不做背景加载开始的时候重新加载背景即可
if (!StringUtils.isEmpty(draftTraining2.getBgSceneJson())) {
groupSimulationService.loadScenes(simulation.getId(), draftTraining2.getBgSceneJson());
@ -1116,4 +1120,22 @@ public class Training2Service {
WebSocketMessageType.Simulation_Training_Status, simulation.getId(), status);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
/**
* 初始化实训成员
*
* @param simulation 仿真
* @param draftTraining2 实训信息
*/
private void initTrainingMember(Simulation simulation, DraftTraining2WithBLOBs draftTraining2) {
if ("single".equals(draftTraining2.getType())) {// 单操不需要初始化成员
return;
}
if (StringUtils.hasText(draftTraining2.getMemberJson())) {
List<SimulationMemberPO> memberPOS = JsonUtils.readCollection(draftTraining2.getMemberJson(),
List.class, SimulationMemberPO.class);
memberManager.loadExtraMembers(simulation, memberPOS);
}
}
}

View File

@ -17,6 +17,7 @@ import club.joylink.rtss.simulation.cbtc.event.SimulationConversationMemberConne
import club.joylink.rtss.simulation.cbtc.event.SimulationErrorEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationIbpStatusEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationMemberAddEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationMemberResetEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationPauseEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationPslStatusEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent;
@ -126,6 +127,15 @@ public class SimulationMainThread {
this.stompMessageService.sendToUser(userIds, message);
}
@EventListener
public void simulationMemberReset(SimulationMemberResetEvent event) {
Simulation simulation = event.getSimulation();
Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationMemberMessageVO> message = SocketMessageFactory
.buildSimulationMemberResetMessage(simulation);
this.stompMessageService.sendToUser(userIds, message);
}
@EventListener
public void conversationCreate(SimulationConversationCreateEvent event) {
Simulation simulation = event.getSimulation();
@ -310,14 +320,16 @@ public class SimulationMainThread {
ScriptActionVO actionVO = ScriptActionVO.buildScriptTipVO(action);
if (actionVO.getType().equals(ScriptActionBO.ActionType.Conversation)) {
LocalDateTime correctSystemTime = simulation.getCorrectSystemTime();
String currentTime = correctSystemTime.getHour() + "" + correctSystemTime.getMinute() + "";
String currentTime =
correctSystemTime.getHour() + "" + correctSystemTime.getMinute() + "";
actionVO.setContent(String.format(actionVO.getContent(), currentTime));
}
SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildScriptTipMessage(simulation.getId(), actionVO);
stompMessageService.sendToUser(action.getMember().getUserId(), message);
log.info(
String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getId(), action.getMember().getId(),
String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getId(),
action.getMember().getId(),
action.getId()));
}
@ -328,7 +340,8 @@ public class SimulationMainThread {
simulation.getId());
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
log.info(
String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(), simulation.getScript().getId()));
String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(),
simulation.getScript().getId()));
}
@EventListener

View File

@ -0,0 +1,12 @@
package club.joylink.rtss.simulation.cbtc.event;
import club.joylink.rtss.simulation.cbtc.Simulation;
import lombok.Getter;
@Getter
public class SimulationMemberResetEvent extends AbstractSimulationEvent {
public SimulationMemberResetEvent(Object source, Simulation simulation) {
super(source, simulation);
}
}

View File

@ -4,86 +4,93 @@ import club.joylink.rtss.constants.MapPrdTypeEnum;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.Simulation.Type;
import club.joylink.rtss.simulation.cbtc.data.map.DisStation;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.event.SimulationMemberAddEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationMemberResetEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserPlayChangeEvent;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.vo.map.graph.MapMemberVO;
import club.joylink.rtss.websocket.StompMessageService;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@Slf4j
@Component
public class MemberManager {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private SimulationManager simulationManager;
@Autowired
private StompMessageService stompMessageService;
@Autowired
private SimulationManager simulationManager;
@Autowired
private StompMessageService stompMessageService;
/**
* 初始化仿真成员
*/
public void init(Simulation simulation) {
/* -----------默认创建一个行调,一个通号;车站和司机按设备创建----------- */
// 调度
if (!simulation.getRepository().getConfig().isRailway()) {
this.addRole(simulation, SimulationMember.Type.DISPATCHER);
/**
* 初始化仿真成员
*/
public void init(Simulation simulation) {
/* -----------默认创建一个行调,一个通号;车站和司机按设备创建----------- */
// 调度
if (!simulation.getRepository().getConfig().isRailway()) {
this.addRole(simulation, SimulationMember.Type.DISPATCHER);
}
// 通号
this.addRole(simulation, SimulationMember.Type.MAINTAINER);
// 行值
List<Station> stationList = simulation.getRepository().getSortedStationList();
for (Station station : stationList) {
if (station.isNormal()) {
this.addRole(simulation, null, SimulationMember.Type.STATION_SUPERVISOR, null, station);
} else if (station.isDepot()) {
// 车辆段调度
this.addRole(simulation, null, SimulationMember.Type.DEPOT_DISPATCHER,
station.getName() + "调度", station);
}
// 大铁CTC
if (simulation.getRepository().getConfig().isRailway()) {
Arrays.asList(
SimulationMember.Type.STATION_ASSISTANT, SimulationMember.Type.STATION_MASTER,
SimulationMember.Type.STATION_SIGNALER, SimulationMember.Type.STATION_PASSENGER,
SimulationMember.Type.STATION_SWITCH_MAN, SimulationMember.Type.STATION_FACILITATOR,
SimulationMember.Type.STATION_WORKER, SimulationMember.Type.DEVICE_MANAGER,
SimulationMember.Type.STATION_ELECTRIC_WORKER
).forEach(type -> this.addRole(simulation, null, type, null, station));
}
}
//调度台
if (simulation.getRepository().getConfig().isRailway()) {
// 调度台--调度关联
List<DisStation> disStationList = simulation.getRepository().getDisStationList();
if (null != disStationList) {
for (DisStation disStation : disStationList) {
this.addRole(simulation, null, SimulationMember.Type.DISPATCHER,
disStation.getName() + "调度", disStation);
}
// 通号
this.addRole(simulation, SimulationMember.Type.MAINTAINER);
// 行值
List<Station> stationList = simulation.getRepository().getSortedStationList();
for (Station station : stationList) {
if (station.isNormal()) {
this.addRole(simulation, null, SimulationMember.Type.STATION_SUPERVISOR, null, station);
} else if (station.isDepot()) {
// 车辆段调度
this.addRole(simulation, null, SimulationMember.Type.DEPOT_DISPATCHER, station.getName() + "调度", station);
}
// 大铁CTC
if (simulation.getRepository().getConfig().isRailway()) {
Arrays.asList(
SimulationMember.Type.STATION_ASSISTANT, SimulationMember.Type.STATION_MASTER,
SimulationMember.Type.STATION_SIGNALER, SimulationMember.Type.STATION_PASSENGER,
SimulationMember.Type.STATION_SWITCH_MAN, SimulationMember.Type.STATION_FACILITATOR,
SimulationMember.Type.STATION_WORKER, SimulationMember.Type.DEVICE_MANAGER,
SimulationMember.Type.STATION_ELECTRIC_WORKER
).forEach(type -> this.addRole(simulation, null, type, null, station));
}
}
//调度台
if (simulation.getRepository().getConfig().isRailway()) {
// 调度台--调度关联
List<DisStation> disStationList = simulation.getRepository().getDisStationList();
if (null != disStationList) {
for (DisStation disStation : disStationList) {
this.addRole(simulation, null, SimulationMember.Type.DISPATCHER, disStation.getName() + "调度", disStation);
}
}
}
// 司机
List<VirtualRealityTrain> vrTrainList = simulation.getRepository().getAllVrTrain();
for (VirtualRealityTrain vrTrain : vrTrainList) {
this.addRole(simulation, null, SimulationMember.Type.DRIVER, null, vrTrain);
}
// 工电调度
this.addRole(simulation, SimulationMember.Type.ELECTRIC_DISPATCHER);
}
}
// 司机
List<VirtualRealityTrain> vrTrainList = simulation.getRepository().getAllVrTrain();
for (VirtualRealityTrain vrTrain : vrTrainList) {
this.addRole(simulation, null, SimulationMember.Type.DRIVER, null, vrTrain);
}
// 工电调度
this.addRole(simulation, SimulationMember.Type.ELECTRIC_DISPATCHER);
// // 车辆段调度
// this.addRole(simulation, SimulationMember.Type.DEPOT_DISPATCHER);
// // 车辆段信号楼
@ -94,194 +101,241 @@ public class MemberManager {
// this.addRole(simulation, SimulationMember.Type.PARENT_DEPARTMENT);
// // 派班员
// this.addRole(simulation, SimulationMember.Type.SCHEDULING);
// 车务段段长
this.addRole(simulation, SimulationMember.Type.TRAIN_MASTER);
// NCC调度员
this.addRole(simulation, SimulationMember.Type.NCC_DISPATCHER);
// 信息调度
this.addRole(simulation, SimulationMember.Type.OCC_DISPATCHER);
}
// 车务段段长
this.addRole(simulation, SimulationMember.Type.TRAIN_MASTER);
// NCC调度员
this.addRole(simulation, SimulationMember.Type.NCC_DISPATCHER);
// 信息调度
this.addRole(simulation, SimulationMember.Type.OCC_DISPATCHER);
}
/**
* 根据仿真类型给用户扮演仿真成员
*/
public void playRoleBySimulationType(Simulation simulation, Long userId) {
MapPrdTypeEnum prdType = simulation.getBuildParams().getProdType();
if (prdType != null) {
switch (prdType) {
case LOCAL: {
List<SimulationMember> supervisorList = simulation.querySimulationMembersOfRole(SimulationMember.Type.STATION_SUPERVISOR);
this.playRole(simulation, userId, supervisorList.get(0).getId());
break;
}
case YJDDZH:
case BIG_SCREEN:
case ISCS:
case CENTER:
case JOINT: {
List<SimulationMember> dispatcherList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DISPATCHER);
this.playRole(simulation, userId, dispatcherList.get(0).getId());
break;
}
case DEPOT_IL: {
List<SimulationMember> ddList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DEPOT_DISPATCHER);
this.playRole(simulation, userId, ddList.get(0).getId());
break;
}
/**
* 根据仿真类型给用户扮演仿真成员
*/
public void playRoleBySimulationType(Simulation simulation, Long userId) {
MapPrdTypeEnum prdType = simulation.getBuildParams().getProdType();
if (prdType != null) {
switch (prdType) {
case LOCAL: {
List<SimulationMember> supervisorList = simulation.querySimulationMembersOfRole(
SimulationMember.Type.STATION_SUPERVISOR);
this.playRole(simulation, userId, supervisorList.get(0).getId());
break;
}
case YJDDZH:
case BIG_SCREEN:
case ISCS:
case CENTER:
case JOINT: {
List<SimulationMember> dispatcherList = simulation.querySimulationMembersOfRole(
SimulationMember.Type.DISPATCHER);
this.playRole(simulation, userId, dispatcherList.get(0).getId());
break;
}
case DEPOT_IL: {
List<SimulationMember> ddList = simulation.querySimulationMembersOfRole(
SimulationMember.Type.DEPOT_DISPATCHER);
this.playRole(simulation, userId, ddList.get(0).getId());
break;
}
// case CTC: {
// List<SimulationMember> list = simulation.querySimulationMembersOfRole(SimulationMember.Type.RAIL_CTC);
// this.playRole(simulation, userId, list.get(0).getId());
// break;
// }
}
}
}
}
}
public SimulationMember addRole(Simulation simulation, SimulationMember.Type type) {
SimulationMember member = this.addRole(simulation, null, type, null, null);
SimulationMemberAddEvent memberAddEvent = new SimulationMemberAddEvent(this, simulation, member);
this.applicationContext.publishEvent(memberAddEvent);
return member;
}
public SimulationMember addRole(Simulation simulation, SimulationMember.Type type) {
SimulationMember member = this.addRole(simulation, null, type, null, null);
SimulationMemberAddEvent memberAddEvent = new SimulationMemberAddEvent(this, simulation,
member);
this.applicationContext.publishEvent(memberAddEvent);
return member;
}
public SimulationMember addRole(Simulation simulation, SimulationMember.Type type, String name) {
return this.addRole(simulation, null, type, name, null);
}
public SimulationMember addRole(Simulation simulation, SimulationMember.Type type, String name) {
return this.addRole(simulation, null, type, name, null);
}
public SimulationMember addRole(Simulation simulation,
String id, SimulationMember.Type type,
String name, MapElement device) {
switch (type) {
case DISPATCHER:
public SimulationMember addRole(Simulation simulation,
String id, SimulationMember.Type type,
String name, MapElement device) {
switch (type) {
case DISPATCHER:
// case SCHEDULING: {
// break;
// }
case DEPOT_DISPATCHER: {
if (Objects.isNull(device) ||
!Objects.equals(device.getDeviceType(), MapElement.DeviceType.STATION) ||
!((Station) device).isDepot()) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.exception("车辆段调度必须关联车辆段/停车场车站");
}
break;
}
case STATION_SUPERVISOR: {
if (Objects.isNull(device) ||
!Objects.equals(device.getDeviceType(), MapElement.DeviceType.STATION) ||
!((Station) device).isNormal()) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
String.format("行值必须关联一般车站"));
}
break;
}
case DRIVER: {
if (Objects.isNull(device) ||
!Objects.equals(device.getDeviceType(), MapElement.DeviceType.TRAIN)) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
String.format("司机必须关联虚拟真实列车"));
}
break;
}
case DEPOT_DISPATCHER: {
if (Objects.isNull(device) ||
!Objects.equals(device.getDeviceType(), MapElement.DeviceType.STATION) ||
!((Station) device).isDepot()) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.exception(
"车辆段调度必须关联车辆段/停车场车站");
}
if (id == null) {
id = simulation.getIdGenerator().nextMemberId();
} else {
Long generatorId = simulation.getIdGenerator().getCurrentMemberId();
if (NumberUtils.isCreatable(id) && generatorId < Long.parseLong(id)) { // 如果ID大于当前记录ID则将ID置于当前大小 防止ID重复导致出错
simulation.getIdGenerator().setMemberId(Long.parseLong(id));
}
break;
}
case STATION_SUPERVISOR: {
if (Objects.isNull(device) ||
!Objects.equals(device.getDeviceType(), MapElement.DeviceType.STATION) ||
!((Station) device).isNormal()) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
String.format("行值必须关联一般车站"));
}
SimulationMember member = new SimulationMember(id, type, device);
member.setName(name);
simulation.addSimulationMember(member);
SimulationMemberAddEvent memberAddEvent = new SimulationMemberAddEvent(this, simulation, member);
this.applicationContext.publishEvent(memberAddEvent);
return member;
break;
}
case DRIVER: {
if (Objects.isNull(device) ||
!Objects.equals(device.getDeviceType(), MapElement.DeviceType.TRAIN)) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
String.format("司机必须关联虚拟真实列车"));
}
break;
}
}
if (id == null) {
id = simulation.getIdGenerator().nextMemberId();
} else {
Long generatorId = simulation.getIdGenerator().getCurrentMemberId();
if (NumberUtils.isCreatable(id) && generatorId < Long.parseLong(
id)) { // 如果ID大于当前记录ID则将ID置于当前大小 防止ID重复导致出错
simulation.getIdGenerator().setMemberId(Long.parseLong(id));
}
}
SimulationMember member = new SimulationMember(id, type, device);
member.setName(name);
simulation.addSimulationMember(member);
SimulationMemberAddEvent memberAddEvent = new SimulationMemberAddEvent(this, simulation,
member);
this.applicationContext.publishEvent(memberAddEvent);
return member;
}
/**
* 用户扮演角色
*
* @param simulation
* @param userId
* @param memberId
*/
public void playRole(Simulation simulation, Long userId, String memberId) {
SimulationUser simulationUser = simulation.getSimulationUserById(userId);
SimulationMember member = simulation.getSimulationMemberById(memberId);
// 可以校验仿真用户是否可以扮演指定的角色
if (!simulationUser.canPlay(member)) {
throw new SimulationException(SimulationExceptionType.Operation_Not_Supported);
}
// 扮演角色
// 如果成员之前被其他用户扮演先取消此用户扮演
String otherId = member.getUserId();
/**
* 用户扮演角色
*
* @param simulation
* @param userId
* @param memberId
*/
public void playRole(Simulation simulation, Long userId, String memberId) {
SimulationUser simulationUser = simulation.getSimulationUserById(userId);
SimulationMember member = simulation.getSimulationMemberById(memberId);
// 可以校验仿真用户是否可以扮演指定的角色
if (!simulationUser.canPlay(member)) {
throw new SimulationException(SimulationExceptionType.Operation_Not_Supported);
}
// 扮演角色
// 如果成员之前被其他用户扮演先取消此用户扮演
String otherId = member.getUserId();
if (Objects.nonNull(otherId) && !Objects.equals(otherId, userId.toString())) {
SimulationUser oldPlayer = simulation.getSimulationUserById(otherId);
this.cancelPlay(simulation, oldPlayer);
}
// 如果用户之前扮演其他角色取消用户之前的扮演
this.cancelPlay(simulation, simulationUser);
if (Objects.nonNull(otherId) && !Objects.equals(otherId, userId.toString())) {
SimulationUser oldPlayer = simulation.getSimulationUserById(otherId);
this.cancelPlay(simulation, oldPlayer);
}
// 如果用户之前扮演其他角色取消用户之前的扮演
this.cancelPlay(simulation, simulationUser);
// SimulationMember playedMember = simulationUser.getPlayedMember();
// if (Objects.nonNull(playedMember) && !Objects.equals(playedMember, member)) {
// this.cancelPlay(simulation, simulationUser);
// }
// 用户扮演指定角色
simulationUser.play(member);
SimulationUserPlayChangeEvent playChangeEvent = new SimulationUserPlayChangeEvent(this, simulation, simulationUser, null);
this.applicationContext.publishEvent(playChangeEvent);
this.simulationManager.memberPlayedByUser(simulation.getId(), memberId, userId.toString());
}
// 用户扮演指定角色
simulationUser.play(member);
SimulationUserPlayChangeEvent playChangeEvent = new SimulationUserPlayChangeEvent(this,
simulation, simulationUser, null);
this.applicationContext.publishEvent(playChangeEvent);
this.simulationManager.memberPlayedByUser(simulation.getId(), memberId, userId.toString());
}
/**
* 取消用户扮演
*/
public void cancelPlay(Simulation simulation, Long userId) {
SimulationUser simulationUser = simulation.getSimulationUserById(userId);
this.cancelPlay(simulation, simulationUser);
}
/**
* 取消用户扮演
*/
public void cancelPlay(Simulation simulation, Long userId) {
SimulationUser simulationUser = simulation.getSimulationUserById(userId);
this.cancelPlay(simulation, simulationUser);
}
/**
* 取消用户扮演
*/
public void cancelPlay(Simulation simulation, SimulationUser simulationUser) {
SimulationMember cancelPlayMember = simulationUser.cancelPlay();
if (cancelPlayMember != null) {
SimulationUserPlayChangeEvent playChangeEvent =
new SimulationUserPlayChangeEvent(this, simulation, simulationUser, cancelPlayMember);
this.applicationContext.publishEvent(playChangeEvent);
/**
* 取消用户扮演
*/
public void cancelPlay(Simulation simulation, SimulationUser simulationUser) {
SimulationMember cancelPlayMember = simulationUser.cancelPlay();
if (cancelPlayMember != null) {
SimulationUserPlayChangeEvent playChangeEvent =
new SimulationUserPlayChangeEvent(this, simulation, simulationUser, cancelPlayMember);
this.applicationContext.publishEvent(playChangeEvent);
}
}
/**
* 取消仿真成员扮演
*
* @param simulation
* @param memberId
*/
private void cancelMemberPlayed(Simulation simulation, String memberId) {
SimulationMember member = simulation.getSimulationMemberById(memberId);
if (Objects.nonNull(member.getUserId())) {
SimulationUser simulationUser = simulation.getSimulationUserById(member.getUserId());
this.cancelPlay(simulation, simulationUser);
}
}
/**
* 根据memberId是否为空扮演/取消扮演角色
*
* @param simulation
* @param userId
* @param memberId
*/
public void playOrCancelPlayRole(Simulation simulation, Long userId, String memberId) {
Objects.requireNonNull(memberId);
if (Objects.nonNull(userId) && StringUtils.hasText(memberId)) {
this.playRole(simulation, userId, memberId);
} else if (Objects.isNull(userId)) {
this.cancelMemberPlayed(simulation, memberId);
} else if (!StringUtils.hasText(memberId)) {
this.cancelPlay(simulation, userId);
}
}
/**
* 加载额外的成员(实训加载时使用)
*/
public void loadExtraMembers(Simulation simulation, List<SimulationMemberPO> memberPOS) {
// 还原到原始状态
Type mapType = simulation.getBuildParams().getWorkParamVO().getType();
List<MapMemberVO> memberVOS = simulation.getBuildParams().getMap()
.getGraphDataNew().getMemberMap().get(mapType);
Map<String, Boolean> originMemberMap = new HashMap<>(memberVOS.size());
for (MapMemberVO m : memberVOS) {
originMemberMap.put(m.getId(), true);
}
// 删除在原始数据中不存在的成员
List<SimulationMember> members = simulation.getSimulationMembers();
for (SimulationMember m : members) {
if (!originMemberMap.containsKey(m.getId())) {
simulation.removeSimulationMember(m.getId());
}
}
// 加入额外的成员
if (!CollectionUtils.isEmpty(memberPOS)) {
for (SimulationMemberPO p : memberPOS) {
if (originMemberMap.containsKey(p.getId())) {
continue;
}
}
/**
* 取消仿真成员扮演
*
* @param simulation
* @param memberId
*/
private void cancelMemberPlayed(Simulation simulation, String memberId) {
SimulationMember member = simulation.getSimulationMemberById(memberId);
if (Objects.nonNull(member.getUserId())) {
SimulationUser simulationUser = simulation.getSimulationUserById(member.getUserId());
this.cancelPlay(simulation, simulationUser);
}
}
/**
* 根据memberId是否为空扮演/取消扮演角色
*
* @param simulation
* @param userId
* @param memberId
*/
public void playOrCancelPlayRole(Simulation simulation, Long userId, String memberId) {
Objects.requireNonNull(memberId);
if (Objects.nonNull(userId) && StringUtils.hasText(memberId)) {
this.playRole(simulation, userId, memberId);
} else if (Objects.isNull(userId)) {
this.cancelMemberPlayed(simulation, memberId);
} else if (!StringUtils.hasText(memberId)) {
this.cancelPlay(simulation, userId);
MapElement mapElement = null;
if (StringUtils.hasText(p.getDeviceCode())) {
mapElement = simulation.getRepository().getByCode(p.getDeviceCode());
}
SimulationMember member = new SimulationMember(p.getId(), p.getType(), mapElement);
member.setName(p.getName());
simulation.addSimulationMember(member);
}
}
// 成员重置事件
SimulationMemberResetEvent memberResetEvent = new SimulationMemberResetEvent(this, simulation);
this.applicationContext.publishEvent(memberResetEvent);
}
}

View File

@ -36,476 +36,518 @@ import club.joylink.rtss.vo.client.script.ScriptActionVO;
import club.joylink.rtss.vo.client.simulationv1.SimulationMemberMessageVO;
import club.joylink.rtss.vo.client.simulationv1.SimulationUserMessageVO;
import club.joylink.rtss.websocket.WebSocketMessage;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
public class SocketMessageFactory {
/**
* 构建非仿真消息
*
* @param messageType
* @param body
* @param <T>
* @return
*/
public static <T> SocketMessageVO<T> buildBasic(WebSocketMessageType messageType, T body) {
List<String> topicList = getTopicsBy(messageType, null);
SocketMessageVO<T> socketMessageVO = new SocketMessageVO<>(messageType, topicList, body);
return socketMessageVO;
}
/**
* 构建非仿真消息
*
* @param messageType
* @param body
* @param <T>
* @return
*/
public static <T> SocketMessageVO<T> buildBasic(WebSocketMessageType messageType, T body) {
List<String> topicList = getTopicsBy(messageType, null);
SocketMessageVO<T> socketMessageVO = new SocketMessageVO<>(messageType, topicList, body);
return socketMessageVO;
}
public static <T> SocketMessageVO<T> build(WebSocketMessageType messageType, String group, T body) {
List<String> topicList = getTopicsBy(messageType, group);
SocketMessageVO<T> socketMessageVO = new SocketMessageVO<>(messageType, topicList, body);
return socketMessageVO;
}
public static <T> SocketMessageVO<T> build(WebSocketMessageType messageType, String group,
T body) {
List<String> topicList = getTopicsBy(messageType, group);
SocketMessageVO<T> socketMessageVO = new SocketMessageVO<>(messageType, topicList, body);
return socketMessageVO;
}
private static List<String> getTopicsBy(WebSocketMessageType messageType, String group) {
List<String> topicList = new ArrayList<>();
switch (messageType) {
case SIMULATION_NCC_STATION_DIAGRAM:{
topicList.add(SimulationSubscribeTopic.NCC_DIAGRAM.buildDestination(group));
break;
}
case YJDDZH_TRAIN_POSITION: {
topicList.add(SimulationSubscribeTopic.YJDDZH_TRAIN_POSITION.buildDestination(group));
private static List<String> getTopicsBy(WebSocketMessageType messageType, String group) {
List<String> topicList = new ArrayList<>();
switch (messageType) {
case SIMULATION_NCC_STATION_DIAGRAM: {
topicList.add(SimulationSubscribeTopic.NCC_DIAGRAM.buildDestination(group));
break;
}
case YJDDZH_TRAIN_POSITION: {
topicList.add(SimulationSubscribeTopic.YJDDZH_TRAIN_POSITION.buildDestination(group));
}
case BROADCAST:
case Order_Pay_Result:
case Be_Logged_Out:
}
case BROADCAST:
case Order_Pay_Result:
case Be_Logged_Out:
// case Simulation_Invite:
{
topicList.add(WebSocketSubscribeTopic.Common);
break;
}
case Simulation_RunFact: {
topicList.add(SimulationSubscribeTopic.RUN_FACT.buildDestination(group));
break;
}
case Simulation_Time_Sync:
case SIMULATION_WORK_PARAM:
case Simulation_User:
case Simulation_Member:
case Simulation_IbpStatus:
case Simulation_PslStatus:
case Simulation_AutoFault_Trigger:
case Simulation_Error:
case Simulation_RunAsPlan_Start:
case Simulation_ApplyHandle:
case Simulation_Control_Pause:
case Simulation_Run_Plan_Reload:
case Simulation_Trip_Plan_Change:
case Simulation_Scenes_Reload:
case Competition_Practical:
case SIMULATION_RAIL_TICKET:
case Simulation_Alarm:
case Simulation_Operation_Mode_Apply:
case Simulation_Conversation_Group:
case Simulation_Control_Mode_Apply_Result:{
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
break;
}
case Simulation_DeviceStatus: {
topicList.add(SimulationSubscribeTopic.DeviceStatus.buildDestination(group));
break;
}
case SIMULATION_RAILWAY_RUN_PLAN_SEND: // 铁路局运行计划下发
case SIMULATION_CTC_RUN_PLAN_CHANGE:
case SIMULATION_CTC_RUN_PLAN_REMOVE:
case SIMULATION_CTC_RUN_PLAN_CONFIRM_SEND:
case SIMULATION_RAIL_CTC_DISPATCH_COMMAND:
case SIMULATION_RAIL_CTC_DIS_COMMAND_ADD:
case SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC:
case Simulation_RailCtcStatus: {
topicList.add(SimulationSubscribeTopic.Ctc.buildDestination(group));
break;
}
{
topicList.add(WebSocketSubscribeTopic.Common);
break;
}
case Simulation_RunFact: {
topicList.add(SimulationSubscribeTopic.RUN_FACT.buildDestination(group));
break;
}
case Simulation_Time_Sync:
case SIMULATION_WORK_PARAM:
case Simulation_User:
case Simulation_Member:
case Simulation_IbpStatus:
case Simulation_PslStatus:
case Simulation_AutoFault_Trigger:
case Simulation_Error:
case Simulation_RunAsPlan_Start:
case Simulation_ApplyHandle:
case Simulation_Control_Pause:
case Simulation_Run_Plan_Reload:
case Simulation_Trip_Plan_Change:
case Simulation_Scenes_Reload:
case Competition_Practical:
case SIMULATION_RAIL_TICKET:
case Simulation_Alarm:
case Simulation_Operation_Mode_Apply:
case Simulation_Conversation_Group:
case Simulation_Control_Mode_Apply_Result: {
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
break;
}
case Simulation_DeviceStatus: {
topicList.add(SimulationSubscribeTopic.DeviceStatus.buildDestination(group));
break;
}
case SIMULATION_RAILWAY_RUN_PLAN_SEND: // 铁路局运行计划下发
case SIMULATION_CTC_RUN_PLAN_CHANGE:
case SIMULATION_CTC_RUN_PLAN_REMOVE:
case SIMULATION_CTC_RUN_PLAN_CONFIRM_SEND:
case SIMULATION_RAIL_CTC_DISPATCH_COMMAND:
case SIMULATION_RAIL_CTC_DIS_COMMAND_ADD:
case SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC:
case Simulation_RailCtcStatus: {
topicList.add(SimulationSubscribeTopic.Ctc.buildDestination(group));
break;
}
case Simulation_Member_Change:
case Simulation_Start_Conversation:
case Simulation_Accept_Conversation:
case Simulation_Exist_Conversation:
case Simulation_Conversation:
case Simulation_Conversation_Operation:
case Simulation_Device:
case Simulation_Quest_Loaded:
case Simulation_Quest_Quit:
case Simulation_Script_Loaded:
case Simulation_Script_Quit:
case Simulation_Script_Action_Tip:
case Simulation_Script_Action_Finish:
case Simulation_Script_Action_Error:
case Simulation_Competition_Practice_Finish:
case Simulation_Script_Action:
case Simulation_Driver_Change:
case Simulation_TrainSpeed:
case Simulation_Drive_Data_Routing: {
topicList.add(SimulationSubscribeTopic.WeChatMini.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
break;
}
// 20220819
case Simulation_Training_Prepare_Start:
case Simulation_Training_Step_Tip:
case Simulation_Training_Step_Finish:
case Simulation_Training_Audio_MATCH_RESULT:
case Simulation_Member_Change:
case Simulation_Start_Conversation:
case Simulation_Accept_Conversation:
case Simulation_Exist_Conversation:
case Simulation_Conversation:
case Simulation_Conversation_Operation:
case Simulation_Device:
case Simulation_Quest_Loaded:
case Simulation_Quest_Quit:
case Simulation_Script_Loaded:
case Simulation_Script_Quit:
case Simulation_Script_Action_Tip:
case Simulation_Script_Action_Finish:
case Simulation_Script_Action_Error:
case Simulation_Competition_Practice_Finish:
case Simulation_Script_Action:
case Simulation_Driver_Change:
case Simulation_TrainSpeed:
case Simulation_Drive_Data_Routing: {
topicList.add(SimulationSubscribeTopic.WeChatMini.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
break;
}
// 20220819
case Simulation_Training_Prepare_Start:
case Simulation_Training_Step_Tip:
case Simulation_Training_Step_Finish:
case Simulation_Training_Audio_MATCH_RESULT:
// case Simulation_Training_Operate_Error:
// case Simulation_Training_Operate_Finish:
case Simulation_Training_Finish:
case Simulation_Training_Status: {
topicList.add(String.format(WebSocketSubscribeTopic.AssistantSimulation, group));
topicList.add(String.format(WebSocketSubscribeTopic.Simulation, group));
topicList.add(String.format(WebSocketSubscribeTopic.Sandbox3D, group));
break;
}
case STAND_PFI_NUM:
case STAND_PFI_TO:
case STAND_PFI:
case TRAIN_PFI_NUM:
case TRAIN_PFI_BL:
case TRAIN_PIS:
case PFV:
case STATION_PFI_NUM:
case LPF_STRATEGY_RECOMMEND: {
topicList.add(SimulationSubscribeTopic.PassengerFlow.buildDestination(group));
break;
}
case TrainRun_3D:
case Device_Fault_Set_3D:
case Device_Fault_Over_3D:
case VR_Sync_3D:
case SJL3D_TrainStatus: {
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
break;
}
case Device_Load_Destroy_3D:
case DeviceCtrl_3D:
case TDT_3D:
case BeAbout2Arrive_3D: {
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
break;
}
case Train_Position_3D:
case Train_Hmi_3D:
case Train_Position: {
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
break;
}
case SDC:
case SDSQ:
case TPM: {
topicList.add(SimulationSubscribeTopic.Wgu3d.buildDestination(group));
break;
}
case Simulation_Reset: {
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
topicList.add(SimulationSubscribeTopic.WeChatMini.buildDestination(group));
topicList.add(SimulationSubscribeTopic.PassengerFlow.buildDestination(group));
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Wgu3d.buildDestination(group));
break;
}
case Simulation_Over: {
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
topicList.add(SimulationSubscribeTopic.PassengerFlow.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
topicList.add(SimulationSubscribeTopic.WeChatMini.buildDestination(group));
}
}
return topicList;
case Simulation_Training_Finish:
case Simulation_Training_Status: {
topicList.add(String.format(WebSocketSubscribeTopic.AssistantSimulation, group));
topicList.add(String.format(WebSocketSubscribeTopic.Simulation, group));
topicList.add(String.format(WebSocketSubscribeTopic.Sandbox3D, group));
break;
}
case STAND_PFI_NUM:
case STAND_PFI_TO:
case STAND_PFI:
case TRAIN_PFI_NUM:
case TRAIN_PFI_BL:
case TRAIN_PIS:
case PFV:
case STATION_PFI_NUM:
case LPF_STRATEGY_RECOMMEND: {
topicList.add(SimulationSubscribeTopic.PassengerFlow.buildDestination(group));
break;
}
case TrainRun_3D:
case Device_Fault_Set_3D:
case Device_Fault_Over_3D:
case VR_Sync_3D:
case SJL3D_TrainStatus: {
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
break;
}
case Device_Load_Destroy_3D:
case DeviceCtrl_3D:
case TDT_3D:
case BeAbout2Arrive_3D: {
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
break;
}
case Train_Position_3D:
case Train_Hmi_3D:
case Train_Position: {
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
break;
}
case SDC:
case SDSQ:
case TPM: {
topicList.add(SimulationSubscribeTopic.Wgu3d.buildDestination(group));
break;
}
case Simulation_Reset: {
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
topicList.add(SimulationSubscribeTopic.WeChatMini.buildDestination(group));
topicList.add(SimulationSubscribeTopic.PassengerFlow.buildDestination(group));
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Wgu3d.buildDestination(group));
break;
}
case Simulation_Over: {
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
topicList.add(SimulationSubscribeTopic.SandBox.buildDestination(group));
topicList.add(SimulationSubscribeTopic.PassengerFlow.buildDestination(group));
topicList.add(SimulationSubscribeTopic.Drive.buildDestination(group));
topicList.add(SimulationSubscribeTopic.WeChatMini.buildDestination(group));
}
}
return topicList;
}
// public static SocketMessageVO<Boolean> buildScriptEndMessage(String group) {
// return build(WebSocketMessageType.Simulation_Script_Finish, group, true);
// }
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOnlineMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ONLINE));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOnlineMessage(
Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ONLINE));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOfflineMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.OFFLINE));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOfflineMessage(
Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.OFFLINE));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserKickOutMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.KICK_OUT));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserKickOutMessage(
Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.KICK_OUT));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserEnterMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ENTER));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserEnterMessage(
Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ENTER));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserPlayChangeMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.PLAY_CHANGE));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserPlayChangeMessage(
Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.PLAY_CHANGE));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserExitMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.EXIT));
}
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserExitMessage(
Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.EXIT));
}
public static SocketMessageVO<SimulationMemberMessageVO> buildSimulationMemberAddMessage(Simulation simulation, SimulationMember simulationMember) {
return build(WebSocketMessageType.Simulation_Member, simulation.getId(),
SimulationMemberMessageVO.buildAddMemberMessage(simulationMember));
}
public static SocketMessageVO<SimulationMemberMessageVO> buildSimulationMemberAddMessage(
Simulation simulation, SimulationMember simulationMember) {
return build(WebSocketMessageType.Simulation_Member, simulation.getId(),
SimulationMemberMessageVO.buildAddMemberMessage(simulationMember));
}
public static SocketMessageVO<SimulationMemberMessageVO> buildSimulationMemberResetMessage(
Simulation simulation) {
return build(WebSocketMessageType.Simulation_Member, simulation.getId(),
SimulationMemberMessageVO.buildResetMemberMessage());
}
// public static SocketMessageVO<SimulationVO> buildSimulationInviteMessage(Simulation simulation) {
// return build(WebSocketMessageType.Simulation_Invite, simulation.getId(),
// SimulationVO.buildBasicInfo(simulation));
// }
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationCreateMessage(Simulation simulation, Conversation conversation) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildCreateMessage(conversation));
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationCreateMessage(
Simulation simulation, Conversation conversation) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildCreateMessage(conversation));
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationInviteMessage(
Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildInviteMessage(conversation, member));
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationMemberConnectConversationMessage(
Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildMemberConnectConversationMessage(conversation, member));
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationChatMessage(
Simulation simulation, Conversation conversation, ConversationMessage conversationMessage) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildConversationChatMessage(conversation,
conversationMessage));
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationExitMessage(
Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildExitMessage(conversation, member));
}
public static SocketMessageVO<Long> buildSimulationTimeSyncMessage(Simulation simulation) {
long systemTime = simulation.getCorrectSystemTimeStamp();
return build(WebSocketMessageType.Simulation_Time_Sync, simulation.getId(), systemTime);
}
public static SocketMessageVO<Map<String, IbpStatus>> buildSimulationIbpStatusMessage(
String group, Map<String, IbpStatus> statusMap) {
return build(WebSocketMessageType.Simulation_IbpStatus, group, statusMap);
}
public static SocketMessageVO<Map<String, PslStatus>> buildSimulationPslStatusMessage(
String group, Map<String, PslStatus> statusMap) {
return build(WebSocketMessageType.Simulation_PslStatus, group, statusMap);
}
public static SocketMessageVO<Boolean> buildSimulationScenesReload(String group,
boolean planRunning) {
return build(WebSocketMessageType.Simulation_Scenes_Reload, group, planRunning);
}
public static SocketMessageVO<PassengerFlowMessage2TD> buildPassengerFlowMessage2TD(String group,
PassengerFlowMessage2TD data) {
return build(WebSocketMessageType.STATION_PFI_NUM, group, data);
}
public static SocketMessageVO<LoginUserInfoVO> buildLoginSomewhereElseMessage(
LoginUserInfoVO infoVO) {
return build(WebSocketMessageType.Be_Logged_Out, null, infoVO);
}
@Component
private static class SpringContextUtil implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationInviteMessage(Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildInviteMessage(conversation, member));
}
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationMemberConnectConversationMessage(Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildMemberConnectConversationMessage(conversation, member));
}
/**
* 构建剧本演出结束消息
*/
public static SocketMessageVO<Boolean> buildCompetitionPracticeFinishMessage(String group) {
return build(WebSocketMessageType.Simulation_Competition_Practice_Finish, group, true);
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationChatMessage(Simulation simulation, Conversation conversation, ConversationMessage conversationMessage) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildConversationChatMessage(conversation, conversationMessage));
}
}
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationExitMessage(Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildExitMessage(conversation, member));
}
/**
* 构建仿真设备状态消息
*/
public static SocketMessageVO<List<DeviceStatusVO>> buildSimulationDeviceStatusesMessage(
String group, List<DeviceStatusVO> deviceStatuses) {
return build(WebSocketMessageType.Simulation_DeviceStatus, group, deviceStatuses);
}
public static SocketMessageVO<Long> buildSimulationTimeSyncMessage(Simulation simulation) {
long systemTime = simulation.getCorrectSystemTimeStamp();
return build(WebSocketMessageType.Simulation_Time_Sync, simulation.getId(), systemTime);
}
/**
* 构建剧本动作消息
*/
public static SocketMessageVO<ScriptActionVO> buildScriptActionMessage(String group,
ScriptActionVO actionNewVO) {
return build(WebSocketMessageType.Simulation_Script_Action, group, actionNewVO);
}
public static SocketMessageVO<Map<String, IbpStatus>> buildSimulationIbpStatusMessage(String group, Map<String, IbpStatus> statusMap) {
return build(WebSocketMessageType.Simulation_IbpStatus, group, statusMap);
}
/**
* 构建Hmi3d消息
*
* @return
*/
public static SocketMessageVO<Object> buildHmiMessage(String group, Object display) {
return build(WebSocketMessageType.Train_Hmi_3D, group,
JsonUtils.writeValueNullableFieldAsString(display));
}
public static SocketMessageVO<Map<String, PslStatus>> buildSimulationPslStatusMessage(String group, Map<String, PslStatus> statusMap) {
return build(WebSocketMessageType.Simulation_PslStatus, group, statusMap);
}
/**
* 构建仿真剧本提示消息
*/
public static SocketMessageVO<ScriptActionVO> buildScriptTipMessage(String group,
ScriptActionVO action) {
return build(WebSocketMessageType.Simulation_Script_Action_Tip, group, action);
}
public static SocketMessageVO<Boolean> buildSimulationScenesReload(String group, boolean planRunning) {
return build(WebSocketMessageType.Simulation_Scenes_Reload, group, planRunning);
}
/**
* 构建仿真剧本动作完成消息
*/
public static SocketMessageVO<ScriptActionVO> buildSimulationScriptActionFinishMessage(
String group, ScriptActionVO action) {
return build(WebSocketMessageType.Simulation_Script_Action_Finish, group, action);
}
public static SocketMessageVO<PassengerFlowMessage2TD> buildPassengerFlowMessage2TD(String group, PassengerFlowMessage2TD data) {
return build(WebSocketMessageType.STATION_PFI_NUM, group, data);
}
/**
* 构建列车即将到站消息
*/
public static SocketMessageVO<TrainIsAbout2ArriveVO> buildTrainIsAbout2ArriveMessage(String group,
TrainIsAbout2ArriveVO arriveVO) {
return build(WebSocketMessageType.BeAbout2Arrive_3D, group, arriveVO);
}
public static SocketMessageVO<LoginUserInfoVO> buildLoginSomewhereElseMessage(LoginUserInfoVO infoVO) {
return build(WebSocketMessageType.Be_Logged_Out, null, infoVO);
}
/**
* 构建列车即将到站消息
*
* @return
*/
public static SocketMessageVO<List<TdtStatusVO>> buildTrainIsAbout2ArriveMessage(String group,
List<TdtStatusVO> list) {
return build(WebSocketMessageType.TDT_3D, group, list);
}
@Component
private static class SpringContextUtil implements ApplicationContextAware {
/**
* 构建VR同步消息
*/
public static SocketMessageVO<String> buildVrMessage(String group, String json) {
return build(WebSocketMessageType.VR_Sync_3D, group, json);
}
private static ApplicationContext applicationContext;
/**
* 司机视角列车位置消息
*/
public static SocketMessageVO<Collection<TrainPosition>> buildTrainPositionMessage(String group,
Collection<TrainPosition> position) {
return build(WebSocketMessageType.Train_Position_3D, group, position);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/**
* 剧本动作执行错误
*/
public static SocketMessageVO<String> buildSimulationScriptActionErrorMessage(String group,
String id) {
return build(WebSocketMessageType.Simulation_Script_Action_Error, group, id);
}
}
/**
* 订单支付成功
*/
public static SocketMessageVO<String> buildOrderPaySuccessMessage(String orderCode) {
return build(WebSocketMessageType.Order_Pay_Result, null, orderCode);
}
/**
* 构建剧本演出结束消息
*/
public static SocketMessageVO<Boolean> buildCompetitionPracticeFinishMessage(String group) {
return build(WebSocketMessageType.Simulation_Competition_Practice_Finish, group, true);
/**
* 车次计划变化
*/
public static SocketMessageVO<RunPlanEChartsDataVO> buildTripPlanChangeMessage(
String simulationId, List<RunPlanTripVO> changeTrips) {
RunPlanEChartsDataVO eChartsDataVO = new RunPlanEChartsDataVO(changeTrips);
return build(WebSocketMessageType.Simulation_Trip_Plan_Change, simulationId, eChartsDataVO);
}
}
/**
* CTC 列车运行计划变化消息
*/
public static SocketMessageVO<List<CtcStationRunPlanLogVO>> buildCtcRunPlanCommonMessage(
String simulationId
, List<CtcStationRunPlanLog> ctcStationRunPlanLogList, WebSocketMessageType type) {
List<CtcStationRunPlanLogVO> ctcStationRunPlanLogVOList = ctcStationRunPlanLogList.stream()
.map(ctcStationRunPlanLog -> new CtcStationRunPlanLogVO(ctcStationRunPlanLog))
.collect(Collectors.toList());
return build(type, simulationId, ctcStationRunPlanLogVOList);
}
/**
* 构建仿真设备状态消息
*/
public static SocketMessageVO<List<DeviceStatusVO>> buildSimulationDeviceStatusesMessage(String group, List<DeviceStatusVO> deviceStatuses) {
return build(WebSocketMessageType.Simulation_DeviceStatus, group, deviceStatuses);
}
/**
* CTC进路序列消息
*/
public static SocketMessageVO<List<BusyBoardVO>> buildCtcBusyBoardMessage(String simulationId,
List<BusyBoardVO> body) {
return build(WebSocketMessageType.Simulation_RailCtcStatus, simulationId, body);
}
/**
* 构建剧本动作消息
*/
public static SocketMessageVO<ScriptActionVO> buildScriptActionMessage(String group, ScriptActionVO actionNewVO) {
return build(WebSocketMessageType.Simulation_Script_Action, group, actionNewVO);
}
/**
* CTC调度命令消息
*/
public static SocketMessageVO<WebSocketMessage<RailDispatchCommandVO.WsMsgType, RailDispatchCommandVO>> buildDispatchCommandMessage
(String simulationId,
WebSocketMessage<RailDispatchCommandVO.WsMsgType, RailDispatchCommandVO> message) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DISPATCH_COMMAND, simulationId, message);
}
/**
* 构建Hmi3d消息
*
* @return
*/
public static SocketMessageVO<Object> buildHmiMessage(String group, Object display) {
return build(WebSocketMessageType.Train_Hmi_3D, group, JsonUtils.writeValueNullableFieldAsString(display));
}
/**
* CTC调度命令消息2,通知前端收令箱收到一条调度命令
*/
public static SocketMessageVO<DisCmd> buildDisCmdAddNotify(String sId, DisCmd body) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, sId, body);
}
/**
* 构建仿真剧本提示消息
*/
public static SocketMessageVO<ScriptActionVO> buildScriptTipMessage(String group, ScriptActionVO action) {
return build(WebSocketMessageType.Simulation_Script_Action_Tip, group, action);
}
/**
* CTC调度命令消息2,将调度服务器端数据变化同步到前端
*/
public static SocketMessageVO<DisCmdSyncMsgVo> buildDisCmdSyncMessage(String sId,
DisCmdSyncMsgVo syncMsg) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC, sId, syncMsg);
}
/**
* 构建仿真剧本动作完成消息
*/
public static SocketMessageVO<ScriptActionVO> buildSimulationScriptActionFinishMessage(String group, ScriptActionVO action) {
return build(WebSocketMessageType.Simulation_Script_Action_Finish, group, action);
}
/**
* CTC路票消息
*/
public static SocketMessageVO<Ticket> buildRailTicketMessage(String sId, Ticket body) {
return build(WebSocketMessageType.SIMULATION_RAIL_TICKET, sId, body);
}
/**
* 构建列车即将到站消息
*/
public static SocketMessageVO<TrainIsAbout2ArriveVO> buildTrainIsAbout2ArriveMessage(String group, TrainIsAbout2ArriveVO arriveVO) {
return build(WebSocketMessageType.BeAbout2Arrive_3D, group, arriveVO);
}
/**
* 构建仿真工作参数
*/
public static SocketMessageVO<SimulationWorkParamVO> buildSimulationWorkParamMessage(String sId,
SimulationWorkParamVO body) {
return build(WebSocketMessageType.SIMULATION_WORK_PARAM, sId, body);
}
/**
* 构建列车即将到站消息
*
* @return
*/
public static SocketMessageVO<List<TdtStatusVO>> buildTrainIsAbout2ArriveMessage(String group, List<TdtStatusVO> list) {
return build(WebSocketMessageType.TDT_3D, group, list);
}
/**
* Ats报警
*/
public static SocketMessageVO<Collection<AtsAlarm>> buildAtsAlarmMessage(String sId,
Collection<AtsAlarm> alarmList) {
return build(WebSocketMessageType.Simulation_Alarm, sId, alarmList);
}
/**
* 构建VR同步消息
*/
public static SocketMessageVO<String> buildVrMessage(String group, String json) {
return build(WebSocketMessageType.VR_Sync_3D, group, json);
}
/**
* ncc 车站图例
*
* @param sId
* @param stationDiagramList
* @return
*/
public static SocketMessageVO<List<StationDiagram>> buildAtsStationDiagram(String sId,
List<StationDiagram> stationDiagramList) {
return build(WebSocketMessageType.SIMULATION_NCC_STATION_DIAGRAM, sId, stationDiagramList);
/**
* 司机视角列车位置消息
*/
public static SocketMessageVO<Collection<TrainPosition>> buildTrainPositionMessage(String group, Collection<TrainPosition> position) {
return build(WebSocketMessageType.Train_Position_3D, group, position);
}
}
/**
* 剧本动作执行错误
*/
public static SocketMessageVO<String> buildSimulationScriptActionErrorMessage(String group, String id) {
return build(WebSocketMessageType.Simulation_Script_Action_Error, group, id);
}
/**
* 订单支付成功
*/
public static SocketMessageVO<String> buildOrderPaySuccessMessage(String orderCode) {
return build(WebSocketMessageType.Order_Pay_Result, null, orderCode);
}
/**
* 车次计划变化
*/
public static SocketMessageVO<RunPlanEChartsDataVO> buildTripPlanChangeMessage(String simulationId, List<RunPlanTripVO> changeTrips) {
RunPlanEChartsDataVO eChartsDataVO = new RunPlanEChartsDataVO(changeTrips);
return build(WebSocketMessageType.Simulation_Trip_Plan_Change, simulationId, eChartsDataVO);
}
/**
* CTC 列车运行计划变化消息
*/
public static SocketMessageVO<List<CtcStationRunPlanLogVO>> buildCtcRunPlanCommonMessage(String simulationId
, List<CtcStationRunPlanLog> ctcStationRunPlanLogList, WebSocketMessageType type) {
List<CtcStationRunPlanLogVO> ctcStationRunPlanLogVOList = ctcStationRunPlanLogList.stream()
.map(ctcStationRunPlanLog -> new CtcStationRunPlanLogVO(ctcStationRunPlanLog)).collect(Collectors.toList());
return build(type, simulationId, ctcStationRunPlanLogVOList);
}
/**
* CTC进路序列消息
*/
public static SocketMessageVO<List<BusyBoardVO>> buildCtcBusyBoardMessage(String simulationId,
List<BusyBoardVO> body) {
return build(WebSocketMessageType.Simulation_RailCtcStatus, simulationId, body);
}
/**
* CTC调度命令消息
*/
public static SocketMessageVO<WebSocketMessage<RailDispatchCommandVO.WsMsgType, RailDispatchCommandVO>> buildDispatchCommandMessage
(String simulationId, WebSocketMessage<RailDispatchCommandVO.WsMsgType, RailDispatchCommandVO> message) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DISPATCH_COMMAND, simulationId, message);
}
/**
* CTC调度命令消息2,通知前端收令箱收到一条调度命令
*/
public static SocketMessageVO<DisCmd> buildDisCmdAddNotify(String sId, DisCmd body) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, sId, body);
}
/**
* CTC调度命令消息2,将调度服务器端数据变化同步到前端
*/
public static SocketMessageVO<DisCmdSyncMsgVo> buildDisCmdSyncMessage(String sId, DisCmdSyncMsgVo syncMsg) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC, sId, syncMsg);
}
/**
* CTC路票消息
*/
public static SocketMessageVO<Ticket> buildRailTicketMessage(String sId, Ticket body) {
return build(WebSocketMessageType.SIMULATION_RAIL_TICKET, sId, body);
}
/**
* 构建仿真工作参数
*/
public static SocketMessageVO<SimulationWorkParamVO> buildSimulationWorkParamMessage(String sId, SimulationWorkParamVO body) {
return build(WebSocketMessageType.SIMULATION_WORK_PARAM, sId, body);
}
/**
* Ats报警
*/
public static SocketMessageVO<Collection<AtsAlarm>> buildAtsAlarmMessage(String sId, Collection<AtsAlarm> alarmList) {
return build(WebSocketMessageType.Simulation_Alarm, sId, alarmList);
}
/**
* ncc 车站图例
* @param sId
* @param stationDiagramList
* @return
*/
public static SocketMessageVO<List<StationDiagram>> buildAtsStationDiagram(String sId, List<StationDiagram> stationDiagramList){
return build(WebSocketMessageType.SIMULATION_NCC_STATION_DIAGRAM,sId,stationDiagramList);
}
public static SocketMessageVO<List<ControlModelApplyResult>> buildControlModelApplyResultMessage(String sId, List<ControlModelApplyResult> results) {
return build(WebSocketMessageType.Simulation_Control_Mode_Apply_Result, sId, results);
}
public static SocketMessageVO<List<ControlModelApplyResult>> buildControlModelApplyResultMessage(
String sId, List<ControlModelApplyResult> results) {
return build(WebSocketMessageType.Simulation_Control_Mode_Apply_Result, sId, results);
}
}

View File

@ -8,18 +8,27 @@ import lombok.Setter;
@Setter
public class SimulationMemberMessageVO extends SimulationMemberVO {
private MessageType messageType;
private MessageType messageType;
protected SimulationMemberMessageVO(SimulationMember member, MessageType messageType) {
super(member);
this.messageType = messageType;
}
protected SimulationMemberMessageVO(MessageType messageType) {
this.messageType = messageType;
}
public static SimulationMemberMessageVO buildAddMemberMessage(SimulationMember member) {
return new SimulationMemberMessageVO(member, MessageType.ADD);
}
protected SimulationMemberMessageVO(SimulationMember member, MessageType messageType) {
super(member);
this.messageType = messageType;
}
public enum MessageType {
ADD
}
public static SimulationMemberMessageVO buildAddMemberMessage(SimulationMember member) {
return new SimulationMemberMessageVO(member, MessageType.ADD);
}
public static SimulationMemberMessageVO buildResetMemberMessage() {
return new SimulationMemberMessageVO(MessageType.Reset);
}
public enum MessageType {
ADD,
Reset
}
}