|
@@ -1,7 +1,10 @@
|
|
|
package com.qmth.distributed.print.business.util;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.qmth.distributed.print.business.config.DictionaryConfig;
|
|
|
+import com.qmth.distributed.print.business.entity.BasicAttachment;
|
|
|
import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
|
+import com.qmth.distributed.print.business.service.BasicAttachmentService;
|
|
|
import com.qmth.distributed.print.common.contant.SystemConstant;
|
|
|
import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
|
|
|
import freemarker.template.Configuration;
|
|
@@ -15,6 +18,7 @@ import org.springframework.util.ResourceUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.StringJoiner;
|
|
@@ -36,6 +40,9 @@ public class FreemarkerUtil {
|
|
|
@Resource
|
|
|
OssUtil ossUtil;
|
|
|
|
|
|
+ @Resource
|
|
|
+ BasicAttachmentService basicAttachmentService;
|
|
|
+
|
|
|
/**
|
|
|
* 单独生成签到表
|
|
|
*
|
|
@@ -71,8 +78,12 @@ public class FreemarkerUtil {
|
|
|
private void createSignBookAndPaperPackageHtml(Map<String, Object> dataMap) throws IOException {
|
|
|
Writer out = null;
|
|
|
try {
|
|
|
- String ftlPath = (String) dataMap.get("ftlPath");
|
|
|
- String ftlName = (String) dataMap.get("ftlName");
|
|
|
+ BasicAttachment basicAttachment = (BasicAttachment) dataMap.get("basicAttachment");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
|
|
|
+ String path = (String) jsonObject.get(SystemConstant.PATH);
|
|
|
+ String ftlPath = path.substring(0, path.lastIndexOf("/"));
|
|
|
+ String ftlName = path.substring(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
|
|
|
+
|
|
|
Configuration configuration = new Configuration(Configuration.VERSION_2_3_29);
|
|
|
File templates = ResourceUtils.getFile(SystemConstant.TEMP_FILES_DIR + File.separator + ftlPath);
|
|
|
configuration.setDirectoryForTemplateLoading(templates);
|
|
@@ -80,7 +91,7 @@ public class FreemarkerUtil {
|
|
|
Template template = configuration.getTemplate(ftlName + SystemConstant.FTL_PREFIX);
|
|
|
// step2 生成数据
|
|
|
StringJoiner localStringJoiner = new StringJoiner("");
|
|
|
- localStringJoiner.add(SystemConstant.TEMP_FILES_DIR + File.separator + ftlPath)
|
|
|
+ localStringJoiner.add(SystemConstant.TEMP_FILES_DIR + File.separator + ftlPath.replaceAll(UploadFileEnum.FILE.getTitle(), UploadFileEnum.HTML.getTitle()))
|
|
|
.add(File.separator)
|
|
|
.add(ftlName)
|
|
|
.add(SystemConstant.HTML_PREFIX);
|
|
@@ -93,13 +104,22 @@ public class FreemarkerUtil {
|
|
|
if (oss) {
|
|
|
LocalDateTime nowTime = LocalDateTime.now();
|
|
|
StringJoiner stringJoiner = new StringJoiner("");
|
|
|
- stringJoiner.add(UploadFileEnum.HTML.name()).add(File.separator)
|
|
|
+ stringJoiner.add(UploadFileEnum.HTML.getTitle()).add(File.separator)
|
|
|
.add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
.add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
- .add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
+ .add(File.separator).add(ftlName).add(SystemConstant.HTML_PREFIX);
|
|
|
ossUtil.ossUpload(stringJoiner.toString(), htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)));
|
|
|
+ jsonObject.put(SystemConstant.HTML_PATH, stringJoiner.toString());
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
+ UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE)),
|
|
|
+ UploadFileEnum.HTML
|
|
|
+ });
|
|
|
+ basicAttachment.setPath(jsonObject.toJSONString());
|
|
|
+ basicAttachmentService.saveAttachmentPdf(basicAttachment, (List<String>) dataMap.get("variablePdfList"));
|
|
|
}
|
|
|
log.info("{}文件创建成功", htmlFile.toString());
|
|
|
+ htmlFile.delete();
|
|
|
} catch (Exception e) {
|
|
|
log.error("请求出错", e);
|
|
|
} finally {
|