update
This commit is contained in:
@@ -127,8 +127,8 @@ public class ExperimentReportController extends JeecgController<ExperimentReport
|
||||
fileName = sampleName + "-" + modelBatch;
|
||||
}
|
||||
experimentReport.setReportName("试验报告-" + fileName);
|
||||
experimentReportService.save(experimentReport);
|
||||
experimentDocService.generate(experimentId, ExperimentDocType.sybg.getType());
|
||||
boolean save = experimentReportService.save(experimentReport);
|
||||
experimentDocService.generateExperimentReport( experimentReport.getId());
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
@@ -156,8 +156,8 @@ public class ExperimentReportController extends JeecgController<ExperimentReport
|
||||
// experimentReport.setStatus(experimentReport.getLastStatus());
|
||||
//}
|
||||
experimentReportService.updateById(experimentReport);
|
||||
experimentDocService.generate(report.getExperimentId(), ExperimentDocType.sybg.getType());
|
||||
return Result.OK("编辑成功!");
|
||||
String generate = experimentDocService.generateExperimentReport(experimentReport.getId());
|
||||
return Result.OK(generate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,8 @@ public interface IExperimentDocService extends IService<ExperimentDoc> {
|
||||
|
||||
ExperimentDoc generate(String experimentId, String type);
|
||||
|
||||
String generateExperimentReport(String experimentReportId);
|
||||
|
||||
List<ExperimentDoc> getHistoryByExperimentId(String experimentId, String type);
|
||||
|
||||
ExperimentDoc getByExperimentId(String experimentId, String type);
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.jeecg.common.util.DateUtils;
|
||||
import org.jeecg.common.util.MinioUtil;
|
||||
import org.jeecg.modules.database.constant.ExperimentDocType;
|
||||
import org.jeecg.modules.database.dto.RadiationDetailDTO;
|
||||
import org.jeecg.modules.database.dto.RadiationMapDTO;
|
||||
import org.jeecg.modules.database.entity.*;
|
||||
@@ -232,9 +233,6 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
||||
FileUtil.mkdir(outputDir);
|
||||
}
|
||||
for (ExperimentReport experimentReport : reportList) {
|
||||
if (StringUtils.isNotBlank(experimentReport.getFileUrl())) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> params = assembleSybg(experimentId, experimentReport);
|
||||
XWPFTemplate render = XWPFTemplate.compile(absolutePath).render(params);
|
||||
String filePath = outputDir + File.separator + experimentReport.getReportName() + ".docx";
|
||||
@@ -245,6 +243,7 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
||||
experimentReport.setFileUrl(reportPath);
|
||||
experimentReportService.updateById(experimentReport);
|
||||
}
|
||||
|
||||
File zip = ZipUtil.zip(outputDir);
|
||||
String zipPath = MinioUtil.upload(FileUtil.getInputStream(zip),
|
||||
"experiment_doc/" + experimentId + "/" + version + "/" + type + "-" + experiment.getName() + ".zip");
|
||||
@@ -745,6 +744,50 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String generateExperimentReport(String experimentReportId) {
|
||||
String version = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
|
||||
ExperimentReport experimentReport = experimentReportService.getById(experimentReportId);
|
||||
if (Objects.isNull(experimentReport)) {
|
||||
return "";
|
||||
}
|
||||
String experimentId = experimentReport.getExperimentId();
|
||||
String absolutePath = templatePath + File.separator + docTempalteMap.get(ExperimentDocType.sybg.getType());
|
||||
log.info("doc template path: " + absolutePath);
|
||||
if (!FileUtil.exist(absolutePath)) {
|
||||
throw new RuntimeException("模板文件不存在!");
|
||||
}
|
||||
try {
|
||||
Experiment experiment = experimentService.getById(experimentId);
|
||||
if (Objects.isNull(experiment)) {
|
||||
throw new RuntimeException("实验数据不存在!");
|
||||
}
|
||||
String tmpDirPath = FileUtil.getTmpDirPath();
|
||||
|
||||
List<String> pathList = new ArrayList<>();
|
||||
|
||||
String outputDir = tmpDirPath + ExperimentDocType.sybg.getType() + File.separator + experimentId + File.separator + version;
|
||||
if (FileUtil.exist(outputDir)) {
|
||||
FileUtil.del(outputDir);
|
||||
}
|
||||
if (!FileUtil.exist(outputDir)) {
|
||||
FileUtil.mkdir(outputDir);
|
||||
}
|
||||
Map<String, Object> params = assembleSybg(experimentId, experimentReport);
|
||||
XWPFTemplate render = XWPFTemplate.compile(absolutePath).render(params);
|
||||
String filePath = outputDir + File.separator + experimentReport.getReportName() + ".docx";
|
||||
render.writeToFile(filePath);
|
||||
String reportPath = MinioUtil.upload(FileUtil.getInputStream(filePath),
|
||||
"experiment_doc/" + experimentId + "/" + version + "/" + experimentReport.getReportName() + ".docx");
|
||||
experimentReport.setFileUrl(reportPath);
|
||||
experimentReportService.updateById(experimentReport);
|
||||
return reportPath;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperimentDoc generate(String experimentId, String type) {
|
||||
String version = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
|
||||
|
||||
Reference in New Issue
Block a user