旧仿真继承新仿真接口

This commit is contained in:
joylink_zhangsai 2021-05-12 18:11:03 +08:00
parent 5de44e7263
commit ddf981be2e
58 changed files with 1020 additions and 815 deletions

View File

@ -169,7 +169,7 @@ public class SimulationV1Controller {
@PostMapping("/{group}/command") @PostMapping("/{group}/command")
public void command(@PathVariable String group, @RequestBody @Validated CommandInitiateVO initiateVO, @ApiIgnore @RequestAttribute UserVO user) { public void command(@PathVariable String group, @RequestBody @Validated CommandInitiateVO initiateVO, @ApiIgnore @RequestAttribute UserVO user) {
Simulation simulation = this.groupSimulationService.getSimulationByGroup(group); Simulation simulation = this.groupSimulationService.getSimulationByGroup(group);
SimulationMember member = simulation.getMemberByUserId(user.getId()); SimulationMember member = simulation.getSimulationMemberByUserId(user.getId());
this.groupSimulationService.command(simulation, initiateVO, member); this.groupSimulationService.command(simulation, initiateVO, member);
} }

View File

@ -24,4 +24,6 @@ public interface IVirtualRealityIbpService {
* @param simulation * @param simulation
*/ */
void collectAndDispatcher(Simulation simulation); void collectAndDispatcher(Simulation simulation);
void addJobs(Simulation simulation);
} }

View File

@ -707,7 +707,7 @@ public class MapService implements IMapService {
} }
// RunPlanVO commonRunPlan = this.iDailyRunPlanService.findCommonRunPlan(mapId, this.iDailyRunPlanService.getRunPlanDate()); // RunPlanVO commonRunPlan = this.iDailyRunPlanService.findCommonRunPlan(mapId, this.iDailyRunPlanService.getRunPlanDate());
// builder.runPlan(commonRunPlan); // builder.runPlan(commonRunPlan);
club.joylink.rtss.simulation.cbtc.Simulation simulation = SimulationBuilder.build(builder.build()); club.joylink.rtss.simulation.cbtc.Simulation simulation = SimulationBuilder.build(null, builder.build());
return simulation.getDataErrMsgList(); return simulation.getDataErrMsgList();
} }
return new ArrayList<>(); return new ArrayList<>();

View File

@ -4,6 +4,8 @@ import club.joylink.rtss.simulation.cbtc.ATS.operation.handler.StandOperateHandl
import club.joylink.rtss.simulation.cbtc.CI.CiApiService; import club.joylink.rtss.simulation.cbtc.CI.CiApiService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapConfig; import club.joylink.rtss.simulation.cbtc.data.map.MapConfig;
import club.joylink.rtss.simulation.cbtc.data.map.Stand; import club.joylink.rtss.simulation.cbtc.data.map.Stand;
@ -142,6 +144,12 @@ public class VirtualRealityIbpService implements IVirtualRealityIbpService {
} }
} }
@Override
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.IBP_STATUS.name(), () -> this.collectAndDispatcher(simulation),
SimulationConstants.IBP_STATUS_COLLECT_RATE);
}
/** /**
* 确保IBP盘存在然后为它收集状态 * 确保IBP盘存在然后为它收集状态
*/ */

View File

@ -258,7 +258,7 @@ public class AuthenticateService implements IAuthenticateService {
case IM: { case IM: {
// 教员机 // 教员机
Simulation simulation = this.projectJointSimulationService.createSimulation(loginUserInfo); Simulation simulation = this.projectJointSimulationService.createSimulation(loginUserInfo);
loginUserInfo.setGroup(simulation.getGroup()); loginUserInfo.setGroup(simulation.getId());
break; break;
} }
case LW: case LW:

View File

@ -227,11 +227,11 @@ public class CompetitionPracticalService implements ICompetitionPracticalService
//重新加载场景 //重新加载场景
loadCompetition(group, competition.getId(), userInfo); loadCompetition(group, competition.getId(), userInfo);
iScriptSimulationService.chooseMemberAndStartScript(group, memberId, mode, userInfo.getUserVO());
competition = simulation.getCompetition(); competition = simulation.getCompetition();
competition.reset(); competition.reset();
competition.start(userInfo.getClient()); competition.start(userInfo.getClient());
atsMessageCollectAndDispatcher.syncTime(simulation); atsMessageCollectAndDispatcher.syncTime(simulation);
iScriptSimulationService.chooseMemberAndStartScript(group, memberId, mode, userInfo.getUserVO());
} }
@Override @Override

View File

