|
@@ -1,5 +1,6 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -9,6 +10,7 @@ import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
|
import com.qmth.distributed.print.business.config.DictionaryConfig;
|
|
|
import com.qmth.distributed.print.business.entity.BasicAttachment;
|
|
|
+import com.qmth.distributed.print.business.entity.ExamDetailCourse;
|
|
|
import com.qmth.distributed.print.business.entity.SysUser;
|
|
|
import com.qmth.distributed.print.business.enums.PageSizeEnum;
|
|
|
import com.qmth.distributed.print.business.enums.UploadFileEnum;
|
|
@@ -238,6 +240,8 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
|
|
|
/**
|
|
|
* 保存附件
|
|
|
*
|
|
|
+ * @param printType
|
|
|
+ * @param examDetailCourse
|
|
|
* @param basicAttachment
|
|
|
* @param pdfList
|
|
|
* @param printCount
|
|
@@ -247,7 +251,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public BasicAttachment saveAttachmentPdf(BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
|
|
|
+ public BasicAttachment saveAttachmentPdf(String printType, ExamDetailCourse examDetailCourse, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
|
|
|
try {
|
|
|
boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
|
|
@@ -264,36 +268,49 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
|
|
|
url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
|
|
|
htmlFile = ossUtil.ossDownload(filePath, url);
|
|
|
}
|
|
|
- String pdfDirName = filePath.replaceAll(SystemConstant.HTML_PREFIX, SystemConstant.PDF_PREFIX).replaceAll(UploadFileEnum.HTML.name().toLowerCase(), UploadFileEnum.PDF.name().toLowerCase());
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ StringJoiner pdfStringJoiner = new StringJoiner("");
|
|
|
+ if (!oss) {
|
|
|
+ pdfStringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
|
|
|
+ }
|
|
|
+ pdfStringJoiner.add(UploadFileEnum.PDF.getTitle()).add(File.separator);
|
|
|
+ pdfStringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()));
|
|
|
+ pdfStringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.PDF_PREFIX);
|
|
|
+
|
|
|
+ String pdfDirName = pdfStringJoiner.toString();
|
|
|
String destUrl = SystemConstant.PDF_TEMP_FILES_DIR + File.separator + pdfDirName;
|
|
|
- HtmlToPdfUtil.convert(htmlFile.getPath(), destUrl, PageSizeEnum.A4);
|
|
|
File pdfFile = new File(destUrl);
|
|
|
+ if (!pdfFile.exists()) {
|
|
|
+ pdfFile.getParentFile().mkdirs();
|
|
|
+ pdfFile.createNewFile();
|
|
|
+ }
|
|
|
+
|
|
|
+ HtmlToPdfUtil.convert(htmlFile.getPath(), destUrl, PageSizeEnum.A4);
|
|
|
String fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
|
|
|
PdfDto pdfDto = null;
|
|
|
if (oss) {//上传至oss
|
|
|
pdfDto = PdfUtil.addPdfPage(pdfFile);
|
|
|
ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
|
|
|
- jsonObject.put(SystemConstant.PDF_PATH, pdfDirName);
|
|
|
- if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.FTL_PREFIX)) {
|
|
|
- jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
- UploadFileEnum.FILE,
|
|
|
- UploadFileEnum.HTML,
|
|
|
- UploadFileEnum.PDF
|
|
|
- });
|
|
|
- } else {
|
|
|
- jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
|
|
|
- UploadFileEnum.FILE,
|
|
|
- UploadFileEnum.PDF
|
|
|
- });
|
|
|
- htmlFile.delete();
|
|
|
- }
|
|
|
+ htmlFile.delete();
|
|
|
}
|
|
|
- basicAttachment.setPath(jsonObject.toJSONString());
|
|
|
+ JSONObject attachmentPath = JSONObject.parseObject(examDetailCourse.getAttachmentPath());
|
|
|
+ attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
|
|
|
+ JSONArray jsonArray = (JSONArray) attachmentPath.get("path");
|
|
|
+ jsonArray = Objects.isNull(jsonArray) ? new JSONArray() : jsonArray;
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put(SystemConstant.TYPE, printType);
|
|
|
+ object.put(SystemConstant.HTML_PATH, filePath);
|
|
|
+ object.put(SystemConstant.PDF_PATH, pdfDirName);
|
|
|
+ object.put(SystemConstant.UPLOAD_TYPE, oss);
|
|
|
+ jsonArray.add(object);
|
|
|
+ attachmentPath.put("path", jsonArray);
|
|
|
+ examDetailCourse.setAttachmentPath(attachmentPath.toJSONString());
|
|
|
basicAttachment.setPages(pdfDto.getActualPageCount());
|
|
|
for (int i = 0; i < printCount; i++) {
|
|
|
pdfList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount(), sequence));
|
|
|
}
|
|
|
- this.updateById(basicAttachment);
|
|
|
} catch (Exception e) {
|
|
|
log.error("请求出错", e);
|
|
|
if (e instanceof ApiException) {
|