|
@@ -429,7 +429,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
public ResponseBodyVO<ProjectDetailsVo> selectProjectDetailsById(SimulationManualProjectParam param) {
|
|
|
|
|
|
ProjectDetailsVo projectDetailsVo = null;
|
|
|
- String evaluationLevel = null;
|
|
|
if (DictConstants.PROJECT_TYPE_MANUAL.equals(param.getProjectType())) { // 手动运行任务
|
|
|
SimulationManualProjectPo po = simulationProjectMapper.selectProjectById(param);
|
|
|
projectDetailsVo = JsonUtil.jsonToBean(po.getDetails(), ProjectDetailsVo.class);
|
|
@@ -3941,7 +3940,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
Optional.ofNullable(automaticRunState).orElseThrow(() -> new RuntimeException("自动运行状态不能为空。"));
|
|
|
|
|
|
//1 修改父项目停用状态
|
|
|
-
|
|
|
SimulationAutomaticProjectPo po = simulationAutomaticProjectMapper.selectById(id); // 查询父项目信息
|
|
|
String algorithmId = po.getAlgorithm();
|
|
|
if ("0".equals(param.getAutomaticRunState())) { // 启动
|
|
@@ -3950,48 +3948,18 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
if (DictConstants.IS_DELETED.equals(isDeleted)) {
|
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "算法已被删除,无法启动项目。", null);
|
|
|
}
|
|
|
-// //获取数据库中的算法版本
|
|
|
-// AlgorithmPO aPo = algorithmMapper.selectDetailsById(algorithmId);
|
|
|
-// String gitVersion = aPo.getGitVersion();
|
|
|
-// //获取当前算法版本
|
|
|
String currentGitVersion = algorithmService.getGitVersion(algorithmId);
|
|
|
-// boolean isRun = false; //判断是否启动运行
|
|
|
-// //首次获取版本
|
|
|
-// if (StringUtil.isEmpty(gitVersion)) {
|
|
|
-// isRun = true;
|
|
|
-// } else {
|
|
|
-// //非首次,比对版本,校验是否执行任务
|
|
|
-// if (!gitVersion.equals(currentGitVersion)) {
|
|
|
-// isRun = true;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// if (isRun) { //启动运行
|
|
|
simulationAutomaticProjectMapper.updateAutomaticRunState(param);
|
|
|
AlgorithmParameter algorithmParam = new AlgorithmParameter();
|
|
|
algorithmParam.setId(algorithmId);
|
|
|
algorithmParam.setGitVersion(currentGitVersion);
|
|
|
runProject(algorithmParam, param, po);
|
|
|
-// }
|
|
|
} else if ("1".equals(param.getAutomaticRunState())) { // 停止
|
|
|
simulationAutomaticProjectMapper.updateAutomaticRunState(param);
|
|
|
//推送定时请求
|
|
|
projectTaskStop(po);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
-
|
|
|
-
|
|
|
- /*String automaticRunState = param.getAutomaticRunState();
|
|
|
- SimulationAutomaticProjectPo po = new SimulationAutomaticProjectPo();
|
|
|
- po.setId("222222");
|
|
|
- po.setOperationCycle("0/2 * * * * ?");
|
|
|
- if("0".equals(automaticRunState)){
|
|
|
- projectTaskStart(po);
|
|
|
- }else{
|
|
|
- projectTaskStop(po);
|
|
|
- }
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);*/
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -4044,63 +4012,66 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
|
|
|
}
|
|
|
|
|
|
- @SneakyThrows
|
|
|
+
|
|
|
@Override
|
|
|
public ResponseBodyVO<String> createAutomaticSubProject(SimulationManualProjectParam param) {
|
|
|
|
|
|
|
|
|
- if (StringUtil.isEmpty(param.getId())) {
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "id不能为空");
|
|
|
+ try {
|
|
|
+ if (StringUtil.isEmpty(param.getId())) {
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.CLIENT_FAILURE, "id不能为空");
|
|
|
+ }
|
|
|
+ SimulationAutomaticProjectPo po = simulationAutomaticProjectMapper.selectById(param.getId());
|
|
|
+ String projectName = po.getProjectName();
|
|
|
+
|
|
|
+ SimulationAutomaticSubProjectPo subprojectPo = new SimulationAutomaticSubProjectPo();
|
|
|
+ subprojectPo.createPo(po.getCreateUserId());
|
|
|
+ subprojectPo.setParentId(po.getId());
|
|
|
+ subprojectPo.setParentProjectId(po.getProjectId());
|
|
|
+ subprojectPo.setProjectName(projectName);
|
|
|
+ subprojectPo.setStartTime(new Date());
|
|
|
+ subprojectPo.setNowRunState(ProjectRunStateEnum.EXECUTION.getCode());//执行中
|
|
|
+ SimulationAutomaticSubProjectPo sPo = simulationAutomaticSubProjectMapper.selectLastProjectId(param.getId());
|
|
|
+ if (StringUtil.isEmpty(sPo)) {
|
|
|
+ subprojectPo.setProjectNum(1);
|
|
|
+ subprojectPo.setProjectId(po.getProjectId() + "-1");
|
|
|
+ } else {
|
|
|
+ Integer projectNum = sPo.getProjectNum() + 1;
|
|
|
+ subprojectPo.setProjectNum(projectNum);
|
|
|
+ subprojectPo.setProjectId(po.getProjectId() + "-" + projectNum);
|
|
|
+ }
|
|
|
+ //修改自动运行次数
|
|
|
+ Long automaticRunTimes = po.getAutomaticRunTimes();
|
|
|
+ if (automaticRunTimes == null) {
|
|
|
+ po.setAutomaticRunTimes(1L);
|
|
|
+ } else {
|
|
|
+ po.setAutomaticRunTimes(automaticRunTimes + 1);
|
|
|
+ }
|
|
|
+ simulationAutomaticProjectMapper.updateAutomaticRunTimes(po);
|
|
|
+ int i = simulationAutomaticSubProjectMapper.addAutomaticSubProject(subprojectPo);
|
|
|
+ // 查询详情信息并保存
|
|
|
+ String projectId = subprojectPo.getId();
|
|
|
+ ProjectDetailsVo info = selectProjectDetailsByIdBackUp(SimulationManualProjectParam.builder()
|
|
|
+ .id(projectId)
|
|
|
+ .projectType(DictConstants.PROJECT_TYPE_AUTO_SUB).build()).getInfo();
|
|
|
+ String infoJson = JsonUtil.beanToJson(info);
|
|
|
+ log.info("updateProjectNowRunState() 项目 " + projectId + " 的详情信息为:" + infoJson);
|
|
|
+ autoSubProjectMapper.updateDetailsById(projectId, infoJson);
|
|
|
+ if (i <= 0) {
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "执行失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //推送消息到kafka
|
|
|
+ autoProjectRunToKafka(po, subprojectPo.getId());
|
|
|
+
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, null);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
- SimulationAutomaticProjectPo po = simulationAutomaticProjectMapper.selectById(param.getId());
|
|
|
- String projectName = po.getProjectName();
|
|
|
-
|
|
|
- SimulationAutomaticSubProjectPo subprojectPo = new SimulationAutomaticSubProjectPo();
|
|
|
- subprojectPo.createPo(po.getCreateUserId());
|
|
|
- subprojectPo.setParentId(po.getId());
|
|
|
- subprojectPo.setParentProjectId(po.getProjectId());
|
|
|
- subprojectPo.setProjectName(projectName);
|
|
|
- subprojectPo.setStartTime(new Date());
|
|
|
- subprojectPo.setNowRunState(ProjectRunStateEnum.EXECUTION.getCode());//执行中
|
|
|
- SimulationAutomaticSubProjectPo sPo = simulationAutomaticSubProjectMapper.selectLastProjectId(param.getId());
|
|
|
- if (StringUtil.isEmpty(sPo)) {
|
|
|
- subprojectPo.setProjectNum(1);
|
|
|
- subprojectPo.setProjectId(po.getProjectId() + "-1");
|
|
|
- } else {
|
|
|
- Integer projectNum = sPo.getProjectNum() + 1;
|
|
|
- subprojectPo.setProjectNum(projectNum);
|
|
|
- subprojectPo.setProjectId(po.getProjectId() + "-" + projectNum);
|
|
|
- }
|
|
|
- //修改自动运行次数
|
|
|
- Long automaticRunTimes = po.getAutomaticRunTimes();
|
|
|
- if (automaticRunTimes == null) {
|
|
|
- po.setAutomaticRunTimes(1L);
|
|
|
- } else {
|
|
|
- po.setAutomaticRunTimes(automaticRunTimes + 1);
|
|
|
- }
|
|
|
- simulationAutomaticProjectMapper.updateAutomaticRunTimes(po);
|
|
|
- int i = simulationAutomaticSubProjectMapper.addAutomaticSubProject(subprojectPo);
|
|
|
- // 查询详情信息并保存
|
|
|
- String projectId = subprojectPo.getId();
|
|
|
- ProjectDetailsVo info = selectProjectDetailsByIdBackUp(SimulationManualProjectParam.builder()
|
|
|
- .id(projectId)
|
|
|
- .projectType(DictConstants.PROJECT_TYPE_AUTO_SUB).build()).getInfo();
|
|
|
- String infoJson = JsonUtil.beanToJson(info);
|
|
|
- log.info("updateProjectNowRunState() 项目 " + projectId + " 的详情信息为:" + infoJson);
|
|
|
- autoSubProjectMapper.updateDetailsById(projectId, infoJson);
|
|
|
- if (i <= 0) {
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "执行失败");
|
|
|
- }
|
|
|
-
|
|
|
- //推送消息到kafka
|
|
|
- autoProjectRunToKafka(po, subprojectPo.getId());
|
|
|
-
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, null);
|
|
|
}
|
|
|
|
|
|
private void autoProjectRunToKafka(SimulationAutomaticProjectPo po, String subId) throws JsonProcessingException {
|
|
|
SimulationManualProjectKafkaParam kafkaParam = new SimulationManualProjectKafkaParam();
|
|
|
-// kafkaParam.setProjectId(po.getId());
|
|
|
kafkaParam.setProjectId(subId); //子任务id
|
|
|
kafkaParam.setAlgorithmId(po.getAlgorithm());
|
|
|
kafkaParam.setVehicleConfigId(po.getVehicle());
|
|
@@ -4110,11 +4081,10 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
kafkaParam.setType(DictConstants.PROJECT_TYPE_AUTO_SUB);
|
|
|
KafkaParameter kafkaParameter = new KafkaParameter();
|
|
|
kafkaParameter.setTopic(ProjectConstants.RUN_TASK_TOPIC);
|
|
|
+ kafkaParam.setModelType(vehicleMapper.selectParameterTypeById(po.getVehicle()));
|
|
|
String data = JsonUtil.beanToJson(kafkaParam);
|
|
|
kafkaParameter.setData(data);
|
|
|
log.info("自动运行项目推送消息到 kafka:" + data);
|
|
|
-// kafkaService.send(kafkaParameter);
|
|
|
-
|
|
|
kafkaTemplate.send(kafkaParameter.getTopic(), kafkaParameter.getData()).addCallback(success -> {
|
|
|
// 消息发送到的topic
|
|
|
String topic = success.getRecordMetadata().topic();
|
|
@@ -4386,7 +4356,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
SimulationManualProjectParam p = new SimulationManualProjectParam();
|
|
|
p.setProjectId(po.getId());
|
|
|
p.setCron(po.getOperationCycle());
|
|
|
- ResponseBodyVO start = monitorService.start(p);
|
|
|
+ ResponseBodyVO<String> start = monitorService.start(p);
|
|
|
boolean status = start.isStatus();
|
|
|
if (!status) {
|
|
|
//定时任务启动失败,抛出异常
|