This commit is contained in:
ls
2024-11-22 15:05:54 +08:00
parent 2717e319c4
commit b63759488e

View File

@@ -9,9 +9,12 @@ import com.deepoove.poi.XWPFTemplate;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.MinioUtil;
import org.jeecg.modules.database.entity.Experiment;
import org.jeecg.modules.database.entity.ExperimentDoc;
import org.jeecg.modules.database.mapper.ExperimentDocMapper;
import org.jeecg.modules.database.service.IExperimentDocService;
import org.jeecg.modules.database.service.IExperimentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@@ -30,7 +33,9 @@ import java.util.*;
public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, ExperimentDoc> implements IExperimentDocService {
@Value("${jeecg.template.path}")
private String templatePath;
private String templatePath;
@Autowired
private IExperimentService experimentService;
static Map<String, String> docTempalteMap = new HashMap<>();
@@ -57,17 +62,20 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
throw new RuntimeException("模板文件不存在!");
}
try {
Experiment experiment = experimentService.getById(experimentId);
if (Objects.isNull(experiment)) {
throw new RuntimeException("实验数据不存在!");
}
String tmpDirPath = FileUtil.getTmpDirPath();
String outputFile = tmpDirPath + fileName + "-" + experimentId + "-" + version + ".docx";
if (FileUtil.exist(outputFile)) {
FileUtil.del(outputFile);
}
log.info("output file path: " + outputFile);
Map<String, Object> params = new HashMap();
XWPFTemplate.compile(absolutePath).render(params).writeToFile(outputFile);
String path = MinioUtil.upload(FileUtil.getInputStream(outputFile),
"experiment_doc/" + experimentId + "/" + version + "/" + fileName + ".docx");
"experiment_doc/" + experimentId + "/" + version + "/" + experiment.getName() + "-" + fileName + ".docx");
return path;
} catch (Exception e) {
log.error(e.getMessage());