Merge branch 'test-training2' of https://git.code.tencent.com/lian-cbtc/rtss-server into test-training2

This commit is contained in:
weizhihong 2022-10-12 14:12:07 +08:00
commit ee8ad73e87
15 changed files with 788 additions and 321 deletions

View File

@ -506,6 +506,14 @@ public class SimulationV1Controller {
simulationService.removeFunctions(simulationId, functions, loginInfo); simulationService.removeFunctions(simulationId, functions, loginInfo);
} }
/**
* 按计划行车
*/
@PutMapping("/new/{simulationId}/runAsPlan")
public void runAsPlanNew(@PathVariable String simulationId, @RequestBody @Validated RunAsPlanParam param) {
simulationService.runAsPlan(simulationId, param);
}
/** /**
* 重置仿真 * 重置仿真
*/ */

View File

@ -681,6 +681,13 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation<Simulati
return this.getSimulationMembers().stream().filter(member1 -> member1.isSame(device)).collect(Collectors.toList()); return this.getSimulationMembers().stream().filter(member1 -> member1.isSame(device)).collect(Collectors.toList());
} }
public List<SimulationMember> getSimulationMembersByDeviceCode(String deviceCode) {
MapElement device = repository.getByCode(deviceCode);
List<SimulationMember> list = getSimulationMembersByDevice(device);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertCollectionNotEmpty(list, "[code:%s]无对应的仿真成员");
return list;
}
public SimulationMember querySimulationMember(MapElement device, SimulationMember.Type memberType) { public SimulationMember querySimulationMember(MapElement device, SimulationMember.Type memberType) {
return getSimulationMembers().stream() return getSimulationMembers().stream()
.filter(member -> Objects.equals(member.getDevice(), device)) .filter(member -> Objects.equals(member.getDevice(), device))

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO; import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import lombok.NonNull; import lombok.NonNull;
import java.util.List; import java.util.List;
@ -23,6 +24,11 @@ public interface SimulationService {
*/ */
void removeFunctions(String simulationId, List<Simulation.Function> functions, LoginUserInfoVO loginInfo); void removeFunctions(String simulationId, List<Simulation.Function> functions, LoginUserInfoVO loginInfo);
/**
* 按计划行车
*/
void runAsPlan(String simulationId, RunAsPlanParam param);
/** /**
* 重置仿真 * 重置仿真
*/ */

View File

@ -3,12 +3,12 @@ package club.joylink.rtss.simulation.cbtc;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.SimulationManager; import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent; import club.joylink.rtss.simulation.cbtc.event.SimulationCreateSuccessEvent;
import club.joylink.rtss.simulation.cbtc.init.SimulationInitService;
import club.joylink.rtss.simulation.cbtc.init.SimulationInitServiceManager;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO; import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.simulation.cbtc.work.SimulationWorkService;
import club.joylink.rtss.simulation.cbtc.work.SimulationWorkServiceManager;
import club.joylink.rtss.simulation.messaging.websocket.DefaultMessageSender; import club.joylink.rtss.simulation.messaging.websocket.DefaultMessageSender;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import lombok.NonNull; import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -24,7 +24,7 @@ public class SimulationServiceImpl implements SimulationService {
@Autowired @Autowired
private SimulationManager simulationManager; private SimulationManager simulationManager;
@Autowired @Autowired
private SimulationInitServiceManager simulationInitServiceManager; private SimulationWorkServiceManager simulationWorkServiceManager;
@Autowired @Autowired
private GroupSimulationService groupSimulationService; private GroupSimulationService groupSimulationService;
@Autowired @Autowired
@ -34,13 +34,7 @@ public class SimulationServiceImpl implements SimulationService {
@Override @Override
public String createSimulation(@NonNull LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) { public String createSimulation(@NonNull LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) {
System.out.println(JsonUtils.writeValueAsString(workParamVO)); SimulationWorkService initService = simulationWorkServiceManager.getInitService(workParamVO.getType());
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO, "仿真创建参数不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO.getMapId(), "仿真线路id不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO.getType(), "仿真类型不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO.findUsage(), "仿真用途不能为空");
SimulationInitService initService = simulationInitServiceManager.getInitService(workParamVO.getType());
Simulation simulation = initService.create(loginUserInfoVO, workParamVO); Simulation simulation = initService.create(loginUserInfoVO, workParamVO);
// 删除旧仿真保存新仿真 // 删除旧仿真保存新仿真
@ -59,6 +53,7 @@ public class SimulationServiceImpl implements SimulationService {
if (!CollectionUtils.isEmpty(workParamVO.getFunctionMap())) { if (!CollectionUtils.isEmpty(workParamVO.getFunctionMap())) {
initService.addFunctions(simulation, workParamVO.getFunctionMap(), loginUserInfoVO); initService.addFunctions(simulation, workParamVO.getFunctionMap(), loginUserInfoVO);
} }
applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation));
// 仿真开始运行 // 仿真开始运行
simulationManager.start(simulation.getId()); simulationManager.start(simulation.getId());
@ -74,7 +69,7 @@ public class SimulationServiceImpl implements SimulationService {
private void addFunctions(@NonNull Simulation simulation, Map<Simulation.Function, Map<String, Object>> functionMap, LoginUserInfoVO loginInfo) { private void addFunctions(@NonNull Simulation simulation, Map<Simulation.Function, Map<String, Object>> functionMap, LoginUserInfoVO loginInfo) {
if (!CollectionUtils.isEmpty(functionMap)) { if (!CollectionUtils.isEmpty(functionMap)) {
Simulation.Type simulationType = simulation.getType(); Simulation.Type simulationType = simulation.getType();
SimulationInitService initService = simulationInitServiceManager.getInitService(simulationType); SimulationWorkService initService = simulationWorkServiceManager.getInitService(simulationType);
if (StringUtils.hasText(simulation.getCreatorId())) { if (StringUtils.hasText(simulation.getCreatorId())) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(), BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(),
"非仿真创建者不能使用该功能"); "非仿真创建者不能使用该功能");
@ -89,17 +84,24 @@ public class SimulationServiceImpl implements SimulationService {
removeFunctions(simulation, functions, loginInfo); removeFunctions(simulation, functions, loginInfo);
} }
@Override
public void runAsPlan(String simulationId, RunAsPlanParam param) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
SimulationWorkService initService = simulationWorkServiceManager.getInitService(simulation.getType());
initService.runAsPlan(simulation, param);
}
@Override @Override
public void reset(String simulationId) { public void reset(String simulationId) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class); Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
SimulationInitService initService = simulationInitServiceManager.getInitService(simulation.getType()); SimulationWorkService initService = simulationWorkServiceManager.getInitService(simulation.getType());
initService.reset(simulation); initService.reset(simulation);
} }
private void removeFunctions(@NonNull Simulation simulation, List<Simulation.Function> functions, LoginUserInfoVO loginInfo) { private void removeFunctions(@NonNull Simulation simulation, List<Simulation.Function> functions, LoginUserInfoVO loginInfo) {
if (!CollectionUtils.isEmpty(functions)) { if (!CollectionUtils.isEmpty(functions)) {
Simulation.Type simulationType = simulation.getType(); Simulation.Type simulationType = simulation.getType();
SimulationInitService initService = simulationInitServiceManager.getInitService(simulationType); SimulationWorkService initService = simulationWorkServiceManager.getInitService(simulationType);
if (StringUtils.hasText(simulation.getCreatorId())) { if (StringUtils.hasText(simulation.getCreatorId())) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(), BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(),
"非仿真创建者不能使用该功能"); "非仿真创建者不能使用该功能");

View File

@ -1,28 +0,0 @@
package club.joylink.rtss.simulation.cbtc.init;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import java.util.Collection;
import java.util.Map;
public interface SimulationInitService {
Simulation.Type getType();
Simulation create(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO createParamVO);
void loadData(Simulation simulation);
void addJobs(Simulation simulation);
void addMessagePublisher(Simulation simulation);
void init(Simulation simulation);
void reset(Simulation simulation);
void addFunctions(Simulation simulation, Map<Simulation.Function, Map<String, Object>> functionMap, LoginUserInfoVO loginInfo);
void removeFunctions(Simulation simulation, Collection<Simulation.Function> functions);
}

View File

@ -76,7 +76,7 @@ public class MemberManager {
public void init(Simulation simulation) { public void init(Simulation simulation) {
/* -----------默认创建一个行调,一个通号;车站和司机按设备创建----------- */ /* -----------默认创建一个行调,一个通号;车站和司机按设备创建----------- */
// 调度 // 调度
if (!simulation.getRepository().getConfig().isRailway()){ if (!simulation.getRepository().getConfig().isRailway()) {
this.addRole(simulation, SimulationMember.Type.DISPATCHER); this.addRole(simulation, SimulationMember.Type.DISPATCHER);
} }
// 通号 // 通号
@ -105,9 +105,9 @@ public class MemberManager {
if (simulation.getRepository().getConfig().isRailway()) { if (simulation.getRepository().getConfig().isRailway()) {
// 调度台--调度关联 // 调度台--调度关联
List<DisStation> disStationList = simulation.getRepository().getDisStationList(); List<DisStation> disStationList = simulation.getRepository().getDisStationList();
if(null!=disStationList){ if (null != disStationList) {
for(DisStation disStation : disStationList){ for (DisStation disStation : disStationList) {
this.addRole(simulation,SimulationMember.Type.DISPATCHER,disStation.getName()+"调度",disStation); this.addRole(simulation, SimulationMember.Type.DISPATCHER, disStation.getName() + "调度", disStation);
} }
} }
} }
@ -305,4 +305,56 @@ public class MemberManager {
this.cancelPlay(simulation, userId); this.cancelPlay(simulation, userId);
} }
} }
public void addRailMembers(Simulation simulation) {
// 调度
if (!simulation.getRepository().getConfig().isRailway()) {
this.addRole(simulation, SimulationMember.Type.DISPATCHER);
}
// 通号
this.addRole(simulation, SimulationMember.Type.MAINTAINER);
// 行值
List<Station> stationList = simulation.getRepository().getSortedStationList();
for (Station station : stationList) {
// if (station.isNormal()) {
// this.addRole(simulation, SimulationMember.Type.STATION_SUPERVISOR, null, station);
// } else if (station.isDepot()) {
// // 车辆段调度
// this.addRole(simulation, SimulationMember.Type.DEPOT_DISPATCHER, station.getName() + "调度", station);
// }
Arrays.asList(
SimulationMember.Type.STATION_SUPERVISOR,
SimulationMember.Type.STATION_ASSISTANT, SimulationMember.Type.STATION_MASTER,
SimulationMember.Type.STATION_SIGNALER, SimulationMember.Type.STATION_PASSENGER,
SimulationMember.Type.STATION_SWITCH_MAN, SimulationMember.Type.STATION_FACILITATOR,
SimulationMember.Type.STATION_WORKER, SimulationMember.Type.DEVICE_MANAGER
).forEach(type -> this.addRole(simulation, type, null, station));
}
// 调度台--调度关联
List<DisStation> disStationList = simulation.getRepository().getDisStationList();
if (null != disStationList) {
for (DisStation disStation : disStationList) {
this.addRole(simulation, SimulationMember.Type.DISPATCHER, disStation.getName() + "调度", disStation);
}
}
// 司机
List<VirtualRealityTrain> vrTrainList = simulation.getRepository().getAllVrTrain();
for (VirtualRealityTrain vrTrain : vrTrainList) {
this.addRole(simulation, SimulationMember.Type.DRIVER, null, vrTrain);
}
// // 工电调度
// this.addRole(simulation, SimulationMember.Type.ELECTRIC_DISPATCHER);
// // 车辆段调度
// this.addRole(simulation, SimulationMember.Type.DEPOT_DISPATCHER);
// // 车辆段信号楼
// this.addRole(simulation, SimulationMember.Type.DEPOT_SIGNAL_BUILDING);
// // 停车场信号楼
// this.addRole(simulation, SimulationMember.Type.PARKING_LOT_SIGNAL_BUILDING);
// 上级部门
this.addRole(simulation, SimulationMember.Type.PARENT_DEPARTMENT);
// // 派班员
// this.addRole(simulation, SimulationMember.Type.SCHEDULING);
// // 车务段段长
// this.addRole(simulation, SimulationMember.Type.TRAIN_MASTER);
}
} }

View File

@ -20,14 +20,14 @@ public class PassengerFlowListener {
@Async("nsExecutor") @Async("nsExecutor")
@EventListener @EventListener
public void handle(SimulationRunAsPlanEvent event) { public void handle(SimulationRunAsPlanEvent event) {
if (passengerFlowSimulateService.initPassengerFlow(event)) { if (passengerFlowSimulateService.initPassengerFlow(event.getSimulation())) {
largePassengerFlowStrategyService.addJobs(event.getSimulation()); largePassengerFlowStrategyService.addJobs(event.getSimulation());
} }
} }
@EventListener @EventListener
public void handle(SimulationResetEvent event) { public void handle(SimulationResetEvent event) {
passengerFlowSimulateService.simulationReset(event); passengerFlowSimulateService.simulationReset(event.getSimulation());
largePassengerFlowStrategyService.removeJobs(event.getSimulation()); largePassengerFlowStrategyService.removeJobs(event.getSimulation());
} }
} }

View File

@ -14,8 +14,6 @@ import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.event.PassengerUserConnectEvent; import club.joylink.rtss.simulation.cbtc.event.PassengerUserConnectEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationDestroyEvent; import club.joylink.rtss.simulation.cbtc.event.SimulationDestroyEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationRunAsPlanEvent;
import club.joylink.rtss.simulation.cbtc.passenger.data.*; import club.joylink.rtss.simulation.cbtc.passenger.data.*;
import club.joylink.rtss.simulation.cbtc.passenger.strategy.Config; import club.joylink.rtss.simulation.cbtc.passenger.strategy.Config;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
@ -86,8 +84,7 @@ public class PassengerFlowSimulateService {
group2mapPassengerFlowID.remove(simulation.getId()); group2mapPassengerFlowID.remove(simulation.getId());
} }
public void simulationReset(SimulationResetEvent event) { public void simulationReset(Simulation simulation) {
Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]初始化,清理客流仿真数据", simulation.getId())); log.info(String.format("仿真[%s]初始化,清理客流仿真数据", simulation.getId()));
passengerFlowSimulationDataMap.remove(simulation.getId()); passengerFlowSimulationDataMap.remove(simulation.getId());
passengerFlowViewMap.remove(simulation.getId()); passengerFlowViewMap.remove(simulation.getId());
@ -98,8 +95,7 @@ public class PassengerFlowSimulateService {
/** /**
* @return 客流初始化成功 * @return 客流初始化成功
*/ */
public boolean initPassengerFlow(SimulationRunAsPlanEvent event) { public boolean initPassengerFlow(Simulation simulation) {
Simulation simulation = event.getSimulation();
MapVO map = simulation.getBuildParams().getMap(); MapVO map = simulation.getBuildParams().getMap();
Long mapId = map.getId(); Long mapId = map.getId();

View File

@ -0,0 +1,15 @@
package club.joylink.rtss.simulation.cbtc.vo;
import club.joylink.rtss.simulation.cbtc.Simulation;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class SingleClientParamVO {
private Simulation.Client client;
private String deviceCode;
}

View File

@ -0,0 +1,65 @@
package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.Map;
@Slf4j
@Service
public class EmergencySimulationWorkServiceImpl implements SimulationWorkService {
@Override
public Simulation.Type getType() {
return Simulation.Type.EMERGENCY;
}
@Override
public Simulation create(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) {
return null;
}
@Override
public void loadData(Simulation simulation) {
}
@Override
public void addJobs(Simulation simulation) {
}
@Override
public void addMessagePublisher(Simulation simulation) {
}
@Override
public void init(Simulation simulation) {
}
@Override
public void runAsPlan(Simulation simulation, RunAsPlanParam param) {
}
@Override
public void reset(Simulation simulation) {
}
@Override
public void addFunctions(Simulation simulation, Map<Simulation.Function, Map<String, Object>> functionMap, LoginUserInfoVO loginInfo) {
}
@Override
public void removeFunctions(Simulation simulation, Collection<Simulation.Function> functions) {
}
}

View File

@ -1,10 +1,11 @@
package club.joylink.rtss.simulation.cbtc.init; package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.entity.Ibp; import club.joylink.rtss.entity.Ibp;
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.iscs.IscsDeviceService; import club.joylink.rtss.services.iscs.IscsDeviceService;
import club.joylink.rtss.services.iscs.IscsSystemResourcesService; import club.joylink.rtss.services.iscs.IscsSystemResourcesService;
import club.joylink.rtss.services.project.DeviceService;
import club.joylink.rtss.services.psl.IVirtualRealityPslService; import club.joylink.rtss.services.psl.IVirtualRealityPslService;
import club.joylink.rtss.services.publishData.IbpService; import club.joylink.rtss.services.publishData.IbpService;
import club.joylink.rtss.services.runplan.IRunPlanParktimeService; import club.joylink.rtss.services.runplan.IRunPlanParktimeService;
@ -31,6 +32,8 @@ 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.onboard.ATP.ATPLogicLoop; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPLogicLoop;
import club.joylink.rtss.simulation.cbtc.onboard.TrainTargetUpdateService; import club.joylink.rtss.simulation.cbtc.onboard.TrainTargetUpdateService;
import club.joylink.rtss.simulation.cbtc.passenger.PassengerFlowSimulateService;
import club.joylink.rtss.simulation.cbtc.passenger.strategy.LargePassengerFlowStrategyService;
import club.joylink.rtss.simulation.cbtc.pis.PisLogicLoop; import club.joylink.rtss.simulation.cbtc.pis.PisLogicLoop;
import club.joylink.rtss.simulation.cbtc.robot.SimulationRobotService; import club.joylink.rtss.simulation.cbtc.robot.SimulationRobotService;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO; import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
@ -49,12 +52,13 @@ import club.joylink.rtss.vo.client.runplan.RunPlanVO;
import club.joylink.rtss.vo.client.runplan.user.RunPlanParkingTimeVO; import club.joylink.rtss.vo.client.runplan.user.RunPlanParkingTimeVO;
import club.joylink.rtss.vo.client.runplan.user.RunPlanRunlevelVO; import club.joylink.rtss.vo.client.runplan.user.RunPlanRunlevelVO;
import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.MapVO;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -65,7 +69,7 @@ import java.util.Objects;
@Slf4j @Slf4j
@Service @Service
public class MetroSimulationInitServiceImpl implements SimulationInitService { public class MetroSimulationWorkServiceImpl implements SimulationWorkService {
@Autowired @Autowired
private IMapService iMapService; private IMapService iMapService;
@Autowired @Autowired
@ -128,6 +132,14 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
private SimulationLifeCycleService simulationLifeCycleService; private SimulationLifeCycleService simulationLifeCycleService;
@Autowired @Autowired
private ITrainingV1Service iTrainingV1Service; private ITrainingV1Service iTrainingV1Service;
@Autowired
private PassengerFlowSimulateService passengerFlowSimulateService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private LargePassengerFlowStrategyService largePassengerFlowStrategyService;
@Autowired
private DeviceService deviceService;
@Override @Override
public Simulation.Type getType() { public Simulation.Type getType() {
@ -135,10 +147,10 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
} }
@Override @Override
public Simulation create(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO createParamVO) { public Simulation create(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) {
checkParam(createParamVO); checkParam(workParamVO);
SimulationBuildParams params = prepareSimulationParams(loginUserInfoVO, createParamVO); SimulationBuildParams params = prepareSimulationParams(loginUserInfoVO, workParamVO);
String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), createParamVO.getMapId()); String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), workParamVO.getMapId());
Simulation simulation = new Simulation(group); Simulation simulation = new Simulation(group);
simulation.setBuildParams(params); simulation.setBuildParams(params);
return simulation; return simulation;
@ -204,9 +216,61 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
playSimulationMember(simulation); playSimulationMember(simulation);
} }
@Override
public void runAsPlan(Simulation simulation, RunAsPlanParam param) {
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<Simulation.Function, Map<String, Object>> functionMap = workParamVO.getFunctionMap();
if (CollectionUtils.isEmpty(functionMap)) {
groupSimulationService.runAsPlan(simulation.getId(), param);
} else {
for (Map.Entry<Simulation.Function, Map<String, Object>> entry : functionMap.entrySet()) {
Simulation.Function function = entry.getKey();
Map<String, Object> funcParam = entry.getValue();
switch (function) {
case LPF:
boolean initSuccess = passengerFlowSimulateService.initPassengerFlow(simulation);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(initSuccess, "大客流初始化失败");
largePassengerFlowStrategyService.addJobs(simulation);
break;
case TRAINING_ROOM:
break;
case TRAINING_DESIGN:
break;
case TRAINING:
break;
case EXAM:
break;
}
}
}
}
@Override @Override
public void reset(Simulation simulation) { public void reset(Simulation simulation) {
simulationLifeCycleService.reset(simulation); simulationLifeCycleService.reset(simulation);
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<Simulation.Function, Map<String, Object>> functionMap = workParamVO.getFunctionMap();
if (!CollectionUtils.isEmpty(functionMap)) {
for (Map.Entry<Simulation.Function, Map<String, Object>> entry : functionMap.entrySet()) {
Simulation.Function function = entry.getKey();
Map<String, Object> funcParam = entry.getValue();
switch (function) {
case LPF:
passengerFlowSimulateService.simulationReset(simulation);
largePassengerFlowStrategyService.removeJobs(simulation);
break;
case TRAINING_ROOM:
break;
case TRAINING_DESIGN:
break;
case TRAINING:
break;
case EXAM:
break;
}
}
}
} }
@Override @Override
@ -267,13 +331,13 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
switch (usageInfo.getUsage()) { switch (usageInfo.getUsage()) {
case SINGLE_MEMBER: case SINGLE_MEMBER:
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertMapNotEmpty(usageInfo.getParam(), "单角色仿真必须指定角色"); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertMapNotEmpty(usageInfo.getParam(), "单角色仿真必须指定角色");
simulationMember = selectSimulationMemberFromParam(simulation, usageInfo); simulationMember = selectSimulationMemberByMemberInfo(simulation, usageInfo);
break; break;
case SINGLE_CLIENT: case SINGLE_CLIENT:
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("待实现"); throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("待实现");
case JOINT: case JOINT:
if (!CollectionUtils.isEmpty(usageInfo.getParam())) { if (!CollectionUtils.isEmpty(usageInfo.getParam())) {
simulationMember = selectSimulationMemberFromParam(simulation, usageInfo); simulationMember = selectSimulationMemberByMemberInfo(simulation, usageInfo);
} else { } else {
simulationMember = simulation.getMemberListByType(SimulationMember.Type.DISPATCHER).get(0); simulationMember = simulation.getMemberListByType(SimulationMember.Type.DISPATCHER).get(0);
} }
@ -287,32 +351,21 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
} }
} }
private SimulationMember selectSimulationMemberFromParam(Simulation simulation, SimulationWorkParamVO.UsageInfo usageInfo) { private SimulationMember selectSimulationMemberByMemberInfo(Simulation simulation, SimulationWorkParamVO.UsageInfo usageInfo) {
SingleMemberParamVO singleMemberParamVO = JsonUtils.read(JsonUtils.writeValueAsString(usageInfo.getParam()), SingleMemberParamVO.class); SingleMemberParamVO singleMemberParamVO = JsonUtils.read(JsonUtils.writeValueAsString(usageInfo.getParam()), SingleMemberParamVO.class);
SimulationMember.Type memberType = singleMemberParamVO.getMemberType(); SimulationMember.Type memberType = singleMemberParamVO.getMemberType();
String deviceCode = singleMemberParamVO.getDeviceCode(); String deviceCode = singleMemberParamVO.getDeviceCode();
SimulationMember simulationMember = null; SimulationMember simulationMember = null;
if (memberType != null && deviceCode != null) { if (memberType != null && StringUtils.hasText(deviceCode)) {
simulationMember = simulation.getSimulationMember(memberType, deviceCode); simulationMember = simulation.getSimulationMember(memberType, deviceCode);
} else if (memberType != null) { } else if (memberType != null) {
simulationMember = simulation.getMemberListByType(memberType).get(0); simulationMember = simulation.getMemberListByType(memberType).get(0);
} else if (deviceCode != null) { } else if (StringUtils.hasText(deviceCode)) {
simulationMember = simulation.getSimulationMember(memberType, deviceCode); simulationMember = simulation.getSimulationMembersByDeviceCode(deviceCode).get(0);
} }
return simulationMember; return simulationMember;
} }
/**
* 检查仿真创建参数
*/
private void checkParam(@NonNull SimulationWorkParamVO createParamVO) {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(createParamVO.getMapId());
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(createParamVO.getType());
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(createParamVO.findUsage());
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(!CollectionUtils.isEmpty(createParamVO.getFunctionMap())
&& createParamVO.getFunctionMap().size() > 1, "功能数量超限");
}
private void loadMapData(Simulation simulation) { private void loadMapData(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams(); SimulationBuildParams buildParams = simulation.getBuildParams();
simulation.setBuildParams(buildParams); simulation.setBuildParams(buildParams);
@ -342,24 +395,19 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap()); simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap());
simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.getSectionArriveNearMap()); simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.getSectionArriveNearMap());
simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap()); simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap());
// simulation.getRepository().setRouteUnitMap(mapDataBuildResult.getRouteUnitMap());
simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap()); simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap());
simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap()); simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap());
simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList()); simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList());
// simulation.getRepository().setRunLevelList(mapDataBuildResult.getRunLevelList());
simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap()); simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap());
simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap()); simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap());
simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap()); simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap());
// simulation.getRepository().setParkTimeMap(mapDataBuildResult.getParkTimeMap());
UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(), UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList()); buildParams.getMap(), mapDataBuildResult.getErrMsgList());
UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(), UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList()); buildParams.getMap(), mapDataBuildResult.getErrMsgList());
if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常 if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常
mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg))); mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg)));
if (!buildParams.getMap().getConfigVO().isRailway()) { simulation.setMapDataError(true);
simulation.setMapDataError(true);
}
simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList()); simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList());
} }
// 加载ISCS资源 // 加载ISCS资源
@ -370,15 +418,11 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
SimulationBuilder.checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan()); SimulationBuilder.checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan());
// 加载车辆段route path // 加载车辆段route path
SimulationBuilder.loadDepotInOutRoutePath(simulation); SimulationBuilder.loadDepotInOutRoutePath(simulation);
// CTC行车日志数据结构构建
if (simulation.getRepository().getConfig().isRailway()) {
SimulationBuilder.buildCtcStationRunPlanLog(simulation);
}
} }
private SimulationBuildParams prepareSimulationParams(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO createParamVO) { private SimulationBuildParams prepareSimulationParams(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) {
// 获取地图数据 // 获取地图数据
Long mapId = createParamVO.getMapId(); Long mapId = workParamVO.getMapId();
MapVO mapVO = iMapService.getMapDetail(mapId); MapVO mapVO = iMapService.getMapDetail(mapId);
List<RunPlanRunlevelVO> runLevelList = this.prepareRunLevelData(loginUserInfoVO, mapId); List<RunPlanRunlevelVO> runLevelList = this.prepareRunLevelData(loginUserInfoVO, mapId);
List<RunPlanParkingTimeVO> parkTimeList = this.prepareParkTimeData(loginUserInfoVO, mapId); List<RunPlanParkingTimeVO> parkTimeList = this.prepareParkTimeData(loginUserInfoVO, mapId);
@ -388,7 +432,7 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder(); SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder();
// 都有的属性构造 // 都有的属性构造
builder.loginUserInfo(loginUserInfoVO) builder.loginUserInfo(loginUserInfoVO)
.workParamVO(createParamVO) .workParamVO(workParamVO)
.createTime(LocalDateTime.now()) .createTime(LocalDateTime.now())
.map(mapVO) .map(mapVO)
.userRunLevelList(runLevelList) .userRunLevelList(runLevelList)
@ -396,7 +440,7 @@ public class MetroSimulationInitServiceImpl implements SimulationInitService {
.operationDefinitionList(operationDefinitionList); .operationDefinitionList(operationDefinitionList);
//运行图选择性构造 //运行图选择性构造
LocalDate runPlanDate = SimulationConstants.getRunPlanDate(); LocalDate runPlanDate = SimulationConstants.getRunPlanDate();
RunPlanVO runPlanVO = findRunPlan(createParamVO, loginUserInfoVO.getAccountVO().getId(), mapId); RunPlanVO runPlanVO = findRunPlan(workParamVO, loginUserInfoVO.getAccountVO().getId(), mapId);
if (Objects.nonNull(runPlanVO)) { if (Objects.nonNull(runPlanVO)) {
runPlanVO.setRunDate(runPlanDate); runPlanVO.setRunDate(runPlanDate);
builder.runPlan(runPlanVO); builder.runPlan(runPlanVO);

View File

@ -0,0 +1,254 @@
package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.ICommandService;
import club.joylink.rtss.services.IMapService;
import club.joylink.rtss.simulation.cbtc.ATS.ATSLogicLoop;
import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher;
import club.joylink.rtss.simulation.cbtc.CI.CiLogic;
import club.joylink.rtss.simulation.cbtc.CTC.CTCLogicLoop;
import club.joylink.rtss.simulation.cbtc.DeviceStatusService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.SimulationIdGenerator;
import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService;
import club.joylink.rtss.simulation.cbtc.fault.FaultGenerator;
import club.joylink.rtss.simulation.cbtc.member.MemberManager;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.member.SimulationUser;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPLogicLoop;
import club.joylink.rtss.simulation.cbtc.robot.SimulationRobotService;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.simulation.cbtc.vo.SingleMemberParamVO;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.CommandDefinitionVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import club.joylink.rtss.vo.map.MapVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@Service
public class RailwaySimulationWorkServiceImpl implements SimulationWorkService {
@Autowired
private IMapService iMapService;
@Autowired
private ICommandService iCommandService;
@Autowired
private MemberManager memberManager;
@Autowired
private ATSLogicLoop atsLogicLoop;
@Autowired
private CTCLogicLoop ctcLogicLoop;
@Autowired
private ATPLogicLoop atpLogicLoop;
@Autowired
private SimulationRobotService simulationRobotService;
@Autowired
private VRTrainRunningService vrTrainRunningService;
@Autowired
private CiLogic ciLogic;
@Autowired
private VRDeviceLogicLoop vrDeviceLogicLoop;
@Autowired
private ATSMessageCollectAndDispatcher atsMessageCollectAndDispatcher;
@Autowired
private Joylink3DMessageService joylink3DMessageService;
@Autowired
private FaultGenerator faultGenerator;
@Autowired
private DeviceStatusService deviceStatusService;
@Autowired
private SimulationLifeCycleService simulationLifeCycleService;
@Override
public Simulation.Type getType() {
return Simulation.Type.RAILWAY;
}
@Override
public Simulation create(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) {
checkParam(workParamVO);
SimulationBuildParams params = prepareSimulationParams(loginUserInfoVO, workParamVO);
String group = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), workParamVO.getMapId());
Simulation simulation = new Simulation(group);
simulation.setBuildParams(params);
return simulation;
}
@Override
public void loadData(Simulation simulation) {
SimulationBuildParams params = simulation.getBuildParams();
// 加载地图数据
loadMapData(simulation);
// // 车辆段
// depotService.loadDepotTrain(simulation);
// 添加仿真用户
SimulationUser simulationUser = new SimulationUser(simulation, params.getLoginUserInfo());
simulation.addSimulationUser(simulationUser);
// 添加仿真成员
memberManager.addRailMembers(simulation);
}
@Override
public void addJobs(Simulation simulation) {
ctcLogicLoop.addJobs(simulation);
atpLogicLoop.addJobs(simulation);
atsLogicLoop.addJobs(simulation);
simulationRobotService.addJobs(simulation);
vrTrainRunningService.addJobs(simulation);
ciLogic.addJobs(simulation);
vrDeviceLogicLoop.addJobs(simulation);
atsMessageCollectAndDispatcher.addJobs(simulation);
joylink3DMessageService.addJobs(simulation);
faultGenerator.addJobs(simulation);
}
@Override
public void addMessagePublisher(Simulation simulation) {
}
@Override
public void init(Simulation simulation) {
// 初始化设备状态
deviceStatusService.init(simulation);
// 根据使用方式设置用户扮演角色
playSimulationMember(simulation);
}
@Override
public void runAsPlan(Simulation simulation, RunAsPlanParam param) {
}
@Override
public void reset(Simulation simulation) {
simulationLifeCycleService.reset(simulation);
}
@Override
public void addFunctions(Simulation simulation, Map<Simulation.Function, Map<String, Object>> functionMap, LoginUserInfoVO loginInfo) {
}
@Override
public void removeFunctions(Simulation simulation, Collection<Simulation.Function> functions) {
}
private SimulationBuildParams prepareSimulationParams(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO) {
// 获取地图数据
Long mapId = workParamVO.getMapId();
MapVO mapVO = iMapService.getMapDetail(mapId);
// 获取操作定义数据
List<CommandDefinitionVO> operationDefinitionList = iCommandService
.queryDefinitionsByLineCode(mapVO.getLineCode());
SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder();
// 都有的属性构造
builder.loginUserInfo(loginUserInfoVO)
.workParamVO(workParamVO)
.createTime(LocalDateTime.now())
.map(mapVO)
.operationDefinitionList(operationDefinitionList);
return builder.build();
}
private void loadMapData(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
simulation.setBuildParams(buildParams);
if (Objects.nonNull(buildParams.getLoginUserInfo())) {
simulation.setCreatorId(buildParams.getLoginUserInfo().getAccountVO().getIdStr());
simulation.setProject(buildParams.getLoginUserInfo().getProject());
simulation.setProjectVO(buildParams.getLoginUserInfo().getProjectInfo());
}
// 线路配置参数
simulation.getRepository().setConfig(SimulationBuilder.buildConfig(buildParams.getMap().getConfigVO(),
buildParams.getMap().getGraphDataNew().getMapFunctionConfig()));
simulation.getRepository().getConfig()
.setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1());
simulation.getRepository().getConfig()
.setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger());
simulation.getRepository().getConfig()
.setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations());
simulation.getRepository().getConfig()
.setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot());
// 地图数据构建
SimulationBuilder.SimulationDeviceBuildResult mapDataBuildResult = SimulationBuilder.checkAndBuildMapData(buildParams.getMap());
simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap());
simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.getSectionArriveNearMap());
simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap());
simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap());
simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap());
simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap());
if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常
mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg)));
// simulation.setMapDataError(true); //目前大铁线路缺少数据导致检验不通过后续修改之后取消注释
simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList());
}
SimulationBuilder.loadDepotInOutRoutePath(simulation);
// CTC行车日志数据结构构建
if (simulation.getRepository().getConfig().isRailway()) {
SimulationBuilder.buildCtcStationRunPlanLog(simulation);
}
}
private void playSimulationMember(Simulation simulation) {
Long creatorId = simulation.getBuildParams().getLoginUserInfo().getAccountVO().getId();
SimulationWorkParamVO createParamVO = simulation.getBuildParams().getWorkParamVO();
SimulationWorkParamVO.UsageInfo usageInfo = createParamVO.getUsageInfo();
SimulationMember simulationMember = null;
if (usageInfo != null) {
switch (usageInfo.getUsage()) {
case SINGLE_MEMBER:
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertMapNotEmpty(usageInfo.getParam(), "单角色仿真必须指定角色");
simulationMember = selectSimulationMemberFromParam(simulation, usageInfo);
break;
case SINGLE_CLIENT:
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("待实现");
case JOINT:
if (!CollectionUtils.isEmpty(usageInfo.getParam())) {
simulationMember = selectSimulationMemberFromParam(simulation, usageInfo);
} else {
simulationMember = simulation.getMemberListByType(SimulationMember.Type.DISPATCHER).get(0);
}
break;
default:
throw new IllegalStateException("Unexpected value: " + usageInfo.getUsage());
}
}
if (simulationMember != null) {
memberManager.playRole(simulation, creatorId, simulationMember.getId());
}
}
private SimulationMember selectSimulationMemberFromParam(Simulation simulation, SimulationWorkParamVO.UsageInfo usageInfo) {
SingleMemberParamVO singleMemberParamVO = JsonUtils.read(JsonUtils.writeValueAsString(usageInfo.getParam()), SingleMemberParamVO.class);
SimulationMember.Type memberType = singleMemberParamVO.getMemberType();
String deviceCode = singleMemberParamVO.getDeviceCode();
SimulationMember simulationMember = null;
if (memberType != null && StringUtils.hasText(deviceCode)) {
simulationMember = simulation.getSimulationMember(memberType, deviceCode);
} else if (memberType != null) {
simulationMember = simulation.getMemberListByType(memberType).get(0);
} else if (StringUtils.hasText(deviceCode)) {
simulationMember = simulation.getSimulationMembersByDeviceCode(deviceCode).get(0);
}
return simulationMember;
}
}

View File

@ -0,0 +1,46 @@
package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import lombok.NonNull;
import org.springframework.util.CollectionUtils;
import java.util.Collection;
import java.util.Map;
public interface SimulationWorkService {
Simulation.Type getType();
Simulation create(LoginUserInfoVO loginUserInfoVO, SimulationWorkParamVO workParamVO);
void loadData(Simulation simulation);
void addJobs(Simulation simulation);
void addMessagePublisher(Simulation simulation);
void init(Simulation simulation);
void runAsPlan(Simulation simulation, RunAsPlanParam param);
void reset(Simulation simulation);
void addFunctions(Simulation simulation, Map<Simulation.Function, Map<String, Object>> functionMap, LoginUserInfoVO loginInfo);
void removeFunctions(Simulation simulation, Collection<Simulation.Function> functions);
/**
* 检查仿真参数
*/
default void checkParam(@NonNull SimulationWorkParamVO workParamVO) {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO, "仿真工作参数不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO.getMapId(), "仿真线路id不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO.getType(), "仿真类型不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(workParamVO.findUsage(), "仿真用途不能为空");
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(!CollectionUtils.isEmpty(workParamVO.getFunctionMap())
&& workParamVO.getFunctionMap().size() > 1, "功能数量超限");
}
}

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.simulation.cbtc.init; package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
@ -13,17 +13,17 @@ import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class SimulationInitServiceManager implements ApplicationContextAware { public class SimulationWorkServiceManager implements ApplicationContextAware {
private Map<Simulation.Type, SimulationInitService> map; private Map<Simulation.Type, SimulationWorkService> map;
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, SimulationInitService> services = applicationContext.getBeansOfType(SimulationInitService.class); Map<String, SimulationWorkService> services = applicationContext.getBeansOfType(SimulationWorkService.class);
map = services.values().stream().collect(Collectors.toMap(SimulationInitService::getType, Function.identity())); map = services.values().stream().collect(Collectors.toMap(SimulationWorkService::getType, Function.identity()));
} }
public SimulationInitService getInitService(@NonNull Simulation.Type simulationType) { public SimulationWorkService getInitService(@NonNull Simulation.Type simulationType) {
SimulationInitService initService = map.get(simulationType); SimulationWorkService initService = map.get(simulationType);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(initService, String.format("[%s]仿真未配置初始化服务", simulationType)); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(initService, String.format("[%s]仿真未配置初始化服务", simulationType));
return initService; return initService;
} }

