|
@@ -6,7 +6,9 @@ import api.common.pojo.constants.DictConstants;
|
|
|
import api.common.pojo.constants.ProjectConstants;
|
|
|
import api.common.pojo.enums.MultiSimulationResultTypeEnum;
|
|
|
import api.common.pojo.enums.MultiSimulationStatusEnum;
|
|
|
+import api.common.pojo.enums.MultiSimulationTaskStatusEnum;
|
|
|
import api.common.pojo.param.KafkaParameter;
|
|
|
+import api.common.pojo.param.MinioParameter;
|
|
|
import api.common.pojo.param.project.*;
|
|
|
import api.common.pojo.po.algorithm.AlgorithmPO;
|
|
|
import api.common.pojo.po.model.ConfigPO;
|
|
@@ -24,19 +26,31 @@ import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.css.simulation.resource.server.app.service.job_manage.MultiSimulationProjectService;
|
|
|
import com.css.simulation.resource.server.infra.db.mysql.mapper.*;
|
|
|
+import com.css.simulation.resource.server.infra.feign.service.FileDownService;
|
|
|
import com.css.simulation.resource.server.infra.util.AuthUtil;
|
|
|
import com.css.simulation.resource.server.infra.util.PageUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import feign.Response;
|
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.kafka.core.KafkaTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
@@ -66,6 +80,13 @@ public class MultiSimulationProjectServiceImpl implements MultiSimulationProject
|
|
|
@Resource
|
|
|
private KafkaTemplate<String, String> kafkaTemplate;
|
|
|
|
|
|
+ @Value("${multi-download-task-temp-path}")
|
|
|
+ private String multiDownloadTaskTempPath;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FileDownService fileDownService;
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
@SneakyThrows
|
|
|
public ResponseBodyVO<PageInfo<MultiSimulationProjectVO>> selectMultiSimulationProject(MultiSimulationProjectParam param) {
|
|
@@ -801,6 +822,104 @@ public class MultiSimulationProjectServiceImpl implements MultiSimulationProject
|
|
|
return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
|
|
|
}
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
+ public void exportProjectTaskFileById(MultiSimulationProjectParam param){
|
|
|
+ String projectId = param.getProjectId();
|
|
|
+ if (StringUtils.isBlank(projectId)){
|
|
|
+ log.info("下载多模式仿真结果失败,projectId为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MultiSimulationProjectVO projectVO = multiSimulationProjectMapper.selectMultiSimulationProjectById(projectId);
|
|
|
+ if (Objects.isNull(projectVO)){
|
|
|
+ log.info("下载多模式仿真结果失败,查询出仿真结果为空projectId:{}", projectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer status = projectVO.getProjectStatus();
|
|
|
+ if (status != MultiSimulationStatusEnum.COMPLETED_STATUS.getProjectStatus()){
|
|
|
+ log.info("下载多模式仿真结果失败,当前任务状态非完成状态projectId:{}", projectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<MultiSimulationProjectTaskRecordPO> recordPOList = taskRecordMapper.selectMultiSimulationProjectTaskRecordList(projectId);
|
|
|
+ if (CollectionUtils.isEmpty(recordPOList)){
|
|
|
+ log.info("下载多模式仿真结果失败,当前任务结果为空:{}", projectId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<MultiSimulationProjectTaskRecordPO> list = new ArrayList<>();
|
|
|
+ for (MultiSimulationProjectTaskRecordPO record: recordPOList) {
|
|
|
+ Integer recordStatus = record.getStatus();
|
|
|
+ if (recordStatus == MultiSimulationTaskStatusEnum.INIT_STATUS.getProjectStatus() || recordStatus == MultiSimulationTaskStatusEnum.RUN_STATUS.getProjectStatus()){
|
|
|
+ log.info("下载多模式仿真结果失败,当前任务存在未完成的任务projectId:{},taskId:{}", projectId, record.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ list.add(record);
|
|
|
+ }
|
|
|
+ ZipOutputStream zos = 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());
|
|
|
+ int len;
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ for (MultiSimulationProjectTaskRecordPO task: list) {
|
|
|
+ String taskBody = task.getTaskBody();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(taskBody);
|
|
|
+ String string = jsonObject.getJSONObject("info").getString("task_path");
|
|
|
+ MinioParameter minioParameter = new MinioParameter();
|
|
|
+ minioParameter.setObjectName(string);
|
|
|
+ ResponseBodyVO<List<String>> list1 = fileDownService.list(minioParameter);
|
|
|
+ List<String> info = list1.getInfo();
|
|
|
+ for (String s: info) {
|
|
|
+ String fileName = null;
|
|
|
+ String zipPath = null;
|
|
|
+ if (s.contains("/")) {
|
|
|
+ fileName = s.substring(s.lastIndexOf("/") + 1);
|
|
|
+ }else {
|
|
|
+ fileName = s.substring(s.lastIndexOf("\\") + 1);
|
|
|
+ }
|
|
|
+ zipPath = multiDownloadTaskTempPath + projectId + File.separator + task.getId() + File.separator + fileName;
|
|
|
+ String substring = s.substring(s.lastIndexOf(".") + 1);
|
|
|
+ if (StringUtils.equals(substring, "mp4")){
|
|
|
+ MinioParameter minioPar = new MinioParameter();
|
|
|
+ minioPar.setObjectName(s);
|
|
|
+ Response down = fileDownService.download(minioPar);
|
|
|
+ Response.Body body = down.body();
|
|
|
+ ZipEntry entry2 = new ZipEntry(zipPath);
|
|
|
+ zos.putNextEntry(entry2);
|
|
|
+ BufferedInputStream in = new BufferedInputStream(body.asInputStream());
|
|
|
+ while ((len = in.read(buffer)) != -1) {
|
|
|
+ zos.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+ }else if ("Ego.csv".equals(fileName) || "evaluation.csv".equals(fileName)) {
|
|
|
+ MinioParameter minioPar = new MinioParameter();
|
|
|
+ minioPar.setObjectName(s);
|
|
|
+ Response down = fileDownService.download(minioPar);
|
|
|
+ Response.Body body = down.body();
|
|
|
+ // 任务文件路径
|
|
|
+ ZipEntry entry = new ZipEntry(zipPath);
|
|
|
+ zos.putNextEntry(entry);
|
|
|
+ BufferedInputStream in = new BufferedInputStream(body.asInputStream());
|
|
|
+ while ((len = in.read(buffer)) != -1) {
|
|
|
+ zos.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("下载失败", e);
|
|
|
+ }finally {
|
|
|
+ try {
|
|
|
+ if (zos != null) {
|
|
|
+ zos.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public static MultiSimulationScenePO buildScenePO(MultiSimulationSceneVO sceneVO, String projectId) {
|
|
|
MultiSimulationScenePO build = MultiSimulationScenePO.builder()
|