update
This commit is contained in:
@@ -9,13 +9,13 @@ import org.jeecg.common.util.MinioUtil;
|
||||
import org.jeecg.modules.database.entity.ExperimentDoc;
|
||||
import org.jeecg.modules.database.mapper.ExperimentDocMapper;
|
||||
import org.jeecg.modules.database.service.IExperimentDocService;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @Description: 试验文档
|
||||
@@ -27,6 +27,9 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, ExperimentDoc> implements IExperimentDocService {
|
||||
|
||||
@Value("${jeecg.template.path}")
|
||||
private String templatePath;
|
||||
|
||||
static Map<String, String> docTempalteMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
@@ -42,17 +45,15 @@ public class ExperimentDocServiceImpl extends ServiceImpl<ExperimentDocMapper, E
|
||||
//The core API uses a minimalist design, only one line of code is required
|
||||
Map<String, Object> maps = new HashMap<>();
|
||||
maps.put("title", "辐照试验计划表");
|
||||
generateExperimentDoc("20241028号实验", "辐照试验计划表", maps);
|
||||
//generateExperimentDoc("20241028号实验", "辐照试验计划表", maps);
|
||||
}
|
||||
|
||||
public static String generateExperimentDoc(String experimentId, String fileName, Map<String, Object> params) {
|
||||
URL resourceUrl = ExperimentDocServiceImpl.class.getClassLoader().getResource("templates/doc/" + docTempalteMap.get(fileName));
|
||||
if (Objects.isNull(resourceUrl)) {
|
||||
public String generateExperimentDoc(String experimentId, String fileName, Map<String, Object> params) {
|
||||
String absolutePath = templatePath + File.separator + docTempalteMap.get(fileName);
|
||||
log.info("doc template path: " + absolutePath);
|
||||
if (FileUtil.exist(absolutePath)) {
|
||||
throw new RuntimeException("模板文件不存在!");
|
||||
}
|
||||
String absolutePath = resourceUrl.getPath();
|
||||
log.info("doc template path: " + absolutePath);
|
||||
|
||||
try {
|
||||
String tmpDirPath = FileUtil.getTmpDirPath();
|
||||
String outputFile = tmpDirPath + fileName + "-" + experimentId + ".docx";
|
||||
|
||||
Reference in New Issue
Block a user