@ -8,6 +8,7 @@ import club.joylink.rtss.simulation.cbtc.GroupSimulationCache;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService; import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService;
import club.joylink.rtss.simulation.cbtc.competition.CompetitionAndScriptManager;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.conversation.Conversation; import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService; import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService;
@ -79,6 +80,9 @@ public class ScriptSimulationService implements IScriptSimulationService {
@Autowired @Autowired
private IScriptService iScriptService; private IScriptService iScriptService;
@Autowired
private CompetitionAndScriptManager competitionAndScriptManager;
@Override @Override
public String scriptWriteSimulation(Long scriptId, LoginUserInfoVO loginUserInfoVO) { public String scriptWriteSimulation(Long scriptId, LoginUserInfoVO loginUserInfoVO) {
// 先拿到剧本 // 先拿到剧本
@ -86,7 +90,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
// 构建一个仿真 // 构建一个仿真
Simulation simulation = this.groupSimulationService.create(loginUserInfoVO, draftScript.getMapId(), null, Simulation simulation = this.groupSimulationService.create(loginUserInfoVO, draftScript.getMapId(), null,
Simulation.FunctionalType.SCRIPT_MAKING); Simulation.FunctionalType.SCRIPT_MAKING);
String group = simulation.getGroup(); String group = simulation.getId();
// 加载剧本场景 // 加载剧本场景
if (StringUtils.hasText(draftScript.getFinalScenesJson())) { if (StringUtils.hasText(draftScript.getFinalScenesJson())) {
groupSimulationService.loadScenes(group, draftScript.getFinalScenesJson()); groupSimulationService.loadScenes(group, draftScript.getFinalScenesJson());
@ -141,7 +145,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
simulationLifeCycleService.reloadRunPlan(simulation, simulation.getBuildParams().getRunPlan(), simulation.getBuildParams().getSchedulingPlan()); simulationLifeCycleService.reloadRunPlan(simulation, simulation.getBuildParams().getRunPlan(), simulation.getBuildParams().getSchedulingPlan());
simulation.setScript(script); simulation.setScript(script);
script.setMemberList(simulation.getAllSimulationMembers()); script.setMemberList(simulation.getSimulationMembers());
SimulationMember dispatcher = simulation.getMemberListByType(SimulationMember.Type.DISPATCHER).get(0); SimulationMember dispatcher = simulation.getMemberListByType(SimulationMember.Type.DISPATCHER).get(0);
this.switchPlayer(group, dispatcher.getId(), user); this.switchPlayer(group, dispatcher.getId(), user);
// simulationLifeCycleService.pause(simulation); // simulationLifeCycleService.pause(simulation);
@ -157,7 +161,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
if (!simulation.isAllConversationOver()) { if (!simulation.isAllConversationOver()) {
throw new SimulationException(SimulationExceptionType.Invalid_Operation, "有会话尚未结束"); throw new SimulationException(SimulationExceptionType.Invalid_Operation, "有会话尚未结束");
} }
script.setMemberList(simulation.getAllSimulationMembers()); script.setMemberList(simulation.getSimulationMembers());
String finalScenesJson = groupSimulationService.getScenesJson(group, true); String finalScenesJson = groupSimulationService.getScenesJson(group, true);
simulationLifeCycleService.pause(simulation); simulationLifeCycleService.pause(simulation);
script.setFinalScenesJson(finalScenesJson); script.setFinalScenesJson(finalScenesJson);
@ -195,7 +199,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
Simulation simulation = this.groupSimulationService.create(loginUserInfoVO, draftScript.getMapId(), null, Simulation simulation = this.groupSimulationService.create(loginUserInfoVO, draftScript.getMapId(), null,
Simulation.FunctionalType.SCRIPT_PREVIEW); Simulation.FunctionalType.SCRIPT_PREVIEW);
loadDraftScript(simulation, draftScriptId); loadDraftScript(simulation, draftScriptId);
return simulation.getGroup(); return simulation.getId();
} }
@Override @Override
@ -237,7 +241,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
throw new SimulationException(SimulationExceptionType.System_Fault, "仿真中没有剧本"); throw new SimulationException(SimulationExceptionType.System_Fault, "仿真中没有剧本");
} }
script.addAction(action); script.addAction(action);
SocketMessageVO<ScriptActionVO> message = SocketMessageFactory.buildScriptActionMessage(simulation.getGroup(), new ScriptActionVO(action)); SocketMessageVO<ScriptActionVO> message = SocketMessageFactory.buildScriptActionMessage(simulation.getId(), new ScriptActionVO(action));
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -248,7 +252,7 @@ public class ScriptSimulationService implements IScriptSimulationService {
throw new SimulationException(SimulationExceptionType.System_Fault, "该仿真不是剧本编制仿真"); throw new SimulationException(SimulationExceptionType.System_Fault, "该仿真不是剧本编制仿真");
} }
memberManager.playRole(simulation, user.getId(), memberId); memberManager.playRole(simulation, user.getId(), memberId);
simulation.getScript().addPlayer(simulation.getMemberById(memberId)); simulation.getScript().addPlayer(simulation.getSimulationMemberById(memberId));
} }
@Override @Override
@ -304,16 +308,17 @@ public class ScriptSimulationService implements IScriptSimulationService {
groupSimulationService.loadScenes(group, script.getBgScenesJson()); groupSimulationService.loadScenes(group, script.getBgScenesJson());
} }
script.start(mode); script.start(mode);
simulationLifeCycleService.resume(simulation);
} }
@Override @Override
public void loadDraftScript(Simulation simulation, Long draftScriptId) { public void loadDraftScript(Simulation simulation, Long draftScriptId) {
ScriptDraftWithBLOBs entity = iScriptDraftService.getEntityById(draftScriptId); ScriptDraftWithBLOBs entity = iScriptDraftService.getEntityById(draftScriptId);
groupSimulationService.loadScenes(simulation.getGroup(), entity.getBgScenesJson()); groupSimulationService.loadScenes(simulation.getId(), entity.getBgScenesJson());
ScriptBO scriptBO = iScriptDraftService.getScriptBO(draftScriptId, simulation); ScriptBO scriptBO = iScriptDraftService.getScriptBO(draftScriptId, simulation);
scriptCoverSimulation(simulation, scriptBO); scriptCoverSimulation(simulation, scriptBO);
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Script_Loaded, SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Script_Loaded,
simulation.getGroup(), true); simulation.getId(), true);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
stompMessageService.sendToUser(userIds, message); stompMessageService.sendToUser(userIds, message);
} }
@ -322,6 +327,8 @@ public class ScriptSimulationService implements IScriptSimulationService {
public void scriptCoverSimulation(Simulation simulation, ScriptBO scriptBO) { public void scriptCoverSimulation(Simulation simulation, ScriptBO scriptBO) {
this.simulationLifeCycleService.pause(simulation); this.simulationLifeCycleService.pause(simulation);
simulation.setScript(scriptBO); simulation.setScript(scriptBO);
//添加剧本任务
simulation.addJobIfAbsent(Simulation.JobName.script, () -> competitionAndScriptManager.run(simulation), SimulationConstants.SCRIPT_LOOP_RATE);
//剧本出演成员覆盖仿真成员 //剧本出演成员覆盖仿真成员
if (!CollectionUtils.isEmpty(scriptBO.getMemberList())) { if (!CollectionUtils.isEmpty(scriptBO.getMemberList())) {
Map<String, SimulationMember> memberMap = scriptBO.getMemberList() Map<String, SimulationMember> memberMap = scriptBO.getMemberList()
@ -372,11 +379,11 @@ public class ScriptSimulationService implements IScriptSimulationService {
public void loadScript(String group, Long scriptId) { public void loadScript(String group, Long scriptId) {
Simulation simulation = groupSimulationCache.getSimulationByGroup(group); Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
ScriptVO detailById = iScriptService.getDetailById(scriptId); ScriptVO detailById = iScriptService.getDetailById(scriptId);
groupSimulationService.loadScenes(simulation.getGroup(), detailById.getBgScenesJson()); groupSimulationService.loadScenes(simulation.getId(), detailById.getBgScenesJson());
ScriptBO scriptBO = iScriptService.getScriptBOById(scriptId, simulation); ScriptBO scriptBO = iScriptService.getScriptBOById(scriptId, simulation);
this.scriptCoverSimulation(simulation, scriptBO); this.scriptCoverSimulation(simulation, scriptBO);
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Script_Loaded, SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Script_Loaded,
simulation.getGroup(), true); simulation.getId(), true);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
stompMessageService.sendToUser(userIds, message); stompMessageService.sendToUser(userIds, message);
} }

View File

@ -73,8 +73,8 @@ public class ProjectSimulationServiceImpl implements ProjectSimulationService {
Simulation simulation = this.groupSimulationService.create(loginUserInfo, mapId, Simulation simulation = this.groupSimulationService.create(loginUserInfo, mapId,
MapPrdTypeEnum.CENTER, Simulation.FunctionalType.SIMULATION); MapPrdTypeEnum.CENTER, Simulation.FunctionalType.SIMULATION);
RunAsPlanParam param = new RunAsPlanParam(LocalTime.now(), null); RunAsPlanParam param = new RunAsPlanParam(LocalTime.now(), null);
this.groupSimulationService.runAsPlan(simulation.getGroup(), param); this.groupSimulationService.runAsPlan(simulation.getId(), param);
return simulation.getGroup(); return simulation.getId();
} }
} }

View File

@ -192,7 +192,7 @@ public class SchedulingServiceImpl implements SchedulingService {
// 生成新的派班计划一个模板运行图生成一个派班计划 // 生成新的派班计划一个模板运行图生成一个派班计划
SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder() SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder()
.map(mapVO); .map(mapVO);
Simulation simulation = SimulationBuilder.build(builder.build()); Simulation simulation = SimulationBuilder.build(null, builder.build());
for (RunPlanVO planVO : planVOList) { for (RunPlanVO planVO : planVOList) {
// 查询运行图车次计划数据 // 查询运行图车次计划数据
RunPlanVO runPlan = this.iRunPlanTemplateService.getRunPlan(planVO.getId()); RunPlanVO runPlan = this.iRunPlanTemplateService.getRunPlan(planVO.getId());

View File

@ -39,7 +39,7 @@ public class SimulationManageServiceImpl implements SimulationManageService {
public void deleteUselessSimulation() { public void deleteUselessSimulation() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) -> { groupSimulationMap.forEach((group, simulation) -> {
List<SimulationUser> userList = simulation.getAllSimulationUsers(); List<SimulationUser> userList = simulation.getSimulationUsers();
boolean hasOnline = false; boolean hasOnline = false;
for (SimulationUser simulationUser : userList) { for (SimulationUser simulationUser : userList) {
if (simulationUser.isOnline()) { if (simulationUser.isOnline()) {
@ -66,7 +66,7 @@ public class SimulationManageServiceImpl implements SimulationManageService {
List<Simulation> simulationList = this.groupSimulationCache.queryAllSimulation(); List<Simulation> simulationList = this.groupSimulationCache.queryAllSimulation();
simulationList.forEach(simulation -> { simulationList.forEach(simulation -> {
SimulationVO simulationVO = SimulationVO.buildBasicInfo(simulation); SimulationVO simulationVO = SimulationVO.buildBasicInfo(simulation);
List<SimulationUser> simulationUserList = simulation.getAllSimulationUsers(); List<SimulationUser> simulationUserList = simulation.getSimulationUsers();
List<String> onlineUserIdList = simulationUserList.stream() List<String> onlineUserIdList = simulationUserList.stream()
.map(simulationUser -> String.format("%s:%s", simulationUser.getUser().getId(), simulationUser.isOnline()?"在线":"不在线")) .map(simulationUser -> String.format("%s:%s", simulationUser.getUser().getId(), simulationUser.isOnline()?"在线":"不在线"))
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -141,7 +141,7 @@ public class GenerateTask {
.prodType(MapPrdTypeEnum.getMapPrdTypeEnumByCode(config.getPrdType())) .prodType(MapPrdTypeEnum.getMapPrdTypeEnumByCode(config.getPrdType()))
.runPlan(planVO) .runPlan(planVO)
.build(); .build();
Simulation simulation = SimulationBuilder.build(params); Simulation simulation = SimulationBuilder.build(null, params);
Map<String, List<CommandDefinitionVO>> groupByOperationObject = cdr.stream() Map<String, List<CommandDefinitionVO>> groupByOperationObject = cdr.stream()
.collect(Collectors.groupingBy(CommandDefinitionVO::getOperateObject)); .collect(Collectors.groupingBy(CommandDefinitionVO::getOperateObject));
groupByOperationObject.forEach((o, cdo) -> { groupByOperationObject.forEach((o, cdo) -> {

View File

@ -8,7 +8,10 @@ import club.joylink.rtss.simulation.job.SimulationScheduledJob;
import club.joylink.rtss.simulation.operation.Operation; import club.joylink.rtss.simulation.operation.Operation;
import club.joylink.rtss.simulation.vo.SimulationFaultVO; import club.joylink.rtss.simulation.vo.SimulationFaultVO;
import club.joylink.rtss.simulation.vo.SimulationInfoVO; import club.joylink.rtss.simulation.vo.SimulationInfoVO;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -79,6 +82,7 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
private static final ExecutorService Message_Executor = Executors.newSingleThreadExecutor(); private static final ExecutorService Message_Executor = Executors.newSingleThreadExecutor();
private Map<String, SimulationRepository> repositoryMap = new ConcurrentHashMap<>(); private Map<String, SimulationRepository> repositoryMap = new ConcurrentHashMap<>();
@Setter
private Map<String, M> simulationMemberMap = new ConcurrentHashMap<>(); private Map<String, M> simulationMemberMap = new ConcurrentHashMap<>();
private Map<String, U> simulationUserMap = new ConcurrentHashMap<>(); private Map<String, U> simulationUserMap = new ConcurrentHashMap<>();
private List<Operation> operationList = new ArrayList<>(); private List<Operation> operationList = new ArrayList<>();
@ -94,12 +98,16 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
public static final String StateSubDestination = String.format("%s/%s", MESSAGE_SUB_PREFIX, "state"); public static final String StateSubDestination = String.format("%s/%s", MESSAGE_SUB_PREFIX, "state");
public Simulation(String id, int speed) { public Simulation(String id, int speed) {
this(id, speed, LocalDateTime.now());
}
public Simulation(String id, int speed, LocalDateTime systemTime) {
if (id == null) { if (id == null) {
throw new IllegalArgumentException("仿真id不能为空"); throw new IllegalArgumentException("仿真id不能为空");
} }
this.id = id; this.id = id;
this.speed = speed; this.speed = speed;
this.systemTime = LocalDateTime.now(); this.systemTime = systemTime;
this.addJob("sys-time-sync", () -> { this.addJob("sys-time-sync", () -> {
this.pushMessage(SysTimeSubDestination, this.systemTime.toLocalTime().toSecondOfDay()); this.pushMessage(SysTimeSubDestination, this.systemTime.toLocalTime().toSecondOfDay());
}, 1000); }, 1000);
@ -161,8 +169,9 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
return speed; return speed;
} }
private void setSystemTime(LocalDateTime systemTime) { public void setSystemTime(LocalDateTime systemTime) {
this.systemTime = systemTime; this.systemTime = systemTime;
this.jobMap.values().forEach(SimulationJob::updateRunTime);
} }
public LocalDateTime getSystemTime() { public LocalDateTime getSystemTime() {
return this.systemTime; return this.systemTime;
@ -204,6 +213,12 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
this.jobMap.put(name, scheduledJob); this.jobMap.put(name, scheduledJob);
} }
public void addJobIfAbsent(String name, Runnable job, int rate) {
if (this.jobMap.containsKey(name))
return;
addJob(name, job, rate);
}
/** /**
* 添加固定频率运行的逻辑可能主要是消息推送类逻辑 * 添加固定频率运行的逻辑可能主要是消息推送类逻辑
* @param name 任务名称同时也是id * @param name 任务名称同时也是id
@ -279,6 +294,14 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
return this.state.get() == START; return this.state.get() == START;
} }
public boolean isPause() {
return this.state.get() == PAUSE;
}
public boolean isError() {
return this.state.get() == ERROR;
}
/** /**
* 更新仿真速度 * 更新仿真速度
* @param speed Simulation.MIN_SPEED <= speed <= Simulation.MAX_SPEED * @param speed Simulation.MIN_SPEED <= speed <= Simulation.MAX_SPEED
@ -349,6 +372,24 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
return member; return member;
} }
public M querySimulationMemberByUserId(String userId) {
Objects.requireNonNull(id, "id 不能为空");
for (M value : simulationMemberMap.values()) {
if (userId.equals(value.getUserId())) {
return value;
}
}
return null;
}
public M getSimulationMemberByUserId(String userId) {
M member = this.querySimulationMemberByUserId(userId);
if (member == null) {
throw new IllegalArgumentException(String.format("仿真[%s]不存在userId为[%s]的仿真成员", this.id, userId));
}
return member;
}
public List<M> getSimulationMembers() { public List<M> getSimulationMembers() {
return new ArrayList<>(this.simulationMemberMap.values()); return new ArrayList<>(this.simulationMemberMap.values());
} }
@ -380,6 +421,10 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
return user; return user;
} }
public boolean containsUser(String uid) {
return this.simulationUserMap.containsKey(uid);
}
public U getSimulationUserById(String id) { public U getSimulationUserById(String id) {
U u = this.querySimulationUserById(id); U u = this.querySimulationUserById(id);
if (null == u) { if (null == u) {
@ -505,9 +550,8 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
} }
} }
public List<SimulationUser> getSimulationUsers() { public List<U> getSimulationUsers() {
ArrayList<SimulationUser> list = new ArrayList(this.simulationUserMap.values()); return new ArrayList<>(this.simulationUserMap.values());
return list;
} }
public void addDeviceFault(SimulationFaultVO faultVO) { public void addDeviceFault(SimulationFaultVO faultVO) {

View File

@ -13,6 +13,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;

View File

@ -3,6 +3,8 @@ package club.joylink.rtss.simulation.cbtc.ATP.ground;
import club.joylink.rtss.simulation.cbtc.ATS.AtsApiService; import club.joylink.rtss.simulation.cbtc.ATS.AtsApiService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.RunLevel; import club.joylink.rtss.simulation.cbtc.constant.RunLevel;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
@ -478,4 +480,7 @@ public class ZCLogicLoop {
return null; return null;
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.ZC.name(), () -> this.run(simulation), SimulationConstants.ZC_LOOP_RATE);
}
} }

View File

@ -2,6 +2,8 @@ package club.joylink.rtss.simulation.cbtc.ATS;
import club.joylink.rtss.simulation.cbtc.ATS.service.*; import club.joylink.rtss.simulation.cbtc.ATS.service.*;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -59,4 +61,7 @@ public class ATSLogicLoop {
// System.out.println(String.format("------------ATS自动排列进路逻辑耗时: %s ms", (end-start))); // System.out.println(String.format("------------ATS自动排列进路逻辑耗时: %s ms", (end-start)));
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.ATS.name(), () -> this.run(simulation), SimulationConstants.ATS_LOOP_RATE);
}
} }

View File

@ -3,6 +3,8 @@ package club.joylink.rtss.simulation.cbtc.ATS;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.OperationMessage; import club.joylink.rtss.simulation.cbtc.command.OperationMessage;
import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService; import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; import club.joylink.rtss.simulation.cbtc.data.plan.RealRun;
@ -48,7 +50,7 @@ public class ATSMessageCollectAndDispatcher {
// 构建并发送设备状态消息 // 构建并发送设备状态消息
SocketMessageVO deviceStatusMessage = SocketMessageVO deviceStatusMessage =
SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus, SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus,
simulation.getGroup(), filterList); simulation.getId(), filterList);
Set<String> sessions = simulation.getSimulationUserIds(); Set<String> sessions = simulation.getSimulationUserIds();
// System.out.println(String.format("发送用户数:[%s], 发送状态条数:[%s]", // System.out.println(String.format("发送用户数:[%s], 发送状态条数:[%s]",
// sessions.size(), filterList.size())); // sessions.size(), filterList.size()));
@ -187,7 +189,7 @@ public class ATSMessageCollectAndDispatcher {
List<DeviceStatusVO> deviceStatuses = collectAll(simulation); List<DeviceStatusVO> deviceStatuses = collectAll(simulation);
// 构建并发送设备状态消息 // 构建并发送设备状态消息
SocketMessageVO<List<DeviceStatusVO>> deviceStatusMessage = SocketMessageVO<List<DeviceStatusVO>> deviceStatusMessage =
SocketMessageFactory.buildSimulationDeviceStatusesMessage(simulation.getGroup(), deviceStatuses); SocketMessageFactory.buildSimulationDeviceStatusesMessage(simulation.getId(), deviceStatuses);
Set<String> sessions = simulation.getSimulationUserIds(); Set<String> sessions = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(sessions, deviceStatusMessage); this.stompMessageService.sendToUser(sessions, deviceStatusMessage);
} }
@ -217,7 +219,7 @@ public class ATSMessageCollectAndDispatcher {
} }
SocketMessageVO deviceStatusMessage = SocketMessageVO deviceStatusMessage =
SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus, SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus,
simulation.getGroup(), filterList); simulation.getId(), filterList);
Set<String> sessions = simulation.getSimulationUserIds(); Set<String> sessions = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(sessions, deviceStatusMessage); this.stompMessageService.sendToUser(sessions, deviceStatusMessage);
} }
@ -317,7 +319,7 @@ public class ATSMessageCollectAndDispatcher {
public void sendTrainRunData(Simulation simulation, RealRun realRun) { public void sendTrainRunData(Simulation simulation, RealRun realRun) {
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), this.stompMessageService.sendToUser(simulation.getSimulationUserIds(),
SocketMessageFactory.build(WebSocketMessageType.Simulation_RunFact, SocketMessageFactory.build(WebSocketMessageType.Simulation_RunFact,
simulation.getGroup(), Arrays.asList(realRun))); simulation.getId(), Arrays.asList(realRun)));
} }
/** /**
@ -332,8 +334,8 @@ public class ATSMessageCollectAndDispatcher {
} }
//目标成员有真人推送对应真人处理 //目标成员有真人推送对应真人处理
SocketMessageVO<OperationMessage> socketMessageVO = SocketMessageVO<OperationMessage> socketMessageVO =
SocketMessageFactory.build(WebSocketMessageType.Simulation_ApplyHandle, simulation.getGroup(), operationMessage); SocketMessageFactory.build(WebSocketMessageType.Simulation_ApplyHandle, simulation.getId(), operationMessage);
this.stompMessageService.sendToUser(humanMembers.stream().map(SimulationMember::getUserIdStr).collect(Collectors.toSet()), socketMessageVO); this.stompMessageService.sendToUser(humanMembers.stream().map(SimulationMember::getUserId).collect(Collectors.toSet()), socketMessageVO);
} }
/** /**
@ -345,4 +347,9 @@ public class ATSMessageCollectAndDispatcher {
SocketMessageVO<Integer> timeSyncMessage = SocketMessageFactory.buildSimulationTimeSyncMessage(simulation); SocketMessageVO<Integer> timeSyncMessage = SocketMessageFactory.buildSimulationTimeSyncMessage(simulation);
this.stompMessageService.sendToUser(sessions, timeSyncMessage); this.stompMessageService.sendToUser(sessions, timeSyncMessage);
} }
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob(SimulationModule.SYNC_TIME.name(), () -> this.syncTime(simulation), SimulationConstants.SYNC_TIME_RATE);
simulation.addFixedRateJob(SimulationModule.MESSAGE.name(), () -> this.run(simulation), SimulationConstants.SEND_CLIENT_RATE);
}
} }

View File

@ -27,7 +27,7 @@ public class AtsOperationDispatcher {
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
public Object dispatch(Simulation simulation, UserVO user, String type, Map<String, Object> params) { public Object dispatch(Simulation simulation, UserVO user, String type, Map<String, Object> params) {
SimulationMember member = simulation.findMemberByUserId(user.getId()); SimulationMember member = simulation.querySimulationMemberByUserId(user.getId());
if (Objects.isNull(member)) throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, "请先设置对应的仿真角色"); if (Objects.isNull(member)) throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, "请先设置对应的仿真角色");
return execute(simulation, member, type, params); return execute(simulation, member, type, params);
} }

View File

@ -213,7 +213,7 @@ public class SwitchOperateHandler {
@OperateHandlerMapping(type = Operation.Type.Switch_Confirm_Axis_Valid) @OperateHandlerMapping(type = Operation.Type.Switch_Confirm_Axis_Valid)
public void confirmAxisValid(Simulation simulation, String switchCode) { public void confirmAxisValid(Simulation simulation, String switchCode) {
//ZC 系统 //ZC 系统
log.debug("仿真[{}] : 道岔[{}]确认计轴有效",simulation.getGroup(),switchCode); log.debug("仿真[{}] : 道岔[{}]确认计轴有效",simulation.getId(),switchCode);
Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class); Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class);
this.atsSectionService.confirmAxleValid(simulation, aSwitch.getA()); this.atsSectionService.confirmAxleValid(simulation, aSwitch.getA());
} }
@ -248,7 +248,7 @@ public class SwitchOperateHandler {
/**区故解*/ /**区故解*/
@OperateHandlerMapping(type = Operation.Type.Switch_Fault_Unlock) @OperateHandlerMapping(type = Operation.Type.Switch_Fault_Unlock)
public void switchSectionFaultUnlock(Simulation simulation, String switchCode) { public void switchSectionFaultUnlock(Simulation simulation, String switchCode) {
log.debug("仿真[{}] : 道岔[{}]区故解",simulation.getGroup(),switchCode); log.debug("仿真[{}] : 道岔[{}]区故解",simulation.getId(),switchCode);
ciApiService.switchSectionFaultUnlock(simulation, switchCode); ciApiService.switchSectionFaultUnlock(simulation, switchCode);
} }

View File

@ -18,7 +18,7 @@ public class AtsSectionService {
/**区段跟踪切除*/ /**区段跟踪切除*/
public void cutoff(Simulation simulation, Section section) { public void cutoff(Simulation simulation, Section section) {
log.debug("仿真[{}] : 区段[{}]切除",simulation.getGroup(),String.format("%s(%s)", section.getName(), section.getCode())); log.debug("仿真[{}] : 区段[{}]切除",simulation.getId(),String.format("%s(%s)", section.getName(), section.getCode()));
if (Objects.nonNull(section.getParent())) { if (Objects.nonNull(section.getParent())) {
section = section.getParent(); section = section.getParent();
} }
@ -32,7 +32,7 @@ public class AtsSectionService {
/**区段跟踪激活*/ /**区段跟踪激活*/
public void active(Simulation simulation, Section section) { public void active(Simulation simulation, Section section) {
log.debug("仿真[{}] : 区段[{}]激活",simulation.getGroup(),String.format("%s(%s)", section.getName(), section.getCode())); log.debug("仿真[{}] : 区段[{}]激活",simulation.getId(),String.format("%s(%s)", section.getName(), section.getCode()));
if (Objects.nonNull(section.getParent())) { if (Objects.nonNull(section.getParent())) {
section = section.getParent(); section = section.getParent();
} }
@ -45,7 +45,7 @@ public class AtsSectionService {
} }
public void confirmAxleValid(Simulation simulation, Section section) { public void confirmAxleValid(Simulation simulation, Section section) {
log.debug("仿真[{}] : 区段[{}]确认计轴有效",simulation.getGroup(),String.format("%s(%s)", section.getName(), section.getCode())); log.debug("仿真[{}] : 区段[{}]确认计轴有效",simulation.getId(),String.format("%s(%s)", section.getName(), section.getCode()));
if (Objects.nonNull(section.getParent())) { if (Objects.nonNull(section.getParent())) {
section = section.getParent(); section = section.getParent();
} }

View File

@ -351,7 +351,7 @@ public class AtsTrainLoadService {
} else { } else {
num = loadNumber; num = loadNumber;
} }
simulation.initSystemTime(simulationTime); simulation.setSystemTime(simulationTime);
this.loadTrainAndInit(simulation, trainLoadList, num); this.loadTrainAndInit(simulation, trainLoadList, num);
simulation.setPlanRunning(true); simulation.setPlanRunning(true);
this.applicationContext.publishEvent(new SimulationRunAsPlanEvent(this, simulation)); this.applicationContext.publishEvent(new SimulationRunAsPlanEvent(this, simulation));

View File

@ -4,6 +4,7 @@ import club.joylink.rtss.simulation.cbtc.ATP.ground.GroundAtpApiService;
import club.joylink.rtss.simulation.cbtc.ATS.AtsApiService; import club.joylink.rtss.simulation.cbtc.ATS.AtsApiService;
import club.joylink.rtss.simulation.cbtc.CI.service.*; import club.joylink.rtss.simulation.cbtc.CI.service.*;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
@ -369,4 +370,8 @@ public class CILogicLoop {
} }
return signalList; return signalList;
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.CI.name(), () -> this.run(simulation), SimulationConstants.CI_LOOP_RATE);
}
} }

View File

@ -1,8 +1,10 @@
package club.joylink.rtss.simulation.cbtc; package club.joylink.rtss.simulation.cbtc;
import club.joylink.rtss.simulation.SimulationManager;
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 lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,6 +16,9 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
@Component @Component
public class GroupSimulationCache { public class GroupSimulationCache {
@Autowired
private SimulationManager simulationManager;
/** /**
* group-仿真数据map * group-仿真数据map
* key-group * key-group
@ -37,15 +42,15 @@ public class GroupSimulationCache {
return new ArrayList<>(groupSimulationMap.values()); return new ArrayList<>(groupSimulationMap.values());
} }
/** // /**
* 保存group仿真 // * 保存group仿真
* @param group // * @param group
* @param simulation // * @param simulation
*/ // */
public void saveGroupSimulation(String group, Simulation simulation) { // public void saveGroupSimulation(String group, Simulation simulation) {
simulation.setGroup(group); // simulation.setGroup(group);
groupSimulationMap.put(group, simulation); // groupSimulationMap.put(group, simulation);
} // }
/** /**
* 根据group查询仿真 * 根据group查询仿真
@ -53,8 +58,10 @@ public class GroupSimulationCache {
* @return * @return
*/ */
public Simulation findSimulationByGroup(String group) { public Simulation findSimulationByGroup(String group) {
Objects.requireNonNull(group); // Objects.requireNonNull(group);
return groupSimulationMap.get(group); // return groupSimulationMap.get(group);
return (Simulation) simulationManager.getById(group);
} }
/** /**

View File

@ -6,7 +6,6 @@ import club.joylink.rtss.constants.MapPrdTypeEnum;
import club.joylink.rtss.constants.Project; import club.joylink.rtss.constants.Project;
import club.joylink.rtss.constants.ProjectDeviceType; import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.constants.SystemEnv; import club.joylink.rtss.constants.SystemEnv;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.*; import club.joylink.rtss.services.*;
import club.joylink.rtss.services.org.IOrgService; import club.joylink.rtss.services.org.IOrgService;
@ -15,6 +14,7 @@ import club.joylink.rtss.services.script.IScriptService;
import club.joylink.rtss.services.script.IScriptSimulationService; import club.joylink.rtss.services.script.IScriptSimulationService;
import club.joylink.rtss.services.simulation.SchedulingService; import club.joylink.rtss.services.simulation.SchedulingService;
import club.joylink.rtss.services.training.ITrainingV1Service; import club.joylink.rtss.services.training.ITrainingV1Service;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher; import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher;
import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm;
import club.joylink.rtss.simulation.cbtc.ATS.data.SimulationLog; import club.joylink.rtss.simulation.cbtc.ATS.data.SimulationLog;
@ -152,6 +152,63 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
@Autowired @Autowired
private IOrgService iOrgService; private IOrgService iOrgService;
@Autowired
private SimulationManager simulationManager;
// /**
// * 创建仿真并进行缓存
// *
// * @param loginUserInfoVO
// * @param mapId
// * @param prdType
// * @param functionalType
// * @return
// */
// public Simulation create(LoginUserInfoVO loginUserInfoVO, Long mapId, MapPrdTypeEnum prdType,
// Simulation.FunctionalType functionalType) {
// Objects.requireNonNull(mapId, "地图id不能为空");
// Objects.requireNonNull(functionalType, "仿真功能类型不能为空");
// // 获取地图数据
// MapVO mapVO = this.iMapService.getMapDetail(mapId);
// // 获取操作定义数据
// List<CommandDefinitionVO> operationDefinitionList = this.iCommandService
// .queryDefinitionsByLineCode(mapVO.getLineCode());
// SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder();
// // 都有的属性构造
// builder.loginUserInfo(loginUserInfoVO)
// .createTime(LocalDateTime.now())
// .map(mapVO)
// .operationDefinitionList(operationDefinitionList)
// .prodType(prdType)
// .functionalType(functionalType);
// //运行图选择性构造
// LocalDate runPlanDate = SimulationConstants.getRunPlanDate();
// RunPlanVO runPlanVO = findRunPlan(functionalType, loginUserInfoVO.getUserVO().getId(), mapId);
// if (Objects.nonNull(runPlanVO)) {
// runPlanVO.setRunDate(runPlanDate);
// builder.runPlan(runPlanVO);
// SchedulingPlanNewVO schedulingPlanNewVO;
// if (loginUserInfoVO.isProjectDeviceLogin()) { // 如果是项目设备登录找通用日期的派班计划
// schedulingPlanNewVO = this.schedulingService.queryCommonSchedulingPlanOfDay(mapId, runPlanDate);
// } else {
// schedulingPlanNewVO = this.schedulingService
// .querySchedulingPlanUserFirst(loginUserInfoVO.getUserVO().getId(), runPlanVO.getId(), runPlanDate);
// }
// builder.schedulingPlan(schedulingPlanNewVO);
// }
// SimulationBuildParams params = builder.build();
// String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getUserVO().getId(), mapId);
// Simulation simulation = this.simulationLifeCycleService.create(params, group);
// // 缓存管理
// this.groupSimulationCache.saveGroupSimulation(group, simulation);
// // 添加仿真成员
// SimulationUser simulationUser = new SimulationUser(simulation, loginUserInfoVO);
// simulation.addSimulationUser(simulationUser);
// // 根据仿真产品类型设置用户扮演角色
// memberManager.playRoleBySimulationType(simulation, loginUserInfoVO.getUserVO().getId());
// return simulation;
// }
/** /**
* 创建仿真并进行缓存 * 创建仿真并进行缓存
* *
@ -196,13 +253,13 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
SimulationBuildParams params = builder.build(); SimulationBuildParams params = builder.build();
String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getUserVO().getId(), mapId); String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getUserVO().getId(), mapId);
Simulation simulation = this.simulationLifeCycleService.create(params, group); Simulation simulation = this.simulationLifeCycleService.create(params, group);
// 缓存管理
this.groupSimulationCache.saveGroupSimulation(group, simulation);
// 添加仿真成员 // 添加仿真成员
SimulationUser simulationUser = new SimulationUser(simulation, loginUserInfoVO); SimulationUser simulationUser = new SimulationUser(simulation, loginUserInfoVO);
simulation.addSimulationUser(simulationUser); simulation.addSimulationUser(simulationUser);
// 根据仿真产品类型设置用户扮演角色 // 根据仿真产品类型设置用户扮演角色
memberManager.playRoleBySimulationType(simulation, loginUserInfoVO.getUserVO().getId()); memberManager.playRoleBySimulationType(simulation, loginUserInfoVO.getUserVO().getId());
// 仿真开始运行
this.simulationManager.start(simulation.getId());
return simulation; return simulation;
} }
@ -213,8 +270,8 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
// runPlanVO.getTripList().sort(Comparator.comparing(runPlanTripVO -> runPlanTripVO.getTimeList().get(0).getArrivalTime())); // runPlanVO.getTripList().sort(Comparator.comparing(runPlanTripVO -> runPlanTripVO.getTimeList().get(0).getArrivalTime()));
// RunAsPlanParam param = new RunAsPlanParam(); // RunAsPlanParam param = new RunAsPlanParam();
// param.setTime(runPlanVO.getTripList().get(0).getTimeList().get(0).getArrivalTime()); // param.setTime(runPlanVO.getTripList().get(0).getTimeList().get(0).getArrivalTime());
// this.runAsPlan(simulation.getGroup(), param); // this.runAsPlan(simulation.getId(), param);
return simulation.getGroup(); return simulation.getId();
} }
/** /**
@ -254,13 +311,13 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
SimulationBuildParams params = builder.build(); SimulationBuildParams params = builder.build();
String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getUserVO().getId(), mapId); String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getUserVO().getId(), mapId);
Simulation simulation = this.simulationLifeCycleService.create(params, group); Simulation simulation = this.simulationLifeCycleService.create(params, group);
// 缓存管理
this.groupSimulationCache.saveGroupSimulation(group, simulation);
// 添加仿真成员 // 添加仿真成员
SimulationUser simulationUser = new SimulationUser(simulation, loginUserInfoVO); SimulationUser simulationUser = new SimulationUser(simulation, loginUserInfoVO);
simulation.addSimulationUser(simulationUser); simulation.addSimulationUser(simulationUser);
// 根据仿真产品类型设置用户扮演角色 // 根据仿真产品类型设置用户扮演角色
memberManager.playRoleBySimulationType(simulation, loginUserInfoVO.getUserVO().getId()); memberManager.playRoleBySimulationType(simulation, loginUserInfoVO.getUserVO().getId());
// 仿真开始运行
simulationManager.start(simulation.getId());
return simulation; return simulation;
} }
@ -309,9 +366,9 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
// 大屏仿真直接按计划行车 // 大屏仿真直接按计划行车
RunAsPlanParam param = new RunAsPlanParam(); RunAsPlanParam param = new RunAsPlanParam();
param.setTime(LocalTime.now()); param.setTime(LocalTime.now());
this.runAsPlan(simulation.getGroup(), param); this.runAsPlan(simulation.getId(), param);
} }
return simulation.getGroup(); return simulation.getId();
} }
@Override @Override
@ -320,8 +377,8 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
Simulation simulation = this.create(loginUserInfoVO, training.getMapId(), Simulation simulation = this.create(loginUserInfoVO, training.getMapId(),
MapPrdTypeEnum.getMapPrdTypeEnumByCode(training.getPrdType()), MapPrdTypeEnum.getMapPrdTypeEnumByCode(training.getPrdType()),
Simulation.FunctionalType.LESSON); Simulation.FunctionalType.LESSON);
iTrainingV1Service.loadTraining(simulation.getGroup(), trainingId); iTrainingV1Service.loadTraining(simulation.getId(), trainingId);
return simulation.getGroup(); return simulation.getId();
} }
@Override @Override
@ -330,7 +387,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
Simulation simulation = this.create(loginUserInfoVO, examDefinitionVO.getMapId(), Simulation simulation = this.create(loginUserInfoVO, examDefinitionVO.getMapId(),
MapPrdTypeEnum.getMapPrdTypeEnumByCode(examDefinitionVO.getPrdType()), MapPrdTypeEnum.getMapPrdTypeEnumByCode(examDefinitionVO.getPrdType()),
Simulation.FunctionalType.EXAM); Simulation.FunctionalType.EXAM);
return simulation.getGroup(); return simulation.getId();
} }
@ -395,7 +452,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group); Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group);
simulation.closeAllAutoFault(); simulation.closeAllAutoFault();
this.stompMessageService.sendToUser(String.valueOf(simulation.getCreator().getId()), this.stompMessageService.sendToUser(String.valueOf(simulation.getCreator().getId()),
SocketMessageFactory.build(WebSocketMessageType.Simulation_AutoFault_Trigger, simulation.getGroup(), null)); SocketMessageFactory.build(WebSocketMessageType.Simulation_AutoFault_Trigger, simulation.getId(), null));
} }
@Override @Override
@ -403,14 +460,14 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group); Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group);
simulation.cancelAutoFault(faultId); simulation.cancelAutoFault(faultId);
this.stompMessageService.sendToUser(String.valueOf(simulation.getCreator().getId()), this.stompMessageService.sendToUser(String.valueOf(simulation.getCreator().getId()),
SocketMessageFactory.build(WebSocketMessageType.Simulation_AutoFault_Trigger, simulation.getGroup(), null)); SocketMessageFactory.build(WebSocketMessageType.Simulation_AutoFault_Trigger, simulation.getId(), null));
} }
@Override @Override
public void triggeringAutoFault(Simulation simulation, FaultRuleVO faultRule) { public void triggeringAutoFault(Simulation simulation, FaultRuleVO faultRule) {
faultRule.setTriggeringTime(simulation.getCorrectSystemTime()); faultRule.setTriggeringTime(simulation.getCorrectSystemTime());
this.stompMessageService.sendToUser(String.valueOf(simulation.getCreator().getId()), this.stompMessageService.sendToUser(String.valueOf(simulation.getCreator().getId()),
SocketMessageFactory.build(WebSocketMessageType.Simulation_AutoFault_Trigger, simulation.getGroup(), faultRule.getId() + "::" + faultRule.getTriggeringTime())); SocketMessageFactory.build(WebSocketMessageType.Simulation_AutoFault_Trigger, simulation.getId(), faultRule.getId() + "::" + faultRule.getTriggeringTime()));
} }
@Override @Override
@ -423,6 +480,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
if (Objects.equals(simulation.getBuildParams().getUser().getId(), user.getId()) || if (Objects.equals(simulation.getBuildParams().getUser().getId(), user.getId()) ||
user.isAdmin()) { // 是仿真创建者或管理员可以清理 user.isAdmin()) { // 是仿真创建者或管理员可以清理
this.simulationLifeCycleService.destroy(simulation); this.simulationLifeCycleService.destroy(simulation);
simulationManager.destroy(simulation.getId());
this.groupSimulationCache.removeSimulation(group); this.groupSimulationCache.removeSimulation(group);
this.iTrainingV1Service.removeGroupTraining(group); this.iTrainingV1Service.removeGroupTraining(group);
} else { } else {
@ -435,7 +493,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
@Override @Override
public List<SimulationMemberVO> getSimulationMembers(String group) { public List<SimulationMemberVO> getSimulationMembers(String group) {
Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group); Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group);
List<SimulationMember> simulationMemberList = simulation.getAllSimulationMembers(); List<SimulationMember> simulationMemberList = simulation.getSimulationMembers();
simulationMemberList.sort(Comparator.comparing(member -> Integer.valueOf(member.getId()))); simulationMemberList.sort(Comparator.comparing(member -> Integer.valueOf(member.getId())));
// // 过滤司机 // // 过滤司机
// simulationMemberList = simulationMemberList.stream() // simulationMemberList = simulationMemberList.stream()
@ -466,7 +524,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
public List<String> getUserRunningSimulationGroups(UserVO userVO) { public List<String> getUserRunningSimulationGroups(UserVO userVO) {
List<String> groupList = new ArrayList<>(); List<String> groupList = new ArrayList<>();
this.groupSimulationCache.getGroupSimulationMap().forEach((group, simulation) -> { this.groupSimulationCache.getGroupSimulationMap().forEach((group, simulation) -> {
SimulationUser simulationUser = simulation.querySimulationUserByUserId(userVO.getId()); SimulationUser simulationUser = simulation.querySimulationUserById(userVO.getId().toString());
if (Objects.nonNull(simulationUser) && simulationUser.isOnline()) { if (Objects.nonNull(simulationUser) && simulationUser.isOnline()) {
groupList.add(group); groupList.add(group);
} }
@ -582,11 +640,11 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
@Override @Override
public void loadScript(Simulation simulation, Long scriptId) { public void loadScript(Simulation simulation, Long scriptId) {
ScriptVO detailById = iScriptService.getDetailById(scriptId); ScriptVO detailById = iScriptService.getDetailById(scriptId);
this.loadScenes(simulation.getGroup(), detailById.getBgScenesJson()); this.loadScenes(simulation.getId(), detailById.getBgScenesJson());
ScriptBO scriptBO = iScriptService.getScriptBOById(scriptId, simulation); ScriptBO scriptBO = iScriptService.getScriptBOById(scriptId, simulation);
iScriptSimulationService.scriptCoverSimulation(simulation, scriptBO); iScriptSimulationService.scriptCoverSimulation(simulation, scriptBO);
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Script_Loaded, SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Script_Loaded,
simulation.getGroup(), true); simulation.getId(), true);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
stompMessageService.sendToUser(userIds, message); stompMessageService.sendToUser(userIds, message);
} }
@ -595,6 +653,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
public void exitScript(String group, UserVO user) { public void exitScript(String group, UserVO user) {
Simulation simulation = groupSimulationCache.getSimulationByGroup(group); Simulation simulation = groupSimulationCache.getSimulationByGroup(group);
simulationLifeCycleService.reset(simulation); simulationLifeCycleService.reset(simulation);
simulation.removeJob(Simulation.JobName.script);
simulation.setScript(null); simulation.setScript(null);
memberManager.playRoleBySimulationType(simulation, user.getId()); memberManager.playRoleBySimulationType(simulation, user.getId());
} }
@ -704,7 +763,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
@Override @Override
public List<SimulationUserVO> queryAllSimulationUsers(String group) { public List<SimulationUserVO> queryAllSimulationUsers(String group) {
Simulation simulation = this.getSimulationByGroup(group); Simulation simulation = this.getSimulationByGroup(group);
List<SimulationUser> simulationUserList = simulation.getAllSimulationUsers(); List<SimulationUser> simulationUserList = simulation.getSimulationUsers();
return SimulationUserVO.convert2VOList(simulationUserList); return SimulationUserVO.convert2VOList(simulationUserList);
} }
@ -739,7 +798,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
.assertTrue(simulation.isJointSimulation()); .assertTrue(simulation.isJointSimulation());
// 是否已经获取权限 // 是否已经获取权限
SimulationUser existSimulationUser = simulation.querySimulationUserByUserId(user.getId()); SimulationUser existSimulationUser = simulation.querySimulationUserById(user.getId().toString());
BusinessExceptionAssertEnum.SIMULATION_PERMISSION_ALREADY_GET BusinessExceptionAssertEnum.SIMULATION_PERMISSION_ALREADY_GET
.assertNull(existSimulationUser); .assertNull(existSimulationUser);
// 检查是否还有权限可以使用 // 检查是否还有权限可以使用
@ -755,7 +814,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
@Override @Override
public SimulationUserVO getSimulationUserInfo(String group, UserVO userVO) { public SimulationUserVO getSimulationUserInfo(String group, UserVO userVO) {
Simulation simulation = this.getSimulationByGroup(group); Simulation simulation = this.getSimulationByGroup(group);
SimulationUser simulationUser = simulation.getSimulationUserByUserId(userVO.getId()); SimulationUser simulationUser = simulation.getSimulationUserById(userVO.getId());
return new SimulationUserVO(simulationUser); return new SimulationUserVO(simulationUser);
} }
@ -777,7 +836,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
Simulation simulation = this.getSimulationByGroup(group); Simulation simulation = this.getSimulationByGroup(group);
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS
.assertTrue(simulation.isAdmin(user)); .assertTrue(simulation.isAdmin(user));
SimulationUser simulationUser = simulation.querySimulationUserByUserId(userId); SimulationUser simulationUser = simulation.querySimulationUserById(userId);
if (Objects.nonNull(simulationUser)) { if (Objects.nonNull(simulationUser)) {
ProjectDeviceVO projectDevice = simulationUser.getProjectDevice(); ProjectDeviceVO projectDevice = simulationUser.getProjectDevice();
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
@ -848,7 +907,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService {
return; return;
} }
SimulationMember targetMember = simulation.getMemberById(initiateVO.getTargetMemberId()); SimulationMember targetMember = simulation.getSimulationMemberById(initiateVO.getTargetMemberId());
List<CommandBO.Step> steps = initiateVO.getCommandType().buildStepList(simulation, targetMember, initiateVO.getParams()); List<CommandBO.Step> steps = initiateVO.getCommandType().buildStepList(simulation, targetMember, initiateVO.getParams());
if (steps == null) { if (steps == null) {
return; return;

View File

@ -1,5 +1,7 @@
package club.joylink.rtss.simulation.cbtc; package club.joylink.rtss.simulation.cbtc;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Catenary; import club.joylink.rtss.simulation.cbtc.data.map.Catenary;
import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.data.map.Section;
@ -38,4 +40,8 @@ public class PowerSupplyService {
} }
} }
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.CATENARY.name(), () -> this.run(simulation), SimulationConstants.POWER_SUPPLY_STATUS_UPDATE_RATE);
}
} }

View File

@ -28,7 +28,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -98,14 +97,14 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
} }
String deviceCode = this.queryDeviceCodeFromConfig(realDevice); String deviceCode = this.queryDeviceCodeFromConfig(realDevice);
if (Objects.nonNull(deviceCode)) { if (Objects.nonNull(deviceCode)) {
this.groupSimulationService.connectDevice(simulation.getGroup(), this.groupSimulationService.connectDevice(simulation.getId(),
deviceCode, realDevice.getProjectDevice().getId()); deviceCode, realDevice.getProjectDevice().getId());
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("仿真加载真实设备异常", e); log.error("仿真加载真实设备异常", e);
// 清理仿真 // 清理仿真
this.groupSimulationService.clearSimulation(simulation.getGroup(), simulation.getCreator()); this.groupSimulationService.clearSimulation(simulation.getId(), simulation.getCreator());
throw BusinessExceptionAssertEnum.TRAINING_ROOM_SIMULATION_LOAD_DEVICE_ERROR.exception(e); throw BusinessExceptionAssertEnum.TRAINING_ROOM_SIMULATION_LOAD_DEVICE_ERROR.exception(e);
} }
} }
@ -165,7 +164,7 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
} }
case CW:{ case CW:{
// 行调工作站 // 行调工作站
List<SimulationMember> dispatcherList = simulation.getSimulationMembersByType(SimulationMember.Type.DISPATCHER); List<SimulationMember> dispatcherList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DISPATCHER);
SimulationMember dispatcher = null; SimulationMember dispatcher = null;
for (SimulationMember member : dispatcherList) { for (SimulationMember member : dispatcherList) {
if (member.isRobot()) { if (member.isRobot()) {
@ -181,7 +180,7 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
break; break;
} }
case DEPOT:{ case DEPOT:{
List<SimulationMember> depoterList = simulation.getSimulationMembersByType(SimulationMember.Type.DEPOT_DISPATCHER); List<SimulationMember> depoterList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DEPOT_DISPATCHER);
SimulationMember depoter = null; SimulationMember depoter = null;
for (SimulationMember member : depoterList) { for (SimulationMember member : depoterList) {
if (member.isRobot()) { if (member.isRobot()) {
@ -196,7 +195,7 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
break; break;
} }
} }
loginUserInfo.setGroup(simulation.getGroup()); loginUserInfo.setGroup(simulation.getId());
} }
@Override @Override
@ -220,7 +219,7 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
case LW:{ case LW:{
ProjectDeviceLogoutEvent lwLogoutEvent = new ProjectDeviceLogoutEvent(this, deviceVO); ProjectDeviceLogoutEvent lwLogoutEvent = new ProjectDeviceLogoutEvent(this, deviceVO);
this.applicationContext.publishEvent(lwLogoutEvent); this.applicationContext.publishEvent(lwLogoutEvent);
SimulationUser simulationUser = simulation.querySimulationUserByUserId(loginUserInfoVO.getUserVO().getId()); SimulationUser simulationUser = simulation.querySimulationUserById(loginUserInfoVO.getUserVO().getId());
if (Objects.nonNull(simulationUser)) { if (Objects.nonNull(simulationUser)) {
this.groupSimulationService.kickOut(simulation, simulationUser); this.groupSimulationService.kickOut(simulation, simulationUser);
} }
@ -230,7 +229,7 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
} }
private void removeSimulation(Simulation simulation, LoginUserInfoVO loginUserInfoVO) { private void removeSimulation(Simulation simulation, LoginUserInfoVO loginUserInfoVO) {
this.groupSimulationService.clearSimulation(simulation.getGroup(), loginUserInfoVO.getUserVO()); this.groupSimulationService.clearSimulation(simulation.getId(), loginUserInfoVO.getUserVO());
projectSimulationMap.remove(simulation.getProject()); projectSimulationMap.remove(simulation.getProject());
} }

View File

@ -19,12 +19,17 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDevice
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1IbpConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1IbpConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PscConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PscConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PslConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PslConfig;
import club.joylink.rtss.simulation.cbtc.event.SimulationErrorEvent;
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.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.member.SimulationUser; import club.joylink.rtss.simulation.cbtc.member.SimulationUser;
import club.joylink.rtss.simulation.cbtc.script.ScriptBO; import club.joylink.rtss.simulation.cbtc.script.ScriptBO;
import club.joylink.rtss.simulation.vo.SimulationInfoVO;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.SocketMessageVO;
import club.joylink.rtss.vo.client.WebSocketMessageType;
import club.joylink.rtss.vo.client.factory.SocketMessageFactory;
import club.joylink.rtss.vo.client.fault.FaultRuleVO; import club.joylink.rtss.vo.client.fault.FaultRuleVO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -32,9 +37,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.lang.reflect.Member;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -47,12 +54,12 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Getter @Getter
@Setter @Setter
public class Simulation { public class Simulation extends club.joylink.rtss.simulation.Simulation<SimulationUser, SimulationMember> {
/** // /**
* 所属group // * 所属group
*/ // */
private String group; // private String id;
/** /**
* 仿真构建参数 * 仿真构建参数
@ -81,19 +88,19 @@ public class Simulation {
*/ */
private ScriptBO script; private ScriptBO script;
/** // /**
* 仿真成员map // * 仿真成员map
* key-仿真成员id // * key-仿真成员id
* val-仿真成员对象 // * val-仿真成员对象
*/ // */
private Map<String, SimulationMember> simulationMemberMap = new ConcurrentHashMap<>(); // private Map<String, SimulationMember> simulationMemberMap = new ConcurrentHashMap<>();
//
/** // /**
* 仿真的用户 // * 仿真的用户
* key-用户id // * key-用户id
* val-仿真用户信息 // * val-仿真用户信息
*/ // */
private Map<Long, SimulationUser> simulationUserMap = new ConcurrentHashMap<>(); // private Map<Long, SimulationUser> simulationUserMap = new ConcurrentHashMap<>();
/** /**
* 真实设备列表 * 真实设备列表
@ -132,30 +139,30 @@ public class Simulation {
*/ */
private boolean planLoaded; private boolean planLoaded;
/** // /**
* 仿真系统时间为实际时间-2小时与运行图对应 // * 仿真系统时间为实际时间-2小时与运行图对应
*/ // */
private LocalDateTime systemTime; // private LocalDateTime systemTime;
/** // /**
* 仿真是否异常 // * 仿真是否异常
*/ // */
private boolean error; // private boolean error;
/** // /**
* 仿真异常信息 // * 仿真异常信息
*/ // */
private Throwable cause; // private Throwable cause;
/** /**
* 是否按计划运行 * 是否按计划运行
*/ */
private boolean planRunning; private boolean planRunning;
/** // /**
* 是否暂停 // * 是否暂停
*/ // */
private volatile boolean pause; // private volatile boolean pause;
// /** // /**
// * 是否自动生成设备故障 // * 是否自动生成设备故障
@ -186,8 +193,8 @@ public class Simulation {
private List<SimulationLog> logs; private List<SimulationLog> logs;
public Simulation() { public Simulation(String id) {
this.initSystemTime(LocalDateTime.now().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME)); super(id, 1, LocalDateTime.now().minusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME));
this.dataErrMsgList = new ArrayList<>(); this.dataErrMsgList = new ArrayList<>();
this.faultRules = new HashSet<>(); this.faultRules = new HashSet<>();
this.repository = new SimulationDataRepository(); this.repository = new SimulationDataRepository();
@ -220,26 +227,17 @@ public class Simulation {
* 获取该角色类型的所有成员 * 获取该角色类型的所有成员
*/ */
public List<SimulationMember> getMemberListByType(SimulationMember.Type type) { public List<SimulationMember> getMemberListByType(SimulationMember.Type type) {
List<SimulationMember> collect = this.simulationMemberMap.values().stream() List<SimulationMember> members = querySimulationMembersOfRole(type);
.filter(member -> member.getType().equals(type)).collect(Collectors.toList()); if (CollectionUtils.isEmpty(members)) {
if (CollectionUtils.isEmpty(collect)) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, throw new SimulationException(SimulationExceptionType.Illegal_Argument,
String.format("未找到角色为[%s]的成员", type)); String.format("未找到角色为[%s]的成员", type));
} }
return collect; return members;
}
public SimulationUser getSimulationUserByUserId(Long userId) {
SimulationUser simulationUser = this.simulationUserMap.get(userId);
if (Objects.isNull(simulationUser)) {
throw new SimulationException(SimulationExceptionType.System_Fault);
}
return simulationUser;
} }
public List<SimulationMember> queryAllUserDriver() { public List<SimulationMember> queryAllUserDriver() {
List<SimulationMember> list = new ArrayList<>(); List<SimulationMember> list = new ArrayList<>();
for (SimulationMember member : this.simulationMemberMap.values()) { for (SimulationMember member : this.getSimulationMembers()) {
if (member.isDriver() && !member.isRobot()) { if (member.isDriver() && !member.isRobot()) {
list.add(member); list.add(member);
} }
@ -247,82 +245,12 @@ public class Simulation {
return list; return list;
} }
private List queryMemberListOfRole(@NotNull SimulationMember.Type type) {
List<SimulationMember> list = new ArrayList<>();
for (SimulationMember member : this.simulationMemberMap.values()) {
if (member.isSame(type)) {
list.add(member);
}
}
return list;
}
public List<SimulationMember> queryAllDrivers() {
return this.queryMemberListOfRole(SimulationMember.Type.DRIVER);
}
public SimulationMember querySimulationMemberByUserId(Long userId) {
for (SimulationMember member : this.simulationMemberMap.values()) {
if (member.isPlayedBy(userId)) {
return member;
}
}
return null;
}
/**
* 根据设备查询成员暂时默认一个设备只一个成员
*
* @param device
* @return
*/
public SimulationMember getSimulationMemberByDevice(MapElement device) {
for (SimulationMember member : this.simulationMemberMap.values()) {
if (member.isSame(device)) {
return member;
}
}
throw new SimulationException(SimulationExceptionType.System_Fault);
}
public List<SimulationUser> getAllSimulationUsers() {
return new ArrayList<>(this.simulationUserMap.values());
}
public SimulationUser querySimulationUserByUserId(Long userId) {
return this.simulationUserMap.get(userId);
}
public void addSimulationUser(SimulationUser simulationUser) {
this.simulationUserMap.put(simulationUser.getUser().getId(), simulationUser);
}
public SimulationUser removeSimulationUser(Long userId) {
return this.simulationUserMap.remove(userId);
}
public void removeSimulationUser(SimulationUser simulationUser) {
this.simulationUserMap.remove(simulationUser.getUser().getId());
}
public List<SimulationMember> getAllSimulationMembers() {
return new ArrayList<>(this.simulationMemberMap.values());
}
public List<SimulationMember> getSimulationMembersByType(SimulationMember.Type type) {
return this.simulationMemberMap.values().stream().filter(member2 -> member2.isSame(type)).collect(Collectors.toList());
}
public boolean isSame(Project project) { public boolean isSame(Project project) {
return Objects.equals(this.project, project); return Objects.equals(this.project, project);
} }
public boolean containsUser(Long userId) {
return this.simulationUserMap.containsKey(userId);
}
public boolean isAdmin(UserVO user) { public boolean isAdmin(UserVO user) {
SimulationUser simulationUser = this.querySimulationUserByUserId(user.getId()); SimulationUser simulationUser = this.querySimulationUserById(user.getId().toString());
if (Objects.nonNull(simulationUser) && simulationUser.isAdmin()) { if (Objects.nonNull(simulationUser) && simulationUser.isAdmin()) {
return true; return true;
} }
@ -333,16 +261,6 @@ public class Simulation {
this.simulationConversationMap.put(conversation.getId(), conversation); this.simulationConversationMap.put(conversation.getId(), conversation);
} }
public SimulationMember getSimulationMemberByUserId(Long userId) {
SimulationUser simulationUser = this.getSimulationUserByUserId(userId);
SimulationMember playedMember = simulationUser.getPlayedMember();
if (Objects.isNull(playedMember)) {
throw new SimulationException(SimulationExceptionType.Simulation_Member_Not_Exist,
String.format("用户[%s]未扮演角色"));
}
return playedMember;
}
public Conversation getSimulationConversationById(String conversationId) { public Conversation getSimulationConversationById(String conversationId) {
Conversation conversation = this.simulationConversationMap.get(conversationId); Conversation conversation = this.simulationConversationMap.get(conversationId);
if (Objects.isNull(conversation)) { if (Objects.isNull(conversation)) {
@ -356,10 +274,6 @@ public class Simulation {
return new ArrayList<>(this.simulationConversationMap.values()); return new ArrayList<>(this.simulationConversationMap.values());
} }
public void setSimulationMemberMap(Map<String, SimulationMember> memberMap) {
this.simulationMemberMap = memberMap;
}
public RealDeviceConfig getRealDeviceById(Long id) { public RealDeviceConfig getRealDeviceById(Long id) {
for (RealDeviceConfig realDevice : this.realDeviceList) { for (RealDeviceConfig realDevice : this.realDeviceList) {
if (Objects.equals(realDevice.getProjectDevice().getId(), id)) { if (Objects.equals(realDevice.getProjectDevice().getId(), id)) {
@ -480,7 +394,12 @@ public class Simulation {
} }
public String debugStr() { public String debugStr() {
return String.format("%s", this.group); return String.format("%s", getId());
}
@Override
public SimulationInfoVO buildVO() {
return null;
} }
public void addLog(SimulationLog log) { public void addLog(SimulationLog log) {
@ -530,68 +449,46 @@ public class Simulation {
return simulationTime; return simulationTime;
} }
/**
* 初始化系统时间
*
* @param initTime
*/
public void initSystemTime(LocalDateTime initTime) {
this.systemTime = initTime;
}
/**
* 更新系统时间单位ms
*
* @param ms
*/
public void updateSystemTime(int ms) {
this.systemTime = this.systemTime.plus(ms, ChronoUnit.MILLIS);
}
/** /**
* 获取系统修正时间 * 获取系统修正时间
* *
* @return * @return
*/ */
public LocalDateTime getCorrectSystemTime() { public LocalDateTime getCorrectSystemTime() {
return this.systemTime.plusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME); return this.getSystemTime().plusHours(SimulationConstants.RUN_DIAGRAM_TRANS_TIME);
} }
/** // /**
* 仿真异常信息 // * 仿真异常信息
* // *
* @param e // * @param e
*/ // */
public void error(Throwable e) { // public void error(Throwable e) {
this.error = true; // this.error = true;
this.cause = e; // this.cause = e;
} // }
public Set<String> getSimulationUserIds() { // public Set<String> getSimulationUserIds() {
return this.simulationUserMap.keySet().stream() // return this.simulationUserMap.keySet().stream()
.map(id -> String.valueOf(id)) // .map(id -> String.valueOf(id))
.collect(Collectors.toSet());
// return this.memberMap.values().stream()
// .filter(member -> Objects.nonNull(member.getUserId()))
// .map(member -> String.valueOf(member.getUserId()))
// .collect(Collectors.toSet()); // .collect(Collectors.toSet());
} //// return this.memberMap.values().stream()
//// .filter(member -> Objects.nonNull(member.getUserId()))
//// .map(member -> String.valueOf(member.getUserId()))
//// .collect(Collectors.toSet());
// }
public Set<SimulationMember> getSimulationMembers() { // public List<SimulationMember> findMemberListByRole(SimulationMember.Type type) {
return new HashSet<>(this.simulationMemberMap.values()); // List<SimulationMember> list = new ArrayList<>(2);
} // if (!CollectionUtils.isEmpty(this.simulationMemberMap)) {
// for (SimulationMember member : this.getSimulationMembers()) {
public List<SimulationMember> findMemberListByRole(SimulationMember.Type type) { // if (member.getType().equals(type)) {
List<SimulationMember> list = new ArrayList<>(2); // list.add(member);
if (!CollectionUtils.isEmpty(this.simulationMemberMap)) { // }
for (SimulationMember member : this.getSimulationMembers()) { // }
if (member.getType().equals(type)) { // }
list.add(member); // return list;
} // }
}
}
return list;
}
public SimulationMember findMemberByRoleAndDeviceCode(SimulationMember.Type memberType, String deviceCode) { public SimulationMember findMemberByRoleAndDeviceCode(SimulationMember.Type memberType, String deviceCode) {
for (SimulationMember member : this.getSimulationMembers()) { for (SimulationMember member : this.getSimulationMembers()) {
@ -611,67 +508,50 @@ public class Simulation {
this.dataErrMsgList.add(errMsg); this.dataErrMsgList.add(errMsg);
} }
public SimulationMember findMemberByUserId(Long userId) { // public SimulationMember findMemberByUserId(Long userId) {
for (SimulationMember member : this.simulationMemberMap.values()) { // for (SimulationMember member : this.simulationMemberMap.values()) {
if (Objects.equals(userId, member.getUserId())) { // if (Objects.equals(userId, member.getUserId())) {
return member; // return member;
} // }
} // }
return null; // return null;
} // }
public SimulationMember getMemberByUserId(Long userId) { // public SimulationMember getMemberByUserId(Long userId) {
SimulationMember member = this.findMemberByUserId(userId); // SimulationMember member = this.findMemberByUserId(userId);
if (Objects.isNull(member)) { // if (Objects.isNull(member)) {
throw new SimulationException(SimulationExceptionType.Simulation_Member_Not_Exist, // throw new SimulationException(SimulationExceptionType.Simulation_Member_Not_Exist,
String.format("id为[%s]的用户没有对应的仿真成员", userId)); // String.format("id为[%s]的用户没有对应的仿真成员", userId));
} // }
return member; // return member;
} // }
public void addMember(SimulationMember member) { public SimulationUser querySimulationUserById(Long id) {
this.simulationMemberMap.put(member.getId(), member); String userId = null;
} if (id != null)
userId = id.toString();
public SimulationMember getSimulationMemberById(String id) { return this.querySimulationUserById(userId);
SimulationMember member = this.simulationMemberMap.get(id);
if (Objects.isNull(member)) {
throw new SimulationException(SimulationExceptionType.System_Fault);
}
return member;
}
public SimulationMember findMemberById(String id) {
return this.simulationMemberMap.get(id);
}
public SimulationMember getMemberById(String memberId) {
SimulationMember member = this.findMemberById(memberId);
if (Objects.isNull(member)) {
throw new SimulationException(SimulationExceptionType.Simulation_Member_Not_Exist,
String.format("id为[%s]的成员不存在", memberId));
}
return member;
} }
/** /**
* 仿真重置中间数据清除设备及虚拟真实设备状态置为初始状态 * 仿真重置中间数据清除设备及虚拟真实设备状态置为初始状态
*/ */
public void reset() { public void reset() {
init();
this.repository.reset(); this.repository.reset();
for (SimulationMember member : this.getAllSimulationMembers()) { this.getSimulationMembers().forEach(member -> member.setCommand(null));
member.setCommand(null);
}
this.error = false;
this.cause = null;
this.planRunning = false; this.planRunning = false;
this.pause = false;
if (!CollectionUtils.isEmpty(simulationConversationMap)) { if (!CollectionUtils.isEmpty(simulationConversationMap)) {
simulationConversationMap.clear(); simulationConversationMap.clear();
} }
this.logs = null; this.logs = null;
} }
@Override
public void runError(Throwable throwable) {
super.runError(throwable);
}
/** /**
* 关闭所有自动故障 * 关闭所有自动故障
*/ */
@ -697,12 +577,12 @@ public class Simulation {
public SimulationUser getAdmin() { public SimulationUser getAdmin() {
for (SimulationUser simulationUser : getAllSimulationUsers()) { for (SimulationUser simulationUser : getSimulationUsers()) {
if (simulationUser.isAdmin()) { if (simulationUser.isAdmin()) {
return simulationUser; return simulationUser;
} }
} }
throw new SimulationException(SimulationExceptionType.Data_Not_Exist, String.format("仿真[%s]没有管理员", group)); throw new SimulationException(SimulationExceptionType.Data_Not_Exist, String.format("仿真[%s]没有管理员", getId()));
} }
/** /**
@ -712,4 +592,55 @@ public class Simulation {
UserVO user = this.buildParams.getUser(); UserVO user = this.buildParams.getUser();
return user; return user;
} }
public Set<String> getSimulationUserIds() {
return this.getSimulationUsers().stream().map(club.joylink.rtss.simulation.SimulationUser::getId).collect(Collectors.toSet());
}
public SimulationUser getSimulationUserById(Long id) {
String userId = null;
if (id != null)
userId = id.toString();
return this.getSimulationUserById(userId);
}
public boolean containsUser(Long userId) {
String uid = null;
if (userId != null)
uid = userId.toString();
return this.containsUser(uid);
}
/**
* 根据设备查询成员暂时默认一个设备只一个成员
*
* @param device
* @return
*/
public SimulationMember getSimulationMemberByDevice(MapElement device) {
for (SimulationMember member : this.getSimulationMembers()) {
if (member.isSame(device)) {
return member;
}
}
throw new SimulationException(SimulationExceptionType.System_Fault);
}
public SimulationMember getSimulationMemberByUserId(Long id) {
String uid = null;
if (id != null)
uid = id.toString();
return this.getSimulationMemberByUserId(uid);
}
public SimulationMember querySimulationMemberByUserId(Long id) {
String uid = null;
if (id != null)
uid = id.toString();
return this.querySimulationMemberByUserId(uid);
}
public interface JobName{
String script = "Script";
}
} }

View File

@ -1,16 +1,29 @@
package club.joylink.rtss.simulation.cbtc; package club.joylink.rtss.simulation.cbtc;
import club.joylink.rtss.services.IVirtualRealityIbpService;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.ATP.ground.ZCLogicLoop;
import club.joylink.rtss.simulation.cbtc.ATS.ATSLogicLoop;
import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher;
import club.joylink.rtss.simulation.cbtc.CI.CILogicLoop;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder; import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO; import club.joylink.rtss.simulation.cbtc.command.VoiceCommandBO;
import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService;
import club.joylink.rtss.simulation.cbtc.event.*; import club.joylink.rtss.simulation.cbtc.event.*;
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.simulation.cbtc.fault.FaultGenerator;
import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.member.MemberManager;
import club.joylink.rtss.services.IVoiceCommandService; import club.joylink.rtss.services.IVoiceCommandService;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPLogicLoop;
import club.joylink.rtss.simulation.cbtc.robot.RobotLogicLoop;
import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO;
import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -38,11 +51,54 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
@Autowired @Autowired
private IVoiceCommandService iVoiceCommandService; private IVoiceCommandService iVoiceCommandService;
@Autowired
private ATSLogicLoop atsLogicLoop;
@Autowired
private ATPLogicLoop atpLogicLoop;
@Autowired
private VRTrainRunningService vrTrainRunningService;
@Autowired
private CILogicLoop ciLogicLoop;
@Autowired
private VRDeviceLogicLoop vrDeviceLogicLoop;
@Autowired
private ZCLogicLoop zcLogicLoop;
@Autowired
private ATSMessageCollectAndDispatcher atsMessageCollectAndDispatcher;
@Autowired
private Joylink3DMessageService joylink3DMessageService;
@Autowired
private FaultGenerator faultGenerator;
@Autowired
private IVirtualRealityIbpService iVirtualRealityIbpService;
@Autowired
private PowerSupplyService powerSupplyService;
@Autowired
private RobotLogicLoop robotLogicLoop;
@Autowired
private SimulationRealDeviceConnectManager simulationRealDeviceConnectManager;
@Autowired
private SimulationManager simulationManager;
@Override @Override
public Simulation create(SimulationBuildParams params, String group) { public Simulation create(SimulationBuildParams params, String group) {
// 构建仿真 // 构建仿真
Simulation simulation = SimulationBuilder.build(params); Simulation simulation = SimulationBuilder.build(group, params);
simulation.setGroup(group); // 缓存
simulationManager.save(simulation);
// 初始化设备状态 // 初始化设备状态
this.deviceStatusService.init(simulation); this.deviceStatusService.init(simulation);
// 初始化成员 // 初始化成员
@ -50,26 +106,47 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
// 初始化语音指令 // 初始化语音指令
List<VoiceCommandBO> voiceCommandBOList = this.iVoiceCommandService.getAll(); List<VoiceCommandBO> voiceCommandBOList = this.iVoiceCommandService.getAll();
simulation.setVoiceCommandBOList(voiceCommandBOList); simulation.setVoiceCommandBOList(voiceCommandBOList);
// 添加任务
addJobs(simulation);
this.applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); this.applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation));
return simulation; return simulation;
} }
private void addJobs(Simulation simulation) {
atsLogicLoop.addJobs(simulation);
atpLogicLoop.addJobs(simulation);
vrTrainRunningService.addJobs(simulation);
ciLogicLoop.addJobs(simulation);
vrDeviceLogicLoop.addJobs(simulation);
zcLogicLoop.addJobs(simulation);
atsMessageCollectAndDispatcher.addJobs(simulation);
joylink3DMessageService.addJobs(simulation);
faultGenerator.addJobs(simulation);
iVirtualRealityIbpService.addJobs(simulation);
powerSupplyService.addJobs(simulation);
robotLogicLoop.addJobs(simulation);
//////////////////////////////////////////////
simulationRealDeviceConnectManager.addJobs(simulation);
}
@Override @Override
public boolean pause(Simulation simulation) { public boolean pause(Simulation simulation) {
simulation.setPause(true); simulation.pause();
// simulation.setPause(true);
this.applicationContext.publishEvent(new SimulationPauseEvent(this, simulation)); this.applicationContext.publishEvent(new SimulationPauseEvent(this, simulation));
return true; return true;
} }
@Override @Override
public void resume(Simulation simulation) { public void resume(Simulation simulation) {
simulation.setPause(false); simulation.start();
this.applicationContext.publishEvent(new SimulationResumeEvent(this, simulation)); this.applicationContext.publishEvent(new SimulationResumeEvent(this, simulation));
} }
@Override @Override
public void error(Simulation simulation, Throwable e) { public void error(Simulation simulation, Throwable e) {
simulation.error(e); // simulation.error(e);
this.applicationContext.publishEvent(new SimulationErrorEvent(this, simulation)); this.applicationContext.publishEvent(new SimulationErrorEvent(this, simulation));
} }
@ -120,7 +197,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic
// simulation.resetFrom(build); // simulation.resetFrom(build);
// // 成员重建 // // 成员重建
// this.memberManager.rebuild(simulation, oldMemberMap); // this.memberManager.rebuild(simulation, oldMemberMap);
log.info(String.format("仿真[%s]重置", simulation.getGroup())); log.info(String.format("仿真[%s]重置", simulation.getId()));
this.applicationContext.publishEvent(new SimulationResetEvent(this, simulation)); this.applicationContext.publishEvent(new SimulationResetEvent(this, simulation));
this.resume(simulation); this.resume(simulation);
} }

View File

@ -123,343 +123,343 @@ public class SimulationMainThread {
@Autowired @Autowired
private PowerSupplyService powerSupplyService; private PowerSupplyService powerSupplyService;
@Scheduled(fixedRate = 1000) // @Scheduled(fixedRate = 1000)
public void updatePlcGatewayOnlineStatus() { // public void updatePlcGatewayOnlineStatus() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); // Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
for (Simulation simulation : groupSimulationMap.values()) { // for (Simulation simulation : groupSimulationMap.values()) {
this.simulationRealDeviceConnectManager.updatePlcGatewayOnlineStatus(simulation); // this.simulationRealDeviceConnectManager.updatePlcGatewayOnlineStatus(simulation);
} // }
} // }
//
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.ATS_LOOP_RATE)
public void ats() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.ATS, group, simulation));
}
}
// @Async("nsExecutor") // @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.TL_LOOP_RATE) // @Scheduled(fixedRate = SimulationConstants.ATS_LOOP_RATE)
// public void tl() { // public void ats() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); // Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) { // if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) -> // groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.TL, group, simulation)); // this.run(SimulationModule.ATS, group, simulation));
// } // }
// } // }
//
@Async("nsExecutor") //// @Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.ATP_LOOP_RATE) //// @Scheduled(fixedRate = SimulationConstants.TL_LOOP_RATE)
public void atp() { //// public void tl() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); //// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) { //// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) -> //// groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.ATP, group, simulation)); //// this.run(SimulationModule.TL, group, simulation));
} //// }
} //// }
//
/** // @Async("nsExecutor")
* 机器人司机驾驶逻辑 // @Scheduled(fixedRate = SimulationConstants.ATP_LOOP_RATE)
*/ // public void atp() {
@Async("nsExecutor") // Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
@Scheduled(fixedRate = SimulationConstants.ATO_LOOP_RATE) // if (!CollectionUtils.isEmpty(groupSimulationMap)) {
public void driver() { // groupSimulationMap.forEach((group, simulation) ->
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); // this.run(SimulationModule.ATP, group, simulation));
if (!CollectionUtils.isEmpty(groupSimulationMap)) { // }
groupSimulationMap.forEach((group, simulation) -> this.run(SimulationModule.ROBOT, group, simulation)); // }
} //
} // /**
// * 机器人司机驾驶逻辑
// */
// @Async("nsExecutor") // @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.ATO_LOOP_RATE) // @Scheduled(fixedRate = SimulationConstants.ATO_LOOP_RATE)
// public void ato() { // public void driver() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) -> this.run(SimulationModule.ROBOT, group, simulation));
// }
// }
//// @Async("nsExecutor")
//// @Scheduled(fixedRate = SimulationConstants.ATO_LOOP_RATE)
//// public void ato() {
//// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
//// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
//// groupSimulationMap.forEach((group, simulation) -> {
//// this.run(SimulationModule.ATO, group, simulation);
//// });
//// }
//
//// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.TRAIN_RUNNING_RATE)
// public void tr() {
//// long start = System.currentTimeMillis();
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.TR, group, simulation));
//// long end = System.currentTimeMillis();
//// System.out.println("列车运行耗时: " + (end-start) + "ms");
// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.CI_LOOP_RATE)
// public void ci() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.CI, group, simulation));
// }
// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.VRD_LOOP_RATE)
// public void vrd() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.VRD, group, simulation));
// }
// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.GROUND_ATP_LOOP_RATE)
// public void groundAtp() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.GROUND_ATP, group, simulation));
// }
// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.ZC_LOOP_RATE)
// public void zc() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.ZC, group, simulation));
// }
// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.TIME_LOOP_RATE)
// public void ts() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.TIME, group, simulation));
// }
// }
//
// @Async("nsExecutor")
// @Scheduled(fixedRate = SimulationConstants.SYNC_TIME_RATE)
// public void syncTime() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.SYNC_TIME, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.SCRIPT_LOOP_RATE)
// public void scriptRun() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); // Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) { // if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) -> { // groupSimulationMap.forEach((group, simulation) -> {
// this.run(SimulationModule.ATO, group, simulation); // competitionAndScriptManager.run(simulation);
//// ScriptBO script = simulation.getScript();
//// if (Objects.nonNull(script) && script.isStarted()) {
//// this.scriptExecuteService.run(simulation);
//// }
// }); // });
// } // }
// } // }
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.TRAIN_RUNNING_RATE)
public void tr() {
// long start = System.currentTimeMillis();
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.TR, group, simulation));
// long end = System.currentTimeMillis();
// System.out.println("列车运行耗时: " + (end-start) + "ms");
}
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.CI_LOOP_RATE)
public void ci() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.CI, group, simulation));
}
}
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.VRD_LOOP_RATE)
public void vrd() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.VRD, group, simulation));
}
}
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.GROUND_ATP_LOOP_RATE)
public void groundAtp() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.GROUND_ATP, group, simulation));
}
}
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.ZC_LOOP_RATE)
public void zc() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.ZC, group, simulation));
}
}
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.TIME_LOOP_RATE)
public void ts() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.TIME, group, simulation));
}
}
@Async("nsExecutor")
@Scheduled(fixedRate = SimulationConstants.SYNC_TIME_RATE)
public void syncTime() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.SYNC_TIME, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.SCRIPT_LOOP_RATE)
public void scriptRun() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) -> {
competitionAndScriptManager.run(simulation);
// ScriptBO script = simulation.getScript();
// if (Objects.nonNull(script) && script.isStarted()) {
// this.scriptExecuteService.run(simulation);
// }
});
}
}
@Scheduled(fixedRate = SimulationConstants.SCRIPT_LOOP_RATE)
public void competitionMonitor() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
if (!CollectionUtils.isEmpty(groupSimulationMap)) {
groupSimulationMap.forEach((group, simulation) -> {
competitionAndScriptManager.monitor(simulation);
});
}
}
/**
* 推送仿真状态到客户端
*/
@Scheduled(fixedRate = SimulationConstants.SEND_CLIENT_RATE)
public void push2Client() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.MESSAGE, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.TRAIN_SPEED_PUSH_RATE)
public void trainSpeedPush() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.TRAIN_SPEED, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.SEND_CLIENT_RATE)
public void push3DMessage() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.MESSAGE_3D, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE)
public void sync3DDrivePositionInfo() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.DRIVE_POSITION, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.FAULT_GENERATE_RATE)
public void faultGenerate() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.FAULT, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.COMMAND_EXECUTE_RATE)
public void commandExecute() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.commandExecuteService.run(simulation));
}
@Scheduled(fixedRate = SimulationConstants.TRAIN_POSITION_RATE)
public void trainPositionSend() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.TRAIN_POSITION_3D, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.IBP_STATUS_COLLECT_RATE)
public void collectIbpStatus() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.IBP_STATUS, group, simulation));
}
@Scheduled(fixedRate = SimulationConstants.POWER_SUPPLY_STATUS_UPDATE_RATE)
public void powerSupplyStatusUpdate() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
groupSimulationMap.forEach((group, simulation) ->
this.run(SimulationModule.CATENARY, group, simulation));
}
/**
* 仿真模块运行
*
* @param module
* @param group
* @param simulation
*/
private void run(SimulationModule module, String group, Simulation simulation) {
try {
if (!simulation.isError() && !simulation.isPause()) { // 判断仿真系统正常运行
simulation.runAdd();
switch (module) {
case ATS: {
this.atsLogicLoop.run(simulation);
break;
}
// case TL: {
// this.tlLogicLoop.run(simulation);
// break;
// }
case ATP: {
this.atpLogicLoop.run(simulation);
break;
}
// case ATO: {
// this.atoLogicLoop.run(simulation);
// break;
// }
case TR: {
this.vrTrainRunningService.trainRunning(simulation);
break;
}
case TL:
break;
case CI: {
this.ciLogicLoop.run(simulation);
break;
}
case RSC:
break;
case VRD: {
this.vrDeviceLogicLoop.run(simulation);
break;
}
case GROUND_ATP: {
// this.atpSectionService.run(simulation);
break;
}
case ZC: {
this.zcLogicLoop.run(simulation);
break;
}
case TIME: {
simulation.updateSystemTime(module.getRateMs());
break;
}
case SYNC_TIME: {
this.atsMessageCollectAndDispatcher.syncTime(simulation);
break;
}
case MESSAGE: {
this.atsMessageCollectAndDispatcher.run(simulation);
break;
}
case TRAIN_SPEED: {
this.joylink3DMessageService.collectAndSendTrainSpeedMessage(simulation);
break;
}
case MESSAGE_3D: {
this.joylink3DMessageService.collectAndSendTrainHmiDisplayMessage(simulation);
this.joylink3DMessageService.tdtStatusCollectAndSend(simulation);
break;
}
case TRAIN_POSITION_3D: {
this.joylink3DMessageService.collectAndSendTrainPositionMessage(simulation);
break;
}
case DRIVE_POSITION: {
this.joylink3DMessageService.syncTrainDrivePosition(simulation);
break;
}
// case SCRIPT: {
// System.out.println("Script_Loop_Rate");
// //
// @Scheduled(fixedRate = SimulationConstants.SCRIPT_LOOP_RATE)
// public void competitionMonitor() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// if (!CollectionUtils.isEmpty(groupSimulationMap)) {
// groupSimulationMap.forEach((group, simulation) -> {
// competitionAndScriptManager.monitor(simulation);
// });
// }
// }
// //
// /**
// * 推送仿真状态到客户端
// */
// @Scheduled(fixedRate = SimulationConstants.SEND_CLIENT_RATE)
// public void push2Client() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.MESSAGE, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.TRAIN_SPEED_PUSH_RATE)
// public void trainSpeedPush() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.TRAIN_SPEED, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.SEND_CLIENT_RATE)
// public void push3DMessage() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.MESSAGE_3D, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE)
// public void sync3DDrivePositionInfo() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.DRIVE_POSITION, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.FAULT_GENERATE_RATE)
// public void faultGenerate() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.FAULT, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.COMMAND_EXECUTE_RATE)
// public void commandExecute() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.commandExecuteService.run(simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.TRAIN_POSITION_RATE)
// public void trainPositionSend() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.TRAIN_POSITION_3D, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.IBP_STATUS_COLLECT_RATE)
// public void collectIbpStatus() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.IBP_STATUS, group, simulation));
// }
//
// @Scheduled(fixedRate = SimulationConstants.POWER_SUPPLY_STATUS_UPDATE_RATE)
// public void powerSupplyStatusUpdate() {
// Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
// groupSimulationMap.forEach((group, simulation) ->
// this.run(SimulationModule.CATENARY, group, simulation));
// }
//
// /**
// * 仿真模块运行
// *
// * @param module
// * @param group
// * @param simulation
// */
// private void run(SimulationModule module, String group, Simulation simulation) {
// try {
// if (!simulation.isError() && !simulation.isPause()) { // 判断仿真系统正常运行
// simulation.runAdd();
// switch (module) {
// case ATS: {
// this.atsLogicLoop.run(simulation);
// break; // break;
// } // }
case FAULT: { //// case TL: {
this.faultGenerator.simulationFaultGenerate(simulation); //// this.tlLogicLoop.run(simulation);
break; //// break;
} //// }
case IBP_STATUS: { // case ATP: {
this.iVirtualRealityIbpService.collectAndDispatcher(simulation); // this.atpLogicLoop.run(simulation);
break; // break;
} // }
case CATENARY: { //// case ATO: {
powerSupplyService.run(simulation); //// this.atoLogicLoop.run(simulation);
break; //// break;
} //// }
case ROBOT: { // case TR: {
robotLogicLoop.run(simulation); // this.vrTrainRunningService.trainRunning(simulation);
break; // break;
} // }
default: { // case TL:
throw new SimulationException(SimulationExceptionType.System_Fault, // break;
String.format("仿真模块[%s]不存在", module)); // case CI: {
} // this.ciLogicLoop.run(simulation);
} // break;
simulation.runOver(); // }
} // case RSC:
} catch (Exception e) { // break;
simulation.runOver(); // case VRD: {
log.error(String.format("[%s]的仿真主线程出现异常:%s", group, e.getMessage()), e); // this.vrDeviceLogicLoop.run(simulation);
this.simulationLifeCycleService.error(simulation, e); // break;
} // }
// case GROUND_ATP: {
} //// this.atpSectionService.run(simulation);
// break;
// }
// case ZC: {
// this.zcLogicLoop.run(simulation);
// break;
// }
// case TIME: {
// simulation.updateSystemTime(module.getRateMs());
// break;
// }
// case SYNC_TIME: {
// this.atsMessageCollectAndDispatcher.syncTime(simulation);
// break;
// }
// case MESSAGE: {
// this.atsMessageCollectAndDispatcher.run(simulation);
// break;
// }
// case TRAIN_SPEED: {
// this.joylink3DMessageService.collectAndSendTrainSpeedMessage(simulation);
// break;
// }
// case MESSAGE_3D: {
// this.joylink3DMessageService.collectAndSendTrainHmiDisplayMessage(simulation);
// this.joylink3DMessageService.tdtStatusCollectAndSend(simulation);
// break;
// }
// case TRAIN_POSITION_3D: {
// this.joylink3DMessageService.collectAndSendTrainPositionMessage(simulation);
// break;
// }
// case DRIVE_POSITION: {
// this.joylink3DMessageService.syncTrainDrivePosition(simulation);
// break;
// }
//// case SCRIPT: {
//// System.out.println("Script_Loop_Rate");
////
////
//// break;
//// }
// case FAULT: {
// this.faultGenerator.simulationFaultGenerate(simulation);
// break;
// }
// case IBP_STATUS: {
// this.iVirtualRealityIbpService.collectAndDispatcher(simulation);
// break;
// }
// case CATENARY: {
// powerSupplyService.run(simulation);
// break;
// }
// case ROBOT: {
// robotLogicLoop.run(simulation);
// break;
// }
// default: {
// throw new SimulationException(SimulationExceptionType.System_Fault,
// String.format("仿真模块[%s]不存在", module));
// }
// }
// simulation.runOver();
// }
// } catch (Exception e) {
// simulation.runOver();
// log.error(String.format("[%s]的仿真主线程出现异常:%s", group, e.getMessage()), e);
// this.simulationLifeCycleService.error(simulation, e);
// }
//
// }
@Async("nsExecutor") @Async("nsExecutor")
@EventListener @EventListener
@ -470,7 +470,7 @@ public class SimulationMainThread {
if (Objects.isNull(simulation)) { if (Objects.isNull(simulation)) {
return; return;
} }
SimulationUser simulationUser = simulation.getSimulationUserByUserId(event.getUserId()); SimulationUser simulationUser = simulation.getSimulationUserById(event.getUserId());
if (Objects.nonNull(simulationUser)) { if (Objects.nonNull(simulationUser)) {
log.info(String.format("仿真[%s]用户[%s]上线,并同步相关仿真状态", group, event.getUserId())); log.info(String.format("仿真[%s]用户[%s]上线,并同步相关仿真状态", group, event.getUserId()));
@ -507,7 +507,7 @@ public class SimulationMainThread {
if (Objects.isNull(simulation)) { if (Objects.isNull(simulation)) {
return; return;
} }
SimulationUser simulationUser = simulation.getSimulationUserByUserId(event.getUserId()); SimulationUser simulationUser = simulation.getSimulationUserById(event.getUserId());
simulationUser.offline(); simulationUser.offline();
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory
@ -520,7 +520,7 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationUser simulationUser = event.getSimulationUser(); SimulationUser simulationUser = event.getSimulationUser();
log.info(String.format("仿真[%s]用户[%s]扮演角色变更事件通知,当前扮演[%s]", log.info(String.format("仿真[%s]用户[%s]扮演角色变更事件通知,当前扮演[%s]",
simulationUser.getUser().getId(), simulation.getGroup(), simulationUser.getUser().getId(), simulation.getId(),
simulationUser.getPlayedMember())); simulationUser.getPlayedMember()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationUserMessageVO> playChangeMessage = SocketMessageFactory SocketMessageVO<SimulationUserMessageVO> playChangeMessage = SocketMessageFactory
@ -533,7 +533,7 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationUser simulationUser = event.getSimulationUser(); SimulationUser simulationUser = event.getSimulationUser();
log.info(String.format("用户[%s]进入综合演练仿真[%s]成为仿真成员事件通知", log.info(String.format("用户[%s]进入综合演练仿真[%s]成为仿真成员事件通知",
simulationUser.getUser().getId(), simulation.getGroup())); simulationUser.getUser().getId(), simulation.getId()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationVO> inviteMessage = SocketMessageFactory.buildSimulationInviteMessage(simulation); SocketMessageVO<SimulationVO> inviteMessage = SocketMessageFactory.buildSimulationInviteMessage(simulation);
this.stompMessageService.sendToUser(simulationUser.getUser().getId().toString(), inviteMessage); this.stompMessageService.sendToUser(simulationUser.getUser().getId().toString(), inviteMessage);
@ -546,7 +546,7 @@ public class SimulationMainThread {
public void kickOutUserNotify(SimulationUserKickOutEvent event) { public void kickOutUserNotify(SimulationUserKickOutEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("综合演练仿真[%s]踢出用户[%s]事件通知", log.info(String.format("综合演练仿真[%s]踢出用户[%s]事件通知",
simulation.getGroup(), event.getSimulationUser().getUser().getId())); simulation.getId(), event.getSimulationUser().getUser().getId()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
userIds.add(event.getSimulationUser().getUser().getId().toString()); userIds.add(event.getSimulationUser().getUser().getId().toString());
SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory
@ -559,7 +559,7 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
log.info(String.format("仿真[%s]添加仿真成员[%s]消息通知", log.info(String.format("仿真[%s]添加仿真成员[%s]消息通知",
simulation.getGroup(), member)); simulation.getId(), member));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationMemberMessageVO> message = SocketMessageFactory SocketMessageVO<SimulationMemberMessageVO> message = SocketMessageFactory
.buildSimulationMemberAddMessage(simulation, member); .buildSimulationMemberAddMessage(simulation, member);
@ -571,7 +571,7 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
log.info(String.format("仿真[%s]会话[%s]创建消息发送", log.info(String.format("仿真[%s]会话[%s]创建消息发送",
simulation.getGroup(), conversation.getId())); simulation.getId(), conversation.getId()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<ConversationSocketMessageVO> createMessage = SocketMessageFactory.buildSimulationConversationCreateMessage(simulation, conversation); SocketMessageVO<ConversationSocketMessageVO> createMessage = SocketMessageFactory.buildSimulationConversationCreateMessage(simulation, conversation);
this.stompMessageService.sendToUser(userIds, createMessage); this.stompMessageService.sendToUser(userIds, createMessage);
@ -583,9 +583,9 @@ public class SimulationMainThread {
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
log.info(String.format("仿真[%s]会话[%s]邀请消息发送", log.info(String.format("仿真[%s]会话[%s]邀请消息发送",
simulation.getGroup(), conversation.getId())); simulation.getId(), conversation.getId()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory.buildSimulationConversationInviteMessage(simulation, conversation, member); SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory.buildSimulationConversationInviteMessage(simulation, conversation, member);
this.stompMessageService.sendToUser(member.getUserIdStr(), message); this.stompMessageService.sendToUser(member.getUserId(), message);
} }
@EventListener @EventListener
@ -594,7 +594,7 @@ public class SimulationMainThread {
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
log.info(String.format("仿真[%s]会话[%s]成员[%s]接受邀请进入会话消息发送", log.info(String.format("仿真[%s]会话[%s]成员[%s]接受邀请进入会话消息发送",
simulation.getGroup(), conversation.getId(), member.toString())); simulation.getId(), conversation.getId(), member.toString()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory
.buildSimulationMemberConnectConversationMessage(simulation, conversation, member); .buildSimulationMemberConnectConversationMessage(simulation, conversation, member);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
@ -607,7 +607,7 @@ public class SimulationMainThread {
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
ConversationMessage conversationMessage = event.getConversationMessage(); ConversationMessage conversationMessage = event.getConversationMessage();
log.info(String.format("仿真[%s]会话[%s]会话消息发送", log.info(String.format("仿真[%s]会话[%s]会话消息发送",
simulation.getGroup(), conversation.getId())); simulation.getId(), conversation.getId()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory
.buildSimulationConversationChatMessage(simulation, conversation, conversationMessage); .buildSimulationConversationChatMessage(simulation, conversation, conversationMessage);
if(conversation.hasOtherMemberConnect()){ if(conversation.hasOtherMemberConnect()){
@ -624,7 +624,7 @@ public class SimulationMainThread {
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
log.info(String.format("仿真[%s]会话[%s]成员[%s]退出消息发送", log.info(String.format("仿真[%s]会话[%s]成员[%s]退出消息发送",
simulation.getGroup(), conversation.getId(), member.getId())); simulation.getId(), conversation.getId(), member.getId()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory
.buildSimulationConversationExitMessage(simulation, conversation, member); .buildSimulationConversationExitMessage(simulation, conversation, member);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
@ -637,10 +637,10 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationPause(SimulationPauseEvent event) { public void simulationPause(SimulationPauseEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]暂停", simulation.getGroup())); log.info(String.format("仿真[%s]暂停", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause, SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause,
simulation.getGroup(), true); simulation.getId(), true);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -652,10 +652,10 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationResume(SimulationResumeEvent event) { public void simulationResume(SimulationResumeEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]恢复运行", simulation.getGroup())); log.info(String.format("仿真[%s]恢复运行", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause, SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause,
simulation.getGroup(), false); simulation.getId(), false);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -670,7 +670,7 @@ public class SimulationMainThread {
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.build( SocketMessageVO<Boolean> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Reset, WebSocketMessageType.Simulation_Reset,
simulation.getGroup(), true); simulation.getId(), true);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -680,11 +680,11 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationRunPlanReload(SimulationRunPlanReloadEvent event) { public void simulationRunPlanReload(SimulationRunPlanReloadEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]加载新的运行计划", simulation.getGroup())); log.info(String.format("仿真[%s]加载新的运行计划", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<String> message = SocketMessageFactory.build( SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Run_Plan_Reload, WebSocketMessageType.Simulation_Run_Plan_Reload,
simulation.getGroup(), "1"); simulation.getId(), "1");
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -694,9 +694,9 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationScenesReload(SimulationScenesReloadEvent event) { public void simulationScenesReload(SimulationScenesReloadEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]背景重新加载", simulation.getGroup())); log.info(String.format("仿真[%s]背景重新加载", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.buildSimulationScenesReload(simulation.getGroup(), simulation.isPlanRunning()); SocketMessageVO<Boolean> message = SocketMessageFactory.buildSimulationScenesReload(simulation.getId(), simulation.isPlanRunning());
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -708,10 +708,10 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationError(SimulationErrorEvent event) { public void simulationError(SimulationErrorEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]运行异常, 时间 [%s]", simulation.getGroup(),simulation.getCorrectSystemTime().format(DateTimeFormatter.ofPattern("yyyy-mm-dd hh:mm:ss")))); log.info(String.format("仿真[%s]运行异常, 时间 [%s]", simulation.getId(),simulation.getCorrectSystemTime().format(DateTimeFormatter.ofPattern("yyyy-mm-dd hh:mm:ss"))));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<String> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Error, SocketMessageVO<String> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Error,
simulation.getGroup(), ""); simulation.getId(), "");
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -723,11 +723,11 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationDestroy(SimulationDestroyEvent event) { public void simulationDestroy(SimulationDestroyEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]销毁", simulation.getGroup())); log.info(String.format("仿真[%s]销毁", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<String> message = SocketMessageFactory.build( SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Over, WebSocketMessageType.Simulation_Over,
simulation.getGroup(), ""); simulation.getId(), "");
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -745,17 +745,17 @@ public class SimulationMainThread {
actionVO.setContent(String.format(actionVO.getContent(), currentTime)); actionVO.setContent(String.format(actionVO.getContent(), currentTime));
} }
SocketMessageVO<ScriptActionVO> message = SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildScriptTipMessage(simulation.getGroup(), actionVO); SocketMessageFactory.buildScriptTipMessage(simulation.getId(), actionVO);
stompMessageService.sendToUser(action.getMember().getUserIdStr(), message); stompMessageService.sendToUser(action.getMember().getUserId(), message);
log.info(String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getGroup(), action.getMember().getId(), action.getId())); log.info(String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getId(), action.getMember().getId(), action.getId()));
} }
@EventListener @EventListener
public void SimulationScriptFinish(SimulationCompetitionPracticeFinishEvent event) { public void SimulationScriptFinish(SimulationCompetitionPracticeFinishEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SocketMessageVO<Boolean> message = SocketMessageFactory.buildCompetitionPracticeFinishMessage(simulation.getGroup()); SocketMessageVO<Boolean> message = SocketMessageFactory.buildCompetitionPracticeFinishMessage(simulation.getId());
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
log.info(String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getGroup(), simulation.getScript().getId())); log.info(String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(), simulation.getScript().getId()));
} }
@EventListener @EventListener
@ -764,9 +764,9 @@ public class SimulationMainThread {
ScriptActionBO action = event.getScriptActionBO(); ScriptActionBO action = event.getScriptActionBO();
ScriptActionVO vo = ScriptActionVO.buildFinishTipVO(action); ScriptActionVO vo = ScriptActionVO.buildFinishTipVO(action);
SocketMessageVO<ScriptActionVO> message = SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildSimulationScriptActionFinishMessage(simulation.getGroup(), vo); SocketMessageFactory.buildSimulationScriptActionFinishMessage(simulation.getId(), vo);
stompMessageService.sendToUser(action.getMember().getUserIdStr(), message); stompMessageService.sendToUser(action.getMember().getUserId(), message);
log.info(String.format("用户[%s]完成仿真[%s]id为[%s]的剧本动作", simulation.getGroup(), action.getMember().getUserId(), action.getId())); log.info(String.format("用户[%s]完成仿真[%s]id为[%s]的剧本动作", simulation.getId(), action.getMember().getUserId(), action.getId()));
} }
@EventListener @EventListener
@ -776,7 +776,7 @@ public class SimulationMainThread {
if (train.getNextStation() != null) { if (train.getNextStation() != null) {
TrainIsAbout2ArriveVO arriveVO = new TrainIsAbout2ArriveVO(train.getGroupNumber(), train.getNextStation().getCode()); TrainIsAbout2ArriveVO arriveVO = new TrainIsAbout2ArriveVO(train.getGroupNumber(), train.getNextStation().getCode());
SocketMessageVO<TrainIsAbout2ArriveVO> message = SocketMessageVO<TrainIsAbout2ArriveVO> message =
SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getGroup(), arriveVO); SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getId(), arriveVO);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
log.info("列车[{}]即将进站", train.getGroupNumber()); log.info("列车[{}]即将进站", train.getGroupNumber());
} }
@ -787,15 +787,15 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
ScriptActionBO action = event.getScriptActionBO(); ScriptActionBO action = event.getScriptActionBO();
SocketMessageVO<String> message = SocketMessageVO<String> message =
SocketMessageFactory.buildSimulationScriptActionErrorMessage(simulation.getGroup(), action.getId()); SocketMessageFactory.buildSimulationScriptActionErrorMessage(simulation.getId(), action.getId());
stompMessageService.sendToUser(action.getMember().getUserIdStr(), message); stompMessageService.sendToUser(action.getMember().getUserId(), message);
} }
@EventListener @EventListener
public void simulationIbpStatus(SimulationIbpStatusEvent event) { public void simulationIbpStatus(SimulationIbpStatusEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SocketMessageVO<Map<String, IbpStatus>> message = SocketMessageVO<Map<String, IbpStatus>> message =
SocketMessageFactory.buildSimulationIbpStatusMessage(simulation.getGroup(), event.getStatusMap()); SocketMessageFactory.buildSimulationIbpStatusMessage(simulation.getId(), event.getStatusMap());
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -806,7 +806,7 @@ public class SimulationMainThread {
AtsAlarm alarm = new AtsAlarm(String.valueOf(simulation.getAlarmList().size() + 1), AtsAlarm alarm = new AtsAlarm(String.valueOf(simulation.getAlarmList().size() + 1),
simulation.getCorrectSystemTime(), "A", deviceFaultInfo.getCode(), deviceFaultInfo.getFault()); simulation.getCorrectSystemTime(), "A", deviceFaultInfo.getCode(), deviceFaultInfo.getFault());
SocketMessageVO<List<AtsAlarm>> alarmMessage = SocketMessageFactory SocketMessageVO<List<AtsAlarm>> alarmMessage = SocketMessageFactory
.build(WebSocketMessageType.Simulation_Alarm, simulation.getGroup(), Collections.singletonList(alarm)); .build(WebSocketMessageType.Simulation_Alarm, simulation.getId(), Collections.singletonList(alarm));
simulation.getAlarmList().add(alarm); simulation.getAlarmList().add(alarm);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), alarmMessage); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), alarmMessage);
} }
@ -818,7 +818,7 @@ public class SimulationMainThread {
List<AtsAlarm> list = simulation.getAlarmList().stream() List<AtsAlarm> list = simulation.getAlarmList().stream()
.filter(atsAlarm -> codes.contains(atsAlarm.getCode())).collect(Collectors.toList()); .filter(atsAlarm -> codes.contains(atsAlarm.getCode())).collect(Collectors.toList());
SocketMessageVO<List<AtsAlarm>> messageVO = SocketMessageFactory SocketMessageVO<List<AtsAlarm>> messageVO = SocketMessageFactory
.build(WebSocketMessageType.Simulation_Alarm, simulation.getGroup(), list); .build(WebSocketMessageType.Simulation_Alarm, simulation.getId(), list);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), messageVO); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), messageVO);
} }
@ -831,7 +831,7 @@ public class SimulationMainThread {
.peek(atsAlarm -> atsAlarm.recover(simulation.getCorrectSystemTime())) .peek(atsAlarm -> atsAlarm.recover(simulation.getCorrectSystemTime()))
.collect(Collectors.toList()); .collect(Collectors.toList());
SocketMessageVO<List<AtsAlarm>> messageVO = SocketMessageFactory SocketMessageVO<List<AtsAlarm>> messageVO = SocketMessageFactory
.build(WebSocketMessageType.Simulation_Alarm, simulation.getGroup(), list); .build(WebSocketMessageType.Simulation_Alarm, simulation.getId(), list);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), messageVO); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), messageVO);
} }