View File

@ -1,222 +1,222 @@
server: server:
port: 9000 port: 9000
modbus-tcp: modbus-tcp:
port: 19000 port: 19000
udp: udp:
serverPort: 20002 serverPort: 20002
clientPort: 20001 clientPort: 20001
spring: spring:
profiles: profiles:
active: dev active: dev
application: application:
name: joylink-rtss name: joylink-rtss
jackson: jackson:
date-format: yyyy-MM-dd HH:mm:ss date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8 time-zone: GMT+8
default-property-inclusion: non_null default-property-inclusion: non_null
# 后续转为MINIO后删除 # 后续转为MINIO后删除
servlet: servlet:
multipart: multipart:
max-file-size: 10MB max-file-size: 10MB
# JavaMailSender 邮件发送的配置 # JavaMailSender 邮件发送的配置
mail: mail:
host: smtp.exmail.qq.com host: smtp.exmail.qq.com
port: 465 port: 465
username: serviceemai@joylink.club username: serviceemai@joylink.club
password: Jiulian0503 password: Jiulian0503
properties: properties:
mail: mail:
smtp: smtp:
auth: true auth: true
starttls: starttls:
enable: true enable: true
required: true required: true
socketFactory: socketFactory:
port: 465 port: 465
class: javax.net.ssl.SSLSocketFactory class: javax.net.ssl.SSLSocketFactory
fallback: false fallback: false
# 数据库连接配置 # 数据库连接配置
datasource: datasource:
driverClassName: com.mysql.cj.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver
hikari: hikari:
minimum-idle: 5 # 连接池维护的最小空闲连接数 minimum-idle: 5 # 连接池维护的最小空闲连接数
maximum-pool-size: 10 #配置最大连接池大小 maximum-pool-size: 10 #配置最大连接池大小
auto-commit: true #配置从池返回的连接的默认自动提交行为 auto-commit: true #配置从池返回的连接的默认自动提交行为
idle-timeout: 30000 # 允许连接在连接池中空闲的最长时间单位ms idle-timeout: 30000 # 允许连接在连接池中空闲的最长时间单位ms
pool-name: HikariPool pool-name: HikariPool
max-lifetime: 1800000 # 池中连接关闭后的最长生命周期单位ms max-lifetime: 1800000 # 池中连接关闭后的最长生命周期单位ms
connection-timeout: 30000 # 等待连接的超时时间单位ms connection-timeout: 30000 # 等待连接的超时时间单位ms
# mybatis 设置 # mybatis 设置
mybatis: mybatis:
mapper-locations: classpath:mybatis/mapper/*.xml mapper-locations: classpath:mybatis/mapper/*.xml
configuration: configuration:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
pagehelper: pagehelper:
helper-dialect: mysql helper-dialect: mysql
reasonable: true reasonable: true
support-methods-arguments: true support-methods-arguments: true
params: count=countSql params: count=countSql
# 微信配置 # 微信配置
wechat: wechat:
domain-uri: https://api.weixin.qq.com domain-uri: https://api.weixin.qq.com
wm-base-url: https://joylink.club/oss/joylink/%s?state=%s wm-base-url: https://joylink.club/oss/joylink/%s?state=%s
sp-app-id: wxe9150dbbcbf9440b sp-app-id: wxe9150dbbcbf9440b
sp-app-secret: 4b5d453e5ec246a3f1b72360c59e4fab sp-app-secret: 4b5d453e5ec246a3f1b72360c59e4fab
sp-app2-id: wxecb0321367be529c sp-app2-id: wxecb0321367be529c
sp-app2-secret: 3c31cb41588f27a78160092249123766 sp-app2-secret: 3c31cb41588f27a78160092249123766
sp-app3-id: wxe6140d5985333338 sp-app3-id: wxe6140d5985333338
sp-app3-secret: 6b7359860c22e3607467df421cd24eef sp-app3-secret: 6b7359860c22e3607467df421cd24eef
# 腾讯云 # 腾讯云
tencent-cloud: tencent-cloud:
app-id: 1400093601 app-id: 1400093601
app-key: 4a724df65b2bb7e4dc9b4302693f2485 app-key: 4a724df65b2bb7e4dc9b4302693f2485
domain-uri: https://yun.tim.qq.com/v5/tlssmssvr domain-uri: https://yun.tim.qq.com/v5/tlssmssvr
allow-send: true allow-send: true
# 环境连接配置 start # 环境连接配置 start
--- ---
spring: spring:
profiles: dev profiles: dev
datasource: datasource:
url: jdbc:mysql://192.168.3.233:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true url: jdbc:mysql://192.168.3.233:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root username: root
password: joylink0503 password: joylink0503
tencent-cloud: tencent-cloud:
allow-send: false allow-send: false
logging: logging:
file: file:
path: /logs/joylink/rtss path: /logs/joylink/rtss
max-size: 100MB max-size: 100MB
level: level:
club.joylink.rtss: DEBUG club.joylink.rtss: DEBUG
minio: minio:
endpoint: http://192.168.3.233 endpoint: http://192.168.3.233
accessKey: jladmin accessKey: jladmin
secretKey: Joylink@0503 secretKey: Joylink@0503
bucket: oss-rtss bucket: oss-rtss
replaceHttps: true replaceHttps: true
common: common:
env: dev env: dev
license-secret-key: joylink license-secret-key: joylink
--- ---
spring: spring:
profiles: local-test profiles: local-test
datasource: datasource:
url: jdbc:mysql://192.168.53.22:3306/joylink?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://192.168.53.22:3306/joylink?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root username: root
password: joylink0503 password: joylink0503
tencent-cloud: tencent-cloud:
allow-send: false allow-send: false
logging: logging:
file: file:
path: /usr/local/joylink/logs/rtss path: /usr/local/joylink/logs/rtss
level: level:
club.joylink.rtss: INFO club.joylink.rtss: INFO
minio: minio:
endpoint: http://192.168.3.233 endpoint: http://192.168.3.233
accessKey: jladmin accessKey: jladmin
secretKey: Joylink@0503 secretKey: Joylink@0503
bucket: oss-rtss bucket: oss-rtss
replaceHttps: true replaceHttps: true
common: common:
env: test env: test
--- ---
spring: spring:
profiles: local profiles: local
datasource: datasource:
url: jdbc:mysql://192.168.0.254:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true url: jdbc:mysql://192.168.0.254:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root username: root
password: localdb password: localdb
tencent-cloud: tencent-cloud:
allow-send: false allow-send: false
logging: logging:
file: file:
path: /usr/local/joylink/logs/rtss path: /usr/local/joylink/logs/rtss
level: level:
club.joylink.rtss: INFO club.joylink.rtss: INFO
minio: minio:
endpoint: http://192.168.3.233 endpoint: http://192.168.3.233
accessKey: jladmin accessKey: jladmin
secretKey: Joylink@0503 secretKey: Joylink@0503
bucket: oss-rtss bucket: oss-rtss
replaceHttps: true replaceHttps: true
common: common:
env: local env: local
license-secret-key: joylink license-secret-key: joylink
--- ---
spring: spring:
profiles: test profiles: test
datasource: datasource:
url: jdbc:mysql://172.16.0.128:3306/joylink?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://172.16.0.128:3306/joylink?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root username: root
password: Joylink@0503 password: Joylink@0503
tencent-cloud: tencent-cloud:
allow-send: false allow-send: false
logging: logging:
file: file:
path: /usr/local/joylink/logs/rtss path: /usr/local/joylink/logs/rtss
level: level:
club.joylink.rtss: INFO club.joylink.rtss: INFO
minio: minio:
endpoint: https://joylink.club endpoint: https://joylink.club
accessKey: jladmin accessKey: jladmin
secretKey: Joylink@0503 secretKey: Joylink@0503
bucket: oss-rtss bucket: oss-rtss
replaceHttps: false replaceHttps: false
common: common:
env: test env: test
--- ---
spring: spring:
profiles: prd profiles: prd
datasource: datasource:
url: jdbc:mysql://192.168.0.169:3306/joylink?useSSL=false&serverTimezone=Asia/Shanghai url: jdbc:mysql://192.168.0.169:3306/joylink?useSSL=false&serverTimezone=Asia/Shanghai
username: root username: root
password: joylink@0503 password: joylink@0503
file: file:
path: https://joylink.club/jlfile/api/upload/joylink/avatar path: https://joylink.club/jlfile/api/upload/joylink/avatar
logging: logging:
file: file:
path: /usr/local/joylink/logs/rtss path: /usr/local/joylink/logs/rtss
level: level:
club.joylink.rtss: INFO club.joylink.rtss: INFO
minio: minio:
endpoint: https://joylink.club endpoint: https://joylink.club
accessKey: jladmin accessKey: jladmin
secretKey: Joylink@0503 secretKey: Joylink@0503
bucket: oss-rtss bucket: oss-rtss
replaceHttps: false replaceHttps: false
common: common:
env: prd env: prd
# 环境连接配置 end # 环境连接配置 end