From 72b4ac8fd5350e1bfff7f1f7a5edde73c4987a7d Mon Sep 17 00:00:00 2001 From: joylink_zhangsai <1021828630@qq.com> Date: Wed, 19 Oct 2022 15:40:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=9F=E6=88=90=E5=AD=90?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapSystem/RtsMapSystemServiceImpl.java | 301 +++++++++++------- .../cbtc/vo/SimulationWorkParamVO.java | 5 + 2 files changed, 184 insertions(+), 122 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/mapSystem/RtsMapSystemServiceImpl.java b/src/main/java/club/joylink/rtss/services/mapSystem/RtsMapSystemServiceImpl.java index e8af806f3..6190ab61c 100644 --- a/src/main/java/club/joylink/rtss/services/mapSystem/RtsMapSystemServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/mapSystem/RtsMapSystemServiceImpl.java @@ -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 mapSystems = getEntitiesByMapId(mapId); + Set systemNameSet = mapSystems.stream().map(RtsMapSystem::getName).collect(Collectors.toSet()); List msgList = new ArrayList<>(); MapVO mapData = iMapService.getMapDetail(mapId); String msgPrefix; List mapMemberVOS; - List> fillCreatVOFunctions; + List> 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 fillParamFunction : fillCreatVOFunctions) { - MapSystemCreateVO createVO = new MapSystemCreateVO(); - createVO.setMapId(mapId); - MapSystemCreateVO filledCreateVO = fillParamFunction.apply(createVO); - if (filledCreateVO != null) { + for (Supplier 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> buildMetroFillCreateVOFunctions(List msgList, String msgPrefix, Simulation.Type simType, List mapMemberVOS) { - List> fillFunctions = new ArrayList<>(); + private List> buildMetroSystemCreateVOSuppliers(long mapId, Set systemNameSet, List msgList, String msgPrefix, Simulation.Type simType, List mapMemberVOS) { + List> fillFunctions = new ArrayList<>(); + Optional dispatcherOptional = mapMemberVOS.stream() + .filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER)) + .findFirst(); + Optional stationSupervisorOptional = mapMemberVOS.stream() + .filter(member -> Objects.equals(member.getType(), SimulationMember.Type.STATION_SUPERVISOR)) + .findFirst(); //ATS行调工作站 - Function dispatchSystem = (vo) -> { + Supplier dispatchSystem = () -> { String name = "ATS行调工作站"; - Optional 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 stationSystem = (vo) -> { + Supplier stationSystem = () -> { String name = "ATS现地工作站"; - Optional 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 driveSystem = (vo) -> { + Supplier driveSystem = () -> { String name = "司机模拟驾驶系统"; + if (systemNameSet.contains(name)) { + msgList.add(String.format("%s已存在,不生成", name)); + return null; + } Optional 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 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 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 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 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 joint = (vo) -> { + Supplier joint = () -> { String name = "综合演练"; - Optional 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> buildRailwayFillCreateVOFunctions(List msgList, String msgPrefix, Simulation.Type simType, List mapMemberVOS) { - List> fillFunctions = new ArrayList<>(); + private List> buildRailwayFillCreateVOSuppliers(long mapId, Set systemNameSet, List msgList, String msgPrefix, + Simulation.Type simType, List mapMemberVOS) { + List> fillFunctions = new ArrayList<>(); + Optional dispatcherOptional = mapMemberVOS.stream() + .filter(member -> Objects.equals(member.getType(), SimulationMember.Type.DISPATCHER)) + .findFirst(); + Optional stationSupervisorOptional = mapMemberVOS.stream() + .filter(member -> Objects.equals(member.getType(), SimulationMember.Type.STATION_SUPERVISOR)) + .findFirst(); //调度台 - Function dispatchSystem = (vo) -> { + Supplier dispatchSystem = () -> { String name = "调度台"; - Optional 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 stationSystem = (vo) -> { + Supplier stationSystem = () -> { String name = "车站"; - Optional 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 getEntitiesByMapId(long mapId) { + RtsMapSystemExample example = new RtsMapSystemExample(); + example.createCriteria().andMapIdEqualTo(mapId); + return rtsMapSystemDAO.selectByExample(example); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/vo/SimulationWorkParamVO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/vo/SimulationWorkParamVO.java index 36265fa42..db6b2528b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/vo/SimulationWorkParamVO.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/vo/SimulationWorkParamVO.java @@ -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; } }