修改生成子系统逻辑

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