feat:任务下归档报告

This commit is contained in:
2026-02-10 11:35:56 +08:00
parent fa43e36a0b
commit beae83c86e
5 changed files with 286 additions and 207 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE spdm_baseline.simulation_task ADD reportTemplate varchar(120) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '报告模板uuid';
ALTER TABLE spdm_baseline.simulation_task ADD reportContent mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '报告模板填充内容';

View File

@@ -1,18 +1,25 @@
package com.sdm.common.entity.req.project; package com.sdm.common.entity.req.project;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@Data @Data
public class EditReportReq { public class EditReportReq {
@Schema(description= "算例uuid")
private String runId; private String runId;
@Schema(description= "报告模板uuid")
private String reportTemplate; private String reportTemplate;
@Schema(description= "报告模板内容")
private String reportContent; private String reportContent;
@Schema(description= "任务uuid")
private String taskId;
} }

View File

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.sdm.common.entity.pojo.BaseEntity; import com.sdm.common.entity.pojo.BaseEntity;
import com.sdm.common.entity.resp.system.CIDUserResp; import com.sdm.common.entity.resp.system.CIDUserResp;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@@ -224,4 +225,10 @@ public class SpdmTaskVo extends BaseEntity {
*/ */
private String eUserId; private String eUserId;
@Schema(description= "报告模板内容")
private String reportContent;
@Schema(description= "任务uuid")
private String taskId;
} }

View File

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable; import java.io.Serializable;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@@ -210,5 +211,13 @@ public class SimulationTask implements Serializable {
@TableField("discipline") @TableField("discipline")
private String discipline; private String discipline;
@Schema(description= "报告模板uuid")
@TableField("reportTemplate")
private String reportTemplate;
@Schema(description= "报告模板填充内容")
@TableField("reportContent")
private String reportContent;
} }

View File

