From 8eab737a6478dce5e477a4050f1debe217f497a1 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 28 Oct 2022 15:14:29 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E8=A7=84?= =?UTF-8?q?=E5=88=99=E7=94=9F=E6=88=90=E5=AE=9E=E8=AE=AD=E9=80=BB=E8=BE=91?= =?UTF-8?q?=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 | 5 +++-- .../joylink/rtss/vo/training2/rule/PropertyValueRule.java | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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 a637680ac..aa866c9b1 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 @@ -1,6 +1,7 @@ package club.joylink.rtss.vo.training2.rule; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.map.Route; import lombok.Getter; import java.util.List; @@ -10,7 +11,7 @@ public enum MapDeviceRule { ROUTE_LIST("进路列表") { @Override - public List filterMapDeviceList(Simulation simulation) { + public List filterMapDeviceList(Simulation simulation) { return simulation.getRepository().getRouteList(); } }; @@ -21,5 +22,5 @@ public enum MapDeviceRule { this.description = description; } - public abstract List filterMapDeviceList(Simulation simulation); + public abstract List filterMapDeviceList(Simulation simulation); } diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java index 2247dcf52..9aa654a47 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/PropertyValueRule.java @@ -32,12 +32,18 @@ public enum PropertyValueRule { STATION_NAME("地图设备所属车站名称") { @Override public String resolve(Simulation simulation, Object mapElement) { + if (mapElement instanceof Route) { + return ((Route) mapElement).getStart().getStation().getName(); + } return null; } }, STATION_CODE("地图设备所属车站编码") { @Override public String resolve(Simulation simulation, Object mapElement) { + if (mapElement instanceof Route) { + return ((Route) mapElement).getStart().getStation().getCode(); + } return null; } }, From f226d2eb761ebd38ed1fcb8afeed9867fc43393e Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 28 Oct 2022 15:16:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=B5=8B=E8=AF=95=E7=B1=BB=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/training/Training2RuleTest.java | 68 ++++++++++++------- 1 file changed, 44 insertions(+), 24 deletions(-) diff --git a/src/test/java/club/joylink/rtss/services/training/Training2RuleTest.java b/src/test/java/club/joylink/rtss/services/training/Training2RuleTest.java index a84bfe36f..4159b9e0e 100644 --- a/src/test/java/club/joylink/rtss/services/training/Training2RuleTest.java +++ b/src/test/java/club/joylink/rtss/services/training/Training2RuleTest.java @@ -1,25 +1,26 @@ package club.joylink.rtss.services.training; -import club.joylink.rtss.constants.MapPrdTypeEnum; import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs; import club.joylink.rtss.services.IMapService; import club.joylink.rtss.services.IRunPlanTemplateService; -import club.joylink.rtss.services.training.data.GenerateConfig; +import club.joylink.rtss.simulation.SimulationManager; +import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; -import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder; +import club.joylink.rtss.simulation.cbtc.SimulationService; import club.joylink.rtss.simulation.cbtc.data.map.Route; +import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO; +import club.joylink.rtss.simulation.cbtc.work.SimulationWorkService; +import club.joylink.rtss.simulation.cbtc.work.SimulationWorkServiceManager; +import club.joylink.rtss.simulation.messaging.websocket.DefaultMessageSender; import club.joylink.rtss.util.JsonUtils; -import club.joylink.rtss.vo.client.runplan.RunPlanVO; -import club.joylink.rtss.vo.map.MapVO; +import club.joylink.rtss.vo.AccountVO; +import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.training2.rule.Training2Rule; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; - @SpringBootTest public class Training2RuleTest { @@ -29,28 +30,47 @@ public class Training2RuleTest { @Autowired private IRunPlanTemplateService iRunPlanTemplateService; + @Autowired + private SimulationWorkServiceManager simulationWorkServiceManager; + + @Autowired + private SimulationService simulationService; + + @Autowired + private SimulationManager simulationManager; + + @Autowired + private DefaultMessageSender defaultMessageSender; + + @Autowired + private GroupSimulationService groupSimulationService; + + @Transactional @Test public void entityTest() { - String trainingRuleStr = "{\"id\":1,\"mapId\":154,\"deviceType\":\"ROUTE\",\"name\":\"【{NAME}】办理\",\"description\":\"【{NAME}】办理\",\"type\":\"SINGLE\",\"labels\":[],\"sceneRule\":null,\"steps\":[{\"id\":1,\"memberId\":\"3\",\"description\":\"点击信号机【{ROUTE_START_NAME}】按钮\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"deviceCode\":\"BUTTON_START_CODE\",\"userOperationType\":\"leftClick\",\"domId\":\"3010\",\"operationType\":\"\",\"params\":{}}],\"triggerRule\":null,\"completionRule\":null,\"failureRule\":null,\"tipPosition\":{\"domId\":\"3010\",\"deviceCode\":\"BUTTON_START_CODE\",\"operateIndex\":0}},{\"id\":2,\"memberId\":\"3\",\"description\":\"点击信号机【{ROUTE_END_NAME}】按钮\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"deviceCode\":\"BUTTON_END_CODE\",\"userOperationType\":\"leftClick\",\"domId\":\"3010\",\"operationType\":\"Signal_Set_Route\",\"params\":{}}],\"tipPosition\":{\"domId\":\"3010\",\"deviceCode\":\"BUTTON_END_CODE\",\"operateIndex\":0}}],\"failureRule\":null,\"creatorId\":5710}"; - String trainingRuleStr2 = "{\"id\":1,\"mapId\":154,\"deviceType\":\"ROUTE\",\"name\":\"取消【{NAME}】进路\",\"description\":\"取消【{NAME}】进路\",\"type\":\"SINGLE\",\"labels\":null,\"sceneRule\": \"ROUTE_BG_SCENE\",\"steps\":[{\"id\":1,\"memberId\":\"3\",\"description\":\"点击总取消\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"userOperationType\":\"leftClick\",\"domId\":\"2994\",\"operationType\":\"\",\"params\":{}}],\"triggerRule\":null,\"completionRule\":null,\"failureRule\":null,\"tipPosition\":{\"domId\":\"2994\",\"operateIndex\":0}},{\"id\":2,\"memberId\":\"3\",\"description\":\"点击信号机【{ROUTE_START_NAME}】\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"deviceCode\":\"BUTTON_START_CODE\",\"userOperationType\":\"leftClick\",\"domId\":\"2994\",\"operationType\":\"Signal_Cancel_Route\",\"params\":{}}],\"tipPosition\":{\"domId\":\"2994\",\"deviceCode\":\"BUTTON_START_CODE\",\"operateIndex\":0}}],\"failureRule\":null,\"creatorId\":5710}"; + String trainingRuleStr = "{\"id\":1,\"mapId\":154,\"deviceRule\":\"ROUTE_LIST\",\"name\":\"取消{NAME}进路\",\"description\":\"取消{NAME}进路\",\"type\":\"SINGLE\",\"labels\":null,\"sceneRule\":\"ROUTE_BG_SCENE\",\"steps\":[{\"id\":1,\"memberRule\":{\"type\":\"STATION_SUPERVISOR\",\"deviceCodeRule\":\"STATION_CODE\"},\"description\":\"点击总取消\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"userOperationType\":\"leftClick\",\"domId\":\"2994\",\"operationType\":\"\",\"params\":{}}],\"triggerRule\":null,\"completionRule\":null,\"failureRule\":null,\"tipPosition\":{\"domId\":\"2994\",\"operateIndex\":0}},{\"id\":2,\"memberRule\":{\"type\":\"STATION_SUPERVISOR\",\"deviceCodeRule\":\"STATION_CODE\"},\"description\":\"点击信号机【{ROUTE_START_NAME}】\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"deviceCode\":\"BUTTON_START_CODE\",\"userOperationType\":\"leftClick\",\"domId\":\"2994\",\"operationType\":\"Signal_Cancel_Route\",\"params\":{}}],\"tipPosition\":{\"domId\":\"2994\",\"deviceCode\":\"BUTTON_START_CODE\",\"operateIndex\":0}}],\"failureRule\":null,\"creatorId\":5710}"; + String trainingRuleStr2 = "{\"id\":1,\"mapId\":154,\"deviceRule\":\"ROUTE_LIST\",\"name\":\"【{NAME}】办理\",\"description\":\"【{NAME}】办理\",\"type\":\"SINGLE\",\"labels\":null,\"sceneRule\":null,\"steps\":[{\"id\":1,\"memberRule\":{\"type\":\"STATION_SUPERVISOR\",\"deviceCodeRule\":\"STATION_CODE\"},\"description\":\"点击信号机【{ROUTE_START_NAME}】按钮\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"deviceCode\":\"BUTTON_START_CODE\",\"userOperationType\":\"leftClick\",\"domId\":\"3010\",\"operationType\":\"\",\"params\":{}}],\"triggerRule\":null,\"completionRule\":null,\"failureRule\":null,\"tipPosition\":{\"domId\":\"3010\",\"deviceCode\":\"BUTTON_START_CODE\",\"operateIndex\":0}},{\"id\":2,\"memberRule\":{\"type\":\"STATION_SUPERVISOR\",\"deviceCodeRule\":\"STATION_CODE\"},\"description\":\"点击信号机【{ROUTE_END_NAME}】按钮\",\"operationRules\":[{\"t\":\"C\",\"id\":0,\"deviceCode\":\"BUTTON_END_CODE\",\"userOperationType\":\"leftClick\",\"domId\":\"3010\",\"operationType\":\"Signal_Set_Route\",\"params\":{}}],\"tipPosition\":{\"domId\":\"3010\",\"deviceCode\":\"BUTTON_END_CODE\",\"operateIndex\":0}}],\"failureRule\":null,\"creatorId\":5710}"; Training2Rule training2Rule = JsonUtils.read(trainingRuleStr, Training2Rule.class); Training2Rule training2Rule2 = JsonUtils.read(trainingRuleStr2, Training2Rule.class); // 生成实训 - MapVO mapVO = iMapService.getMapDetail(training2Rule.getMapId()); - // 仿真配置 - GenerateConfig config = new GenerateConfig(); - config.setMapId(training2Rule.getMapId()); - // 查询通用运行图 - RunPlanVO planVO = this.iRunPlanTemplateService.getFirstRunPlanByMapId(mapVO.getId()); - SimulationBuildParams params = SimulationBuildParams.builder() - .createTime(LocalDateTime.now()) - .map(mapVO) - .prodType(MapPrdTypeEnum.getMapPrdTypeEnumByCode(config.getPrdType())) - .runPlan(planVO) - .build(); - Simulation simulation = SimulationBuilder.build("", params); - Route route = simulation.getRepository().getByCode("Route94", Route.class); + SimulationWorkParamVO workParamVO = JsonUtils.read("{\"type\":\"RAILWAY\",\"memberId\":\"1\",\"domConfig\":{\"singleMember\":true,\"singleClient\":false,\"hasTraining\":false,\"hasExam\":false},\"mapId\":154}", SimulationWorkParamVO.class); + LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO(); + AccountVO accountVO = new AccountVO(); + accountVO.setId(5710L); + loginUserInfoVO.setAccountVO(accountVO); + SimulationWorkService initService = simulationWorkServiceManager.getInitService(workParamVO.getType()); + Simulation simulation = initService.create(training2Rule.getMapId(), workParamVO, loginUserInfoVO); + // 删除旧仿真,保存新仿真 + club.joylink.rtss.simulation.Simulation oldSimulation = simulationManager.queryByCreatorId(simulation.getCreatorId()); + if (oldSimulation != null) { + groupSimulationService.clearSimulation(oldSimulation.getId()); + } + simulationManager.saveNew(simulation); + initService.loadData(simulation); + initService.init(simulation); + + Route route = simulation.getRepository().getByCode("Route1", Route.class); DraftTraining2WithBLOBs draftTraining2WithBLOBs = training2Rule.convert2BO(simulation, route); System.out.println(JsonUtils.writeValueAsString(draftTraining2WithBLOBs)); DraftTraining2WithBLOBs draftTraining2WithBLOBs2 = training2Rule2.convert2BO(simulation, route);