|
@@ -57,10 +57,13 @@ import java.io.*;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
|
|
+import java.nio.file.Files;
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -241,8 +244,6 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
@Override
|
|
@Override
|
|
public ResponseBodyVO updateProjectNowRunState(SimulationManualProjectParam param) {
|
|
public ResponseBodyVO updateProjectNowRunState(SimulationManualProjectParam param) {
|
|
- log.info("updateProjectNowRunState_id:"+param.getId());
|
|
|
|
- log.info("updateProjectNowRunState_nowRunState:"+param.getNowRunState());
|
|
|
|
|
|
|
|
SimulationManualProjectPo po = simulationProjectMapper.selectProjectById(param);
|
|
SimulationManualProjectPo po = simulationProjectMapper.selectProjectById(param);
|
|
|
|
|
|
@@ -253,24 +254,46 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
if(isEmpty(param.getId()) || isEmpty(param.getNowRunState())){
|
|
if(isEmpty(param.getId()) || isEmpty(param.getNowRunState())){
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE);
|
|
}
|
|
}
|
|
- if("20".equals(param.getNowRunState())){
|
|
|
|
- //设置开始时间
|
|
|
|
- param.setStartTime(new Date());
|
|
|
|
|
|
|
|
|
|
+ //已经完成的项目再次运行
|
|
|
|
+ if("30".equals(po.getNowRunState()) && "20".equals(param.getNowRunState())){
|
|
|
|
+ po.createPo(AuthUtil.getCurrentUserId());
|
|
|
|
+ //生成id
|
|
|
|
+ createProjectId(po);
|
|
|
|
+ //初始化数据
|
|
|
|
+ po.setNowRunState(param.getNowRunState());
|
|
|
|
+ po.setEvaluationLevel("");
|
|
|
|
+ po.setStartTime(new Date());
|
|
|
|
+ po.setFinishTime(null);
|
|
|
|
+ int add = simulationProjectMapper.add(po);
|
|
|
|
+ if(add <= 0){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE,"生成新工作失败");
|
|
|
|
+ }
|
|
//Kafka推送消息
|
|
//Kafka推送消息
|
|
projectRunToKafka(po);
|
|
projectRunToKafka(po);
|
|
|
|
|
|
- }else if("30".equals(param.getNowRunState())){
|
|
|
|
- //设置完成时间
|
|
|
|
- param.setFinishTime(new Date());
|
|
|
|
|
|
+ } else{
|
|
|
|
+ if("20".equals(param.getNowRunState())){
|
|
|
|
+ //设置开始时间
|
|
|
|
+ param.setStartTime(new Date());
|
|
|
|
+
|
|
|
|
+ //Kafka推送消息
|
|
|
|
+ projectRunToKafka(po);
|
|
|
|
+
|
|
|
|
+ }else if("30".equals(param.getNowRunState())){
|
|
|
|
+ //设置完成时间
|
|
|
|
+ param.setFinishTime(new Date());
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ int i = simulationProjectMapper.updateProjectNowRunState(param);
|
|
|
|
+ if(i <= 0){
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
- int i = simulationProjectMapper.updateProjectNowRunState(param);
|
|
|
|
- if(i > 0){
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
- }
|
|
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.SERVER_FAILURE);
|
|
|
|
|
|
|
|
|
|
+ return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -458,7 +481,7 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
for(String key : dict.keySet()){
|
|
for(String key : dict.keySet()){
|
|
boolean b = false;
|
|
boolean b = false;
|
|
for(ProjectRunResultRatioNumVo pv : vos){
|
|
for(ProjectRunResultRatioNumVo pv : vos){
|
|
- if(pv.getResultName().equals(dict.get(key))){
|
|
|
|
|
|
+ if(dict.get(key).equals(pv.getResultName())){
|
|
b = true;
|
|
b = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2166,11 +2189,17 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
ResponseBodyVO bodyVO = selectProjectReportById(param);
|
|
ResponseBodyVO bodyVO = selectProjectReportById(param);
|
|
ProjectReportVo vo = (ProjectReportVo)bodyVO.getInfo();
|
|
ProjectReportVo vo = (ProjectReportVo)bodyVO.getInfo();
|
|
|
|
|
|
- //下载
|
|
|
|
- String fileName=vo.getProjectId()+"_"+vo.getProjectName();
|
|
|
|
- response.setContentType("application/x-download");
|
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".pdf");
|
|
|
|
- os = new BufferedOutputStream(response.getOutputStream());
|
|
|
|
|
|
+ //下载 or 保存本地
|
|
|
|
+ if(param.getIsCreateLocalPdfFile() != null && param.getIsCreateLocalPdfFile() == true){
|
|
|
|
+ File file = new File(param.getLocalPdfFilePath());
|
|
|
|
+ os = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
+ }else{
|
|
|
|
+ String fileName=vo.getProjectId()+"_"+vo.getProjectName();
|
|
|
|
+ response.setContentType("application/x-download");
|
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".pdf");
|
|
|
|
+ os = new BufferedOutputStream(response.getOutputStream());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
//监听生成pdf数据
|
|
//监听生成pdf数据
|
|
PdfWriter.getInstance(document, os);
|
|
PdfWriter.getInstance(document, os);
|
|
@@ -3197,13 +3226,129 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public ResponseBodyVO exportProjectTaskFileById(SimulationManualProjectParam param) {
|
|
|
|
|
|
+ public void exportProjectTaskFileById(SimulationManualProjectParam param) {
|
|
String id = param.getId();
|
|
String id = param.getId();
|
|
if(StringUtil.isEmpty(id)){
|
|
if(StringUtil.isEmpty(id)){
|
|
- return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE,"工作id不能为空");
|
|
|
|
|
|
+ throw new RuntimeException("工作id不能为空");
|
|
}
|
|
}
|
|
|
|
|
|
- return null;
|
|
|
|
|
|
+ //获取任务包信息
|
|
|
|
+ ProjectTaskParam projectTaskParam = new ProjectTaskParam();
|
|
|
|
+ projectTaskParam.setPId(id);
|
|
|
|
+ List<ManualProjectTaskVo> manualProjectTaskVos = simulationProjectTaskMapper.selectProjectTaskByProjectId(projectTaskParam);
|
|
|
|
+ if(isEmpty(manualProjectTaskVos)){
|
|
|
|
+ throw new RuntimeException("没有获取到任务信息");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //压缩包根路径
|
|
|
|
+ SimulationManualProjectParam sp = new SimulationManualProjectParam();
|
|
|
|
+ sp.setId(id);
|
|
|
|
+ SimulationManualProjectPo spo = simulationProjectMapper.selectProjectBaseById(sp);
|
|
|
|
+ String rootPath = spo.getProjectName()+"_"+StringUtil.getRandomUUID();
|
|
|
|
+// FileUtil.createDirectory(rootPath);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ int len;
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ BufferedInputStream in = null;
|
|
|
|
+ ZipOutputStream zos = null;
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ File pdfFile = null;
|
|
|
|
+ try {
|
|
|
|
+ HttpServletResponse response = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getResponse();
|
|
|
|
+ response.setContentType("multipart/form-data");
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode("运行任务包.zip", "UTF-8"));
|
|
|
|
+ zos = new ZipOutputStream(response.getOutputStream());
|
|
|
|
+ for(ManualProjectTaskVo v : manualProjectTaskVos){
|
|
|
|
+ String runResultFilePath = v.getRunResultFilePath();
|
|
|
|
+ if(!isEmpty(runResultFilePath)){
|
|
|
|
+ MinioParameter minioParameter = new MinioParameter();
|
|
|
|
+ minioParameter.setObjectName(runResultFilePath+"/Ego.csv");
|
|
|
|
+ Response download = fileDownService.download(minioParameter);
|
|
|
|
+ Response.Body body = download.body();
|
|
|
|
+ inputStream = body.asInputStream();
|
|
|
|
+
|
|
|
|
+ //获取场景名
|
|
|
|
+ SceneBaseInfoVo sceneBaseInfoVo = getsceneNameAndOther(v.getSceneId(), v.getSceneType());
|
|
|
|
+ String sceneName = sceneBaseInfoVo.getCommonSceneName();
|
|
|
|
+
|
|
|
|
+ //任务包路径
|
|
|
|
+ String taskPagePath = rootPath+File.separator+sceneName+"_"+StringUtil.getRandomUUID();
|
|
|
|
+// FileUtil.createDirectory(taskPagePath);
|
|
|
|
+
|
|
|
|
+ //任务文件路径
|
|
|
|
+ String taskFilePath = taskPagePath +File.separator+ ".Ego.csv";
|
|
|
|
+// FileUtil.writeInputStreamToLocalFile(inputStream,taskFilePath);
|
|
|
|
+
|
|
|
|
+ ZipEntry entry = new ZipEntry(taskFilePath);
|
|
|
|
+ in = new BufferedInputStream(inputStream);
|
|
|
|
+ zos.putNextEntry(entry);
|
|
|
|
+ while ((len = in.read(buffer)) != -1 ) {
|
|
|
|
+ zos.write(buffer, 0, len);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //打包pdf
|
|
|
|
+ if(param.getIsPagePdf() != null && param.getIsPagePdf() == true){
|
|
|
|
+ //获取工作信息
|
|
|
|
+ SimulationManualProjectPo p = simulationProjectMapper.selectProjectBaseById(param);
|
|
|
|
+
|
|
|
|
+ pdfFile = new File(param.getLocalPdfFilePath());
|
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(pdfFile);
|
|
|
|
+ in = new BufferedInputStream(fileInputStream);
|
|
|
|
+ ZipEntry entry = new ZipEntry(rootPath+File.separator+p.getProjectName()+"_"+StringUtil.getRandomUUID()+".pdf");
|
|
|
|
+ zos.putNextEntry(entry);
|
|
|
|
+ while ((len = in.read(buffer)) != -1 ) {
|
|
|
|
+ zos.write(buffer, 0, len);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ try {
|
|
|
|
+ if(in != null){
|
|
|
|
+ in.close();
|
|
|
|
+ }
|
|
|
|
+ if(zos != null){
|
|
|
|
+ zos.close();
|
|
|
|
+ }
|
|
|
|
+ if(inputStream != null){
|
|
|
|
+ inputStream.close();
|
|
|
|
+ }
|
|
|
|
+ if(pdfFile != null){
|
|
|
|
+ pdfFile.delete();
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void exportProjectReportAndTaskFileById(SimulationManualProjectParam param) {
|
|
|
|
+
|
|
|
|
+ String id = param.getId();
|
|
|
|
+ if(StringUtil.isEmpty(id)){
|
|
|
|
+ throw new RuntimeException("工作id不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //生成本地pdf
|
|
|
|
+ String path = StringUtil.getRandomUUID();
|
|
|
|
+ param.setIsCreateLocalPdfFile(true);
|
|
|
|
+ param.setLocalPdfFilePath(path);
|
|
|
|
+
|
|
|
|
+ exportProjectReport(param);
|
|
|
|
+
|
|
|
|
+ //下载报告和任务包
|
|
|
|
+ param.setIsPagePdf(true);
|
|
|
|
+
|
|
|
|
+ exportProjectTaskFileById(param);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|