@@ -915,6 +915,7 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
if (StringUtils.isEmpty(req.getFileTypeDictValue())) { if (StringUtils.isEmpty(req.getFileTypeDictValue())) {
req.setFileTypeDictClass(FileDictTagEnum.FILE_TYPE.getDictClass()); req.setFileTypeDictClass(FileDictTagEnum.FILE_TYPE.getDictClass());
req.setFileTypeDictValue(String.valueOf(req.getFileType())); req.setFileTypeDictValue(String.valueOf(req.getFileType()));
req.setDictTags(Arrays.asList(FileDictTagEnum.FILE_TYPE.getDictClassFieldName(), FileDictTagEnum.FILE_TYPE.getDictValueFieldName()));
} }
SdmResponse response = uploadKeyResultFiles(filesReq); SdmResponse response = uploadKeyResultFiles(filesReq);
if (response.isSuccess() && response.getData() != null) { if (response.isSuccess() && response.getData() != null) {
@@ -1626,83 +1627,242 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
@Override @Override
public SdmResponse editReport(EditReportReq req) { public SdmResponse editReport(EditReportReq req) {
log.info("编辑报告参数为:{}", req); log.info("编辑报告参数为:{}", req);
SimulationRun simulationRun = this.lambdaQuery().eq(SimulationRun::getUuid, req.getRunId()).one(); String reportContent = req.getReportContent();
if (simulationRun != null) { if (StringUtils.isNotEmpty(req.getTaskId())) {
String reportContent = req.getReportContent(); SimulationTask simulationTask = simulationTaskService.lambdaQuery().eq(SimulationTask::getUuid, req.getTaskId()).one();
// 算例绑定报告模板 if (simulationTask != null) {
simulationRun.setReportTemplate(req.getReportTemplate()); // 任务绑定报告模板
simulationRun.setReportContent(reportContent); simulationTask.setReportTemplate(req.getReportTemplate());
this.updateById(simulationRun); simulationTask.setReportContent(reportContent);
simulationTaskService.updateById(simulationTask);
String randomId = RandomUtil.generateString(16);
// 创建临时文件夹
Path folder = Paths.get(TEMP_REPORT_PATH + randomId);
if (!Files.exists(folder) || !Files.isDirectory(folder)) {
if (!new File(TEMP_REPORT_PATH + randomId).mkdir()) {
log.error("创建临时文件夹:{}失败",TEMP_REPORT_PATH + randomId);
throw new RuntimeException("生成报告失败,原因为:创建临时文件夹失败");
}
} }
log.info("临时路径为:{}", randomId); } else {
SimulationRun simulationRun = this.lambdaQuery().eq(SimulationRun::getUuid, req.getRunId()).one();
if (simulationRun != null) {
// 算例绑定报告模板
simulationRun.setReportTemplate(req.getReportTemplate());
simulationRun.setReportContent(reportContent);
this.updateById(simulationRun);
}
}
// 根据文件id下载文件到临时目录 String randomId = RandomUtil.generateString(16);
SdmResponse<ReportTemplateResp> reportResponse = reportFeignClient.queryReportTemplateInfo(req.getReportTemplate()); // 创建临时文件夹
if (reportResponse.isSuccess()) { Path folder = Paths.get(TEMP_REPORT_PATH + randomId);
Long reportTemplateFileId = reportResponse.getData().getFileId(); if (!Files.exists(folder) || !Files.isDirectory(folder)) {
// 获取报告模板名称 if (!new File(TEMP_REPORT_PATH + randomId).mkdir()) {
GetFileBaseInfoReq getFileBaseInfoReq = new GetFileBaseInfoReq(); log.error("创建临时文件夹:{}失败",TEMP_REPORT_PATH + randomId);
getFileBaseInfoReq.setFileId(reportTemplateFileId); throw new RuntimeException("生成报告失败,原因为:创建临时文件夹失败");
SdmResponse<FileMetadataInfoResp> fileBaseInfoResp = dataFeignClient.getFileBaseInfo(getFileBaseInfoReq); }
String originalName = fileBaseInfoResp.getData().getOriginalName(); }
// 下载到本地临时目录 log.info("临时路径为:{}", randomId);
dataFeignClient.downloadFileToLocal(reportTemplateFileId, TEMP_REPORT_PATH + randomId);
// 构建python命令 // 根据文件id下载文件到临时目录
List<String> command = new ArrayList<>(); SdmResponse<ReportTemplateResp> reportResponse = reportFeignClient.queryReportTemplateInfo(req.getReportTemplate());
command.add("python"); if (reportResponse.isSuccess()) {
command.add("/opt/script/modifyReport.py"); Long reportTemplateFileId = reportResponse.getData().getFileId();
// 获取报告模板名称
GetFileBaseInfoReq getFileBaseInfoReq = new GetFileBaseInfoReq();
getFileBaseInfoReq.setFileId(reportTemplateFileId);
SdmResponse<FileMetadataInfoResp> fileBaseInfoResp = dataFeignClient.getFileBaseInfo(getFileBaseInfoReq);
String originalName = fileBaseInfoResp.getData().getOriginalName();
// 下载到本地临时目录
dataFeignClient.downloadFileToLocal(reportTemplateFileId, TEMP_REPORT_PATH + randomId);
// 构建python命令
List<String> command = new ArrayList<>();
command.add("python");
command.add("/opt/script/modifyReport.py");
// command.add(TEMP_REPORT_PATH + File.separator +"modifyReport.py"); // command.add(TEMP_REPORT_PATH + File.separator +"modifyReport.py");
command.add(TEMP_REPORT_PATH + randomId); command.add(TEMP_REPORT_PATH + randomId);
command.add(TEMP_REPORT_PATH + randomId + File.separator + originalName); command.add(TEMP_REPORT_PATH + randomId + File.separator + originalName);
String commands = String.join(" ", command); String commands = String.join(" ", command);
// 前端参数写入临时目录 // 前端参数写入临时目录
FileOutputStream projectInfoOutputStream = null; FileOutputStream projectInfoOutputStream = null;
try { try {
projectInfoOutputStream = new FileOutputStream(TEMP_REPORT_PATH + randomId + File.separator + "reportContent.json"); projectInfoOutputStream = new FileOutputStream(TEMP_REPORT_PATH + randomId + File.separator + "reportContent.json");
projectInfoOutputStream.write(reportContent.getBytes(StandardCharsets.UTF_8)); projectInfoOutputStream.write(reportContent.getBytes(StandardCharsets.UTF_8));
projectInfoOutputStream.flush(); projectInfoOutputStream.flush();
projectInfoOutputStream.close(); projectInfoOutputStream.close();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
}
// 调用脚本
log.info("执行 Python 命令: {}", commands);
int runningStatus = -1;
try {
log.info("开始同步执行脚本");
Process process = Runtime.getRuntime().exec(commands);
log.info("开始获取脚本输出");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info("executePython" + line);
} }
log.info("脚本执行完成");
runningStatus = process.waitFor();
log.info("脚本运行状态:" + runningStatus);
} catch (IOException | InterruptedException e) {
log.error("执行脚本失败:" + e);
return SdmResponse.failed("执行脚本失败");
}
if (runningStatus != 0) {
log.error("执行脚本失败");
return SdmResponse.failed("执行脚本失败");
} else {
log.info(commands + "执行脚本完成!");
}
byte[] fileData = null;
try {
// 获取临时路径中脚本生成的报告
String reportName = "report_" +
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) +
".docx";
FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + reportName);
fileData = fileInputStream.readAllBytes();
// 调用脚本 // 创建临时MultipartFile
log.info("执行 Python 命令: {}", commands); MockMultipartFile multipartFile = new MockMultipartFile(
int runningStatus = -1; reportName,
try { reportName,
log.info("开始同步执行脚本"); "application/json",
Process process = Runtime.getRuntime().exec(commands); fileData);
log.info("开始获取脚本输出"); if (StringUtils.isNotEmpty(req.getTaskId())) {
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); // 上传到任务下的交付物文件夹的报告文件夹下
String line; Long parentId = getParentDirId(req.getTaskId(), FileBizTypeEnum.REPORT_FILE.getDirName());
while ((line = reader.readLine()) != null) { UploadFilesReq filesReq = new UploadFilesReq();
log.info("executePython" + line); filesReq.setFile(multipartFile);
filesReq.setFileName(reportName);
filesReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue());
filesReq.setUuid(null);
filesReq.setDirId(parentId);
SdmResponse sdmResponse = uploadKeyResultFiles(filesReq);
if (!sdmResponse.isSuccess()) {
throw new RuntimeException("生成自动化报告上传任务报告结果目录失败");
} }
log.info("脚本执行完成");
runningStatus = process.waitFor();
log.info("脚本运行状态:" + runningStatus);
} catch (IOException | InterruptedException e) {
log.error("执行脚本失败:" + e);
return SdmResponse.failed("执行脚本失败");
}
if (runningStatus != 0) {
log.error("执行脚本失败");
return SdmResponse.failed("执行脚本失败");
} else { } else {
log.info(commands + "执行脚本完成!"); // 上传到算例下的报告文件夹下
KeyResultReq resultReq = new KeyResultReq();
resultReq.setKeyResultType(KeyResultTypeEnum.DOCUMENT.getKeyResultType());
resultReq.setRunId(req.getRunId());
resultReq.setName(reportName);
resultReq.setFile(multipartFile);
resultReq.setFileName(reportName);
resultReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue());
SdmResponse sdmResponse = addSimulationKeyResult(resultReq);
if (!sdmResponse.isSuccess()) {
throw new RuntimeException("生成自动化报告上传算例报告结果目录失败");
}
} }
byte[] fileData = null;
fileInputStream.close();
// 删除临时路径
log.info("删除临时路径:{},中。。。。。。", randomId);
deleteFolder(new File(TEMP_REPORT_PATH + randomId));
return SdmResponse.success();
} catch (Exception ex) {
log.error("生成自动化报告失败:{}", ex.getMessage());
throw new RuntimeException("生成自动化报告失败");
}
}
return SdmResponse.failed("生成自动化报告失败");
}
@Override
public void editReportAndDownload(EditReportReq req, HttpServletResponse response) {
log.info("编辑报告参数为:{}", req);
String reportContent = req.getReportContent();
if (StringUtils.isNotEmpty(req.getTaskId())) {
SimulationTask simulationTask = simulationTaskService.lambdaQuery().eq(SimulationTask::getUuid, req.getTaskId()).one();
if (simulationTask != null) {
// 任务绑定报告模板
simulationTask.setReportTemplate(req.getReportTemplate());
simulationTask.setReportContent(reportContent);
simulationTaskService.updateById(simulationTask);
}
} else {
SimulationRun simulationRun = this.lambdaQuery().eq(SimulationRun::getUuid, req.getRunId()).one();
if (simulationRun != null) {
// 算例绑定报告模板
simulationRun.setReportTemplate(req.getReportTemplate());
simulationRun.setReportContent(reportContent);
this.updateById(simulationRun);
}
}
String randomId = RandomUtil.generateString(16);
// 创建临时文件夹
Path folder = Paths.get(TEMP_REPORT_PATH + randomId);
if (!Files.exists(folder) || !Files.isDirectory(folder)) {
if (!new File(TEMP_REPORT_PATH + randomId).mkdir()) {
log.error("创建临时文件夹:{}失败",TEMP_REPORT_PATH + randomId);
throw new RuntimeException("生成报告失败,原因为:创建临时文件夹失败");
}
}
log.info("临时路径为:{}", randomId);
// 根据文件id下载文件到临时目录
SdmResponse<ReportTemplateResp> reportResponse = reportFeignClient.queryReportTemplateInfo(req.getReportTemplate());
if (reportResponse.isSuccess()) {
Long reportTemplateFileId = reportResponse.getData().getFileId();
// 获取报告模板名称
GetFileBaseInfoReq getFileBaseInfoReq = new GetFileBaseInfoReq();
getFileBaseInfoReq.setFileId(reportTemplateFileId);
SdmResponse<FileMetadataInfoResp> fileBaseInfoResp = dataFeignClient.getFileBaseInfo(getFileBaseInfoReq);
String originalName = fileBaseInfoResp.getData().getOriginalName();
// 下载到本地临时目录
dataFeignClient.downloadFileToLocal(reportTemplateFileId, TEMP_REPORT_PATH + randomId);
// 构建python命令
List<String> command = new ArrayList<>();
command.add("python");
command.add("/opt/script/modifyReport.py");
// command.add(TEMP_REPORT_PATH + File.separator +"modifyReport.py");
command.add(TEMP_REPORT_PATH + randomId);
command.add(TEMP_REPORT_PATH + randomId + File.separator + originalName);
String commands = String.join(" ", command);
// 前端参数写入临时目录
FileOutputStream projectInfoOutputStream = null;
try {
projectInfoOutputStream = new FileOutputStream(TEMP_REPORT_PATH + randomId + File.separator + "reportContent.json");
projectInfoOutputStream.write(reportContent.getBytes(StandardCharsets.UTF_8));
projectInfoOutputStream.flush();
projectInfoOutputStream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
// 调用脚本
log.info("执行 Python 命令: {}", commands);
int runningStatus = -1;
try {
log.info("开始同步执行脚本");
Process process = Runtime.getRuntime().exec(commands);
log.info("开始获取脚本输出");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info("executePython" + line);
}
log.info("脚本执行完成");
runningStatus = process.waitFor();
log.info("脚本运行状态:" + runningStatus);
} catch (IOException | InterruptedException e) {
log.error("执行脚本失败:" + e);
return;
}
if (runningStatus != 0) {
log.error("执行脚本失败");
return;
} else {
log.info(commands + "执行脚本完成!");
}
byte[] fileData = null;
if (response != null) {
try { try {
// 获取临时路径中脚本生成的报告 // 获取临时路径中脚本生成的报告
String reportName = "report_" + String reportName = "report_" +
@@ -1711,166 +1871,60 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + reportName); FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + reportName);
fileData = fileInputStream.readAllBytes(); fileData = fileInputStream.readAllBytes();
// 上传到算例下的报告文件夹下
KeyResultReq resultReq = new KeyResultReq();
resultReq.setKeyResultType(KeyResultTypeEnum.DOCUMENT.getKeyResultType());
resultReq.setRunId(req.getRunId());
resultReq.setName(reportName);
// 创建临时MultipartFile // 创建临时MultipartFile
MockMultipartFile multipartFile = new MockMultipartFile( MockMultipartFile multipartFile = new MockMultipartFile(
reportName, reportName,
reportName, reportName,
"application/json", "application/json",
fileData); fileData);
resultReq.setFile(multipartFile); if (StringUtils.isNotEmpty(req.getTaskId())) {
resultReq.setFileName(reportName); // 上传到任务下的交付物文件夹的报告文件夹下
resultReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue()); Long parentId = getParentDirId(req.getTaskId(), FileBizTypeEnum.REPORT_FILE.getDirName());
SdmResponse sdmResponse = addSimulationKeyResult(resultReq); UploadFilesReq filesReq = new UploadFilesReq();
if (!sdmResponse.isSuccess()) { filesReq.setFile(multipartFile);
throw new RuntimeException("生成自动化报告上传报告结果目录失败"); filesReq.setFileName(reportName);
} filesReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue());
fileInputStream.close(); filesReq.setUuid(null);
// 删除临时路径 filesReq.setDirId(parentId);
log.info("删除临时路径:{},中。。。。。。", randomId); SdmResponse sdmResponse = uploadKeyResultFiles(filesReq);
deleteFolder(new File(TEMP_REPORT_PATH + randomId)); if (!sdmResponse.isSuccess()) {
return SdmResponse.success(); throw new RuntimeException("生成自动化报告上传任务报告结果目录失败");
} catch (Exception ex) { }
log.error("生成自动化报告失败:{}", ex.getMessage()); } else {
throw new RuntimeException("生成自动化报告失败");
}
}
}
return SdmResponse.failed("算例不存在");
}
@Override
public void editReportAndDownload(EditReportReq req, HttpServletResponse response) {
log.info("编辑报告参数为:{}", req);
SimulationRun simulationRun = this.lambdaQuery().eq(SimulationRun::getUuid, req.getRunId()).one();
if (simulationRun != null) {
String reportContent = req.getReportContent();
// 算例绑定报告模板
simulationRun.setReportTemplate(req.getReportTemplate());
simulationRun.setReportContent(reportContent);
this.updateById(simulationRun);
String randomId = RandomUtil.generateString(16);
// 创建临时文件夹
Path folder = Paths.get(TEMP_REPORT_PATH + randomId);
if (!Files.exists(folder) || !Files.isDirectory(folder)) {
if (!new File(TEMP_REPORT_PATH + randomId).mkdir()) {
log.error("创建临时文件夹:{}失败",TEMP_REPORT_PATH + randomId);
throw new RuntimeException("生成报告失败,原因为:创建临时文件夹失败");
}
}
log.info("临时路径为:{}", randomId);
// 根据文件id下载文件到临时目录
SdmResponse<ReportTemplateResp> reportResponse = reportFeignClient.queryReportTemplateInfo(req.getReportTemplate());
if (reportResponse.isSuccess()) {
Long reportTemplateFileId = reportResponse.getData().getFileId();
// 获取报告模板名称
GetFileBaseInfoReq getFileBaseInfoReq = new GetFileBaseInfoReq();
getFileBaseInfoReq.setFileId(reportTemplateFileId);
SdmResponse<FileMetadataInfoResp> fileBaseInfoResp = dataFeignClient.getFileBaseInfo(getFileBaseInfoReq);
String originalName = fileBaseInfoResp.getData().getOriginalName();
// 下载到本地临时目录
dataFeignClient.downloadFileToLocal(reportTemplateFileId, TEMP_REPORT_PATH + randomId);
// 构建python命令
List<String> command = new ArrayList<>();
command.add("python");
command.add("/opt/script/modifyReport.py");
// command.add(TEMP_REPORT_PATH + File.separator +"modifyReport.py");
command.add(TEMP_REPORT_PATH + randomId);
command.add(TEMP_REPORT_PATH + randomId + File.separator + originalName);
String commands = String.join(" ", command);
// 前端参数写入临时目录
FileOutputStream projectInfoOutputStream = null;
try {
projectInfoOutputStream = new FileOutputStream(TEMP_REPORT_PATH + randomId + File.separator + "reportContent.json");
projectInfoOutputStream.write(reportContent.getBytes(StandardCharsets.UTF_8));
projectInfoOutputStream.flush();
projectInfoOutputStream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
// 调用脚本
log.info("执行 Python 命令: {}", commands);
int runningStatus = -1;
try {
log.info("开始同步执行脚本");
Process process = Runtime.getRuntime().exec(commands);
log.info("开始获取脚本输出");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info("executePython" + line);
}
log.info("脚本执行完成");
runningStatus = process.waitFor();
log.info("脚本运行状态:" + runningStatus);
} catch (IOException | InterruptedException e) {
log.error("执行脚本失败:" + e);
return;
}
if (runningStatus != 0) {
log.error("执行脚本失败");
return;
} else {
log.info(commands + "执行脚本完成!");
}
byte[] fileData = null;
if (response != null) {
try {
// 获取临时路径中脚本生成的报告
String reportName = "report_" +
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) +
".docx";
FileInputStream fileInputStream = new FileInputStream(TEMP_REPORT_PATH + randomId + File.separator + reportName);
fileData = fileInputStream.readAllBytes();
// 上传到算例下的报告文件夹下 // 上传到算例下的报告文件夹下
KeyResultReq resultReq = new KeyResultReq(); KeyResultReq resultReq = new KeyResultReq();
resultReq.setKeyResultType(KeyResultTypeEnum.DOCUMENT.getKeyResultType()); resultReq.setKeyResultType(KeyResultTypeEnum.DOCUMENT.getKeyResultType());
resultReq.setRunId(req.getRunId()); resultReq.setRunId(req.getRunId());
resultReq.setName(reportName); resultReq.setName(reportName);
// 创建临时MultipartFile
MockMultipartFile multipartFile = new MockMultipartFile(
reportName,
reportName,
"application/json",
fileData);
resultReq.setFile(multipartFile); resultReq.setFile(multipartFile);
resultReq.setFileName(reportName); resultReq.setFileName(reportName);
resultReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue()); resultReq.setFileType(FileBizTypeEnum.REPORT_FILE.getValue());
SdmResponse sdmResponse = addSimulationKeyResult(resultReq); SdmResponse sdmResponse = addSimulationKeyResult(resultReq);
if (!sdmResponse.isSuccess()) { if (!sdmResponse.isSuccess()) {
throw new RuntimeException("生成自动化报告上传报告结果目录失败"); throw new RuntimeException("生成自动化报告上传算例报告结果目录失败");
} }
// 下载到本地
// 设置响应头
response.reset();
response.setContentType("application/octet-stream;charset=UTF-8");
response.addHeader("Content-Length", String.valueOf(fileData.length));
// 写入响应流
OutputStream outputStream = response.getOutputStream();
outputStream.write(fileData);
outputStream.flush();
outputStream.close();
fileInputStream.close();
} catch (Exception ex) {
log.error("生成自动化报告失败:{}", ex.getMessage());
throw new RuntimeException("生成自动化报告失败");
} }
// 下载到本地
// 设置响应头
response.reset();
response.setContentType("application/octet-stream;charset=UTF-8");
response.addHeader("Content-Length", String.valueOf(fileData.length));
// 写入响应流
OutputStream outputStream = response.getOutputStream();
outputStream.write(fileData);
outputStream.flush();
outputStream.close();
fileInputStream.close();
} catch (Exception ex) {
log.error("生成自动化报告失败:{}", ex.getMessage());
throw new RuntimeException("生成自动化报告失败");
} }
// 删除临时路径
log.info("删除临时路径:{},中。。。。。。", randomId);
deleteFolder(new File(TEMP_REPORT_PATH + randomId));
} }
// 删除临时路径
log.info("删除临时路径:{},中。。。。。。", randomId);
deleteFolder(new File(TEMP_REPORT_PATH + randomId));
} }
} }