|
@@ -45,9 +45,11 @@ import com.itextpdf.text.pdf.PdfPTable;
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
import com.itextpdf.text.pdf.PdfWriter;
|
|
import feign.Response;
|
|
import feign.Response;
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
|
+import lombok.Synchronized;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.tomcat.util.buf.StringUtils;
|
|
import org.apache.tomcat.util.buf.StringUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
import org.springframework.scheduling.support.CronExpression;
|
|
import org.springframework.scheduling.support.CronExpression;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -73,6 +75,8 @@ import java.util.zip.ZipOutputStream;
|
|
@Slf4j
|
|
@Slf4j
|
|
public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
@Resource
|
|
@Resource
|
|
private SimulationManualProjectMapper simulationManualProjectMapper;
|
|
private SimulationManualProjectMapper simulationManualProjectMapper;
|
|
@Resource
|
|
@Resource
|
|
@@ -132,12 +136,8 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
// }
|
|
// }
|
|
po.createPo(AuthUtil.getCurrentUserId());
|
|
po.createPo(AuthUtil.getCurrentUserId());
|
|
// 生成id
|
|
// 生成id
|
|
- createProjectId(po);
|
|
|
|
- int add = simulationManualProjectMapper.add(po);
|
|
|
|
- if (add > 0) {
|
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
|
|
|
|
- }
|
|
|
|
- return new ResponseBodyVO<>(ResponseBodyVO.Response.SERVER_FAILURE, "添加失败。");
|
|
|
|
|
|
+ createProjectIdAndAdd(po);
|
|
|
|
+ return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
|
|
} else {
|
|
} else {
|
|
// 取工作状态,仅未开始的才可以修改信息
|
|
// 取工作状态,仅未开始的才可以修改信息
|
|
SimulationManualProjectPO simulationManualProjectPo = simulationManualProjectMapper.selectProjectById(param);
|
|
SimulationManualProjectPO simulationManualProjectPo = simulationManualProjectMapper.selectProjectById(param);
|
|
@@ -296,15 +296,17 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
projectDetailsVO.setStartTime(TimeUtil.dateToString(new Date()));
|
|
projectDetailsVO.setStartTime(TimeUtil.dateToString(new Date()));
|
|
//1 初始化数据
|
|
//1 初始化数据
|
|
newProjectPO.createPo(AuthUtil.getCurrentUserId()); // 创建新ID
|
|
newProjectPO.createPo(AuthUtil.getCurrentUserId()); // 创建新ID
|
|
- createProjectId(newProjectPO);
|
|
|
|
- newProjectPO.setNowRunState(DictConstants.PROJECT_RUNNING);
|
|
|
|
- newProjectPO.setEvaluationLevel("");
|
|
|
|
- newProjectPO.setStartTime(new Date());
|
|
|
|
- newProjectPO.setFinishTime(null);
|
|
|
|
- projectDetailsVO.setProjectId(newProjectPO.getProjectId());
|
|
|
|
- String projectDetailsVOJson = JsonUtil.beanToJson(projectDetailsVO);
|
|
|
|
- newProjectPO.setDetails(projectDetailsVOJson);
|
|
|
|
- simulationManualProjectMapper.add(newProjectPO);
|
|
|
|
|
|
+ synchronized (newProjectPO) {
|
|
|
|
+ newProjectPO.setNowRunState(DictConstants.PROJECT_RUNNING);
|
|
|
|
+ newProjectPO.setEvaluationLevel("");
|
|
|
|
+ newProjectPO.setStartTime(new Date());
|
|
|
|
+ newProjectPO.setFinishTime(null);
|
|
|
|
+ projectDetailsVO.setProjectId(newProjectPO.getProjectId());
|
|
|
|
+ String projectDetailsVOJson = JsonUtil.beanToJson(projectDetailsVO);
|
|
|
|
+ newProjectPO.setDetails(projectDetailsVOJson);
|
|
|
|
+ createProjectIdAndAdd(newProjectPO);
|
|
|
|
+
|
|
|
|
+ }
|
|
projectRunToKafka(newProjectPO);
|
|
projectRunToKafka(newProjectPO);
|
|
} else if (DictConstants.PROJECT_TERMINATED.equals(oldState)) { //重新运行被终止的项目需要修改新的ID
|
|
} else if (DictConstants.PROJECT_TERMINATED.equals(oldState)) { //重新运行被终止的项目需要修改新的ID
|
|
// 如果是重新运行的项目,修改项目ID
|
|
// 如果是重新运行的项目,修改项目ID
|
|
@@ -406,21 +408,28 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
String details;
|
|
String details;
|
|
String algorithmType;
|
|
String algorithmType;
|
|
String algorithmId;
|
|
String algorithmId;
|
|
|
|
+ String projectId;
|
|
if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) { // 手动运行任务
|
|
if (DictConstants.PROJECT_TYPE_MANUAL.equals(projectType)) { // 手动运行任务
|
|
SimulationManualProjectPO simulationManualProjectPO = simulationManualProjectMapper.selectProjectById(param);
|
|
SimulationManualProjectPO simulationManualProjectPO = simulationManualProjectMapper.selectProjectById(param);
|
|
details = simulationManualProjectPO.getDetails();
|
|
details = simulationManualProjectPO.getDetails();
|
|
algorithmType = simulationManualProjectPO.getAlgorithmType();
|
|
algorithmType = simulationManualProjectPO.getAlgorithmType();
|
|
algorithmId = simulationManualProjectPO.getAlgorithm();
|
|
algorithmId = simulationManualProjectPO.getAlgorithm();
|
|
|
|
+ projectId = simulationManualProjectPO.getProjectId();
|
|
} else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
} else if (DictConstants.PROJECT_TYPE_AUTO_SUB.equals(projectType)) {
|
|
SimulationManualProjectVO simulationManualProjectVO = simulationAutomaticSubProjectMapper.selectProjectInfo(param);
|
|
SimulationManualProjectVO simulationManualProjectVO = simulationAutomaticSubProjectMapper.selectProjectInfo(param);
|
|
details = simulationManualProjectVO.getDetails();
|
|
details = simulationManualProjectVO.getDetails();
|
|
algorithmType = simulationManualProjectVO.getAlgorithmType();
|
|
algorithmType = simulationManualProjectVO.getAlgorithmType();
|
|
algorithmId = simulationManualProjectVO.getAlgorithm();
|
|
algorithmId = simulationManualProjectVO.getAlgorithm();
|
|
|
|
+ projectId = simulationManualProjectVO.getProjectId();
|
|
} else {
|
|
} else {
|
|
throw new RuntimeException("未知项目类型:" + projectType);
|
|
throw new RuntimeException("未知项目类型:" + projectType);
|
|
}
|
|
}
|
|
projectDetailsVO = JsonUtil.jsonToBean(details, ProjectDetailsVO.class);
|
|
projectDetailsVO = JsonUtil.jsonToBean(details, ProjectDetailsVO.class);
|
|
|
|
|
|
|
|
+ // 修正项目ID
|
|
|
|
+ {
|
|
|
|
+ projectDetailsVO.setProjectId(projectId);
|
|
|
|
+ }
|
|
//TODO 修正算法名称,后期可删掉
|
|
//TODO 修正算法名称,后期可删掉
|
|
{
|
|
{
|
|
String algorithmName = null;
|
|
String algorithmName = null;
|
|
@@ -1780,10 +1789,12 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Synchronized
|
|
private void createProjectId(SimulationManualProjectPO po) {
|
|
private void createProjectId(SimulationManualProjectPO po) {
|
|
- Integer nowRq = getRq(null, 0);
|
|
|
|
- po.setProjectDate(nowRq);
|
|
|
|
- SimulationManualProjectPO po1 = simulationManualProjectMapper.selectLastProjectId(nowRq);
|
|
|
|
|
|
+
|
|
|
|
+ String nowDateString = TimeUtil.dateToString(new Date(), "yyyyMMdd");
|
|
|
|
+ po.setProjectDate(Integer.valueOf(nowDateString));
|
|
|
|
+ SimulationManualProjectPO po1 = simulationManualProjectMapper.selectLastProjectId(Integer.valueOf(nowDateString));
|
|
if (po1 == null) {
|
|
if (po1 == null) {
|
|
// 生成新id
|
|
// 生成新id
|
|
po.setProjectNum(1);
|
|
po.setProjectNum(1);
|
|
@@ -1791,9 +1802,26 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
po.setProjectNum(po1.getProjectNum() + 1);
|
|
po.setProjectNum(po1.getProjectNum() + 1);
|
|
}
|
|
}
|
|
po.setProjectId(po.getProjectDate() + "-" + po.getProjectNum());
|
|
po.setProjectId(po.getProjectDate() + "-" + po.getProjectNum());
|
|
|
|
+ simulationManualProjectMapper.add(po);
|
|
}
|
|
}
|
|
|
|
|
|
- private void createProjectId(SimulationAutomaticProjectPO po) {
|
|
|
|
|
|
+ @Synchronized
|
|
|
|
+ private void createProjectIdAndAdd(SimulationManualProjectPO po) {
|
|
|
|
+ String nowDateString = TimeUtil.dateToString(new Date(), "yyyyMMdd");
|
|
|
|
+ po.setProjectDate(Integer.valueOf(nowDateString));
|
|
|
|
+ SimulationManualProjectPO po1 = simulationManualProjectMapper.selectLastProjectId(Integer.valueOf(nowDateString));
|
|
|
|
+ if (po1 == null) {
|
|
|
|
+ // 生成新id
|
|
|
|
+ po.setProjectNum(1);
|
|
|
|
+ } else {
|
|
|
|
+ po.setProjectNum(po1.getProjectNum() + 1);
|
|
|
|
+ }
|
|
|
|
+ po.setProjectId(po.getProjectDate() + "-" + po.getProjectNum());
|
|
|
|
+ simulationManualProjectMapper.add(po);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Synchronized
|
|
|
|
+ private void createProjectIdAndAdd(SimulationAutomaticProjectPO po) {
|
|
Integer nowRq = getRq(null, 0);
|
|
Integer nowRq = getRq(null, 0);
|
|
po.setProjectDate(nowRq);
|
|
po.setProjectDate(nowRq);
|
|
SimulationAutomaticProjectPO po1 = simulationAutomaticProjectMapper.selectLastProjectId(nowRq);
|
|
SimulationAutomaticProjectPO po1 = simulationAutomaticProjectMapper.selectLastProjectId(nowRq);
|
|
@@ -1804,7 +1832,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
po.setProjectNum(po1.getProjectNum() + 1);
|
|
po.setProjectNum(po1.getProjectNum() + 1);
|
|
}
|
|
}
|
|
po.setProjectId(po.getProjectDate() + "-" + po.getProjectNum());
|
|
po.setProjectId(po.getProjectDate() + "-" + po.getProjectNum());
|
|
-
|
|
|
|
|
|
+ simulationAutomaticProjectMapper.add(po);
|
|
}
|
|
}
|
|
|
|
|
|
private Integer getRq(Date date, int index) {
|
|
private Integer getRq(Date date, int index) {
|
|
@@ -4658,12 +4686,8 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
}
|
|
}
|
|
po.createPo(AuthUtil.getCurrentUserId());
|
|
po.createPo(AuthUtil.getCurrentUserId());
|
|
// 生成id
|
|
// 生成id
|
|
- createProjectId(po);
|
|
|
|
- int add = simulationAutomaticProjectMapper.add(po);
|
|
|
|
- if (add > 0) {
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
|
|
|
|
- }
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE, "添加失败");
|
|
|
|
|
|
+ createProjectIdAndAdd(po);
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, ResponseBodyVO.Response.SUCCESS.getMessage(), po.getId());
|
|
} else {
|
|
} else {
|
|
|
|
|
|
SimulationAutomaticProjectPO saPo = simulationAutomaticProjectMapper.selectById(param.getId());
|
|
SimulationAutomaticProjectPO saPo = simulationAutomaticProjectMapper.selectById(param.getId());
|