Просмотр исходного кода

王耀栋--工作台模块代码,添加下载任务包功能

wangyaodong 3 лет назад
Родитель
Сommit
d7a01bc9ac

+ 10 - 0
api-common/src/main/java/api/common/pojo/param/project/SimulationManualProjectParam.java

@@ -106,4 +106,14 @@ public class SimulationManualProjectParam extends PageVO {
     private String runResultFilePath;
 
 
+    //是否生成本地pdf文件
+    private Boolean isCreateLocalPdfFile;
+
+    //本地pdf文件路径
+    private String LocalPdfFilePath;
+
+    //是否打包报告pdf
+    private Boolean isPagePdf;
+
+
 }

+ 3 - 0
api-common/src/main/java/api/common/pojo/vo/project/ManualProjectTaskVo.java

@@ -58,5 +58,8 @@ public class ManualProjectTaskVo {
     //返回的场景id
     private String returnSceneId;
 
+    //运行结果文件minio路径
+    private String runResultFilePath;
+
 
 }

+ 12 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/project/ctrl/SimulationProjectCtrl.java

@@ -207,8 +207,18 @@ public class SimulationProjectCtrl {
      */
     @RequestMapping("exportProjectTaskFileById")
     @ResponseBody
-    public ResponseBodyVO exportProjectTaskFileById(@RequestBody SimulationManualProjectParam param){
-        return service.exportProjectTaskFileById(param);
+    public void exportProjectTaskFileById(@RequestBody SimulationManualProjectParam param){
+        service.exportProjectTaskFileById(param);
+    }
+
+    /**
+     * 同时导出工作报告和任务包
+     * @param param
+     */
+    @RequestMapping("exportProjectReportAndTaskFileById")
+    @ResponseBody
+    public void exportProjectReportAndTaskFileById(@RequestBody SimulationManualProjectParam param){
+        service.exportProjectReportAndTaskFileById(param);
     }
 
 

+ 133 - 8
simulation-resource-server/src/main/java/com/css/simulation/resource/project/impl/SimulationProjectServiceImpl.java

@@ -57,10 +57,13 @@ import java.io.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.URLEncoder;
+import java.nio.file.Files;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
 @Service
 @Slf4j
@@ -2166,11 +2169,17 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
             ResponseBodyVO bodyVO = selectProjectReportById(param);
             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数据
             PdfWriter.getInstance(document, os);
@@ -3197,13 +3206,129 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
     }
 
     @Override
-    public ResponseBodyVO exportProjectTaskFileById(SimulationManualProjectParam param) {
+    public void exportProjectTaskFileById(SimulationManualProjectParam param) {
         String id = param.getId();
         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);
+
     }
 
     /**

+ 3 - 1
simulation-resource-server/src/main/java/com/css/simulation/resource/project/service/SimulationProjectService.java

@@ -58,5 +58,7 @@ public interface SimulationProjectService {
     //仿真结果保存到数据库
     ResponseBodyVO saveTaskResult(SimulationManualProjectParam param);
 
-    ResponseBodyVO exportProjectTaskFileById(SimulationManualProjectParam param);
+    void exportProjectTaskFileById(SimulationManualProjectParam param);
+
+    void exportProjectReportAndTaskFileById(SimulationManualProjectParam param);
 }