Commit 923b2211 authored by 韩桐桐's avatar 韩桐桐

fix(jg):告知模板回退

parent 40bfdba5
...@@ -20,8 +20,9 @@ import java.io.*; ...@@ -20,8 +20,9 @@ import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.sql.Array; import java.util.HashMap;
import java.util.*; import java.util.Map;
import java.util.UUID;
@Slf4j @Slf4j
public class WordTemplateUtils { public class WordTemplateUtils {
...@@ -49,7 +50,7 @@ public class WordTemplateUtils { ...@@ -49,7 +50,7 @@ public class WordTemplateUtils {
* @param template 模板 * @param template 模板
* @return doc文件 * @return doc文件
*/ */
public static File createDoc(String templatePath, List<Map<String, ?>> dataMap, Template template) throws TemplateException, IOException { public static File createDoc(String templatePath, Map<String, ?> dataMap, Template template) throws TemplateException, IOException {
// templatePath在后缀之前加上UUID是为了防止并发时多个线程使用同一个模板文件而导致生成的Word文档内容不一致 // templatePath在后缀之前加上UUID是为了防止并发时多个线程使用同一个模板文件而导致生成的Word文档内容不一致
int i = templatePath.lastIndexOf("."); int i = templatePath.lastIndexOf(".");
templatePath = UUID.randomUUID() + templatePath.substring(i); templatePath = UUID.randomUUID() + templatePath.substring(i);
...@@ -62,16 +63,12 @@ public class WordTemplateUtils { ...@@ -62,16 +63,12 @@ public class WordTemplateUtils {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开 // 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer writer = new OutputStreamWriter(Files.newOutputStream(docFile.toPath()), StandardCharsets.UTF_8) Writer writer = new OutputStreamWriter(Files.newOutputStream(docFile.toPath()), StandardCharsets.UTF_8)
) { ) {
ArrayList<Map<String, Object>> arrayList = new ArrayList<>(); template.process(escapeSpecialCharacters(dataMap), writer);
for (Map<String, ?> stringMap : dataMap) {
arrayList.add(escapeSpecialCharacters(stringMap));
}
template.process(arrayList, writer);
} }
return docFile; return docFile;
} }
public File fillAndConvertDocFile(String templatePath, String targetFileName, List<Map<String, ?>> map, int saveFormat) throws Exception { public File fillAndConvertDocFile(String templatePath, String targetFileName, Map<String, ?> map, int saveFormat) throws Exception {
// 指定模板所在包路径 // 指定模板所在包路径
configuration.setClassForTemplateLoading(this.getClass(), BASE_PACKAGE_PATH); configuration.setClassForTemplateLoading(this.getClass(), BASE_PACKAGE_PATH);
...@@ -157,7 +154,7 @@ public class WordTemplateUtils { ...@@ -157,7 +154,7 @@ public class WordTemplateUtils {
return url; return url;
} }
public static void templateToPdfDownload(String pdfName, String wordPath, List<Map<String, Object>> placeholders, HttpServletResponse response) { public static void templateToPdfDownload(String pdfName, String wordPath, Map<String, Object> placeholders, HttpServletResponse response) {
// word转pdf // word转pdf
File pdfFile; File pdfFile;
try { try {
...@@ -222,7 +219,7 @@ public class WordTemplateUtils { ...@@ -222,7 +219,7 @@ public class WordTemplateUtils {
* *
* @param wordPath word文件路径 * @param wordPath word文件路径
*/ */
private static File wordToPdf(String pdfName, String wordPath, List<Map<String, Object>> placeholders) throws Exception { private static File wordToPdf(String pdfName, String wordPath, Map<String, Object> placeholders) throws Exception {
Assert.hasText(wordPath, "word文件路径不能为空"); Assert.hasText(wordPath, "word文件路径不能为空");
WordTemplateUtils instance = WordTemplateUtils.getInstance(); WordTemplateUtils instance = WordTemplateUtils.getInstance();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment