李春阳 1 рік тому
батько
коміт
20ca2bb8b8

+ 186 - 3
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/impl/SimulationProjectServiceImpl.java

@@ -49,9 +49,6 @@ import lombok.SneakyThrows;
 import lombok.Synchronized;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.tomcat.util.buf.StringUtils;
-import org.jfree.chart.ChartUtils;
-import org.jfree.data.category.DefaultCategoryDataset;
-import org.jfree.data.general.DefaultPieDataset;
 import org.springframework.beans.BeanUtils;
 import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.scheduling.support.CronExpression;
@@ -5126,6 +5123,192 @@ public class SimulationProjectServiceImpl implements SimulationProjectService {
         exportProjectTaskFileById(param);
     }
 
+    @Override
+    public void exportProjectEvaluationReportAndTaskFileById(SimulationManualProjectParam param) {
+        String id = param.getId();
+        ProjectTaskParam projectTaskParam = new ProjectTaskParam();
+        projectTaskParam.setPId(id);
+        List<ManualProjectTaskVo> manualProjectTaskVos = simulationManualProjectTaskMapper.selectProjectTaskByProjectId(projectTaskParam);
+        if (isEmpty(manualProjectTaskVos)) {
+            throw new RuntimeException("没有获取到任务信息。");
+        }
+
+        // 压缩包根路径
+        SimulationManualProjectParam sp = new SimulationManualProjectParam();
+        sp.setId(id);
+        SimulationManualProjectPO spo = simulationManualProjectMapper.selectProjectBaseById(sp);
+        String rootPath = spo.getProjectName();
+
+        int len;
+        byte[] buffer = new byte[1024];
+        ZipOutputStream zos = 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());
+            // 下载所有任务的数据文件
+            log.info("项目 {} 共有 {} 个任务。", id, manualProjectTaskVos.size());
+            int i = 1;
+            List<String> naturalList = new ArrayList<>();
+            List<String> regulationlList = new ArrayList<>();
+            List<String> accidentList = new ArrayList<>();
+            List<String> referenceLibList = new ArrayList<>();
+
+            for (ManualProjectTaskVo task : manualProjectTaskVos) {
+                // 先分类,后续用于查询具体字段内容
+                String sceneType = task.getSceneType();
+                String sceneId = task.getSceneId();
+                if (DictConstants.SCENE_NATURAL.equals(sceneType)) {
+                    naturalList.add(sceneId);
+                } else if (DictConstants.SCENE_STANDARD.equals(sceneType)) {
+                    regulationlList.add(sceneId);
+                } else if (DictConstants.SCENE_ACCIDENT.equals(sceneType)) {
+                    accidentList.add(sceneId);
+                } else if (DictConstants.SCENE_REFERENCE_LIB.equals(sceneType)) {
+                    referenceLibList.add(sceneId);
+                }
+            }
+
+            for (ManualProjectTaskVo task : manualProjectTaskVos) {
+                log.info("当前下载进度为 {}/{}。", i++, manualProjectTaskVos.size());
+                String taskId = task.getId();
+                String runResultFilePath = task.getRunResultFilePath();
+                if (!isEmpty(runResultFilePath)) {
+                    // 获取场景名
+                    SceneBaseInfoVo sceneBaseInfoVo = getSceneNameAndOther(task.getSceneId(), task.getSceneType());
+                    String sceneName = sceneBaseInfoVo.getCommonSceneName();
+                    // 任务包路径
+                    String taskPagePath = rootPath + File.separator + sceneName + "- " + taskId.substring(0, 8);
+                    // 视频文件路径
+                    MinioParameter minioParameter1 = new MinioParameter();
+                    minioParameter1.setObjectName(runResultFilePath);
+                    ResponseBodyVO<List<String>> list = fileDownService.list(minioParameter1);
+                    List<String> info = list.getInfo();
+                    // 防止下载两次,因为结果目录里有测试用的同名文件
+                    boolean mp4_done = false;
+                    boolean Ego_csv_done = false;
+                    boolean evaluation_csv_done = false;
+
+                    for (String s : info) {
+                        String fileName;
+                        String zipPath;
+                        // 获取文件名
+                        if (s.contains("/")) {
+                            fileName = s.substring(s.lastIndexOf("/") + 1);
+                        } else {
+                            fileName = s.substring(s.lastIndexOf("\\") + 1);
+                        }
+                        zipPath = taskPagePath + File.separator + fileName;
+                        // 文件后缀
+                        String substring = s.substring(s.lastIndexOf(".") + 1);
+                        if ("mp4".equals(substring)) {
+                            if (mp4_done) {
+                                continue;
+                            }
+                            // mp4视频文件导出
+                            MinioParameter minioParameter2 = new MinioParameter();
+                            minioParameter2.setObjectName(s);
+                            Response download2 = fileDownService.download(minioParameter2);
+                            Response.Body body2 = download2.body();
+                            ZipEntry entry2 = new ZipEntry(zipPath);
+                            zos.putNextEntry(entry2);
+                            BufferedInputStream in = new BufferedInputStream(body2.asInputStream());
+                            while ((len = in.read(buffer)) != -1) {
+                                zos.write(buffer, 0, len);
+                            }
+                            in.close();
+                            mp4_done = true;
+                        } else if ("Ego.csv".equals(fileName)) {
+                            if (Ego_csv_done) {
+                                continue;
+                            }
+                            MinioParameter minioParameter = new MinioParameter();
+                            if (s.contains("/")) {
+                                minioParameter.setObjectName(runResultFilePath + "/" + fileName);
+                            } else {
+                                minioParameter.setObjectName(runResultFilePath + "\\" + fileName);
+                            }
+
+                            Response download = fileDownService.download(minioParameter);
+                            Response.Body body = download.body();
+
+                            // 任务文件路径
+                            String taskFilePath = taskPagePath + File.separator + fileName;
+
+                            ZipEntry entry = new ZipEntry(taskFilePath);
+                            zos.putNextEntry(entry);
+                            BufferedInputStream in = new BufferedInputStream(body.asInputStream());
+                            while ((len = in.read(buffer)) != -1) {
+                                zos.write(buffer, 0, len);
+                            }
+                            in.close();
+                            Ego_csv_done = true;
+                        } else if ("evaluation.csv".equals(fileName)) {
+                            if (evaluation_csv_done) {
+                                continue;
+                            }
+                            MinioParameter minioParameter = new MinioParameter();
+                            if (s.contains("/")) {
+                                minioParameter.setObjectName(runResultFilePath + "/" + fileName);
+                            } else {
+                                minioParameter.setObjectName(runResultFilePath + "\\" + fileName);
+                            }
+
+                            Response download = fileDownService.download(minioParameter);
+                            Response.Body body = download.body();
+
+                            // 任务文件路径
+                            String taskFilePath = taskPagePath + File.separator + fileName;
+
+                            ZipEntry entry = new ZipEntry(taskFilePath);
+                            zos.putNextEntry(entry);
+                            BufferedInputStream in = new BufferedInputStream(body.asInputStream());
+                            while ((len = in.read(buffer)) != -1) {
+                                zos.write(buffer, 0, len);
+                            }
+                            in.close();
+                            evaluation_csv_done = true;
+                        }
+                    }
+                }
+            }
+
+            // 打包pdf
+            if (param.getIsPagePdf() != null && param.getIsPagePdf()) {
+                // 获取工作信息
+                SimulationManualProjectPO p = simulationManualProjectMapper.selectProjectBaseById(param);
+                final String algorithmName = algorithmMapper.selectAlgorithmNameByAlgorithmId(spo.getAlgorithm());
+
+                pdfFile = new File(param.getLocalPdfFilePath());
+                FileInputStream fileInputStream = new FileInputStream(pdfFile);
+                BufferedInputStream in = new BufferedInputStream(fileInputStream);
+                ZipEntry entry = new ZipEntry(rootPath + File.separator + algorithmName + "评价报告.pdf");
+                zos.putNextEntry(entry);
+                while ((len = in.read(buffer)) != -1) {
+                    zos.write(buffer, 0, len);
+                }
+                in.close();
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (zos != null) {
+                    zos.close();
+                }
+                if (pdfFile != null) {
+                    pdfFile.delete();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+
+        }
+    }
+
     @Override
     public ResponseBodyVO addOrUpdateAutomaticProject(SimulationManualProjectParam param) {
 

+ 2 - 0
simulation-resource-server/src/main/java/com/css/simulation/resource/server/app/service/job_manage/SimulationProjectService.java

@@ -65,6 +65,8 @@ public interface SimulationProjectService {
 
   void exportProjectReportAndTaskFileById(SimulationManualProjectParam param);
 
+  void exportProjectEvaluationReportAndTaskFileById(SimulationManualProjectParam param);
+
   ResponseBodyVO addOrUpdateAutomaticProject(SimulationManualProjectParam param);
 
   ResponseBodyVO<String> deleteAutomaticProjectByids(SimulationManualProjectParam param);