修改生成子系统逻辑

This commit is contained in:
joylink_zhangsai 2022-10-19 15:40:39 +08:00
parent 66ac5d7b02
commit 72b4ac8fd5
2 changed files with 184 additions and 122 deletions

View File

@ -16,16 +16,13 @@ import club.joylink.rtss.vo.map.graph.MapMemberVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.internal.Function;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@Service
@ -39,6 +36,8 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
@Override
public void create(MapSystemCreateVO createVO, long creatorId) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(createVO.getMapId());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(createVO.getName());
confirmNameNotExist(createVO.getMapId(), createVO.getName());
RtsMapSystem entity = createVO.convert2DB();
entity.setCreatorId(creatorId);
@ -89,16 +88,15 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(paramVO.getSimTypes(),
"要生成子系统的仿真系统类型不能为空");
//删除所有旧数据
RtsMapSystemExample example = new RtsMapSystemExample();
example.createCriteria().andMapIdEqualTo(mapId);
rtsMapSystemDAO.deleteByExample(example);
List<RtsMapSystem> mapSystems = getEntitiesByMapId(mapId);
Set<String> systemNameSet = mapSystems.stream().map(RtsMapSystem::getName).collect(Collectors.toSet());
List<String> msgList = new ArrayList<>();
MapVO mapData = iMapService.getMapDetail(mapId);
String msgPrefix;
List<MapMemberVO> mapMemberVOS;
List<Function<MapSystemCreateVO, MapSystemCreateVO>> fillCreatVOFunctions;
List<Supplier<MapSystemCreateVO>> createVOSuppliers;
for (Simulation.Type simType : paramVO.getSimTypes()) {
mapMemberVOS = mapData.getGraphDataNew().getMemberMap().get(simType);
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertCollectionNotEmpty(mapMemberVOS,
@ -106,11 +104,11 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
switch (simType) {
case METRO:
msgPrefix = "地铁CBTC系统";
fillCreatVOFunctions = buildMetroFillCreateVOFunctions(msgList, msgPrefix, simType, mapMemberVOS);
createVOSuppliers = buildMetroSystemCreateVOSuppliers(mapId, systemNameSet, msgList, msgPrefix, simType, mapMemberVOS);
break;
case RAILWAY:
msgPrefix = "大铁CTC系统";
fillCreatVOFunctions = buildRailwayFillCreateVOFunctions(msgList, msgPrefix, simType, mapMemberVOS);
createVOSuppliers = buildRailwayFillCreateVOSuppliers(mapId, systemNameSet, msgList, msgPrefix, simType, mapMemberVOS);
break;
case EMERGENCY:
throw BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.exception("未实现");
@ -120,11 +118,9 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
throw new IllegalStateException("Unexpected value: " + simType);
}
//填充参数并创建子系统
for (Function<MapSystemCreateVO, MapSystemCreateVO> fillParamFunction : fillCreatVOFunctions) {
MapSystemCreateVO createVO = new MapSystemCreateVO();
createVO.setMapId(mapId);
MapSystemCreateVO filledCreateVO = fillParamFunction.apply(createVO);
if (filledCreateVO != null) {
for (Supplier<MapSystemCreateVO> supplier : createVOSuppliers) {
MapSystemCreateVO createVO = supplier.get();
if (createVO != null) {
create(createVO, creatorId);
}
}
@ -133,103 +129,161 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
return msgList;
}
public MapSystemCreateVO buildCreateVO(long mapId, String name, String desc, Simulation.Type simType, String memberId, SimulationWorkParamVO.DomConfigVO domConfig) {
MapSystemCreateVO createVO = new MapSystemCreateVO();
createVO.setMapId(mapId);
createVO.setName(name);
createVO.setDesc(desc);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
workParamVO.setType(simType);
workParamVO.setMemberId(memberId);
workParamVO.setDomConfig(domConfig);
createVO.setParamVO(workParamVO);
return createVO;
}
/**
* 构建填充{@link MapSystemCreateVO}的方法
* 构建提供{@link MapSystemCreateVO}的方法
*
* @param msgList 记录特殊但不算异常的信息
* @param msgPrefix 特殊信息的统一前缀
* @param simType 仿真类型
* @param mapMemberVOS 地图成员列表
* @return 调用apply方法时当地图子系统的参数有问题无法创建子系统时返回null否则返回填充好所有参数的{@link MapSystemCreateVO}
* @param mapId
* @param systemNameSet 已存在的子系统名称这些子系统不再生成
* @param msgList 记录特殊但不算异常的信息
* @param msgPrefix 特殊信息的统一前缀
* @param simType 仿真类型
* @param mapMemberVOS 地图成员列表
* @return 调用apply方法时当该地图子系统无法或无需创建时返回null否则返回填充好所有参数的{@link MapSystemCreateVO}
*/
private List<Function<MapSystemCreateVO, MapSystemCreateVO>> buildMetroFillCreateVOFunctions(List<String> msgList, String msgPrefix, Simulation.Type simType, List<MapMemberVO> mapMemberVOS) {
List<Function<MapSystemCreateVO, MapSystemCreateVO>> fillFunctions = new ArrayList<>();
private List<Supplier<MapSystemCreateVO>> buildMetroSystemCreateVOSuppliers(long mapId, Set<String> systemNameSet, List<String> msgList, String msgPrefix, Simulation.Type simType, List<MapMemberVO> mapMemberVOS) {
List<Supplier<MapSystemCreateVO>> fillFunctions = new ArrayList<>();
Optional<MapMemberVO> dispatcherOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER))
.findFirst();
Optional<MapMemberVO> stationSupervisorOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.STATION_SUPERVISOR))
.findFirst();
//ATS行调工作站
Function<MapSystemCreateVO, MapSystemCreateVO> dispatchSystem = (vo) -> {
Supplier<MapSystemCreateVO> dispatchSystem = () -> {
String name = "ATS行调工作站";
Optional<MapMemberVO> memberOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER))
.findFirst();
if (memberOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未生成%s", msgPrefix, name));
} else {
vo.setName(name);
vo.setDesc(name);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
vo.setParamVO(workParamVO);
workParamVO.setType(simType);
workParamVO.setMemberId(memberOptional.get().getId());
workParamVO.setDomConfig(new SimulationWorkParamVO.DomConfigVO(true, false, false));
return vo;
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
return null;
if (dispatcherOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(true, false, false, false);
return buildCreateVO(mapId, name, name, simType, dispatcherOptional.get().getId(), domConfig);
};
//ATS现地工作站
Function<MapSystemCreateVO, MapSystemCreateVO> stationSystem = (vo) -> {
Supplier<MapSystemCreateVO> stationSystem = () -> {
String name = "ATS现地工作站";
Optional<MapMemberVO> memberOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.STATION_SUPERVISOR))
.findFirst();
if (memberOptional.isEmpty()) {
msgList.add(String.format("%s无行值成员未生成%s", msgPrefix, name));
} else {
vo.setName(name);
vo.setDesc(name);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
vo.setParamVO(workParamVO);
workParamVO.setType(simType);
workParamVO.setMemberId(memberOptional.get().getId());
workParamVO.setDomConfig(new SimulationWorkParamVO.DomConfigVO(true, false, false));
return vo;
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
return null;
if (stationSupervisorOptional.isEmpty()) {
msgList.add(String.format("%s无行值成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(true, false, false, false);
return buildCreateVO(mapId, name, name, simType, stationSupervisorOptional.get().getId(), domConfig);
};
//司机模拟驾驶系统
Function<MapSystemCreateVO, MapSystemCreateVO> driveSystem = (vo) -> {
Supplier<MapSystemCreateVO> driveSystem = () -> {
String name = "司机模拟驾驶系统";
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
Optional<MapMemberVO> memberOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DRIVER))
.findFirst();
if (memberOptional.isEmpty()) {
msgList.add(String.format("%s无司机角色未生成%s", msgPrefix, name));
} else {
vo.setName(name);
vo.setDesc(name);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
vo.setParamVO(workParamVO);
workParamVO.setType(simType);
workParamVO.setMemberId(memberOptional.get().getId());
workParamVO.setDomConfig(new SimulationWorkParamVO.DomConfigVO(true, false, false));
return vo;
return null;
}
return null;
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(true, false, false, false);
return buildCreateVO(mapId, name, name, simType, memberOptional.get().getId(), domConfig);
};
//ATS行调实训系统
Supplier<MapSystemCreateVO> dispatchTrainingSystem = () -> {
String name = "ATS行调实训系统";
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
if (dispatcherOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(false, false, true, false);
return buildCreateVO(mapId, name, name, simType, dispatcherOptional.get().getId(), domConfig);
};
//ATS现地实训系统
Supplier<MapSystemCreateVO> stationTrainingSystem = () -> {
String name = "ATS现地实训系统";
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
if (stationSupervisorOptional.isEmpty()) {
msgList.add(String.format("%s无行值成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(false, false, true, false);
return buildCreateVO(mapId, name, name, simType, stationSupervisorOptional.get().getId(), domConfig);
};
//ATS行调考试系统
Supplier<MapSystemCreateVO> dispatchExamSystem = () -> {
String name = "ATS行调考试系统";
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
if (dispatcherOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(false, false, false, true);
return buildCreateVO(mapId, name, name, simType, dispatcherOptional.get().getId(), domConfig);
};
//ATS现地实训系统
Supplier<MapSystemCreateVO> stationExamSystem = () -> {
String name = "ATS现地考试系统";
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
if (stationSupervisorOptional.isEmpty()) {
msgList.add(String.format("%s无行值成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(false, false, false, true);
return buildCreateVO(mapId, name, name, simType, stationSupervisorOptional.get().getId(), domConfig);
};
//综合演练
Function<MapSystemCreateVO, MapSystemCreateVO> joint = (vo) -> {
Supplier<MapSystemCreateVO> joint = () -> {
String name = "综合演练";
Optional<MapMemberVO> memberOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER))
.findFirst();
String memberId;
if (memberOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员%s未设置默认扮演成员", msgPrefix, name));
memberId = null;
} else {
memberId = memberOptional.get().getId();
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
vo.setName(name);
vo.setDesc(name);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
vo.setParamVO(workParamVO);
workParamVO.setType(simType);
workParamVO.setMemberId(memberId);
workParamVO.setDomConfig(new SimulationWorkParamVO.DomConfigVO(false, false, false));
return vo;
if (dispatcherOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未设置%s默认扮演成员", msgPrefix, name));
}
String memberId = dispatcherOptional.map(MapMemberVO::getId).orElse(null);
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(false, false, false, false);
return buildCreateVO(mapId, name, name, simType, memberId, domConfig);
};
fillFunctions.add(dispatchSystem);
fillFunctions.add(stationSystem);
fillFunctions.add(driveSystem);
fillFunctions.add(dispatchTrainingSystem);
fillFunctions.add(stationTrainingSystem);
fillFunctions.add(dispatchExamSystem);
fillFunctions.add(stationExamSystem);
fillFunctions.add(joint);
return fillFunctions;
@ -238,52 +292,49 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
/**
* 构建大铁填充{@link MapSystemCreateVO}的方法列表
*
* @param msgList 记录特殊的但是不算异常的信息
* @param msgPrefix msgList内容的统一前缀
* @param mapMemberVOS 地图数据中的成员列表
* @param mapId
* @param systemNameSet
* @param msgList 记录特殊的但是不算异常的信息
* @param msgPrefix msgList内容的统一前缀
* @param mapMemberVOS 地图数据中的成员列表
* @return 调用apply方法时当地图子系统的参数有问题无法创建子系统时返回null否则返回填充好所有参数的{@link MapSystemCreateVO}
*/
private List<Function<MapSystemCreateVO, MapSystemCreateVO>> buildRailwayFillCreateVOFunctions(List<String> msgList, String msgPrefix, Simulation.Type simType, List<MapMemberVO> mapMemberVOS) {
List<Function<MapSystemCreateVO, MapSystemCreateVO>> fillFunctions = new ArrayList<>();
private List<Supplier<MapSystemCreateVO>> buildRailwayFillCreateVOSuppliers(long mapId, Set<String> systemNameSet, List<String> msgList, String msgPrefix,
Simulation.Type simType, List<MapMemberVO> mapMemberVOS) {
List<Supplier<MapSystemCreateVO>> fillFunctions = new ArrayList<>();
Optional<MapMemberVO> dispatcherOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER))
.findFirst();
Optional<MapMemberVO> stationSupervisorOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.STATION_SUPERVISOR))
.findFirst();
//调度台
Function<MapSystemCreateVO, MapSystemCreateVO> dispatchSystem = (vo) -> {
Supplier<MapSystemCreateVO> dispatchSystem = () -> {
String name = "调度台";
Optional<MapMemberVO> memberOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER))
.findFirst();
if (memberOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未生成%s", msgPrefix, name));
} else {
vo.setName(name);
vo.setDesc(name);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
vo.setParamVO(workParamVO);
workParamVO.setType(simType);
workParamVO.setMemberId(memberOptional.get().getId());
workParamVO.setDomConfig(new SimulationWorkParamVO.DomConfigVO(true, false, false));
return vo;
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
return null;
if (dispatcherOptional.isEmpty()) {
msgList.add(String.format("%s无行调成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(true, false, false, false);
return buildCreateVO(mapId, name, name, simType, dispatcherOptional.get().getId(), domConfig);
};
//车站
Function<MapSystemCreateVO, MapSystemCreateVO> stationSystem = (vo) -> {
Supplier<MapSystemCreateVO> stationSystem = () -> {
String name = "车站";
Optional<MapMemberVO> memberOptional = mapMemberVOS.stream()
.filter(member -> Objects.equals(member.getType(), SimulationMember.Type.STATION_SUPERVISOR))
.findFirst();
if (memberOptional.isEmpty()) {
msgList.add(String.format("%s无行值成员未生成%s", msgPrefix, name));
} else {
vo.setName(name);
vo.setDesc(name);
SimulationWorkParamVO workParamVO = new SimulationWorkParamVO();
vo.setParamVO(workParamVO);
workParamVO.setType(simType);
workParamVO.setMemberId(memberOptional.get().getId());
workParamVO.setDomConfig(new SimulationWorkParamVO.DomConfigVO(true, false, false));
return vo;
if (systemNameSet.contains(name)) {
msgList.add(String.format("%s已存在不生成", name));
return null;
}
return null;
if (stationSupervisorOptional.isEmpty()) {
msgList.add(String.format("%s无行值成员未生成%s", msgPrefix, name));
return null;
}
SimulationWorkParamVO.DomConfigVO domConfig = new SimulationWorkParamVO.DomConfigVO(true, false, false, false);
return buildCreateVO(mapId, name, name, simType, stationSupervisorOptional.get().getId(), domConfig);
};
fillFunctions.add(dispatchSystem);
@ -312,4 +363,10 @@ public class RtsMapSystemServiceImpl implements RtsMapSystemService {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(rtsMapSystemDAO.countByExample(example) < 1,
String.format("名称[%s]的系统已存在", name));
}
private List<RtsMapSystem> getEntitiesByMapId(long mapId) {
RtsMapSystemExample example = new RtsMapSystemExample();
example.createCriteria().andMapIdEqualTo(mapId);
return rtsMapSystemDAO.selectByExample(example);
}
}

View File

@ -64,6 +64,9 @@ public class SimulationWorkParamVO {
private Long id;
}
/**
* 前端控制元素显隐的配置
*/
@Getter
@Setter
@NoArgsConstructor
@ -74,5 +77,7 @@ public class SimulationWorkParamVO {
private boolean singleClient;
private boolean hasTraining;
private boolean hasExam;
}
}