Merge remote-tracking branch 'origin/test-training2' into test-training2

This commit is contained in:
tiger_zhou 2022-10-28 15:59:04 +08:00
commit aedab56c37
3 changed files with 53 additions and 26 deletions

View File

@ -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<? extends Object> filterMapDeviceList(Simulation simulation) {
public List<Route> filterMapDeviceList(Simulation simulation) {
return simulation.getRepository().getRouteList();
}
};
@ -21,5 +22,5 @@ public enum MapDeviceRule {
this.description = description;
}
public abstract List<? extends Object> filterMapDeviceList(Simulation simulation);
public abstract <T> List<T> filterMapDeviceList(Simulation simulation);
}

View File

@ -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;
}
},

View File

@ -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);