View File

@ -25,11 +25,13 @@ public class SimulationBuilder {
/** /**
* 构造仿真对象 * 构造仿真对象
* *
*
* @param group
* @param buildParams * @param buildParams
* @return * @return
*/ */
public static Simulation build(SimulationBuildParams buildParams) { public static Simulation build(String group, SimulationBuildParams buildParams) {
Simulation simulation = new Simulation(); Simulation simulation = new Simulation(group);
simulation.setBuildParams(buildParams); simulation.setBuildParams(buildParams);
if (Objects.nonNull(buildParams.getLoginUserInfo())) { if (Objects.nonNull(buildParams.getLoginUserInfo())) {
simulation.setProject(buildParams.getLoginUserInfo().getProject()); simulation.setProject(buildParams.getLoginUserInfo().getProject());

View File

@ -24,7 +24,7 @@ public class CommandExecuteService {
public void run(Simulation simulation) { public void run(Simulation simulation) {
List<SimulationMember> haveCommandMember = List<SimulationMember> haveCommandMember =
simulation.getAllSimulationMembers().stream().filter(member -> member.getCommand() != null).collect(Collectors.toList()); simulation.getSimulationMembers().stream().filter(member -> member.getCommand() != null).collect(Collectors.toList());
for (SimulationMember member : haveCommandMember) { for (SimulationMember member : haveCommandMember) {
CommandBO command = member.getCommand(); CommandBO command = member.getCommand();
if (!member.isRobot()) { if (!member.isRobot()) {

View File

@ -5,6 +5,8 @@ import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.communication.vo.*; import club.joylink.rtss.simulation.cbtc.communication.vo.*;
import club.joylink.rtss.simulation.cbtc.communication.vo.fault.DeviceFaultInfo; import club.joylink.rtss.simulation.cbtc.communication.vo.fault.DeviceFaultInfo;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Stand; import club.joylink.rtss.simulation.cbtc.data.map.Stand;
@ -56,7 +58,7 @@ public class Joylink3DMessageService {
trainList.forEach(train -> msgList.add(new TrainSpeed(train))); trainList.forEach(train -> msgList.add(new TrainSpeed(train)));
SocketMessageVO message = SocketMessageFactory SocketMessageVO message = SocketMessageFactory
.build(WebSocketMessageType.TrainRun_3D, .build(WebSocketMessageType.TrainRun_3D,
simulation.getGroup(), msgList); simulation.getId(), msgList);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
} }
@ -79,7 +81,7 @@ public class Joylink3DMessageService {
} }
} }
} }
SocketMessageVO message = SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getGroup(), list); SocketMessageVO message = SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getId(), list);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -89,7 +91,7 @@ public class Joylink3DMessageService {
* @param simulation * @param simulation
*/ */
public void collectAndSendTrainHmiDisplayMessage(Simulation simulation) { public void collectAndSendTrainHmiDisplayMessage(Simulation simulation) {
List<SimulationMember> drivers = simulation.queryAllDrivers(); List<SimulationMember> drivers = simulation.querySimulationMembersOfRole(SimulationMember.Type.DRIVER);
SimulationDataRepository repository = simulation.getRepository(); SimulationDataRepository repository = simulation.getRepository();
for (SimulationMember driver : drivers) { for (SimulationMember driver : drivers) {
if (!driver.isRobot()) { if (!driver.isRobot()) {
@ -100,13 +102,13 @@ public class Joylink3DMessageService {
trainHmi = new TrainHmiDisplay(train); trainHmi = new TrainHmiDisplay(train);
repository.addTrainHmi(trainHmi); repository.addTrainHmi(trainHmi);
message = SocketMessageFactory message = SocketMessageFactory
.buildHmiMessage(simulation.getGroup(), new TrainHmiDisplay(train)); .buildHmiMessage(simulation.getId(), new TrainHmiDisplay(train));
} else { } else {
Map<String, Object> map = trainHmi.changeAndCollectDiff(train); Map<String, Object> map = trainHmi.changeAndCollectDiff(train);
message = SocketMessageFactory message = SocketMessageFactory
.buildHmiMessage(simulation.getGroup(), map); .buildHmiMessage(simulation.getId(), map);
} }
this.stompMessageService.sendToUser(driver.getUserIdStr(), message); this.stompMessageService.sendToUser(driver.getUserId(), message);
} }
} }
} }
@ -122,7 +124,7 @@ public class Joylink3DMessageService {
} }
SocketMessageVO message = SocketMessageFactory SocketMessageVO message = SocketMessageFactory
.build(WebSocketMessageType.Device_Load_Destroy_3D, .build(WebSocketMessageType.Device_Load_Destroy_3D,
simulation.getGroup(), displayList); simulation.getId(), displayList);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -138,8 +140,8 @@ public class Joylink3DMessageService {
if (simulation.getRepository().isVrTrainOnline(train.getGroupNumber())) { if (simulation.getRepository().isVrTrainOnline(train.getGroupNumber())) {
TrainPosition position = new TrainPosition(train); TrainPosition position = new TrainPosition(train);
SocketMessageVO<TrainPosition> message = SocketMessageFactory SocketMessageVO<TrainPosition> message = SocketMessageFactory
.build(WebSocketMessageType.Train_Position, simulation.getGroup(), position); .build(WebSocketMessageType.Train_Position, simulation.getId(), position);
this.stompMessageService.sendToUser(member.getUserIdStr(), message); this.stompMessageService.sendToUser(member.getUserId(), message);
} }
} }
}); });
@ -251,10 +253,10 @@ public class Joylink3DMessageService {
List<VirtualRealityTrain> onlineTrainList = repository.getOnlineTrainList(); List<VirtualRealityTrain> onlineTrainList = repository.getOnlineTrainList();
onlineTrainList.forEach(train -> initDeviceList.addAll(this.collectTrainInitData(train))); onlineTrainList.forEach(train -> initDeviceList.addAll(this.collectTrainInitData(train)));
// 设备故障信息 // 设备故障信息
List<DeviceFaultInfo> deviceFaultInfos = this.groupSimulationService.getSimulationDeviceFaultInfoList(simulation.getGroup()); List<DeviceFaultInfo> deviceFaultInfos = this.groupSimulationService.getSimulationDeviceFaultInfoList(simulation.getId());
SandBoxInitDeviceVO initDeviceVO = new SandBoxInitDeviceVO(initDeviceList, deviceFaultInfos); SandBoxInitDeviceVO initDeviceVO = new SandBoxInitDeviceVO(initDeviceList, deviceFaultInfos);
SocketMessageVO<SandBoxInitDeviceVO> message = SocketMessageFactory SocketMessageVO<SandBoxInitDeviceVO> message = SocketMessageFactory
.build(WebSocketMessageType.Device_Load_Destroy_3D, simulation.getGroup(), initDeviceVO); .build(WebSocketMessageType.Device_Load_Destroy_3D, simulation.getId(), initDeviceVO);
this.stompMessageService.sendToUser(new HashSet<>(userList), message); this.stompMessageService.sendToUser(new HashSet<>(userList), message);
} }
@ -262,9 +264,9 @@ public class Joylink3DMessageService {
List<VirtualRealityTrain> allTrain = simulation.getRepository().getOnlineTrainList(); List<VirtualRealityTrain> allTrain = simulation.getRepository().getOnlineTrainList();
List<TrainPosition> trainPositions = List<TrainPosition> trainPositions =
allTrain.stream().map(TrainPosition::new).collect(Collectors.toList()); allTrain.stream().map(TrainPosition::new).collect(Collectors.toList());
List<SimulationMember> drivers = simulation.getSimulationMembersByType(SimulationMember.Type.DRIVER); List<SimulationMember> drivers = simulation.querySimulationMembersOfRole(SimulationMember.Type.DRIVER);
SocketMessageVO<Collection<TrainPosition>> message = SocketMessageFactory.buildTrainPositionMessage(simulation.getGroup(), trainPositions); SocketMessageVO<Collection<TrainPosition>> message = SocketMessageFactory.buildTrainPositionMessage(simulation.getId(), trainPositions);
Set<String> driverUserIds = drivers.stream().map(SimulationMember::getUserIdStr).collect(Collectors.toSet()); Set<String> driverUserIds = drivers.stream().map(SimulationMember::getUserId).collect(Collectors.toSet());
this.stompMessageService.sendToUser(driverUserIds, message); this.stompMessageService.sendToUser(driverUserIds, message);
} }
@ -274,7 +276,7 @@ public class Joylink3DMessageService {
ControllableDevice ctrlMsg = event.getCtrlMsg(); ControllableDevice ctrlMsg = event.getCtrlMsg();
SocketMessageVO message = SocketMessageFactory SocketMessageVO message = SocketMessageFactory
.build(WebSocketMessageType.DeviceCtrl_3D, .build(WebSocketMessageType.DeviceCtrl_3D,
simulation.getGroup(), ctrlMsg); simulation.getId(), ctrlMsg);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -284,7 +286,7 @@ public class Joylink3DMessageService {
DeviceFaultInfo deviceFaultInfo = event.getDeviceFaultInfo(); DeviceFaultInfo deviceFaultInfo = event.getDeviceFaultInfo();
SocketMessageVO message = SocketMessageFactory SocketMessageVO message = SocketMessageFactory
.build(WebSocketMessageType.Device_Fault_Set_3D, .build(WebSocketMessageType.Device_Fault_Set_3D,
simulation.getGroup(), deviceFaultInfo); simulation.getId(), deviceFaultInfo);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -294,7 +296,7 @@ public class Joylink3DMessageService {
DeviceFaultInfo deviceFaultInfo = event.getDeviceFaultInfo(); DeviceFaultInfo deviceFaultInfo = event.getDeviceFaultInfo();
SocketMessageVO message = SocketMessageFactory SocketMessageVO message = SocketMessageFactory
.build(WebSocketMessageType.Device_Fault_Over_3D, .build(WebSocketMessageType.Device_Fault_Over_3D,
simulation.getGroup(), deviceFaultInfo); simulation.getId(), deviceFaultInfo);
this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); this.stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -320,8 +322,8 @@ public class Joylink3DMessageService {
if (member.getDevice() != null && member.getDevice() instanceof VirtualRealityTrain) { if (member.getDevice() != null && member.getDevice() instanceof VirtualRealityTrain) {
String groupNumber = ((VirtualRealityTrain) member.getDevice()).getGroupNumber(); String groupNumber = ((VirtualRealityTrain) member.getDevice()).getGroupNumber();
TrainHmiDisplay trainHmi = simulation.getRepository().queryTrainHmi(groupNumber); TrainHmiDisplay trainHmi = simulation.getRepository().queryTrainHmi(groupNumber);
if (trainHmi != null && StringUtils.hasText(member.getUserIdStr())) { if (trainHmi != null && StringUtils.hasText(member.getUserId())) {
this.stompMessageService.sendToUser(member.getUserIdStr(), SocketMessageFactory.buildHmiMessage(simulation.getGroup(), trainHmi)); this.stompMessageService.sendToUser(member.getUserId(), SocketMessageFactory.buildHmiMessage(simulation.getId(), trainHmi));
} }
} }
this.collectAndSend3DInitDeviceList(simulation, Arrays.asList(event.getUserId().toString())); this.collectAndSend3DInitDeviceList(simulation, Arrays.asList(event.getUserId().toString()));
@ -340,4 +342,13 @@ public class Joylink3DMessageService {
} }
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob(SimulationModule.TRAIN_SPEED.name(), () -> this.collectAndSendTrainSpeedMessage(simulation), SimulationConstants.TRAIN_SPEED_PUSH_RATE);
simulation.addFixedRateJob(SimulationModule.MESSAGE_3D.name(), () -> {
this.collectAndSendTrainHmiDisplayMessage(simulation);
this.tdtStatusCollectAndSend(simulation);
}, SimulationConstants.SEND_CLIENT_RATE);
simulation.addFixedRateJob(SimulationModule.TRAIN_POSITION_3D.name(), () -> this.collectAndSendTrainPositionMessage(simulation), SimulationConstants.TRAIN_POSITION_RATE);
simulation.addFixedRateJob(SimulationModule.DRIVE_POSITION.name(), () -> this.syncTrainDrivePosition(simulation), SimulationConstants.TRAIN_DRIVE_POSITION_SYNC_RATE);
}
} }

