update
This commit is contained in:
@@ -50,8 +50,8 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
|||||||
//generateExperimentDoc("20241028号实验", "辐照试验计划表", maps);
|
//generateExperimentDoc("20241028号实验", "辐照试验计划表", maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateExperimentDoc(String experimentId, String fileName, Map<String, Object> params) {
|
public String generateExperimentDoc(String experimentId, String fileName, String version) {
|
||||||
String absolutePath = templatePath + File.separator + docTempalteMap.get(fileName);
|
String absolutePath = templatePath + File.separator + version + File.separator + docTempalteMap.get(fileName);
|
||||||
log.info("doc template path: " + absolutePath);
|
log.info("doc template path: " + absolutePath);
|
||||||
if (!FileUtil.exist(absolutePath)) {
|
if (!FileUtil.exist(absolutePath)) {
|
||||||
throw new RuntimeException("模板文件不存在!");
|
throw new RuntimeException("模板文件不存在!");
|
||||||
@@ -64,9 +64,10 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
|||||||
}
|
}
|
||||||
log.info("output file path: " + outputFile);
|
log.info("output file path: " + outputFile);
|
||||||
|
|
||||||
|
Map<String, Object> params = new HashMap();
|
||||||
XWPFTemplate.compile(absolutePath).render(params).writeToFile(outputFile);
|
XWPFTemplate.compile(absolutePath).render(params).writeToFile(outputFile);
|
||||||
String path = MinioUtil.upload(FileUtil.getInputStream(outputFile),
|
String path = MinioUtil.upload(FileUtil.getInputStream(outputFile),
|
||||||
"experiment_doc/" + experimentId + "/" + fileName + ".docx");
|
"experiment_doc/" + experimentId + "/" + version + "/" + fileName + ".docx");
|
||||||
return path;
|
return path;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
@@ -76,13 +77,14 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExperimentDoc generate(String experimentId, String type) {
|
public ExperimentDoc generate(String experimentId, String type) {
|
||||||
String filePath = generateExperimentDoc(experimentId, type, new HashMap<>());
|
String version = DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
|
||||||
|
String filePath = generateExperimentDoc(experimentId, type, version);
|
||||||
if (StringUtils.isNotBlank(filePath)) {
|
if (StringUtils.isNotBlank(filePath)) {
|
||||||
ExperimentDoc experimentDoc = new ExperimentDoc();
|
ExperimentDoc experimentDoc = new ExperimentDoc();
|
||||||
experimentDoc.setDocType(type);
|
experimentDoc.setDocType(type);
|
||||||
experimentDoc.setExperimentId(experimentId);
|
experimentDoc.setExperimentId(experimentId);
|
||||||
experimentDoc.setFilePath(filePath);
|
experimentDoc.setFilePath(filePath);
|
||||||
experimentDoc.setVersion(DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
|
experimentDoc.setVersion(version);
|
||||||
this.save(experimentDoc);
|
this.save(experimentDoc);
|
||||||
return experimentDoc;
|
return experimentDoc;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user