From 9329c973c63f25cf83f27dec17720dd96d7dde78 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 6 Jan 2023 18:17:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E3=80=90=E6=A0=B9=E6=8D=AE=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E5=88=97=E8=A1=A8=E7=94=9F=E6=88=90=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E3=80=91=E3=80=90=E7=94=9F=E6=88=90=E5=85=A8=E9=83=A8=E5=9C=B0?= =?UTF-8?q?=E5=9B=BE=E5=AE=9E=E8=AE=AD=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../training2/TrainingRuleController.java | 14 ++- .../training2/Training2RuleService.java | 108 +++++++++++++++++- .../simulation/cbtc/SimulationService.java | 4 + .../cbtc/SimulationServiceImpl.java | 81 ++++++++----- 4 files changed, 171 insertions(+), 36 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java index 983176afa..b2cf91526 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java @@ -1,6 +1,8 @@ package club.joylink.rtss.controller.training2; +import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.services.training2.Training2RuleService; +import club.joylink.rtss.vo.LoginUserInfoVO; import lombok.extern.slf4j.Slf4j; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; @@ -36,9 +38,15 @@ public class TrainingRuleController { return training2RuleService.generateTrainingByMapIdAndFunId(mapId, functionId); } - @PostMapping("{groupId}/test") - public void test(@PathVariable String groupId){ - training2RuleService.test(groupId); + @PostMapping("generate/all") + public void generateAllTraining(@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ + training2RuleService.generateAllTrainingByRule(loginUserInfoVO); + } + + @PostMapping("generate/mapId") + public void generateTrainingByMapId(@RequestBody List mapIdList + , @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ + training2RuleService.generateTrainingByMapId(mapIdList, loginUserInfoVO); } } diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java index 54a95fe9c..37255cb10 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java @@ -1,7 +1,15 @@ package club.joylink.rtss.services.training2; +import club.joylink.rtss.constants.MapStatus; +import club.joylink.rtss.controller.advice.AuthenticateInterceptor; +import club.joylink.rtss.dao.MapInfoDAO; import club.joylink.rtss.dao.PublishedTraining2DAO; +import club.joylink.rtss.dao.RtsMapFunctionDAO; import club.joylink.rtss.dao.training.RtsTraining2RuleMapper; +import club.joylink.rtss.entity.MapInfo; +import club.joylink.rtss.entity.MapInfoExample; +import club.joylink.rtss.entity.RtsMapFunction; +import club.joylink.rtss.entity.RtsMapFunctionExample; import club.joylink.rtss.entity.training2.*; import club.joylink.rtss.services.mapFunction.RtsMapFunctionService; import club.joylink.rtss.simulation.SimulationManager; @@ -11,6 +19,7 @@ import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement; import club.joylink.rtss.simulation.cbtc.data.map.Route; import club.joylink.rtss.simulation.cbtc.data.map.Stand; import club.joylink.rtss.simulation.cbtc.data.map.Switch; +import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.training2.rule.BgSceneStatusRule; import club.joylink.rtss.vo.training2.rule.MapLocationRule; import club.joylink.rtss.vo.training2.rule.Training2Rule; @@ -18,8 +27,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.RequestAttribute; +import org.springframework.web.bind.annotation.RequestBody; import java.util.*; +import java.util.stream.Collectors; /** * 实训规则Service @@ -41,6 +53,12 @@ public class Training2RuleService { @Autowired private PublishedTraining2DAO publishedTraining2DAO; + @Autowired + private MapInfoDAO mapInfoDAO; + + @Autowired + private RtsMapFunctionDAO rtsMapFunctionDAO; + /** * 正在生成的地图Id */ @@ -109,9 +127,91 @@ public class Training2RuleService { return generateTrainingByRule(groupId); } - public void test(String groupId) { - Simulation simulation = simulationManager.getById(groupId , Simulation.class); - Switch aSwitch = simulation.getRepository().getByCode("W32728", Switch.class); - System.out.println(aSwitch.isSingleLock()); + + public void generateTrainingByMapId(List mapIdList, LoginUserInfoVO loginUserInfoVO){ + MapInfoExample example = new MapInfoExample(); + MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); + criteria.andIdIn(mapIdList); + List mapList = mapInfoDAO.selectByExample(example); + List lineCodeList = mapList.stream().map(MapInfo::getLineCode).collect(Collectors.toList()); + // 规则列表 + RtsTraining2RuleExample rtsTraining2RuleExample = new RtsTraining2RuleExample(); + rtsTraining2RuleExample.createCriteria().andLineCodeIn(lineCodeList); + List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(rtsTraining2RuleExample); + Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + mapList.forEach(mapInfo -> { + RtsMapFunctionExample rtsExample = new RtsMapFunctionExample(); + RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria(); + rtsCriteria.andMapIdEqualTo(mapInfo.getId()); + rtsCriteria.andNameEqualTo("单操实训"); + List entities = rtsMapFunctionDAO.selectByExampleWithBLOBs(rtsExample); + if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) { + Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); + generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode())); + } + }); } + + + public void generateAllTrainingByRule(LoginUserInfoVO loginUserInfoVO) { + // 规则列表 + List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(null); + Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + lineCodeRuleMap.forEach((k,v) -> { + MapInfoExample example = new MapInfoExample(); + MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); + criteria.andLineCodeEqualTo(k); + List mapList = mapInfoDAO.selectByExample(example); + mapList.forEach(mapInfo -> { + RtsMapFunctionExample rtsExample = new RtsMapFunctionExample(); + RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria(); + rtsCriteria.andMapIdEqualTo(mapInfo.getId()); + rtsCriteria.andNameEqualTo("单操实训"); + List entities = rtsMapFunctionDAO.selectByExampleWithBLOBs(rtsExample); + if (!CollectionUtils.isEmpty(entities)) { + Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); + generateTraining(simulation, v); + } + }); + }); + } + + private void generateTraining(Simulation simulation, List ruleList) { + Long mapId = simulation.getBuildParams().getMap().getId(); + if (runningMapIdSet.contains(mapId)) { + return; + } + synchronized (Training2RuleService.class) { + try { + if (!runningMapIdSet.contains(mapId)) { + runningMapIdSet.add(mapId); + // 清除数据库原有数据 + PublishedTraining2Example publishedTraining2Example = new PublishedTraining2Example(); + publishedTraining2Example.createCriteria().andMapIdEqualTo(mapId).andCreatorIdEqualTo(0L); + publishedTraining2DAO.deleteByExample(publishedTraining2Example); + // 生成新数据 + for (RtsTraining2RuleWithBLOBs rule : ruleList) { + if (StringUtils.isEmpty(rule.getSteps())) { + continue; + } + Training2Rule training2Rule = new Training2Rule(rule); + List deviceList = training2Rule.getDeviceRule().filterMapDeviceList(simulation); + if (CollectionUtils.isEmpty(deviceList)) { + continue; + } + List training2WithBLOBs = new ArrayList<>(deviceList.size()); + for (MapNamedElement device : deviceList) { + simulationService.reset(simulation.getId()); + training2WithBLOBs.add(training2Rule.convert2BO(simulation, device)); + } + // 新数据入库 + publishedTraining2DAO.insertList(training2WithBLOBs); + } + } + } finally { + runningMapIdSet.remove(mapId); + } + } + } + } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java index 794d40c15..45db45daf 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java @@ -58,4 +58,8 @@ public interface SimulationService { * 监控仿真 */ void monitor(String simulationId, AccountVO user); + + Simulation createSimulationPojo(long mapId, Long mapFunctionId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO); + + Simulation createSimulationPojo(Long mapFunctionId, LoginUserInfoVO loginInfo); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java index 7b716e4b3..fbea1ccea 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java @@ -56,35 +56,7 @@ public class SimulationServiceImpl implements SimulationService { @Override public String createSimulation(long mapId, Long mapFunctionId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO) { - //获取仿真工作服务 - SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType()); - //创建仿真 - String simulationId = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), mapId); - Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId); - simulation.setMapFunctionId(mapFunctionId); - LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo(); - if (Objects.nonNull(loginUserInfo)) { - simulation.setCreatorId(loginUserInfo.getAccountVO().getIdStr()); - simulation.setProject(loginUserInfo.getProject()); - simulation.setProjectVO(loginUserInfo.getProjectInfo()); - } - // 删除旧仿真,保存新仿真 - simulation.setMessageSender(this.defaultMessageSender); // 设置默认的消息发布器 - simulation.loadModule(); // 加载通用模块 - groupSimulationService.clearSimulation(simulation.getId()); - simulationManager.saveNew(simulation); - - initService.loadData(simulation); - initService.addJobs(simulation); - initService.addMessagePublisher(simulation); - initService.init(simulation); - if (!CollectionUtils.isEmpty(workParamVO.getItemMap())) { - initService.addItems(simulation, workParamVO.getItemMap()); - } - applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); - // 仿真开始运行 - simulationManager.start(simulation.getId()); - return simulation.getId(); + return createSimulationPojo(mapId, mapFunctionId, workParamVO, loginUserInfoVO).getId(); } //只获取所有与该功能相关的权限信息 @@ -223,4 +195,55 @@ public class SimulationServiceImpl implements SimulationService { SimulationUser simulationUser = new SimulationUser(simulation, user, club.joylink.rtss.simulation.SimulationUser.Type.TEACHER); simulationWorkServiceManager.addSimulationUser(simulation, simulationUser); } + + @Override + public Simulation createSimulationPojo(long mapId, Long mapFunctionId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO) { + //获取仿真工作服务 + SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType()); + //创建仿真 + String simulationId = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), mapId); + Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId); + simulation.setMapFunctionId(mapFunctionId); + LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo(); + if (Objects.nonNull(loginUserInfo)) { + simulation.setCreatorId(loginUserInfo.getAccountVO().getIdStr()); + simulation.setProject(loginUserInfo.getProject()); + simulation.setProjectVO(loginUserInfo.getProjectInfo()); + } + // 删除旧仿真,保存新仿真 + simulation.setMessageSender(this.defaultMessageSender); // 设置默认的消息发布器 + simulation.loadModule(); // 加载通用模块 + groupSimulationService.clearSimulation(simulation.getId()); + simulationManager.saveNew(simulation); + initService.loadData(simulation); + initService.addJobs(simulation); + initService.addMessagePublisher(simulation); + initService.init(simulation); + if (!CollectionUtils.isEmpty(workParamVO.getItemMap())) { + initService.addItems(simulation, workParamVO.getItemMap()); + } + applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); + // 仿真开始运行 + simulationManager.start(simulation.getId()); + return simulation; + } + + @Override + public Simulation createSimulationPojo(Long mapFunctionId, LoginUserInfoVO loginInfo) { + RtsMapFunctionVO rtsMapFunctionVO = rtsMapFunctionService.get(mapFunctionId); + this.checkUserPermission(rtsMapFunctionVO,loginInfo); + Long mapId = rtsMapFunctionVO.getMapId(); + SimulationWorkParamVO workParamVO = rtsMapFunctionVO.getParamVO(); + + if (workParamVO.containsRealDeviceItem()) { + //有实体设备加载项的地图功能(实训室)同时只能存在一个 + Stream stream = simulationManager.getSimulationStream(); + Optional oldSimulationOptional = stream + .filter(sim -> Objects.equals(sim.getMapFunctionId(), mapFunctionId)) + .findFirst(); + oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId())); + } + + return createSimulationPojo(mapId, mapFunctionId, workParamVO, loginInfo); + } } From 643b931bd02259f4c2efcad31ce7bd5eb74a638d Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 9 Jan 2023 09:50:10 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E3=80=90=E7=94=9F=E6=88=90=E5=AE=9E?= =?UTF-8?q?=E8=AE=AD=E6=89=93=E5=8D=B0=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E3=80=91=E3=80=90=E8=B0=83=E6=95=B4=E5=AE=9E=E8=AE=AD=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=88=97=E8=A1=A8=E7=AD=9B=E9=80=89=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../training2/TrainingRuleController.java | 8 +-- .../training2/Training2RuleService.java | 56 +++++++++++++------ .../rtss/vo/training2/rule/MapDeviceRule.java | 10 ++-- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java index b2cf91526..26d673a06 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java @@ -39,14 +39,14 @@ public class TrainingRuleController { } @PostMapping("generate/all") - public void generateAllTraining(@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ - training2RuleService.generateAllTrainingByRule(loginUserInfoVO); + public List generateAllTraining(@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ + return training2RuleService.generateAllTrainingByRule(loginUserInfoVO); } @PostMapping("generate/mapId") - public void generateTrainingByMapId(@RequestBody List mapIdList + public List generateTrainingByMapId(@RequestBody List mapIdList , @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ - training2RuleService.generateTrainingByMapId(mapIdList, loginUserInfoVO); + return training2RuleService.generateTrainingByMapId(mapIdList, loginUserInfoVO); } } diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java index 37255cb10..1a1c551ea 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java @@ -128,7 +128,7 @@ public class Training2RuleService { } - public void generateTrainingByMapId(List mapIdList, LoginUserInfoVO loginUserInfoVO){ + public List generateTrainingByMapId(List mapIdList, LoginUserInfoVO loginUserInfoVO){ MapInfoExample example = new MapInfoExample(); MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); criteria.andIdIn(mapIdList); @@ -139,6 +139,7 @@ public class Training2RuleService { rtsTraining2RuleExample.createCriteria().andLineCodeIn(lineCodeList); List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(rtsTraining2RuleExample); Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + List errorMsgList = new ArrayList<>(); mapList.forEach(mapInfo -> { RtsMapFunctionExample rtsExample = new RtsMapFunctionExample(); RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria(); @@ -146,17 +147,23 @@ public class Training2RuleService { rtsCriteria.andNameEqualTo("单操实训"); List entities = rtsMapFunctionDAO.selectByExampleWithBLOBs(rtsExample); if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) { - Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); - generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode())); + try { + Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); + errorMsgList.addAll(generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode()))); + } catch (Exception e) { + errorMsgList.add(String.format("地图%d创建仿真报错,原因:%s", mapInfo.getId(), e.getMessage(), Locale.ENGLISH)); + } } }); + return errorMsgList; } - public void generateAllTrainingByRule(LoginUserInfoVO loginUserInfoVO) { + public List generateAllTrainingByRule(LoginUserInfoVO loginUserInfoVO) { // 规则列表 List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(null); Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + List errorMsgList = new ArrayList<>(); lineCodeRuleMap.forEach((k,v) -> { MapInfoExample example = new MapInfoExample(); MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); @@ -169,17 +176,24 @@ public class Training2RuleService { rtsCriteria.andNameEqualTo("单操实训"); List entities = rtsMapFunctionDAO.selectByExampleWithBLOBs(rtsExample); if (!CollectionUtils.isEmpty(entities)) { - Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); - generateTraining(simulation, v); + try { + Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); + errorMsgList.addAll(generateTraining(simulation, v)); + } catch (Exception e) { + errorMsgList.add(String.format("地图%d创建仿真报错,原因:%s", mapInfo.getId(), e.getMessage(), Locale.ENGLISH)); + } } }); }); + return errorMsgList; } - private void generateTraining(Simulation simulation, List ruleList) { + private List generateTraining(Simulation simulation, List ruleList) { + List errorMsgList = new ArrayList<>(ruleList.size()); Long mapId = simulation.getBuildParams().getMap().getId(); if (runningMapIdSet.contains(mapId)) { - return; + errorMsgList.add(String.format("地图%d正在生成", mapId, Locale.ENGLISH)); + return errorMsgList; } synchronized (Training2RuleService.class) { try { @@ -195,23 +209,29 @@ public class Training2RuleService { continue; } Training2Rule training2Rule = new Training2Rule(rule); - List deviceList = training2Rule.getDeviceRule().filterMapDeviceList(simulation); - if (CollectionUtils.isEmpty(deviceList)) { - continue; + try { + List deviceList = training2Rule.getDeviceRule().filterMapDeviceList(simulation); + if (CollectionUtils.isEmpty(deviceList)) { + continue; + } + List training2WithBLOBs = new ArrayList<>(deviceList.size()); + for (MapNamedElement device : deviceList) { + simulationService.reset(simulation.getId()); + training2WithBLOBs.add(training2Rule.convert2BO(simulation, device)); + } + // 新数据入库 + publishedTraining2DAO.insertList(training2WithBLOBs); + } catch (Exception e) { + errorMsgList.add(String.format("地图%d实训[%s]生成失败,设备信息【%s】,原因:%s", mapId, + training2Rule.getName(), training2Rule.getDeviceRule(),e.getMessage(),Locale.ENGLISH)); } - List training2WithBLOBs = new ArrayList<>(deviceList.size()); - for (MapNamedElement device : deviceList) { - simulationService.reset(simulation.getId()); - training2WithBLOBs.add(training2Rule.convert2BO(simulation, device)); - } - // 新数据入库 - publishedTraining2DAO.insertList(training2WithBLOBs); } } } finally { runningMapIdSet.remove(mapId); } } + return errorMsgList; } } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java index 1dddbc467..ca4df27fd 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java @@ -349,7 +349,7 @@ public enum MapDeviceRule { @Override public List filterMapDeviceList(Simulation simulation) { Station station = simulation.getRepository().getStationList().stream() - .filter(s -> s.isCentralized() && s.isInterlock() && s.isHasControlMode() && !s.isDepot()) + .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { throw new SimulationException(SimulationExceptionType.Data_Not_Exist); @@ -454,7 +454,7 @@ public enum MapDeviceRule { @Override public List
filterMapDeviceList(Simulation simulation) { Station station = simulation.getRepository().getStationList().stream() - .filter(s -> s.isCentralized() && s.isInterlock() && s.isHasControlMode() && !s.isDepot()) + .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { throw new SimulationException(SimulationExceptionType.Data_Not_Exist); @@ -521,7 +521,7 @@ public enum MapDeviceRule { @Override public List filterMapDeviceList(Simulation simulation) { Station station = simulation.getRepository().getStationList().stream() - .filter(s -> s.isCentralized() && s.isInterlock() && s.isHasControlMode() && !s.isDepot()) + .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { throw new SimulationException(SimulationExceptionType.Data_Not_Exist); @@ -555,7 +555,7 @@ public enum MapDeviceRule { @Override public List filterMapDeviceList(Simulation simulation) { Station station = simulation.getRepository().getStationList().stream() - .filter(s -> s.isCentralized() && s.isInterlock() && s.isHasControlMode() && !s.isDepot()) + .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { throw new SimulationException(SimulationExceptionType.Data_Not_Exist); @@ -642,7 +642,7 @@ public enum MapDeviceRule { @Override public List filterMapDeviceList(Simulation simulation) { Station station = simulation.getRepository().getStationList().stream() - .filter(s -> s.isCentralized() && s.isInterlock() && s.isHasControlMode() && !s.isDepot()) + .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { throw new SimulationException(SimulationExceptionType.Data_Not_Exist); From 70b3bbd11edf30b865861615ccf3d740c775c398 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 9 Jan 2023 10:32:51 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E3=80=90=E6=A0=B9=E6=8D=AE=E7=BA=BF?= =?UTF-8?q?=E8=B7=AF=E5=88=97=E8=A1=A8=E7=94=9F=E6=88=90=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../training2/TrainingRuleController.java | 6 ++ .../training2/Training2RuleService.java | 87 ++++++++++++------- .../rtss/vo/training2/rule/MapDeviceRule.java | 22 ++--- 3 files changed, 69 insertions(+), 46 deletions(-) diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java index 26d673a06..566da6e32 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java @@ -49,4 +49,10 @@ public class TrainingRuleController { return training2RuleService.generateTrainingByMapId(mapIdList, loginUserInfoVO); } + @PostMapping("generate/lineCode") + public List generateTrainingByLineCode(@RequestBody List lineCodeList + , @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO) { + return training2RuleService.generateTrainingByLineCode(lineCodeList, loginUserInfoVO); + } + } diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java index 1a1c551ea..13a361258 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java @@ -127,19 +127,73 @@ public class Training2RuleService { return generateTrainingByRule(groupId); } - + /** + * 根据地图ID生成实训 + */ public List generateTrainingByMapId(List mapIdList, LoginUserInfoVO loginUserInfoVO){ + // 地图列表 MapInfoExample example = new MapInfoExample(); MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); criteria.andIdIn(mapIdList); List mapList = mapInfoDAO.selectByExample(example); List lineCodeList = mapList.stream().map(MapInfo::getLineCode).collect(Collectors.toList()); + // 规则列表 RtsTraining2RuleExample rtsTraining2RuleExample = new RtsTraining2RuleExample(); rtsTraining2RuleExample.createCriteria().andLineCodeIn(lineCodeList); List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(rtsTraining2RuleExample); Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + List errorMsgList = new ArrayList<>(); + loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList); + return errorMsgList; + } + + /** + * 生成所有地图实训 + */ + public List generateAllTrainingByRule(LoginUserInfoVO loginUserInfoVO) { + // 规则列表 + List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(null); + Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + + // 地图列表 + MapInfoExample example = new MapInfoExample(); + MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); + criteria.andLineCodeIn(lineCodeRuleMap.keySet().stream().collect(Collectors.toList())); + List mapList = mapInfoDAO.selectByExample(example); + + List errorMsgList = new ArrayList<>(); + loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList); + return errorMsgList; + } + + /** + * 根据线路类型生成实训 + */ + public List generateTrainingByLineCode(List lineCodeList, LoginUserInfoVO loginUserInfoVO) { + // 规则列表 + RtsTraining2RuleExample rtsTraining2RuleExample = new RtsTraining2RuleExample(); + rtsTraining2RuleExample.createCriteria().andLineCodeIn(lineCodeList); + List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(rtsTraining2RuleExample); + Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); + + // 地图列表 + MapInfoExample example = new MapInfoExample(); + MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); + criteria.andLineCodeIn(lineCodeList); + List mapList = mapInfoDAO.selectByExample(example); + + List errorMsgList = new ArrayList<>(); + loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList); + return errorMsgList; + } + + /** + * 循环地图列表生成实训信息 + */ + private void loopMapListGenerateTraining(LoginUserInfoVO loginUserInfoVO, List mapList + , Map> lineCodeRuleMap, List errorMsgList) { mapList.forEach(mapInfo -> { RtsMapFunctionExample rtsExample = new RtsMapFunctionExample(); RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria(); @@ -155,37 +209,6 @@ public class Training2RuleService { } } }); - return errorMsgList; - } - - - public List generateAllTrainingByRule(LoginUserInfoVO loginUserInfoVO) { - // 规则列表 - List ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(null); - Map> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode)); - List errorMsgList = new ArrayList<>(); - lineCodeRuleMap.forEach((k,v) -> { - MapInfoExample example = new MapInfoExample(); - MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); - criteria.andLineCodeEqualTo(k); - List mapList = mapInfoDAO.selectByExample(example); - mapList.forEach(mapInfo -> { - RtsMapFunctionExample rtsExample = new RtsMapFunctionExample(); - RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria(); - rtsCriteria.andMapIdEqualTo(mapInfo.getId()); - rtsCriteria.andNameEqualTo("单操实训"); - List entities = rtsMapFunctionDAO.selectByExampleWithBLOBs(rtsExample); - if (!CollectionUtils.isEmpty(entities)) { - try { - Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO); - errorMsgList.addAll(generateTraining(simulation, v)); - } catch (Exception e) { - errorMsgList.add(String.format("地图%d创建仿真报错,原因:%s", mapInfo.getId(), e.getMessage(), Locale.ENGLISH)); - } - } - }); - }); - return errorMsgList; } private List generateTraining(Simulation simulation, List ruleList) { diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java index ca4df27fd..5ff75b424 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java @@ -352,7 +352,7 @@ public enum MapDeviceRule { .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { - throw new SimulationException(SimulationExceptionType.Data_Not_Exist); + throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "没找到第一个站站台设备"); } List standList = simulation.getRepository().getStandList().stream() .filter(stand -> Objects.equals(station, stand.getStation())).collect(Collectors.toList()); @@ -457,7 +457,7 @@ public enum MapDeviceRule { .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { - throw new SimulationException(SimulationExceptionType.Data_Not_Exist); + throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "没有找到第一个站物理区段设备"); } List
sectionList = simulation.getRepository().getSectionList().stream() .filter(s -> { @@ -524,7 +524,7 @@ public enum MapDeviceRule { .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { - throw new SimulationException(SimulationExceptionType.Data_Not_Exist); + throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "没找到第一个站信号机数据"); } List signalList = simulation.getRepository().getSignalList().stream() .filter(signal -> Objects.equals(signal.getDeviceStation(), station) && !signal.getRouteList().isEmpty()) @@ -558,7 +558,7 @@ public enum MapDeviceRule { .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { - throw new SimulationException(SimulationExceptionType.Data_Not_Exist); + throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "没找到第一个站道岔数据"); } List switchList = simulation.getRepository().getSwitchList().stream() .filter(aSwitch -> Objects.equals(aSwitch.getDeviceStation(), station)) @@ -587,9 +587,7 @@ public enum MapDeviceRule { ROUTE_ATP_LIST("ATP进路列表") { @Override public List filterMapDeviceList(Simulation simulation) { - return generateRandomElement(queryNormalRouteList(simulation, route ->{ - return route.getInterlockStation().isCentralized() && route.isAtp() && !route.isGuide(); - }), NUMBER); + return generateRandomElement(queryNormalRouteList(simulation, r -> r.getInterlockStation().isCentralized() && r.isAtp() && !r.isGuide()), NUMBER); } }, ROUTE_CENTRALIZED_LIST("集中站本站进路列表"){ @@ -606,17 +604,13 @@ public enum MapDeviceRule { ROUTE_CONTROL_LIST("控制模式车站进路列表") { @Override public List filterMapDeviceList(Simulation simulation) { - return generateRandomElement(queryNormalRouteList(simulation, route ->{ - return route.getInterlockStation().isHasControlMode() && !route.isGuide() && !route.isTurnBack(); - }), NUMBER); + return generateRandomElement(queryNormalRouteList(simulation, r -> r.getInterlockStation().isHasControlMode() && !r.isGuide() && !r.isTurnBack()), NUMBER); } }, ROUTE_GUIDE_LIST("引导进路列表") { @Override public List filterMapDeviceList(Simulation simulation) { - return generateRandomElement(queryNormalRouteList(simulation, route -> { - return route.getStart().isCallOn() && route.isGuide(); - }), NUMBER); + return generateRandomElement(queryNormalRouteList(simulation, r -> r.getStart().isCallOn() && r.isGuide()), NUMBER); } }, ROUTE_DEPARTURE_LIST("发车进路列表") { @@ -645,7 +639,7 @@ public enum MapDeviceRule { .filter(s -> s.isCentralized() && s.isInterlock() && !s.isDepot()) .min(Comparator.comparingInt(Station::getSn)).orElse(null); if (station == null) { - throw new SimulationException(SimulationExceptionType.Data_Not_Exist); + throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "没找到第一个站进路设备"); } List routeList = simulation.getRepository().getRouteList().stream().filter(r -> { if (!Objects.equals(station, r.getInterlockStation())) { From 0cb9f412f2dde04be8a35124544b84cbcb8167b3 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 9 Jan 2023 10:58:22 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=AA=8C=E8=AF=81=E5=8F=82=E6=95=B0val=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/training2/TrainingRuleController.java | 10 +++++++++- .../rtss/simulation/cbtc/training2/Operation2.java | 3 +++ .../joylink/rtss/vo/client/training2/Operation2VO.java | 2 ++ .../joylink/rtss/vo/training2/rule/OperationRule.java | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java index 566da6e32..c580bda34 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingRuleController.java @@ -21,7 +21,6 @@ public class TrainingRuleController { @Autowired private Training2RuleService training2RuleService; - /** * 根据仿真生成 */ @@ -38,17 +37,26 @@ public class TrainingRuleController { return training2RuleService.generateTrainingByMapIdAndFunId(mapId, functionId); } + /** + * 生成所有地图实训 + */ @PostMapping("generate/all") public List generateAllTraining(@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ return training2RuleService.generateAllTrainingByRule(loginUserInfoVO); } + /** + * 根据地图ID生成实训 + */ @PostMapping("generate/mapId") public List generateTrainingByMapId(@RequestBody List mapIdList , @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO){ return training2RuleService.generateTrainingByMapId(mapIdList, loginUserInfoVO); } + /** + * 根据线路编号生成实训 + */ @PostMapping("generate/lineCode") public List generateTrainingByLineCode(@RequestBody List lineCodeList , @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Operation2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Operation2.java index 11c631e9b..e41fa738b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Operation2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Operation2.java @@ -170,6 +170,8 @@ public abstract class Operation2 { private String subType; + private String val; + public ClientOperation2(Operation2VO.ClientOperation2VO vo, Simulation simulation) { super(vo.getId()); this.deviceCode = vo.getDeviceCode(); @@ -179,6 +181,7 @@ public abstract class Operation2 { this.params = vo.getParams(); this.commandId = vo.getCommandId(); this.subType = vo.getSubType(); + this.val = vo.getVal(); if (vo.getTriggerCondition() != null) { this.setTriggerCondition(vo.getTriggerCondition().convert2BO(simulation.getRepository())); } diff --git a/src/main/java/club/joylink/rtss/vo/client/training2/Operation2VO.java b/src/main/java/club/joylink/rtss/vo/client/training2/Operation2VO.java index a3a6077fe..3ce16d152 100644 --- a/src/main/java/club/joylink/rtss/vo/client/training2/Operation2VO.java +++ b/src/main/java/club/joylink/rtss/vo/client/training2/Operation2VO.java @@ -79,6 +79,8 @@ public abstract class Operation2VO { private String subType; + private String val; + @Override public Operation2 convert2BO(Simulation simulation) { return new Operation2.ClientOperation2(this, simulation); diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java index ab81b767e..07fc690fd 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/OperationRule.java @@ -94,6 +94,8 @@ public abstract class OperationRule { private String subType; + private String val; + @Override public Operation2VO.ClientOperation2VO convert2BO(Simulation simulation, Object mapElement) { Operation2VO.ClientOperation2VO operation2 = new Operation2VO.ClientOperation2VO(); @@ -113,6 +115,8 @@ public abstract class OperationRule { operation2.setParams(new HashMap<>()); // 二级定位 operation2.setSubType(subType); + // 参数校验 + operation2.setVal(val); if (!CollectionUtils.isEmpty(params)) { params.forEach((k, v) -> { String vStr = String.valueOf(v); From 9ce414e3ee0c2c8cf2f2b8fa987fcdb9185d7aee Mon Sep 17 00:00:00 2001 From: weizhihong Date: Mon, 9 Jan 2023 13:15:06 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8E=A7=E5=88=B6=E6=A8=A1=E5=BC=8F=E8=BD=A6=E7=AB=99?= =?UTF-8?q?=E4=BF=A1=E5=8F=B7=E6=9C=BA=E7=AD=9B=E9=80=89=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/joylink/rtss/vo/training2/rule/MapDeviceRule.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java index 5ff75b424..17414b316 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MapDeviceRule.java @@ -517,6 +517,13 @@ public enum MapDeviceRule { ? signal.getStation().isCentralized() : signal.getDeviceStation().isCentralized()), NUMBER); } }, + SIGNAL_CONTROL_LIST("控制模式车站信号机列表") { + @Override + public List filterMapDeviceList(Simulation simulation) { + return generateRandomElement(queryNormalSignalList(simulation, signal -> signal.getStation() != null + ? signal.getStation().isInterlock() : signal.getDeviceStation().isInterlock()), NUMBER); + } + }, SIGNAL_FIRST_STATION_LIST("获取第一个站信号机列表") { @Override public List filterMapDeviceList(Simulation simulation) {