View File

@ -64,7 +64,6 @@ public class CompetitionAndScriptManager {
@Autowired @Autowired
private CompetitionErrorSetDAO competitionErrorSetDAO; private CompetitionErrorSetDAO competitionErrorSetDAO;
@Deprecated
public void run(Simulation simulation) { public void run(Simulation simulation) {
//--- 确认剧本需要运行 --- //--- 确认剧本需要运行 ---
CompetitionBO competition = simulation.getCompetition(); CompetitionBO competition = simulation.getCompetition();
@ -72,9 +71,6 @@ public class CompetitionAndScriptManager {
if (script == null || !script.isStarted()) { if (script == null || !script.isStarted()) {
return; return;
} }
if (simulation.isPause()) {
this.simulationLifeCycleService.resume(simulation);
}
ScriptActionBO unfinishedAction = script.getNextNeedPassAction(); ScriptActionBO unfinishedAction = script.getNextNeedPassAction();
if (unfinishedAction == null) { if (unfinishedAction == null) {
script.end(); script.end();
@ -296,7 +292,7 @@ public class CompetitionAndScriptManager {
//保存错误信息 //保存错误信息
CompetitionErrorSet error = new CompetitionErrorSet(); CompetitionErrorSet error = new CompetitionErrorSet();
error.setCompetitionId(competition.getId()); error.setCompetitionId(competition.getId());
error.setUserId(conversationMessage.getMember().getUserId()); error.setUserId(Long.parseLong(conversationMessage.getMember().getUserId()));
error.setActionId(action.getId()); error.setActionId(action.getId());
error.setRight(action.getContent()); error.setRight(action.getContent());
error.setWrong(replacedContent); error.setWrong(replacedContent);
@ -433,7 +429,7 @@ public class CompetitionAndScriptManager {
} }
ScriptBO script = simulation.getScript(); ScriptBO script = simulation.getScript();
ScriptActionBO action = script.getNextNeedPassAction(); ScriptActionBO action = script.getNextNeedPassAction();
SimulationMember member = simulation.getMemberByUserId(user.getId()); SimulationMember member = simulation.getSimulationMemberByUserId(user.getId());
if (action == null if (action == null
|| !ScriptActionBO.ActionType.Operation.equals(action.getType()) || !ScriptActionBO.ActionType.Operation.equals(action.getType())
|| !action.getMember().getId().equals(member.getId()) || !action.getMember().getId().equals(member.getId())
@ -454,11 +450,11 @@ public class CompetitionAndScriptManager {
} }
ScriptActionBO action = script.getNextNeedPassAction(); ScriptActionBO action = script.getNextNeedPassAction();
if (action == null || !ScriptActionBO.ActionType.Conversation.equals(action.getType())) { if (action == null || !ScriptActionBO.ActionType.Conversation.equals(action.getType())) {
log.warn(String.format("仿真[%s]剧本中没有需通过的动作或动作类型不是会话", simulation.getGroup())); log.warn(String.format("仿真[%s]剧本中没有需通过的动作或动作类型不是会话", simulation.getId()));
return; return;
} }
if (!conversationMessageId.equals(action.getConversationMessageId())) { if (!conversationMessageId.equals(action.getConversationMessageId())) {
log.warn(String.format("仿真[%s]播放完毕的语音和需通过的动作不匹配", simulation.getGroup())); log.warn(String.format("仿真[%s]播放完毕的语音和需通过的动作不匹配", simulation.getId()));
return; return;
} }
action.finish(); action.finish();

View File

@ -36,7 +36,7 @@ public interface SimulationConstants {
int TIME_LOOP_RATE = 20; int TIME_LOOP_RATE = 20;
/** 时间同步给客户端循环逻辑频率单位ms */ /** 时间同步给客户端循环逻辑频率单位ms */
int SYNC_TIME_RATE = 10 * 1000; int SYNC_TIME_RATE = 1000;
/**状态推送间隔,单位ms*/ /**状态推送间隔,单位ms*/
int SEND_CLIENT_RATE = 1000; int SEND_CLIENT_RATE = 1000;

View File

@ -65,7 +65,7 @@ public class ConversationManagerService {
throw new SimulationException(SimulationExceptionType.Invalid_Operation, "一个人不能开启会话"); throw new SimulationException(SimulationExceptionType.Invalid_Operation, "一个人不能开启会话");
} }
Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group); Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group);
SimulationUser simulationUser = simulation.getSimulationUserByUserId(userVO.getId()); SimulationUser simulationUser = simulation.getSimulationUserById(userVO.getId());
SimulationMember creator = simulationUser.getPlayedMember(); SimulationMember creator = simulationUser.getPlayedMember();
if (Objects.isNull(creator)) { if (Objects.isNull(creator)) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL); throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL);
@ -96,7 +96,7 @@ public class ConversationManagerService {
if (simulationMember.isRobot()) { if (simulationMember.isRobot()) {
conversationMember.connect(); conversationMember.connect();
} else { } else {
SimulationUser simulationUser = simulation.getSimulationUserByUserId(simulationMember.getUserId()); SimulationUser simulationUser = simulation.getSimulationUserById(simulationMember.getUserId());
if (simulationUser.isOnline()) { if (simulationUser.isOnline()) {
conversationMember.connect(); conversationMember.connect();
} }
@ -112,7 +112,7 @@ public class ConversationManagerService {
/*---------------------------------- (创建会话)需要被邀请者同意 ----------------------------------*/ /*---------------------------------- (创建会话)需要被邀请者同意 ----------------------------------*/
public ConversationVO createConversation(String group, UserVO user, CommunicationObject object, List<String> memberIds) { public ConversationVO createConversation(String group, UserVO user, CommunicationObject object, List<String> memberIds) {
Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group); Simulation simulation = this.groupSimulationCache.getSimulationByGroup(group);
SimulationUser simulationUser = simulation.getSimulationUserByUserId(user.getId()); SimulationUser simulationUser = simulation.getSimulationUserById(user.getId());
SimulationMember creator = simulationUser.getPlayedMember(); SimulationMember creator = simulationUser.getPlayedMember();
if (Objects.isNull(creator)) { if (Objects.isNull(creator)) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL); throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL);
@ -125,7 +125,7 @@ public class ConversationManagerService {
if (!CollectionUtils.isEmpty(memberIds)) { if (!CollectionUtils.isEmpty(memberIds)) {
members.addAll(memberIds.stream().map(simulation::getSimulationMemberById).filter(simulationMember -> { members.addAll(memberIds.stream().map(simulation::getSimulationMemberById).filter(simulationMember -> {
if(Objects.nonNull(simulationMember.getUserId())){ if(Objects.nonNull(simulationMember.getUserId())){
SimulationUser simulationUser = simulation.querySimulationUserByUserId(simulationMember.getUserId()); SimulationUser simulationUser = simulation.querySimulationUserById(simulationMember.getUserId());
return simulationUser.isOnline(); return simulationUser.isOnline();
} }
return true; return true;
@ -141,7 +141,7 @@ public class ConversationManagerService {
members.addAll(simulation.getMemberListByType(SimulationMember.Type.DRIVER)); members.addAll(simulation.getMemberListByType(SimulationMember.Type.DRIVER));
break; break;
case ALL_STATION: case ALL_STATION:
members.addAll(simulation.getSimulationMembersByType(SimulationMember.Type.STATION_SUPERVISOR)); members.addAll(simulation.getMemberListByType(SimulationMember.Type.STATION_SUPERVISOR));
break; break;
// case DEVICE_STATION:{ // case DEVICE_STATION:{
// Set<Station> stations = repository.getStationsByDeviceStations((Station) device); // Set<Station> stations = repository.getStationsByDeviceStations((Station) device);
@ -188,7 +188,7 @@ public class ConversationManagerService {
} }
if (!member.isRobot()) { if (!member.isRobot()) {
log.info(String.format("仿真[%s]会话[%s]邀请成员[%s]事件发布", log.info(String.format("仿真[%s]会话[%s]邀请成员[%s]事件发布",
simulation.getGroup(), conversation.getId(), member.toString())); simulation.getId(), conversation.getId(), member.toString()));
this.applicationEventPublisher.publishEvent(new SimulationConversationInviteEvent(this, simulation, conversation, member)); this.applicationEventPublisher.publishEvent(new SimulationConversationInviteEvent(this, simulation, conversation, member));
} else { } else {
this.connect2Conversation(simulation, conversation, member); this.connect2Conversation(simulation, conversation, member);

View File

@ -116,7 +116,7 @@ public class StorageStation extends StorageDevice {
if (applicant == null) { if (applicant == null) {
station.setApplicant(null); station.setApplicant(null);
} else { } else {
station.setApplicant(simulation.getMemberById(applicant)); station.setApplicant(simulation.getSimulationMemberById(applicant));
} }
station.setApply2TheControlMode(apply2TheControlMode); station.setApply2TheControlMode(apply2TheControlMode);
station.setValidDuration(validDuration); station.setValidDuration(validDuration);

View File

@ -73,7 +73,7 @@ public class SimulationVO {
creator.setNickname(user.getNickname()); creator.setNickname(user.getNickname());
int systemTime = simulation.getCorrectSystemTime().toLocalTime().toSecondOfDay(); int systemTime = simulation.getCorrectSystemTime().toLocalTime().toSecondOfDay();
return SimulationVO.builder() return SimulationVO.builder()
.group(simulation.getGroup()) .group(simulation.getId())
.map(mapVO) .map(mapVO)
.runPlan(runPlan) .runPlan(runPlan)
.creator(creator) .creator(creator)

View File

@ -23,7 +23,7 @@ public class VirtualRealityTrainVO extends DeviceVO {
public VirtualRealityTrainVO(VirtualRealityTrain train, SimulationMember driverMember) { public VirtualRealityTrainVO(VirtualRealityTrain train, SimulationMember driverMember) {
super(train.getCode(), train.getDeviceType()); super(train.getCode(), train.getDeviceType());
if(Objects.nonNull(driverMember) && !driverMember.isRobot()) { if(Objects.nonNull(driverMember) && !driverMember.isRobot()) {
this.driverId =driverMember.getUserIdStr(); this.driverId =driverMember.getUserId();
this.name = driverMember.getName(); this.name = driverMember.getName();
} }
this.groupNumber = train.getGroupNumber(); this.groupNumber = train.getGroupNumber();

View File

@ -157,7 +157,7 @@ public class SimulationRealDeviceThread {
} }
} catch (Exception e) { } catch (Exception e) {
log.error(String.format("仿真[%s]Modbus响应处理异常" log.error(String.format("仿真[%s]Modbus响应处理异常"
,simulation.getGroup()), e); ,simulation.getId()), e);
} }
} }
} }

View File

@ -117,4 +117,8 @@ public class SimulationRealDeviceConnectManager {
realDevice.disconnect(); realDevice.disconnect();
} }
} }
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob("PlcGatewayOnline", () -> this.updatePlcGatewayOnlineStatus(simulation), 1000);
}
} }

View File

@ -129,13 +129,13 @@ public class Heb1IbpServiceImpl implements RealDeviceService {
if (rbsxkm && !rbsxgm) { if (rbsxkm && !rbsxgm) {
if (!vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) { if (!vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) {
log.info(String.format("仿真[%s]IBP设备[%s]执行控制上行PSD开门", log.info(String.format("仿真[%s]IBP设备[%s]执行控制上行PSD开门",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
this.standService.controlVrPSD(simulation, vrPsd, true); this.standService.controlVrPSD(simulation, vrPsd, true);
} }
} else if (rbsxgm && !rbsxkm) { } else if (rbsxgm && !rbsxkm) {
if (!vrPsd.isSettingClose() && !vrPsd.isClose()) { if (!vrPsd.isSettingClose() && !vrPsd.isClose()) {
log.info(String.format("仿真[%s]IBP设备[%s]执行控制上行PSD关门", log.info(String.format("仿真[%s]IBP设备[%s]执行控制上行PSD关门",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
this.standService.controlVrPSD(simulation, vrPsd, false); this.standService.controlVrPSD(simulation, vrPsd, false);
} }
} }
@ -179,13 +179,13 @@ public class Heb1IbpServiceImpl implements RealDeviceService {
if (rbxxkm && !rbxxgm) { if (rbxxkm && !rbxxgm) {
if (!vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) { if (!vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) {
log.info(String.format("仿真[%s]IBP设备[%s]执行控制下行PSD开门", log.info(String.format("仿真[%s]IBP设备[%s]执行控制下行PSD开门",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
this.standService.controlVrPSD(simulation, vrPsd, true); this.standService.controlVrPSD(simulation, vrPsd, true);
} }
} else if (rbxxgm && !rbxxkm) { } else if (rbxxgm && !rbxxkm) {
if (!vrPsd.isSettingClose() && !vrPsd.isClose()) { if (!vrPsd.isSettingClose() && !vrPsd.isClose()) {
log.info(String.format("仿真[%s]IBP设备[%s]执行控制下行PSD关门", log.info(String.format("仿真[%s]IBP设备[%s]执行控制下行PSD关门",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
this.standService.controlVrPSD(simulation, vrPsd, false); this.standService.controlVrPSD(simulation, vrPsd, false);
} }
} }

View File

@ -106,7 +106,7 @@ public class Heb1PslServiceImpl implements RealDeviceService {
// 开门指令 // 开门指令
if (vrExist && !vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) { if (vrExist && !vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) {
log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD开门", log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD开门",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
this.standService.controlVrPSD(simulation, vrPsd, true); this.standService.controlVrPSD(simulation, vrPsd, true);
} }
} }
@ -115,7 +115,7 @@ public class Heb1PslServiceImpl implements RealDeviceService {
// 关门指令 // 关门指令
if (vrExist && !vrPsd.isSettingClose() && !vrPsd.isClose()) { if (vrExist && !vrPsd.isSettingClose() && !vrPsd.isClose()) {
log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD关门", log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD关门",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
this.standService.controlVrPSD(simulation, vrPsd, false); this.standService.controlVrPSD(simulation, vrPsd, false);
} }
} }
@ -123,11 +123,11 @@ public class Heb1PslServiceImpl implements RealDeviceService {
if (Objects.nonNull(vrPsd)) { if (Objects.nonNull(vrPsd)) {
if (rhsjc && !vrPsd.isInterlockRelease()) { if (rhsjc && !vrPsd.isInterlockRelease()) {
log.info(String.format("仿真[%s]PSL设备[%s]互锁解除执行", log.info(String.format("仿真[%s]PSL设备[%s]互锁解除执行",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
vrPsd.updateIL(true); vrPsd.updateIL(true);
} else if(!rhsjc && vrPsd.isInterlockRelease()) { } else if(!rhsjc && vrPsd.isInterlockRelease()) {
log.info(String.format("仿真[%s]PSL设备[%s]互锁解除取消", log.info(String.format("仿真[%s]PSL设备[%s]互锁解除取消",
simulation.getGroup(), pslConfig.getProjectDevice())); simulation.getId(), pslConfig.getProjectDevice()));
vrPsd.updateIL(false); vrPsd.updateIL(false);
} }
} }

View File

@ -1,8 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy; package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.PSD;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
@ -63,7 +61,7 @@ public class SdyPsdServiceImpl implements RealDeviceService {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice(); PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) { if (plcGateway == null) {
log.error(String.format("仿真[%s]没有plc", simulation.getGroup())); log.error(String.format("仿真[%s]没有plc", simulation.getId()));
return; return;
} }
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr(); int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();

View File

@ -1,6 +1,8 @@
package club.joylink.rtss.simulation.cbtc.device.virtual; package club.joylink.rtss.simulation.cbtc.device.virtual;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
@ -82,4 +84,7 @@ public class VRDeviceLogicLoop {
occupySectionList.forEach(section -> section.getVirtualAxleCounter().occupied(right)); occupySectionList.forEach(section -> section.getVirtualAxleCounter().occupied(right));
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.VRD.name(), () -> this.run(simulation), SimulationConstants.VRD_LOOP_RATE);
}
} }

View File

@ -200,4 +200,7 @@ public class VRTrainRunningService {
} }
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.TR.name(), () -> this.trainRunning(simulation), SimulationConstants.TRAIN_RUNNING_RATE);
}
} }

View File

@ -4,6 +4,8 @@ import club.joylink.rtss.simulation.cbtc.ATS.operation.service.*;
import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.FaultParam; import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.FaultParam;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.vo.client.fault.FaultRuleVO; import club.joylink.rtss.vo.client.fault.FaultRuleVO;
@ -88,7 +90,7 @@ public class FaultGenerator {
break; break;
} }
} }
log.debug("仿真[{}]自动故障[{}]触发",simulation.getGroup(),faultRule.getFaultType()); log.debug("仿真[{}]自动故障[{}]触发",simulation.getId(),faultRule.getFaultType());
} }
/** /**
@ -151,4 +153,7 @@ public class FaultGenerator {
return false; return false;
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.FAULT.name(), () -> this.simulationFaultGenerate(simulation), SimulationConstants.FAULT_GENERATE_RATE);
}
} }

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.simulation.cbtc.member; package club.joylink.rtss.simulation.cbtc.member;
import club.joylink.rtss.constants.MapPrdTypeEnum; import club.joylink.rtss.constants.MapPrdTypeEnum;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; 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.map.Station;
@ -25,6 +26,9 @@ public class MemberManager {
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired
private SimulationManager simulationManager;
/** /**
* 初始化仿真成员 * 初始化仿真成员
*/ */
@ -66,7 +70,7 @@ public class MemberManager {
if (prdType != null) { if (prdType != null) {
switch (prdType) { switch (prdType) {
case LOCAL: { case LOCAL: {
List<SimulationMember> supervisorList = simulation.getSimulationMembersByType(SimulationMember.Type.STATION_SUPERVISOR); List<SimulationMember> supervisorList = simulation.querySimulationMembersOfRole(SimulationMember.Type.STATION_SUPERVISOR);
this.playRole(simulation, userId, supervisorList.get(0).getId()); this.playRole(simulation, userId, supervisorList.get(0).getId());
break; break;
} }
@ -74,7 +78,7 @@ public class MemberManager {
case ISCS: case ISCS:
case CENTER: case CENTER:
case JOINT: { case JOINT: {
List<SimulationMember> dispatcherList = simulation.getSimulationMembersByType(SimulationMember.Type.DISPATCHER); List<SimulationMember> dispatcherList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DISPATCHER);
this.playRole(simulation, userId, dispatcherList.get(0).getId()); this.playRole(simulation, userId, dispatcherList.get(0).getId());
break; break;
} }
@ -123,7 +127,7 @@ public class MemberManager {
} }
SimulationMember member = new SimulationMember(simulation.getIdGenerator().nextMemberId(), type, device); SimulationMember member = new SimulationMember(simulation.getIdGenerator().nextMemberId(), type, device);
member.setName(name); member.setName(name);
simulation.addMember(member); simulation.addSimulationMember(member);
return member; return member;
} }
@ -134,7 +138,7 @@ public class MemberManager {
* @param memberId * @param memberId
*/ */
public void playRole(Simulation simulation, Long userId, String memberId) { public void playRole(Simulation simulation, Long userId, String memberId) {
SimulationUser simulationUser = simulation.getSimulationUserByUserId(userId); SimulationUser simulationUser = simulation.getSimulationUserById(userId);
SimulationMember member = simulation.getSimulationMemberById(memberId); SimulationMember member = simulation.getSimulationMemberById(memberId);
// 可以校验仿真用户是否可以扮演指定的角色 // 可以校验仿真用户是否可以扮演指定的角色
if (!simulationUser.canPlay(member)) { if (!simulationUser.canPlay(member)) {
@ -142,9 +146,10 @@ public class MemberManager {
} }
// 扮演角色 // 扮演角色
// 如果成员之前被其他用户扮演先取消此用户扮演 // 如果成员之前被其他用户扮演先取消此用户扮演
Long otherId = member.getUserId(); String otherId = member.getUserId();
if (Objects.nonNull(otherId) && !Objects.equals(otherId, userId)) {
SimulationUser oldPlayer = simulation.getSimulationUserByUserId(otherId); if (Objects.nonNull(otherId) && !Objects.equals(otherId, userId.toString())) {
SimulationUser oldPlayer = simulation.getSimulationUserById(otherId);
this.cancelPlay(simulation, oldPlayer); this.cancelPlay(simulation, oldPlayer);
} }
// 如果用户之前扮演其他角色取消用户之前的扮演 // 如果用户之前扮演其他角色取消用户之前的扮演
@ -157,13 +162,14 @@ public class MemberManager {
simulationUser.play(member); simulationUser.play(member);
SimulationUserPlayChangeEvent playChangeEvent = new SimulationUserPlayChangeEvent(this, simulation, simulationUser, null); SimulationUserPlayChangeEvent playChangeEvent = new SimulationUserPlayChangeEvent(this, simulation, simulationUser, null);
this.applicationContext.publishEvent(playChangeEvent); this.applicationContext.publishEvent(playChangeEvent);
this.simulationManager.memberPlayedByUser(simulation.getId(), memberId, userId.toString());
} }
/** /**
* 取消用户扮演 * 取消用户扮演
*/ */
public void cancelPlay(Simulation simulation, Long userId) { public void cancelPlay(Simulation simulation, Long userId) {
SimulationUser simulationUser = simulation.getSimulationUserByUserId(userId); SimulationUser simulationUser = simulation.getSimulationUserById(userId);
this.cancelPlay(simulation, simulationUser); this.cancelPlay(simulation, simulationUser);
} }
@ -187,7 +193,7 @@ public class MemberManager {
private void cancelMemberPlayed(Simulation simulation, String memberId) { private void cancelMemberPlayed(Simulation simulation, String memberId) {
SimulationMember member = simulation.getSimulationMemberById(memberId); SimulationMember member = simulation.getSimulationMemberById(memberId);
if (Objects.nonNull(member.getUserId())) { if (Objects.nonNull(member.getUserId())) {
SimulationUser simulationUser = simulation.getSimulationUserByUserId(member.getUserId()); SimulationUser simulationUser = simulation.getSimulationUserById(member.getUserId());
this.cancelPlay(simulation, simulationUser); this.cancelPlay(simulation, simulationUser);
} }
} }

View File

@ -3,6 +3,7 @@ package club.joylink.rtss.simulation.cbtc.member;
import club.joylink.rtss.simulation.cbtc.command.CommandBO; import club.joylink.rtss.simulation.cbtc.command.CommandBO;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement; import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.vo.SimulationMemberVO;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -14,7 +15,7 @@ import java.util.Objects;
* 仿真成员 * 仿真成员
*/ */
@Getter @Getter
public class SimulationMember { public class SimulationMember extends club.joylink.rtss.simulation.SimulationMember<SimulationMember.Type> {
private String id; private String id;
@ -27,11 +28,6 @@ public class SimulationMember {
*/ */
private Gender gender; private Gender gender;
/**
* 扮演用户id
*/
private Long userId;
/** /**
* 成员名称 * 成员名称
*/ */
@ -54,26 +50,15 @@ public class SimulationMember {
} }
public SimulationMember(String id, Type type, MapElement device, String name) { public SimulationMember(String id, Type type, MapElement device, String name) {
super(id, type);
this.id = id; this.id = id;
this.type = type; this.type = type;
this.device = device; this.device = device;
this.name = name; this.name = name;
} }
public void playedBy(UserVO user) {
this.userId = user.getId();
}
public void overPlay() {
this.userId = null;
}
public String getUserIdStr() {
return this.userId + "";
}
public boolean isRobot() { public boolean isRobot() {
return Objects.isNull(this.userId); return Objects.isNull(getUserId());
} }
public boolean isDriver() { public boolean isDriver() {
@ -111,11 +96,16 @@ public class SimulationMember {
"id='" + id + '\'' + "id='" + id + '\'' +
", role=" + type + ", role=" + type +
", device=" + deviceInfo + ", device=" + deviceInfo +
", userId=" + userId + ", userId=" + getUserId() +
", name='" + name + '\'' + ", name='" + name + '\'' +
'}'; '}';
} }
@Override
protected SimulationMemberVO buildVO() {
return null;
}
/** /**
* 仿真成员岗位 * 仿真成员岗位
*/ */

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.member;
import club.joylink.rtss.constants.Client; import club.joylink.rtss.constants.Client;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.vo.SimulationUserVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO; import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
@ -10,7 +11,7 @@ import lombok.Getter;
import java.util.Objects; import java.util.Objects;
@Getter @Getter
public class SimulationUser { public class SimulationUser extends club.joylink.rtss.simulation.SimulationUser {
private String group; private String group;
@ -42,7 +43,8 @@ public class SimulationUser {
private SimulationMember playedMember; private SimulationMember playedMember;
public SimulationUser(Simulation simulation, LoginUserInfoVO loginUserInfoVO) { public SimulationUser(Simulation simulation, LoginUserInfoVO loginUserInfoVO) {
this.group = simulation.getGroup(); super(String.valueOf(loginUserInfoVO.getUserVO().getId()));
this.group = simulation.getId();
this.user = loginUserInfoVO.getUserVO(); this.user = loginUserInfoVO.getUserVO();
this.projectDevice = loginUserInfoVO.getDeviceVO(); this.projectDevice = loginUserInfoVO.getDeviceVO();
if (Client.Referee.equals(loginUserInfoVO.getClient())) { if (Client.Referee.equals(loginUserInfoVO.getClient())) {
@ -54,13 +56,14 @@ public class SimulationUser {
} }
public SimulationUser(Simulation simulation, UserVO user) { public SimulationUser(Simulation simulation, UserVO user) {
this.group = simulation.getGroup(); super(user.getId().toString());
this.group = simulation.getId();
this.user = user; this.user = user;
} }
public void play(SimulationMember member) { public void play(SimulationMember member) {
this.playedMember = member; this.playedMember = member;
member.playedBy(this.user); member.playedBy(this);
} }
public void online() { public void online() {
@ -78,7 +81,7 @@ public class SimulationUser {
public SimulationMember cancelPlay() { public SimulationMember cancelPlay() {
SimulationMember member = this.playedMember; SimulationMember member = this.playedMember;
if (Objects.nonNull(this.playedMember)) { if (Objects.nonNull(this.playedMember)) {
this.playedMember.overPlay(); this.playedMember.playedBy(null);
this.playedMember = null; this.playedMember = null;
} }
return member; return member;
@ -103,4 +106,9 @@ public class SimulationUser {
} }
return true; return true;
} }
@Override
protected SimulationUserVO buildVO() {
return null;
}
} }

View File

@ -74,7 +74,7 @@ public class UserSimulationStatsManager {
if (simulation.isScriptMakingSimulation() || simulation.isScriptPreviewSimulation()) { if (simulation.isScriptMakingSimulation() || simulation.isScriptPreviewSimulation()) {
return; return;
} }
SimulationMember simulationMemberForSelf = simulation.findMemberByUserId(userId); SimulationMember simulationMemberForSelf = simulation.querySimulationMemberByUserId(userId);
if(Objects.nonNull(simulationMemberForSelf)){ if(Objects.nonNull(simulationMemberForSelf)){
simulation.exitValidConversationOnExitingSimulation(simulationMemberForSelf); simulation.exitValidConversationOnExitingSimulation(simulationMemberForSelf);
@ -94,7 +94,7 @@ public class UserSimulationStatsManager {
} }
//暂停并从map中移除仿真使用记录 //暂停并从map中移除仿真使用记录
String group = simulation.getGroup(); String group = simulation.getId();
Set<SimulationUseInfo> useInfos = simulationAndUseInfosMap.remove(group); Set<SimulationUseInfo> useInfos = simulationAndUseInfosMap.remove(group);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertCollectionNotEmpty(useInfos, String.format("仿真[%s]的使用未被记录", group)); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertCollectionNotEmpty(useInfos, String.format("仿真[%s]的使用未被记录", group));
useInfos.forEach(info -> { useInfos.forEach(info -> {
@ -105,7 +105,7 @@ public class UserSimulationStatsManager {
SimulationBuildParams buildParams = simulation.getBuildParams(); SimulationBuildParams buildParams = simulation.getBuildParams();
useInfos.forEach(info -> { useInfos.forEach(info -> {
Long userId = info.getUserId(); Long userId = info.getUserId();
SimulationMember member = simulation.findMemberByUserId(userId); SimulationMember member = simulation.querySimulationMemberByUserId(userId);
String memberType = member == null ? null : member.getType().name(); String memberType = member == null ? null : member.getType().name();
String prdType = buildParams.getProdType() == null ? null : buildParams.getProdType().getCode(); String prdType = buildParams.getProdType() == null ? null : buildParams.getProdType().getCode();
iUserSimulationStatService.addUserSimulationStats(userId, buildParams.getMap().getId(), iUserSimulationStatService.addUserSimulationStats(userId, buildParams.getMap().getId(),

View File

@ -716,4 +716,8 @@ public class ATPLogicLoop {
train.depart(); train.depart();
} }
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.ATP.name(), () -> this.run(simulation), SimulationConstants.ATP_LOOP_RATE);
}
} }

View File

@ -77,18 +77,18 @@ public class PassengerFlowSimulateService {
@EventListener @EventListener
public void simulationDestroy(SimulationDestroyEvent event) { public void simulationDestroy(SimulationDestroyEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]销毁,清理客流仿真数据", simulation.getGroup())); log.info(String.format("仿真[%s]销毁,清理客流仿真数据", simulation.getId()));
passengerFlowSimulationDataMap.remove(simulation.getGroup()); passengerFlowSimulationDataMap.remove(simulation.getId());
passengerFlowViewMap.remove(simulation.getGroup()); passengerFlowViewMap.remove(simulation.getId());
group2mapPassengerFlowID.remove(simulation.getGroup()); group2mapPassengerFlowID.remove(simulation.getId());
} }
@EventListener @EventListener
public void simulationReset(SimulationResetEvent event) { public void simulationReset(SimulationResetEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]初始化,清理客流仿真数据", simulation.getGroup())); log.info(String.format("仿真[%s]初始化,清理客流仿真数据", simulation.getId()));
passengerFlowSimulationDataMap.remove(simulation.getGroup()); passengerFlowSimulationDataMap.remove(simulation.getId());
passengerFlowViewMap.remove(simulation.getGroup()); passengerFlowViewMap.remove(simulation.getId());
} }
@Async("nsExecutor") @Async("nsExecutor")
@ -100,15 +100,15 @@ public class PassengerFlowSimulateService {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
PassengerFlowData passengerFlowData; PassengerFlowData passengerFlowData;
if(Objects.isNull(group2mapPassengerFlowID.get(simulation.getGroup()))){ if(Objects.isNull(group2mapPassengerFlowID.get(simulation.getId()))){
//查询默认的数据 //查询默认的数据
passengerFlowData = this.mapPassengerFlowDataService.queryPassengerFlowDataOfMap(mapId,null); passengerFlowData = this.mapPassengerFlowDataService.queryPassengerFlowDataOfMap(mapId,null);
if (passengerFlowData != null) { if (passengerFlowData != null) {
group2mapPassengerFlowID.put(simulation.getGroup(),passengerFlowData.getId()); group2mapPassengerFlowID.put(simulation.getId(),passengerFlowData.getId());
} }
}else{ }else{
//根据id查询数据 //根据id查询数据
passengerFlowData = this.mapPassengerFlowDataService.queryPassengerFlowDataOfMap(mapId,group2mapPassengerFlowID.get(simulation.getGroup())); passengerFlowData = this.mapPassengerFlowDataService.queryPassengerFlowDataOfMap(mapId,group2mapPassengerFlowID.get(simulation.getId()));
} }
if (Objects.isNull(passengerFlowData)) { if (Objects.isNull(passengerFlowData)) {
log.debug(String.format("仿真[%s]没有客流数据,不初始化客流", simulation.debugStr())); log.debug(String.format("仿真[%s]没有客流数据,不初始化客流", simulation.debugStr()));
@ -119,11 +119,11 @@ public class PassengerFlowSimulateService {
Map<String, TrainPassengerFlow> trainPassengerFlowMap = this.loadTrainPassengerFlow(simulation, passengerFlowData); Map<String, TrainPassengerFlow> trainPassengerFlowMap = this.loadTrainPassengerFlow(simulation, passengerFlowData);
PassengerFlowSimulationData data = new PassengerFlowSimulationData( PassengerFlowSimulationData data = new PassengerFlowSimulationData(
simulation.getGroup(), simulation.getId(),
passengerFlowData, passengerFlowData,
standPassengerFlowMap, standPassengerFlowMap,
trainPassengerFlowMap); trainPassengerFlowMap);
passengerFlowSimulationDataMap.put(simulation.getGroup(), data); passengerFlowSimulationDataMap.put(simulation.getId(), data);
// 发送初始化数据 // 发送初始化数据
this.sendStandPassengerFlowData(simulation, standPassengerFlowMap); this.sendStandPassengerFlowData(simulation, standPassengerFlowMap);
@ -148,7 +148,7 @@ public class PassengerFlowSimulateService {
String json = JsonUtils.writeValueNullableFieldAsString(trainPisList); String json = JsonUtils.writeValueNullableFieldAsString(trainPisList);
SocketMessageVO<String> message = SocketMessageFactory.build( SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.TRAIN_PIS, WebSocketMessageType.TRAIN_PIS,
simulation.getGroup(), json); simulation.getId(), json);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
} }
@ -166,7 +166,7 @@ public class PassengerFlowSimulateService {
String json2 = JsonUtils.writeValueNullableFieldAsString(trainPFNumList); String json2 = JsonUtils.writeValueNullableFieldAsString(trainPFNumList);
SocketMessageVO<String> message2 = SocketMessageFactory.build( SocketMessageVO<String> message2 = SocketMessageFactory.build(
WebSocketMessageType.TRAIN_PFI_NUM, WebSocketMessageType.TRAIN_PFI_NUM,
simulation.getGroup(), json2); simulation.getId(), json2);
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(users, message2); this.stompMessageService.sendToUser(users, message2);
} }
@ -182,7 +182,7 @@ public class PassengerFlowSimulateService {
String json1 = JsonUtils.writeValueNullableFieldAsString(standPFNumList); String json1 = JsonUtils.writeValueNullableFieldAsString(standPFNumList);
SocketMessageVO<String> message1 = SocketMessageFactory.build( SocketMessageVO<String> message1 = SocketMessageFactory.build(
WebSocketMessageType.STAND_PFI, WebSocketMessageType.STAND_PFI,
simulation.getGroup(), json1); simulation.getId(), json1);
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(users, message1); this.stompMessageService.sendToUser(users, message1);
} }
@ -193,9 +193,9 @@ public class PassengerFlowSimulateService {
if (Objects.isNull(simulation)) { if (Objects.isNull(simulation)) {
return; return;
} }
PassengerFlowSimulationData passengerFlowSimulationData = this.passengerFlowSimulationDataMap.get(simulation.getGroup()); PassengerFlowSimulationData passengerFlowSimulationData = this.passengerFlowSimulationDataMap.get(simulation.getId());
if (Objects.isNull(passengerFlowSimulationData)) { if (Objects.isNull(passengerFlowSimulationData)) {
log.debug(String.format("仿真[%s]没有客流数据", simulation.getGroup())); log.debug(String.format("仿真[%s]没有客流数据", simulation.getId()));
return; return;
} }
this.sendStandPassengerFlowData(simulation, passengerFlowSimulationData.getStandPassengerFlowMap()); this.sendStandPassengerFlowData(simulation, passengerFlowSimulationData.getStandPassengerFlowMap());
@ -313,7 +313,7 @@ public class PassengerFlowSimulateService {
String json = JsonUtils.writeValueNullableFieldAsString(sendDataList); String json = JsonUtils.writeValueNullableFieldAsString(sendDataList);
SocketMessageVO<String> message = SocketMessageFactory.build( SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.STAND_PFI, WebSocketMessageType.STAND_PFI,
simulation.getGroup(), json); simulation.getId(), json);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
//发给二维 //发给二维
Map<String, StandPassengerFlow> standPassengerFlowMap = passengerFlowSimulationData.getStandPassengerFlowMap(); Map<String, StandPassengerFlow> standPassengerFlowMap = passengerFlowSimulationData.getStandPassengerFlowMap();
@ -327,7 +327,7 @@ public class PassengerFlowSimulateService {
data.add(message2TD.new PassengerFlowMessageData2TD(station.getCode(), stationPassengerQuantity)); data.add(message2TD.new PassengerFlowMessageData2TD(station.getCode(), stationPassengerQuantity));
} }
SocketMessageVO<PassengerFlowMessage2TD> sendMessage = SocketMessageVO<PassengerFlowMessage2TD> sendMessage =
SocketMessageFactory.buildPassengerFlowMessage2TD(simulation.getGroup(), message2TD); SocketMessageFactory.buildPassengerFlowMessage2TD(simulation.getId(), message2TD);
stompMessageService.sendToUser(users, sendMessage); stompMessageService.sendToUser(users, sendMessage);
passengerFlowSimulationData.getHistoryPassengerMessage2TD().add(message2TD); passengerFlowSimulationData.getHistoryPassengerMessage2TD().add(message2TD);
} }
@ -402,7 +402,7 @@ public class PassengerFlowSimulateService {
String json = JsonUtils.writeValueNullableFieldAsString(sendData); String json = JsonUtils.writeValueNullableFieldAsString(sendData);
SocketMessageVO<String> message = SocketMessageFactory.build( SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.TRAIN_PFI_BL, WebSocketMessageType.TRAIN_PFI_BL,
simulation.getGroup(), json); simulation.getId(), json);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
// 发送站台数据变更 // 发送站台数据变更
Map<String, Object> sendStandData = new HashMap<>(); Map<String, Object> sendStandData = new HashMap<>();
@ -444,7 +444,7 @@ public class PassengerFlowSimulateService {
String json = JsonUtils.writeValueNullableFieldAsString(trainPisList); String json = JsonUtils.writeValueNullableFieldAsString(trainPisList);
SocketMessageVO<String> message = SocketMessageFactory.build( SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.TRAIN_PIS, WebSocketMessageType.TRAIN_PIS,
simulation.getGroup(), json); simulation.getId(), json);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
}); });
} }
@ -522,10 +522,10 @@ public class PassengerFlowSimulateService {
} }
private boolean handleOpenOrChangeView(UserVO userVO, Simulation simulation, MapElement mapElement) { private boolean handleOpenOrChangeView(UserVO userVO, Simulation simulation, MapElement mapElement) {
PassengerFlowViewInfo viewInfo = passengerFlowViewMap.get(simulation.getGroup()); PassengerFlowViewInfo viewInfo = passengerFlowViewMap.get(simulation.getId());
if (viewInfo == null) { if (viewInfo == null) {
viewInfo = new PassengerFlowViewInfo(userVO, simulation.getGroup()); viewInfo = new PassengerFlowViewInfo(userVO, simulation.getId());
passengerFlowViewMap.put(simulation.getGroup(), viewInfo); passengerFlowViewMap.put(simulation.getId(), viewInfo);
} }
if (!viewInfo.containsView(mapElement.getDeviceType())) { if (!viewInfo.containsView(mapElement.getDeviceType())) {
// 添加视图 // 添加视图
@ -535,14 +535,14 @@ public class PassengerFlowSimulateService {
// 发送视图设备变更消息 // 发送视图设备变更消息
SocketMessageVO message = SocketMessageFactory.build( SocketMessageVO message = SocketMessageFactory.build(
WebSocketMessageType.PFV, WebSocketMessageType.PFV,
simulation.getGroup(), mapElement.getCode()); simulation.getId(), mapElement.getCode());
this.stompMessageService.sendToUser(userVO.getIdStr(), message); this.stompMessageService.sendToUser(userVO.getIdStr(), message);
return false; return false;
} }
} }
private boolean handleCloseView(UserVO userVO, Simulation simulation, MapElement mapElement) { private boolean handleCloseView(UserVO userVO, Simulation simulation, MapElement mapElement) {
PassengerFlowViewInfo viewInfo = passengerFlowViewMap.get(simulation.getGroup()); PassengerFlowViewInfo viewInfo = passengerFlowViewMap.get(simulation.getId());
if (viewInfo == null) { if (viewInfo == null) {
return false; return false;
} }

View File

@ -74,7 +74,7 @@ public class LargePassengerFlowStrategyService {
LpfStrategyRecommend recommend = new LpfStrategyRecommend(strategyCalculateData, recommendList); LpfStrategyRecommend recommend = new LpfStrategyRecommend(strategyCalculateData, recommendList);
String body = JsonUtils.writeValueAsString(recommend); String body = JsonUtils.writeValueAsString(recommend);
SocketMessageVO<String> message = SocketMessageFactory SocketMessageVO<String> message = SocketMessageFactory
.build(WebSocketMessageType.LPF_STRATEGY_RECOMMEND, simulation.getGroup(), body); .build(WebSocketMessageType.LPF_STRATEGY_RECOMMEND, simulation.getId(), body);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
// 设置下次推荐时间 // 设置下次推荐时间

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.simulation.cbtc.ATS.operation.handler.DriverOperateHand
import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStationService; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
@ -61,7 +62,7 @@ public class RobotLogicLoop {
* 机器人司机驾驶逻辑循环 * 机器人司机驾驶逻辑循环
*/ */
private void robotDriverLogicLoop(Simulation simulation) { private void robotDriverLogicLoop(Simulation simulation) {
List<SimulationMember> drivers = simulation.findMemberListByRole(SimulationMember.Type.DRIVER); List<SimulationMember> drivers = simulation.querySimulationMembersOfRole(SimulationMember.Type.DRIVER);
for (SimulationMember driver : drivers) { for (SimulationMember driver : drivers) {
if (!driver.isRobot()) if (!driver.isRobot())
continue; continue;
@ -282,4 +283,8 @@ public class RobotLogicLoop {
float fbMax = train.getCurrentFbMax(); float fbMax = train.getCurrentFbMax();
driverOperateHandler.changeTrainForce(simulation, train.getGroupNumber(), Math.max(fb / fbMax, -1)); driverOperateHandler.changeTrainForce(simulation, train.getGroupNumber(), Math.max(fb / fbMax, -1));
} }
public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.ROBOT.name(), () -> this.run(simulation), SimulationConstants.ROBOT_LOGIC_LOOP_RATE);
}
} }

View File

@ -119,7 +119,7 @@ public class ScriptActionBO {
private String conversationMessageId; private String conversationMessageId;
public ScriptActionBO(Simulation simulation, ScriptActionVO actionVO) { public ScriptActionBO(Simulation simulation, ScriptActionVO actionVO) {
SimulationMember member = simulation.findMemberById(actionVO.getMemberId()); SimulationMember member = simulation.querySimulationMemberById(actionVO.getMemberId());
this.id = simulation.getIdGenerator().nextActionId(); this.id = simulation.getIdGenerator().nextActionId();
this.type = actionVO.getType(); this.type = actionVO.getType();
this.member = member; this.member = member;

View File

@ -35,5 +35,9 @@ public abstract class SimulationJob {
} }
} }
public void updateRunTime() {
this.runtime = simulation.getSystemTime();
}
public abstract void afterRun(); public abstract void afterRun();
} }

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepositoryBuilder; import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepositoryBuilder;
import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic; import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import club.joylink.rtss.simulation.rt.RtSimulationUser;
import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.map.MapVO;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -34,7 +35,7 @@ public class AtsLogicService {
AtsRepository repository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class); AtsRepository repository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class);
List<List<Object>> messages = repository.removeReady2SendMessages(); List<List<Object>> messages = repository.removeReady2SendMessages();
if (!CollectionUtils.isEmpty(messages)) { if (!CollectionUtils.isEmpty(messages)) {
List<SimulationUser> simulationUsers = rtSimulation.getSimulationUsers(); List<RtSimulationUser> simulationUsers = rtSimulation.getSimulationUsers();
String dest = topic.buildDestination(rtSimulation.getId()); String dest = topic.buildDestination(rtSimulation.getId());
for (SimulationUser simulationUser : simulationUsers) { for (SimulationUser simulationUser : simulationUsers) {
if (simulationUser.isSubscribe(dest)) { if (simulationUser.isSubscribe(dest)) {

View File

@ -184,68 +184,68 @@ public class SocketMessageFactory {
// } // }
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOnlineMessage(Simulation simulation, SimulationUser simulationUser) { public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOnlineMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getGroup(), return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ONLINE)); new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ONLINE));
} }
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOfflineMessage(Simulation simulation, SimulationUser simulationUser) { public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserOfflineMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getGroup(), return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.OFFLINE)); new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.OFFLINE));
} }
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserKickOutMessage(Simulation simulation, SimulationUser simulationUser) { public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserKickOutMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getGroup(), return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.KICK_OUT)); new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.KICK_OUT));
} }
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserEnterMessage(Simulation simulation, SimulationUser simulationUser) { public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserEnterMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getGroup(), return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ENTER)); new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.ENTER));
} }
public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserPlayChangeMessage(Simulation simulation, SimulationUser simulationUser) { public static SocketMessageVO<SimulationUserMessageVO> buildSimulationUserPlayChangeMessage(Simulation simulation, SimulationUser simulationUser) {
return build(WebSocketMessageType.Simulation_User, simulation.getGroup(), return build(WebSocketMessageType.Simulation_User, simulation.getId(),
new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.PLAY_CHANGE)); new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.PLAY_CHANGE));
} }
public static SocketMessageVO<SimulationMemberMessageVO> buildSimulationMemberAddMessage(Simulation simulation, SimulationMember simulationMember) { public static SocketMessageVO<SimulationMemberMessageVO> buildSimulationMemberAddMessage(Simulation simulation, SimulationMember simulationMember) {
return build(WebSocketMessageType.Simulation_Member, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Member, simulation.getId(),
SimulationMemberMessageVO.buildAddMemberMessage(simulationMember)); SimulationMemberMessageVO.buildAddMemberMessage(simulationMember));
} }
public static SocketMessageVO<SimulationVO> buildSimulationInviteMessage(Simulation simulation) { public static SocketMessageVO<SimulationVO> buildSimulationInviteMessage(Simulation simulation) {
return build(WebSocketMessageType.Simulation_Invite, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Invite, simulation.getId(),
SimulationVO.buildBasicInfo(simulation)); SimulationVO.buildBasicInfo(simulation));
} }
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationCreateMessage(Simulation simulation, Conversation conversation) { public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationCreateMessage(Simulation simulation, Conversation conversation) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildCreateMessage(conversation)); ConversationSocketMessageVO.buildCreateMessage(conversation));
} }
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationInviteMessage(Simulation simulation, Conversation conversation, SimulationMember member) { public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationInviteMessage(Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildInviteMessage(conversation, member)); ConversationSocketMessageVO.buildInviteMessage(conversation, member));
} }
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationMemberConnectConversationMessage(Simulation simulation, Conversation conversation, SimulationMember member) { public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationMemberConnectConversationMessage(Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildMemberConnectConversationMessage(conversation, member)); ConversationSocketMessageVO.buildMemberConnectConversationMessage(conversation, member));
} }
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationChatMessage(Simulation simulation, Conversation conversation, ConversationMessage conversationMessage) { public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationChatMessage(Simulation simulation, Conversation conversation, ConversationMessage conversationMessage) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildConversationChatMessage(conversation, conversationMessage)); ConversationSocketMessageVO.buildConversationChatMessage(conversation, conversationMessage));
} }
public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationExitMessage(Simulation simulation, Conversation conversation, SimulationMember member) { public static SocketMessageVO<ConversationSocketMessageVO> buildSimulationConversationExitMessage(Simulation simulation, Conversation conversation, SimulationMember member) {
return build(WebSocketMessageType.Simulation_Conversation, simulation.getGroup(), return build(WebSocketMessageType.Simulation_Conversation, simulation.getId(),
ConversationSocketMessageVO.buildExitMessage(conversation, member)); ConversationSocketMessageVO.buildExitMessage(conversation, member));
} }
public static SocketMessageVO<Integer> buildSimulationTimeSyncMessage(Simulation simulation) { public static SocketMessageVO<Integer> buildSimulationTimeSyncMessage(Simulation simulation) {
int systemTime = simulation.getCorrectSystemTime().toLocalTime().toSecondOfDay(); int systemTime = simulation.getCorrectSystemTime().toLocalTime().toSecondOfDay();
return build(WebSocketMessageType.Simulation_Time_Sync, simulation.getGroup(), systemTime); return build(WebSocketMessageType.Simulation_Time_Sync, simulation.getId(), systemTime);
} }
public static SocketMessageVO<Map<String, IbpStatus>> buildSimulationIbpStatusMessage(String group, Map<String, IbpStatus> statusMap) { public static SocketMessageVO<Map<String, IbpStatus>> buildSimulationIbpStatusMessage(String group, Map<String, IbpStatus> statusMap) {

View File

@ -50,7 +50,7 @@ public class SimulationMemberVO {
this.deviceCode = member.getDevice().getCode(); this.deviceCode = member.getDevice().getCode();
} }
this.gender = member.getGender(); this.gender = member.getGender();
this.userId = member.getUserId(); this.userId = member.getUserId() == null ? null : Long.parseLong(member.getUserId());
this.name = member.getName(); this.name = member.getName();
} }