轨道交通仿真——创建过程添加初始化仿真成员和创建者扮演成员,调通操作调用

This commit is contained in:
walker-sheng 2021-04-22 14:40:20 +08:00
parent 89d8c4b198
commit 303760220a
8 changed files with 70 additions and 12 deletions

View File

@ -249,7 +249,8 @@ public class DraftMapService implements IDraftMapService {
DraftMapWithBLOBs draftMap = getEntity(id); DraftMapWithBLOBs draftMap = getEntity(id);
MapVO mapVO = new MapVO(draftMap); MapVO mapVO = new MapVO(draftMap);
MapDataVO mapDataVO; MapDataVO mapDataVO;
mapDataVO = new MapDataVO(this.buildShapeData(draftMap), this.getMapLogicDataNew(id), MapCheckConfig.fromJson(draftMap.getCheckConfig())); mapDataVO = new MapDataVO(this.buildShapeData(draftMap), this.getMapLogicDataNew(id),
MapCheckConfig.fromJson(draftMap.getCheckConfig()));
mapDataVO.setMap3dDataVO(this.find3dMapDataByMapId(id)); mapDataVO.setMap3dDataVO(this.find3dMapDataByMapId(id));
mapVO.setMapData(mapDataVO); mapVO.setMapData(mapDataVO);
return mapVO; return mapVO;
@ -350,12 +351,13 @@ public class DraftMapService implements IDraftMapService {
@Override @Override
public List<String> checkData(MapDataVO mapDataVO) { public List<String> checkData(MapDataVO mapDataVO) {
List<String> exDataList = null; List<String> exDataList = new ArrayList<>();
try { try {
if (mapDataVO.getCheckConfig() == null || mapDataVO.getCheckConfig().isCheck()) {
MapVO map = new MapVO(); MapVO map = new MapVO();
map.setMapData(mapDataVO); map.setMapData(mapDataVO);
exDataList = SimulationBuilder.checkAndBuildMapData(map).getErrMsgList(); exDataList = SimulationBuilder.checkAndBuildMapData(map).getErrMsgList();
}
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
if (e.getMessage().startsWith("Duplicate key")) { if (e.getMessage().startsWith("Duplicate key")) {
exDataList = new ArrayList<>(); exDataList = new ArrayList<>();

View File

@ -15,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
@Component @Component
public class SimulationOperationHandlerManager implements ApplicationContextAware { public class SimulationOperationHandlerManager implements ApplicationContextAware {
public static final Map<String, OperationHandlerMethod> handlerMap = new ConcurrentHashMap<>(); public static final Map<String, OperationHandlerMethod> handlerMethodMap = new ConcurrentHashMap<>();
@Override @Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
@ -28,9 +28,9 @@ public class SimulationOperationHandlerManager implements ApplicationContextAwar
continue; continue;
} }
String name = operationMapping.value(); String name = operationMapping.value();
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(handlerMap.containsKey(name)); BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(handlerMethodMap.containsKey(name));
OperationHandlerMethod handlerMethod = new OperationHandlerMethod(handler, method); OperationHandlerMethod handlerMethod = new OperationHandlerMethod(handler, method);
handlerMap.put(name, handlerMethod); handlerMethodMap.put(name, handlerMethod);
log.info(String.format("成功加载仿真操作{name: %s, method: %s::%s}", name, handler.getClass().getName(), method.getName())); log.info(String.format("成功加载仿真操作{name: %s, method: %s::%s}", name, handler.getClass().getName(), method.getName()));
} }
} }
@ -38,7 +38,7 @@ public class SimulationOperationHandlerManager implements ApplicationContextAwar
public OperationHandlerMethod getHandlerMethod(String operation) { public OperationHandlerMethod getHandlerMethod(String operation) {
Objects.requireNonNull(operation); Objects.requireNonNull(operation);
OperationHandlerMethod method = handlerMap.get(operation); OperationHandlerMethod method = handlerMethodMap.get(operation);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(method, BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(method,
String.format("操作[%s]没有对应的处理方法", operation)); String.format("操作[%s]没有对应的处理方法", operation));
return method; return method;

View File

@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.HashMap; 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;
public class CilRepository extends SimulationRepository { public class CilRepository extends SimulationRepository {
public static final String NAME = "CIL"; public static final String NAME = "CIL";
@ -38,6 +39,7 @@ public class CilRepository extends SimulationRepository {
this.psdMap = new HashMap<>(); this.psdMap = new HashMap<>();
this.espMap = new HashMap<>(); this.espMap = new HashMap<>();
this.routeMap = new HashMap<>(); this.routeMap = new HashMap<>();
this.supervisedRouteMap = new ConcurrentHashMap<>();
this.autoSignalMap = new HashMap<>(); this.autoSignalMap = new HashMap<>();
this.flsMap = new HashMap<>(); this.flsMap = new HashMap<>();
this.overlapMap = new HashMap<>(); this.overlapMap = new HashMap<>();

View File

@ -10,13 +10,19 @@ import java.time.LocalDateTime;
@Getter @Getter
public class RtSimulation extends Simulation<RtSimulationUser, RtSimulationMember> { public class RtSimulation extends Simulation<RtSimulationUser, RtSimulationMember> {
public static final int TIME_OFFSET_HOUR = 2; public static final int TIME_OFFSET_HOUR = 2;
RtSimulationUser creator;
MapVO mapVO; MapVO mapVO;
MapPrdTypeEnum prdType; MapPrdTypeEnum prdType;
public RtSimulation(String id) { SimulationIdGenerator idGenerator;
public RtSimulation(String id, RtSimulationUser creator) {
super(id); super(id);
this.idGenerator = new SimulationIdGenerator();
this.creator = creator;
this.addSimulationUser(creator);
} }
public LocalDateTime convertToSystemTime(LocalDateTime dateTime) { public LocalDateTime convertToSystemTime(LocalDateTime dateTime) {

View File

@ -3,11 +3,25 @@ package club.joylink.rtss.simulation.rt;
import club.joylink.rtss.simulation.SimulationMember; import club.joylink.rtss.simulation.SimulationMember;
public class RtSimulationMember extends SimulationMember<RtSimulationMember.Role> { public class RtSimulationMember extends SimulationMember<RtSimulationMember.Role> {
String deviceId;
public RtSimulationMember(String id, Role role) { public RtSimulationMember(String id, Role role) {
super(id, role); super(id, role);
} }
public enum Role { public RtSimulationMember(String id, Role role, String deviceId) {
super(id, role);
this.deviceId = deviceId;
}
public enum Role {
/**
* 行调
*/
DISP,
/**
* 车站值班员
*/
LOWS
} }
} }

View File

@ -6,14 +6,16 @@ import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.data.vo.SimulationVO; import club.joylink.rtss.simulation.cbtc.data.vo.SimulationVO;
import club.joylink.rtss.simulation.rt.ATS.AtsLogicService; import club.joylink.rtss.simulation.rt.ATS.AtsLogicService;
import club.joylink.rtss.simulation.rt.CIL.CilLogicService; import club.joylink.rtss.simulation.rt.CIL.CilLogicService;
import club.joylink.rtss.simulation.rt.CIL.CilLogicService;
import club.joylink.rtss.simulation.rt.SRD.SrdLogicService; import club.joylink.rtss.simulation.rt.SRD.SrdLogicService;
import club.joylink.rtss.simulation.rt.repo.CommonRepoService; import club.joylink.rtss.simulation.rt.repo.CommonRepoService;
import club.joylink.rtss.simulation.rt.repo.CommonRepository;
import club.joylink.rtss.simulation.rt.repo.CommonStation;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.map.MapVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Component @Component
@ -34,14 +36,34 @@ public class RtSimulationService {
public RtSimulation create(UserVO userVO, Long mapId, MapPrdTypeEnum prdTypeEnum) { public RtSimulation create(UserVO userVO, Long mapId, MapPrdTypeEnum prdTypeEnum) {
Objects.requireNonNull(mapId); Objects.requireNonNull(mapId);
MapVO mapVO = this.mapService.getMapDetail(mapId); MapVO mapVO = this.mapService.getMapDetail(mapId);
RtSimulation rtSimulation = new RtSimulation(SimulationIdGenerator.buildId()); RtSimulationUser creator = new RtSimulationUser(userVO.getId().toString());
RtSimulation rtSimulation = new RtSimulation(SimulationIdGenerator.buildId(), creator);
rtSimulation.mapVO = mapVO; rtSimulation.mapVO = mapVO;
this.loadData(rtSimulation, mapVO); this.loadData(rtSimulation, mapVO);
this.srdLogicService.addJobs(rtSimulation);
this.simulationManager.save(rtSimulation); this.simulationManager.save(rtSimulation);
this.srdLogicService.addJobs(rtSimulation);
this.cilLogicService.addJobs(rtSimulation);
this.initSimulationMember(rtSimulation);
this.initCreatorPlayMember(rtSimulation);
return rtSimulation; return rtSimulation;
} }
private void initCreatorPlayMember(RtSimulation rtSimulation) {
if (MapPrdTypeEnum.LOCAL.equals(rtSimulation.getPrdType())) {
List<RtSimulationMember> memberList = rtSimulation.querySimulationMembersOfRole(RtSimulationMember.Role.LOWS);
this.simulationManager.memberPlayedByUser(rtSimulation.getId(), memberList.get(0).getId(), rtSimulation.getCreator().getId());
}
}
private void initSimulationMember(RtSimulation rtSimulation) {
CommonRepository repository = rtSimulation.getRepository(CommonRepository.NAME, CommonRepository.class);
for (CommonStation station : repository.getStationMap().values()) {
rtSimulation.addSimulationMember(
new RtSimulationMember(rtSimulation.getIdGenerator().next(),
RtSimulationMember.Role.LOWS, station.getId()));
}
}
/** /**
* 加载相关数据 * 加载相关数据
*/ */

View File

@ -8,4 +8,14 @@ public class SimulationIdGenerator {
public static String buildId() { public static String buildId() {
return String.valueOf(sn.incrementAndGet()); return String.valueOf(sn.incrementAndGet());
} }
private AtomicInteger bsn;
public SimulationIdGenerator() {
this.bsn = new AtomicInteger(1);
}
public String next() {
return String.valueOf(this.bsn.getAndIncrement());
}
} }

View File

@ -2,10 +2,12 @@ package club.joylink.rtss.simulation.rt.repo;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.SimulationRepository; import club.joylink.rtss.simulation.SimulationRepository;
import lombok.Getter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Getter
public class CommonRepository extends SimulationRepository { public class CommonRepository extends SimulationRepository {
public static final String NAME = "COMMON"; public static final String NAME = "COMMON";