Browse Source

生成pdf修改逻辑,oss|trueOrFalse

wangliang 2 years ago
parent
commit
1aae6ced6a
13 changed files with 643 additions and 620 deletions
  1. 5 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/PrintCommonService.java
  2. 33 23
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java
  3. 31 57
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java
  4. 24 19
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java
  5. 349 346
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java
  6. 152 152
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java
  7. 3 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java
  8. 17 1
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java
  9. 1 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/BasicAttachmentService.java
  10. 2 1
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TeachcloudCommonService.java
  11. 4 5
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicAttachmentServiceImpl.java
  12. 8 11
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java
  13. 14 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/FileStoreUtil.java

+ 5 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/PrintCommonService.java

@@ -48,9 +48,9 @@ public interface PrintCommonService {
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException;
+    public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence, List<File> fileTempList) throws IOException, DocumentException;
 
-    public void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount);
+    public void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount, List<File> fileTempList);
 
     /**
      * 保存html附件
@@ -59,10 +59,11 @@ public interface PrintCommonService {
      * @param htmlContent
      * @param userId
      * @param localFileList
+     * @param fileTempList
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList) throws IOException;
+    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList, List<File> fileTempList) throws IOException;
 
     /**
      * 保存html附件和该html转成pdf的附件
@@ -309,7 +310,7 @@ public interface PrintCommonService {
      */
     public void updateGradeBatchStatus(Long schoolId, String paperNumber, String paperType);
 
-    void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> variablePdfList, Integer printCount);
+    void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> variablePdfList, Integer printCount, List<File> fileTempList);
 
     JSONObject uploadPdfFile(File pdfFile, ClassifyEnum classifyEnum);
 }

+ 33 - 23
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -163,13 +163,13 @@ public class PrintCommonServiceImpl implements PrintCommonService {
      * @param pdfList
      * @param printCount
      * @param sequence
+     * @param fileTempList
      * @return
      * @throws IOException
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence) throws IOException, DocumentException {
-        File htmlFileTemp = null;
+    public BasicAttachment saveAttachmentPdf(ClassifyEnum classifyEnum, ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> pdfList, Integer printCount, Integer sequence, List<File> fileTempList) throws IOException, DocumentException {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -182,7 +182,8 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
                 if (oss) {
                     ossStr = SystemConstant.OSS;
-                    htmlFileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
+                    File htmlFileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
+                    fileTempList.add(htmlFileTemp);
                     htmlFile = fileStoreUtil.ossDownload(filePath, htmlFileTemp.getPath(), uploadType.getFssType());
                 } else {
                     ossStr = SystemConstant.LOCAL;
@@ -202,6 +203,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
             String pdfDirName = pdfStringJoiner.toString();
             File pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            fileTempList.add(pdfFileTemp);
             HtmlToPdfUtil.convert(htmlFile.getPath(), pdfFileTemp.getPath(), PageSizeEnum.A4);
 
 //            File pdfFile = asposePdfUtil.documentToPdf(htmlFile.getPath(), destUrl, PaperSize.A4);
@@ -211,8 +213,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
             } else {
                 if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
-                    File file = new File(pdfStringJoiner.toString());
-                    FileCopyUtils.copy(file, pdfFileTemp);
+                    fileStoreUtil.localUpload(pdfDirName, new FileInputStream(pdfFileTemp), pdfFileMd5, LocalCatalogEnum.LOCAL_PDF);
                 } else {
                     fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
                 }
@@ -258,11 +259,11 @@ public class PrintCommonServiceImpl implements PrintCommonService {
      * @param examDetail
      * @param pdfList
      * @param printCount
+     * @param fileTempList
      */
     @Override
     @Transactional
-    public void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount) {
-        File pdfFileTemp = null;
+    public void saveAttachmentSignPdf(PdfSignDto pdfFillDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount, List<File> fileTempList) {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             StringJoiner pdfStringJoiner = new StringJoiner("");
@@ -273,7 +274,8 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             pdfStringJoiner = SystemConstant.getDirName(pdfStringJoiner, UploadFileEnum.PDF, true);
             pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
 
-            pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            File pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            fileTempList.add(pdfFileTemp);
             createPrintPdfUtil.createSignPdf(pdfFillDto, pdfFileTemp.getPath());
 
             String pdfDirName = pdfStringJoiner.toString().replaceAll("\\\\", "/");
@@ -285,8 +287,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             } else {
                 ossStr = SystemConstant.LOCAL;
                 if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
-                    File file = new File(pdfStringJoiner.toString());
-                    FileCopyUtils.copy(file, pdfFileTemp);
+                    fileStoreUtil.localUpload(pdfDirName, new FileInputStream(pdfFileTemp), pdfFileMd5, LocalCatalogEnum.LOCAL_PDF);
                 } else {
                     fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
                 }
@@ -328,18 +329,21 @@ public class PrintCommonServiceImpl implements PrintCommonService {
      * @param htmlContent
      * @param userId
      * @param localFileList
+     * @param fileTempList
      * @return
      * @throws IOException
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList) throws IOException {
+    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId, List<PdfDto> localFileList, List<File> fileTempList) throws IOException {
         BasicAttachment basicAttachment = null;
         PdfDto pdfDto = null;
-        File htmlFileTemp = null, pdfFileTemp = null;
         try {
-            htmlFileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
-            pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            File htmlFileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
+            File pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            fileTempList.add(htmlFileTemp);
+            fileTempList.add(pdfFileTemp);
+
             FileCopyUtils.copy(htmlContent.getBytes(), htmlFileTemp);
             boolean oss = dictionaryConfig.sysDomain().isOss();
             StringJoiner stringJoiner = new StringJoiner("");
@@ -367,8 +371,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 fileStoreUtil.ossUpload(htmlDirName, htmlFileTemp, htmlFileMd5, fileStoreUtil.getUploadEnumByPath(htmlDirName).getFssType());
             } else {
                 if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-                    File file = new File(stringJoiner.toString());
-                    FileCopyUtils.copy(file, htmlFileTemp);
+                    fileStoreUtil.localUpload(htmlDirName, new FileInputStream(htmlFileTemp), htmlFileMd5, LocalCatalogEnum.LOCAL_FILE);
                 } else {
                     fileStoreUtil.ossUpload(htmlDirName, htmlFileTemp, htmlFileMd5, fileStoreUtil.getUploadEnumByPath(htmlDirName).getFssType());
                 }
@@ -384,8 +387,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
             } else {
                 if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
-                    File file = new File(pdfStringJoiner.toString());
-                    FileCopyUtils.copy(file, pdfFileTemp);
+                    fileStoreUtil.localUpload(pdfDirName, new FileInputStream(pdfFileTemp), pdfFileMd5, LocalCatalogEnum.LOCAL_PDF);
                 } else {
                     fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
                 }
@@ -1307,9 +1309,17 @@ public class PrintCommonServiceImpl implements PrintCommonService {
         }
     }
 
+    /**
+     * 生成卷袋贴
+     *
+     * @param pdfPackageDto
+     * @param examDetail
+     * @param pdfList
+     * @param printCount
+     * @param fileTempList
+     */
     @Override
-    public void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount) {
-        File pdfFileTemp = null;
+    public void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> pdfList, Integer printCount, List<File> fileTempList) {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             StringJoiner pdfStringJoiner = new StringJoiner("");
@@ -1321,7 +1331,8 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
 
             String pdfDirName = pdfStringJoiner.toString().replaceAll("\\\\", "/");
-            pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            File pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+            fileTempList.add(pdfFileTemp);
             createPrintPdfUtil.createPackagePdf(pdfPackageDto, pdfFileTemp.getPath());
             //pdf生成和上传
             String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFileTemp));
@@ -1331,8 +1342,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
             } else {
                 ossStr = SystemConstant.LOCAL;
                 if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
-                    File file = new File(pdfStringJoiner.toString());
-                    FileCopyUtils.copy(file, pdfFileTemp);
+                    fileStoreUtil.localUpload(pdfDirName, new FileInputStream(pdfFileTemp), pdfFileMd5, LocalCatalogEnum.LOCAL_PDF);
                 } else {
                     fileStoreUtil.ossUpload(pdfDirName, pdfFileTemp, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
                 }

+ 31 - 57
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -15,12 +15,14 @@ import com.qmth.teachcloud.common.util.FileStoreUtil;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.scheduling.annotation.Async;
 
 import java.io.*;
+import java.nio.charset.StandardCharsets;
 import java.text.MessageFormat;
 import java.util.Date;
 import java.util.Map;
@@ -90,67 +92,47 @@ public abstract class AsyncImportTaskTemplete {
      *
      * @param tbTask
      */
-    public void createTxt(TBTask tbTask) {
-        FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
+    public void createTxt(TBTask tbTask) throws IOException {
         TBTaskService tbTaskService = SpringContextHolder.getBean(TBTaskService.class);
-        DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
-        ByteArrayOutputStream out = null;
-        InputStream inputStream = null;
+        File txtFileTemp = null;
         try {
-            JSONObject jsonObject = JSONObject.parseObject(tbTask.getImportFilePath());
-            if (Objects.isNull(jsonObject)) {
-                jsonObject = new JSONObject();
-                StringJoiner stringJoiner = new StringJoiner("");
-                if (Objects.nonNull(dictionaryConfig) && dictionaryConfig.sysDomain().isOss()) {
-                    jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
-                } else {
-                    if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-                        stringJoiner.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
-                    }
-                    jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
-                }
-                stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.FILE, true);
-                stringJoiner.add(SystemConstant.getNanoId()).add(TXT_PREFIX);
-                jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
-            }
-            String path = (String) jsonObject.get(SystemConstant.PATH);
-            path = path.replaceAll("\\\\", "/");
-            String type = (String) jsonObject.get(SystemConstant.TYPE);
-
-            String charset = SystemConstant.CHARSET_GBK;
+            FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
+            DictionaryConfig dictionaryConfig = SpringContextHolder.getBean(DictionaryConfig.class);
             CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
-            if (commonCacheService != null) {
-                SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_CONFIG_KEY_CHARSETS);
-                if (sysConfig != null && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
-                    charset = sysConfig.getConfigValue();
-                }
+            boolean oss = dictionaryConfig.sysDomain().isOss();
+            String ossStr = null;
+            StringJoiner stringJoiner = new StringJoiner("");
+            if (!oss && Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
+                stringJoiner.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
             }
+            stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.FILE, true);
+            stringJoiner.add(SystemConstant.getNanoId()).add(TXT_PREFIX);
 
-            out = new ByteArrayOutputStream();
-            out.write(tbTask.getSummary().getBytes(charset));
-            byte[] bookByteAry = out.toByteArray();
-            inputStream = new ByteArrayInputStream(bookByteAry);
-            StringJoiner stringJoiner = new StringJoiner("");
-            if (tbTask.getType() == TaskTypeEnum.CREATE_PDF) {
-                path = path.replaceAll(UploadFileEnum.PDF.getTitle(), UploadFileEnum.FILE.getTitle());
+            String txtDirName = stringJoiner.toString();
+            txtFileTemp = SystemConstant.getFileTempVar(TXT_PREFIX);
+            SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SYS_CONFIG_KEY_CHARSETS);
+            if (Objects.nonNull(sysConfig) && Objects.nonNull(sysConfig.getConfigValue())) {
+                IOUtils.write(tbTask.getSummary().getBytes(sysConfig.getConfigValue()), new FileOutputStream(txtFileTemp));
+            } else {
+                IOUtils.write(tbTask.getSummary().getBytes(StandardCharsets.UTF_8), new FileOutputStream(txtFileTemp));
             }
 
-            path = path.substring(0, path.lastIndexOf("/") + 1);
-            stringJoiner.add(path).add(SystemConstant.getNanoId()).add(TXT_PREFIX).toString();
-            if (Objects.equals(type, SystemConstant.OSS)) {//上传至oss
-                fileStoreUtil.ossUpload(stringJoiner.toString(), inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), fileStoreUtil.getUploadEnumByPath(stringJoiner.toString()).getFssType());
-            } else {//上传至服务器
+            String txtFileMd5 = DigestUtils.md5Hex(new FileInputStream(txtFileTemp));
+            if (oss) {
+                ossStr = SystemConstant.OSS;
+                fileStoreUtil.ossUpload(txtDirName, txtFileTemp, txtFileMd5, fileStoreUtil.getUploadEnumByPath(txtDirName).getFssType());
+            } else {
+                ossStr = SystemConstant.LOCAL;
                 if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-                    fileStoreUtil.copyInputStreamToFile(inputStream, new File(stringJoiner.toString()), DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), LocalCatalogEnum.LOCAL_FILE);
+                    fileStoreUtil.localUpload(txtDirName, new FileInputStream(txtFileTemp), txtFileMd5, LocalCatalogEnum.LOCAL_FILE);
                 } else {
-                    fileStoreUtil.ossUpload(stringJoiner.toString(), inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), UploadFileEnum.FILE.getFssType());
+                    fileStoreUtil.ossUpload(txtDirName, txtFileTemp, txtFileMd5, fileStoreUtil.getUploadEnumByPath(txtDirName).getFssType());
                 }
             }
             JSONObject json = new JSONObject();
             json.put(SystemConstant.PATH, stringJoiner.toString());
-            json.put(SystemConstant.TYPE, type);
+            json.put(SystemConstant.TYPE, ossStr);
             json.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
-
             tbTask.setReportFilePath(json.toJSONString());
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
@@ -174,16 +156,8 @@ public abstract class AsyncImportTaskTemplete {
                 ResultUtil.error(e.getMessage());
             }
         } finally {
-            try {
-                if (Objects.nonNull(inputStream)) {
-                    inputStream.close();
-                }
-                if (Objects.nonNull(out)) {
-                    out.flush();
-                    out.close();
-                }
-            } catch (IOException e) {
-                log.error(SystemConstant.LOG_ERROR, e);
+            if (Objects.nonNull(txtFileTemp)) {
+                txtFileTemp.delete();
             }
             tbTask.setStatus(TaskStatusEnum.FINISH);
             if (tbTask.getType() == TaskTypeEnum.CREATE_PDF) {

+ 24 - 19
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -239,6 +239,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @param paperTypeParam       试卷类型
      * @param basicAttachmentList  附件集合
      * @param attachmentIds
+     * @param fileTempList
      * @param list
      */
     @Transactional
@@ -249,6 +250,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                                     String paperTypeParam,
                                                     List<BasicAttachment> basicAttachmentList,
                                                     Set<Long> attachmentIds,
+                                                    List<File> fileTempList,
                                                     List<PdfDto>... list
     ) throws Exception {
         if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
@@ -368,7 +370,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
                     // 试卷数据组装
                     if (printContent.contains("PAPER")) {
-                        List<PaperPdfDto> paperPdfDto = createPdfUtil.getPaperPdfFile(examDetailCourse.getPaperType(), examTaskDetail);
+                        List<PaperPdfDto> paperPdfDto = createPdfUtil.getPaperPdfFile(examDetailCourse.getPaperType(), examTaskDetail, fileTempList);
 
                         //获取试卷pdf
                         PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperPdfList);
@@ -424,7 +426,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             String cardContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
 
                             for (int i = 1; i <= backupCount; i++) {
-                                BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format(SystemConstant.DATE_TIME_FORMAT, i), cardContent, examDetail, examDetailCourse, s, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
+                                BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format(SystemConstant.DATE_TIME_FORMAT, i), cardContent, examDetail, examDetailCourse, s, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule, fileTempList);
                                 examDetailCourse.setCardPagesA3(basicAttachment.getPages());
                                 basicAttachmentList.add(basicAttachment);
                             }
@@ -437,7 +439,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         if (examStudentList != null && examStudentList.size() > 0) {
                             for (ExamStudent t : examStudentList) {
                                 // 用带条码的模板
-                                basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetailMap.get(t.getPaperType()).getHtmlContent(), t, paperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
+                                basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetailMap.get(t.getPaperType()).getHtmlContent(), t, paperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule, fileTempList));
                             }
                         } else if (examDetail.getPrintCount() != null) {
                             AtomicInteger atomicInteger = new AtomicInteger(0);
@@ -447,7 +449,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                 int seq = atomicInteger.getAndIncrement();
                                 int mod = seq % examTaskDetail.getDrawCount();
                                 String tempPaperType = paperTypes.get(mod);
-                                BasicAttachment basicAttachment = createPdfUtil.examStudentHtml(cardContentMap.get(tempPaperType), null, tempPaperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule);
+                                BasicAttachment basicAttachment = createPdfUtil.examStudentHtml(cardContentMap.get(tempPaperType), null, tempPaperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule, fileTempList);
 
                                 if (!stringBasicAttachmentMap.containsKey(tempPaperType)) {
                                     stringBasicAttachmentMap.put(tempPaperType, basicAttachment);
@@ -487,12 +489,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @param examDetail
      * @param basicSchool
      * @param examDetailCourseList
+     * @param fileTempList
      * @param list
      * @throws IOException
      * @throws DocumentException
      */
     @Transactional
-    public void createA4File(ExamPrintPlan examPrintPlan, ExamDetail examDetail, BasicSchool basicSchool, List<ExamDetailCourse> examDetailCourseList, List<PdfDto>... list) throws Exception {
+    public void createA4File(ExamPrintPlan examPrintPlan, ExamDetail examDetail, BasicSchool basicSchool, List<ExamDetailCourse> examDetailCourseList, List<File> fileTempList, List<PdfDto>... list) throws Exception {
         // 印品
         String ordinaryContent = examPrintPlan.getOrdinaryContent();
         if (StringUtils.isNotBlank(ordinaryContent)) {
@@ -503,7 +506,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 if (Objects.nonNull(jsonObjectOrdinary.get("attachmentId")) && !Objects.equals("", jsonObjectOrdinary.get("attachmentId"))) {
                     Long attachmentId = Long.parseLong((String) jsonObjectOrdinary.get("attachmentId"));
                     BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                    createPdfUtil.createCheckIn(examDetail, basicAttachment, list[0], (Integer) jsonObjectOrdinary.get("backupCount"));
+                    createPdfUtil.createCheckIn(examDetail, basicAttachment, list[0], (Integer) jsonObjectOrdinary.get("backupCount"), fileTempList);
                 }
             }
         }
@@ -520,9 +523,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 if (Objects.nonNull(jsonObjectVariable.get("templateId")) && !Objects.equals("", jsonObjectVariable.get("templateId"))) {
                     Long templateId = Long.parseLong((String) jsonObjectVariable.get("templateId"));
                     if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
-                        createPdfUtil.createSignBook(templateId, basicSchool.getName(), examDetail, examStudentCourseDtoList, list[1], (Integer) jsonObjectVariable.get("backupCount"), examDetailCourseList);
+                        createPdfUtil.createSignBook(templateId, basicSchool.getName(), examDetail, examStudentCourseDtoList, list[1], (Integer) jsonObjectVariable.get("backupCount"), examDetailCourseList, fileTempList);
                     } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAGE")) {//卷袋贴
-                        createPdfUtil.createPaperPackage(templateId, basicSchool.getName(), examDetail, examStudentCourseDtoList, list[1], (Integer) jsonObjectVariable.get("backupCount"), examDetailCourseList, examPrintPlan.getExamId());
+                        createPdfUtil.createPaperPackage(templateId, basicSchool.getName(), examDetail, examStudentCourseDtoList, list[1], (Integer) jsonObjectVariable.get("backupCount"), examDetailCourseList, examPrintPlan.getExamId(), fileTempList);
                     }
                 }
             }
@@ -541,12 +544,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 //    @Transactional
     public Map<String, Object> executeCreatePdfLogic(Map<String, Object> map) throws IOException {
         List<BasicAttachment> basicAttachmentList = null;
+        List<File> fileTempList = new ArrayList<>();
         try {
             TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
             SysUser sysUser = (SysUser) map.get(SystemConstant.USER);
             Long examDetailId = tbTask.getEntityId();
             List<Long> examDetailIds = Objects.nonNull(map.get("examDetailIds")) ? (List<Long>) map.get("examDetailIds") : null;
-//            Long schoolId = tbTask.getSchoolId();
             List<Long> examDetailCourseIds = Objects.nonNull(map.get("examDetailCourseIds")) ? (List<Long>) map.get("examDetailCourseIds") : null;
             String paperTypeParam = Objects.nonNull(map.get("paperType")) ? (String) map.get("paperType") : null;
 
@@ -602,27 +605,25 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         paperTypeParam,
                         basicAttachmentList,
                         attachmentIds,
+                        fileTempList,
                         backupPaperPdfList,
                         backupCardPdfList,
                         paperPdfList,
                         examStudentPdfList);
 
-                createA4File(examPrintPlan, examDetail, basicSchool, examDetailCourseList, ordinaryPdfList, variablePdfList);
+                createA4File(examPrintPlan, examDetail, basicSchool, examDetailCourseList, fileTempList, ordinaryPdfList, variablePdfList);
 
                 //合并A3(试卷+题卡+备用试卷+备用题卡)
 //                String dirNameA3 = createPdfUtil.mergeA3Pdf(paperPdfList, examStudentPdfList, backupPaperPdfList, backupCardPdfList);
                 //合并(试卷+备用试卷)
-                String dirNamePaper = createPdfUtil.mergeA3Pdf(paperPdfList, backupPaperPdfList);
+                String dirNamePaper = createPdfUtil.mergeA3Pdf(fileTempList, paperPdfList, backupPaperPdfList);
                 //合并A4(签到表+卷袋贴+登记表)
-                String dirNameA4 = createPdfUtil.mergeA4Pdf(variablePdfList, ordinaryPdfList);
+                String dirNameA4 = createPdfUtil.mergeA4Pdf(fileTempList, variablePdfList, ordinaryPdfList);
                 //合并A3(题卡+备用题卡)
-                String dirNameCardA3 = createPdfUtil.mergeA3Pdf(examStudentPdfList, backupCardPdfList);
+                String dirNameCardA3 = createPdfUtil.mergeA3Pdf(fileTempList, examStudentPdfList, backupCardPdfList);
 
-                List<PdfDto> mergePdfDeleteList = new ArrayList<>();
-                mergePdfDeleteList.addAll(examStudentPdfList);
-                mergePdfDeleteList.addAll(backupCardPdfList);
 //                BasicAttachment attachment = createPdfUtil.mergePdfSaveDb(dirNameA4, dirNameA3, dirNameCardA3, tbTask, sysUser.getId(), examDetail, basicExamRule, mergePdfDeleteList);
-                BasicAttachment attachment = createPdfUtil.mergePdfSaveDb(dirNameA4, dirNamePaper, dirNameCardA3, tbTask, sysUser.getId(), examDetail, basicExam, mergePdfDeleteList);
+                BasicAttachment attachment = createPdfUtil.mergePdfSaveDb(dirNamePaper, dirNameCardA3, tbTask, sysUser.getId(), examDetail, basicExam, fileTempList);
                 if (basicAttachmentList != null) {
                     basicAttachmentList.add(attachment);
                 }
@@ -631,8 +632,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             }
             updateExamPrintPlan(basicExam, examPrintPlan);
             map.computeIfAbsent("size", v -> examDetailList.size());
-            //最后一步删除附件
-//            createPdfUtil.deleteAttachment(attachmentIds, ftlList);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
@@ -643,6 +642,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             } else {
                 ResultUtil.error(e.getMessage());
             }
+        } finally {
+            if (!CollectionUtils.isEmpty(fileTempList)) {
+                for (File file : fileTempList) {
+                    file.delete();
+                }
+            }
         }
         return map;
     }

+ 349 - 346
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -5,7 +5,6 @@ import cn.hutool.core.util.ReflectUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.google.gson.Gson;
 import com.qmth.boot.tools.models.ByteArray;
 import com.qmth.distributed.print.business.bean.dto.*;
 import com.qmth.distributed.print.business.cache.CreatePdfCacheUtil;
@@ -52,8 +51,8 @@ public class CreatePdfUtil {
     @Resource
     BasicAttachmentService basicAttachmentService;
 
-    @Resource
-    FreemarkerUtil freemarkerUtil;
+//    @Resource
+//    FreemarkerUtil freemarkerUtil;
 
     @Resource
     @Lazy
@@ -102,8 +101,9 @@ public class CreatePdfUtil {
      * @param basicAttachment
      * @param ordinaryPdfList
      * @param printCount
+     * @param fileTempList
      */
-    public void createCheckIn(ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws Exception {
+    public void createCheckIn(ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount, List<File> fileTempList) throws Exception {
         Optional.ofNullable(basicAttachment).orElseThrow(() -> ExceptionResultEnum.ATTACHMENT_IS_NULL.exception());
 
         String type = basicAttachment.getType();
@@ -148,143 +148,143 @@ public class CreatePdfUtil {
                 ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount()));
             }
         } else {
-            printCommonService.saveAttachmentPdf(ClassifyEnum.CHECK_IN, examDetail, basicAttachment, ordinaryPdfList, printCount, 0);
+            printCommonService.saveAttachmentPdf(ClassifyEnum.CHECK_IN, examDetail, basicAttachment, ordinaryPdfList, printCount, 0, fileTempList);
         }
     }
 
-    /**
-     * 生成卷袋贴
-     *
-     * @param tag
-     * @param basicAttachment
-     * @param schoolName
-     * @param examStudentList
-     * @param variablePdfList
-     * @param printCount
-     * @param examDetailCourseList
-     * @throws IOException
-     */
-    public void createPaperPackage(boolean tag, BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount, List<ExamDetailCourse> examDetailCourseList) throws IOException {
-        if (Objects.isNull(basicAttachment)) {
-            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
-        }
-        Map<String, Object> htmlMap = new HashMap<>();
-        if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
-            List<String> paperNumbers = examDetailCourseList.stream().map(s -> s.getPaperNumber()).collect(Collectors.toList());
-            List<String> courseCodes = examDetailCourseList.stream().map(s -> s.getCourseCode()).collect(Collectors.toList());
-            List<String> courseNames = examDetailCourseList.stream().map(s -> s.getCourseName()).collect(Collectors.toList());
-            htmlMap.put("courseName", String.join(", ", courseNames));
-            htmlMap.put("courseCode", String.join(", ", paperNumbers));
-            // 学院
-//            Set<String> stringSet = new HashSet<>();
-//            List<BasicCourse> basicCourses = basicCourseService.findBySchoolIdAndCourseCode(examDetail.getSchoolId(), courseCodes);
-//            for (BasicCourse basicCours : basicCourses) {
-//                List<SysOrg> sysOrgs = sysOrgService.findParentsByOrgId(basicCours.getTeachingRoomId());
-//                Set<String> collegeName = sysOrgs.stream().filter(m -> OrgTypeEnum.COLLEGE.equals(m.getType())).map(m -> m.getName()).collect(Collectors.toSet());
-//                if (CollectionUtils.isEmpty(collegeName)) {
-//                    collegeName = sysOrgs.stream().filter(m -> OrgTypeEnum.FACULTY.equals(m.getType())).map(m -> m.getName()).collect(Collectors.toSet());
-//                }
-//                if (!CollectionUtils.isEmpty(collegeName)) {
-//                    stringSet.addAll(collegeName);
-//                }
+//    /**
+//     * 生成卷袋贴
+//     *
+//     * @param tag
+//     * @param basicAttachment
+//     * @param schoolName
+//     * @param examStudentList
+//     * @param variablePdfList
+//     * @param printCount
+//     * @param examDetailCourseList
+//     * @throws IOException
+//     */
+//    public void createPaperPackage(boolean tag, BasicAttachment basicAttachment, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount, List<ExamDetailCourse> examDetailCourseList) throws IOException {
+//        if (Objects.isNull(basicAttachment)) {
+//            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
+//        }
+//        Map<String, Object> htmlMap = new HashMap<>();
+//        if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
+//            List<String> paperNumbers = examDetailCourseList.stream().map(s -> s.getPaperNumber()).collect(Collectors.toList());
+//            List<String> courseCodes = examDetailCourseList.stream().map(s -> s.getCourseCode()).collect(Collectors.toList());
+//            List<String> courseNames = examDetailCourseList.stream().map(s -> s.getCourseName()).collect(Collectors.toList());
+//            htmlMap.put("courseName", String.join(", ", courseNames));
+//            htmlMap.put("courseCode", String.join(", ", paperNumbers));
+//            // 学院
+////            Set<String> stringSet = new HashSet<>();
+////            List<BasicCourse> basicCourses = basicCourseService.findBySchoolIdAndCourseCode(examDetail.getSchoolId(), courseCodes);
+////            for (BasicCourse basicCours : basicCourses) {
+////                List<SysOrg> sysOrgs = sysOrgService.findParentsByOrgId(basicCours.getTeachingRoomId());
+////                Set<String> collegeName = sysOrgs.stream().filter(m -> OrgTypeEnum.COLLEGE.equals(m.getType())).map(m -> m.getName()).collect(Collectors.toSet());
+////                if (CollectionUtils.isEmpty(collegeName)) {
+////                    collegeName = sysOrgs.stream().filter(m -> OrgTypeEnum.FACULTY.equals(m.getType())).map(m -> m.getName()).collect(Collectors.toSet());
+////                }
+////                if (!CollectionUtils.isEmpty(collegeName)) {
+////                    stringSet.addAll(collegeName);
+////                }
+////            }
+////            htmlMap.put("collegeName", CollectionUtils.isEmpty(stringSet) ? "" : String.join(",", stringSet));
+//        } else {
+//            htmlMap.put("courseName", "");
+//            htmlMap.put("courseCode", "");
+//            htmlMap.put("collegeName", "");
+//        }
+//        Set<Long> clazzIdSet = new HashSet<>();
+//        for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
+//            String clazzInfo = examDetailCourse.getClazzId();
+//            if (SystemConstant.strNotNull(clazzInfo)) {
+//                Set<Long> clazzIdSetCell = Arrays.stream(clazzInfo.split(",")).map(SystemConstant::convertIdToLong).collect(Collectors.toSet());
+//                clazzIdSet.addAll(clazzIdSetCell);
 //            }
-//            htmlMap.put("collegeName", CollectionUtils.isEmpty(stringSet) ? "" : String.join(",", stringSet));
-        } else {
-            htmlMap.put("courseName", "");
-            htmlMap.put("courseCode", "");
-            htmlMap.put("collegeName", "");
-        }
-        Set<Long> clazzIdSet = new HashSet<>();
-        for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
-            String clazzInfo = examDetailCourse.getClazzId();
-            if (SystemConstant.strNotNull(clazzInfo)) {
-                Set<Long> clazzIdSetCell = Arrays.stream(clazzInfo.split(",")).map(SystemConstant::convertIdToLong).collect(Collectors.toSet());
-                clazzIdSet.addAll(clazzIdSetCell);
-            }
-        }
-        List<Long> classIds = new ArrayList<>(clazzIdSet);
-
-//        String campusName = CollectionUtils.isEmpty(classIds) ? "" : basicCampusService.findCampusNamesByClazzIdList(classIds, ",");
-        htmlMap.put("schoolName", schoolName);
-//        htmlMap.put("campusName", campusName);
-        htmlMap.put("examSite", examDetail.getExamPlace());
-        htmlMap.put("examRoom", examDetail.getExamRoom());
-        htmlMap.put("startTime", DateUtil.format(new Date(examDetail.getExamStartTime()), SystemConstant.DEFAULT_DATE_PATTERN));
-        htmlMap.put("endTime", DateUtil.format(new Date(examDetail.getExamEndTime()), SystemConstant.DEFAULT_DATE_PATTERN));
-        htmlMap.put("paperCode", examDetail.getPackageCode());
-        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
-
-        List<String> extendColumnList = examStudentList.stream().map(m -> m.getExtendFields()).distinct().collect(Collectors.toList());
-        Set<String> startCollege = new HashSet();
-        Set<String> className = new HashSet();
-        Set<String> proctorCollege = new HashSet();
-        Set<String> examManager = new HashSet();
-
-        String className1 = examDetailService.findClazzNamesByClazzIds(classIds, ",");
-
-        if (Objects.nonNull(extendColumnList) && extendColumnList.size() > 0) {
-            for (String s : extendColumnList) {
-                List<Map> mapList = JSONObject.parseArray(s, Map.class);
-                for (Map map : mapList) {
-                    if (Objects.equals("startCollege", map.get("code").toString())) {
-                        startCollege.add(map.get("value").toString());
-                    }
-                    if (Objects.equals("className", map.get("code").toString())) {
-                        className.add(map.get("value").toString());
-                    }
-                    if (Objects.equals("proctorCollege", map.get("code").toString())) {
-                        proctorCollege.add(map.get("value").toString());
-                    }
-                    if (Objects.equals("examManager", map.get("code").toString())) {
-                        examManager.add(map.get("value").toString());
-                    }
-                }
-            }
-        }
-
-        htmlMap.put("startCollege", String.join(",", startCollege));
-        htmlMap.put("className", StringUtils.isNotBlank(className1) ? className1 : String.join(",", className));
-        htmlMap.put("proctorCollege", String.join(",", proctorCollege));
-        htmlMap.put("examManager", String.join(",", examManager));
-
-//        List<ExamStudent> tempList = examStudentList.stream().filter(s -> (Objects.nonNull(s.getSiteNumber()) && !Objects.equals("", s.getSiteNumber().trim()))).collect(Collectors.toList());
-//        String minSite = "", maxSite = "";
-//        if (Objects.nonNull(tempList) && tempList.size() > 0) {
-//            minSite = tempList.stream().min((a, b) -> a.getSiteNumber().compareTo(b.getSiteNumber())).get().getSiteNumber();
-//            maxSite = tempList.stream().max((a, b) -> a.getSiteNumber().compareTo(b.getSiteNumber())).get().getSiteNumber();
 //        }
-
-        Optional<ExamStudentCourseDto> minSite = null;
-        Optional<ExamStudentCourseDto> maxSite = null;
-        List<ExamStudentCourseDto> tempList = examStudentList.stream().filter(s -> (Objects.nonNull(s.getSiteNumber()) && !Objects.equals("", s.getSiteNumber().trim()))).collect(Collectors.toList());
-        if (Objects.nonNull(tempList) && tempList.size() > 0) {
-//            for (ExamStudentCourseDto e : tempList) {
-//                char[] chars = e.getSiteNumber().toLowerCase().toCharArray();
-//                String ascii = "";
-//                for (int i = 0; i < chars.length; i++) {
-//                    ascii = ascii + chars[i];
+//        List<Long> classIds = new ArrayList<>(clazzIdSet);
+//
+////        String campusName = CollectionUtils.isEmpty(classIds) ? "" : basicCampusService.findCampusNamesByClazzIdList(classIds, ",");
+//        htmlMap.put("schoolName", schoolName);
+////        htmlMap.put("campusName", campusName);
+//        htmlMap.put("examSite", examDetail.getExamPlace());
+//        htmlMap.put("examRoom", examDetail.getExamRoom());
+//        htmlMap.put("startTime", DateUtil.format(new Date(examDetail.getExamStartTime()), SystemConstant.DEFAULT_DATE_PATTERN));
+//        htmlMap.put("endTime", DateUtil.format(new Date(examDetail.getExamEndTime()), SystemConstant.DEFAULT_DATE_PATTERN));
+//        htmlMap.put("paperCode", examDetail.getPackageCode());
+//        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
+//
+//        List<String> extendColumnList = examStudentList.stream().map(m -> m.getExtendFields()).distinct().collect(Collectors.toList());
+//        Set<String> startCollege = new HashSet();
+//        Set<String> className = new HashSet();
+//        Set<String> proctorCollege = new HashSet();
+//        Set<String> examManager = new HashSet();
+//
+//        String className1 = examDetailService.findClazzNamesByClazzIds(classIds, ",");
+//
+//        if (Objects.nonNull(extendColumnList) && extendColumnList.size() > 0) {
+//            for (String s : extendColumnList) {
+//                List<Map> mapList = JSONObject.parseArray(s, Map.class);
+//                for (Map map : mapList) {
+//                    if (Objects.equals("startCollege", map.get("code").toString())) {
+//                        startCollege.add(map.get("value").toString());
+//                    }
+//                    if (Objects.equals("className", map.get("code").toString())) {
+//                        className.add(map.get("value").toString());
+//                    }
+//                    if (Objects.equals("proctorCollege", map.get("code").toString())) {
+//                        proctorCollege.add(map.get("value").toString());
+//                    }
+//                    if (Objects.equals("examManager", map.get("code").toString())) {
+//                        examManager.add(map.get("value").toString());
+//                    }
 //                }
-//                e.setAscii(ascii.hashCode());
 //            }
-            minSite = tempList.stream().min(Comparator.comparing(s -> s.getSiteNumber().hashCode()));
-            maxSite = tempList.stream().max(Comparator.comparing(s -> s.getSiteNumber().hashCode()));
-        }
-
-        htmlMap.put("minSite", Optional.ofNullable(minSite).map(s -> s.get().getSiteNumber()).orElse(""));
-        htmlMap.put("maxSite", Optional.ofNullable(maxSite).map(s -> s.get().getSiteNumber()).orElse(""));
-        htmlMap.put("studentCount", examStudentList != null && examStudentList.size() > 0 ? examStudentList.size() : examDetail.getPrintCount());
-
-        String tagValue = tag ? "订" : null;
-        htmlMap.put("tag", tagValue);
-
-        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
-        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
-        htmlMap.computeIfAbsent("printCount", v -> printCount);
-        htmlMap.computeIfAbsent("sequence", v -> 1);
-        htmlMap.computeIfAbsent("examDetail", v -> examDetail);
-        htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.PACKAGE);
-        freemarkerUtil.createPaperPackage(htmlMap);
-    }
+//        }
+//
+//        htmlMap.put("startCollege", String.join(",", startCollege));
+//        htmlMap.put("className", StringUtils.isNotBlank(className1) ? className1 : String.join(",", className));
+//        htmlMap.put("proctorCollege", String.join(",", proctorCollege));
+//        htmlMap.put("examManager", String.join(",", examManager));
+//
+////        List<ExamStudent> tempList = examStudentList.stream().filter(s -> (Objects.nonNull(s.getSiteNumber()) && !Objects.equals("", s.getSiteNumber().trim()))).collect(Collectors.toList());
+////        String minSite = "", maxSite = "";
+////        if (Objects.nonNull(tempList) && tempList.size() > 0) {
+////            minSite = tempList.stream().min((a, b) -> a.getSiteNumber().compareTo(b.getSiteNumber())).get().getSiteNumber();
+////            maxSite = tempList.stream().max((a, b) -> a.getSiteNumber().compareTo(b.getSiteNumber())).get().getSiteNumber();
+////        }
+//
+//        Optional<ExamStudentCourseDto> minSite = null;
+//        Optional<ExamStudentCourseDto> maxSite = null;
+//        List<ExamStudentCourseDto> tempList = examStudentList.stream().filter(s -> (Objects.nonNull(s.getSiteNumber()) && !Objects.equals("", s.getSiteNumber().trim()))).collect(Collectors.toList());
+//        if (Objects.nonNull(tempList) && tempList.size() > 0) {
+////            for (ExamStudentCourseDto e : tempList) {
+////                char[] chars = e.getSiteNumber().toLowerCase().toCharArray();
+////                String ascii = "";
+////                for (int i = 0; i < chars.length; i++) {
+////                    ascii = ascii + chars[i];
+////                }
+////                e.setAscii(ascii.hashCode());
+////            }
+//            minSite = tempList.stream().min(Comparator.comparing(s -> s.getSiteNumber().hashCode()));
+//            maxSite = tempList.stream().max(Comparator.comparing(s -> s.getSiteNumber().hashCode()));
+//        }
+//
+//        htmlMap.put("minSite", Optional.ofNullable(minSite).map(s -> s.get().getSiteNumber()).orElse(""));
+//        htmlMap.put("maxSite", Optional.ofNullable(maxSite).map(s -> s.get().getSiteNumber()).orElse(""));
+//        htmlMap.put("studentCount", examStudentList != null && examStudentList.size() > 0 ? examStudentList.size() : examDetail.getPrintCount());
+//
+//        String tagValue = tag ? "订" : null;
+//        htmlMap.put("tag", tagValue);
+//
+//        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
+//        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
+//        htmlMap.computeIfAbsent("printCount", v -> printCount);
+//        htmlMap.computeIfAbsent("sequence", v -> 1);
+//        htmlMap.computeIfAbsent("examDetail", v -> examDetail);
+//        htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.PACKAGE);
+//        freemarkerUtil.createPaperPackage(htmlMap);
+//    }
 
     /**
      * 生成卷袋贴
@@ -294,8 +294,9 @@ public class CreatePdfUtil {
      * @param variablePdfList
      * @param printCount
      * @param examDetailCourseList
+     * @param fileTempList
      */
-    public void createPaperPackage(Long templateId, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount, List<ExamDetailCourse> examDetailCourseList, Long examId) {
+    public void createPaperPackage(Long templateId, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount, List<ExamDetailCourse> examDetailCourseList, Long examId, List<File> fileTempList) {
         BasicTemplate basicTemplate = basicTemplateService.getById(templateId);
         if (Objects.isNull(basicTemplate)) {
             throw ExceptionResultEnum.ERROR.exception("印品数据有误");
@@ -443,201 +444,201 @@ public class CreatePdfUtil {
             }
         }
         pdfPackageDto.setBasicPlate(basicPlate);
-        printCommonService.saveAttachmentPackagePdf(pdfPackageDto, examDetail, variablePdfList, printCount);
+        printCommonService.saveAttachmentPackagePdf(pdfPackageDto, examDetail, variablePdfList, printCount, fileTempList);
     }
 
-    /**
-     * 创建签到表
-     *
-     * @param basicAttachment
-     * @param schoolName
-     * @param examDetail
-     * @param examStudentList
-     * @param variablePdfList
-     * @param printCount
-     * @param examDetailCourseList
-     */
-    public void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetail
-            examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer
-                                       printCount, List<ExamDetailCourse> examDetailCourseList) throws IOException {
-        if (Objects.isNull(basicAttachment)) {
-            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
-        }
-        Map<String, Object> htmlMap = new HashMap<>();
-        if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
-            List<String> paperNumbers = examDetailCourseList.stream().map(ExamDetailCourse::getPaperNumber).collect(Collectors.toList());
-            List<String> courseNames = examDetailCourseList.stream().map(ExamDetailCourse::getCourseName).collect(Collectors.toList());
-            htmlMap.put("courseName", String.join(", ", courseNames));
-            htmlMap.put("courseCode", String.join(", ", paperNumbers));
-        } else {
-            htmlMap.put("courseName", "");
-            htmlMap.put("courseCode", "");
-        }
-        htmlMap.put("schoolName", schoolName);
-        htmlMap.put("examRoom", examDetail.getExamRoom());
-
-        List<String> extendColumnList = examStudentList.stream().map(ExamStudent::getExtendFields).distinct().collect(Collectors.toList());
-        Set<String> classTeacher = new HashSet();
-        if (extendColumnList.size() > 0) {
-            for (String s : extendColumnList) {
-                List<Map> mapList = JSONObject.parseArray(s, Map.class);
-                for (Map map : mapList) {
-                    if (Objects.equals("classTeacher", map.get("code").toString())) {
-                        classTeacher.add(map.get("value").toString());
-                    }
-                }
-            }
-        }
-        htmlMap.put("classTeacher", String.join(",", classTeacher));
-        htmlMap.put("startTime", DateUtil.format(new Date(examDetail.getExamStartTime()), SystemConstant.DEFAULT_DATE_PATTERN));
-        htmlMap.put("endTime", DateUtil.format(new Date(examDetail.getExamEndTime()), SystemConstant.DEFAULT_DATE_PATTERN));
-        htmlMap.put("paperCode", examDetail.getPackageCode());
-        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
-
-        int pageSize = 60;
-        int halfPageSize = pageSize / 2;
-
-        if (examStudentList.size() > 0) {
-            int totalCount = examStudentList.size();
-            List<Map> subList = new ArrayList<>();
-            int pageCount = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
-            for (int i = 0; i < pageCount; i++) {
-                Map subMap = new HashMap();
-                subMap.put("index", i + 1);
-                int studentCount;
-                List<ExamStudentCourseDto> subStudents;
-                if (pageCount == 1) {
-                    studentCount = totalCount;
-                    subStudents = examStudentList;
-                } else if (i == pageCount - 1) {
-                    studentCount = totalCount - (pageCount - 1) * pageSize;
-                    subStudents = examStudentList.subList(pageSize * i, examStudentList.size());
-                } else {
-                    studentCount = pageSize;
-                    subStudents = examStudentList.subList(pageSize * i, pageSize * (i + 1));
-                }
-                subMap.put("studentCount", totalCount);
-                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
-                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
-
-                Gson gson = new Gson();
-                int mod = subStudents.size() % 2;
-                int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
-                for (int j = 0; j < htmlTableCount; j++) {
-                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
-                    examStudentDto.setIndex(j + 1);
-                    String clazzName = getClassName(examStudentDto);
-                    examStudentDto.setClazzName(clazzName);
-                    examStudentList1.add(examStudentDto);
-                }
-                for (int j = htmlTableCount; j < subStudents.size(); j++) {
-                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
-                    examStudentDto.setIndex(j + 1);
-                    String clazzName = getClassName(examStudentDto);
-                    examStudentDto.setClazzName(clazzName);
-                    examStudentList2.add(examStudentDto);
-                }
-//                if (examStudentList1.size() > examStudentList2.size()) {
-//                    for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
-//                        examStudentList2.add(new ExamStudentDto());
+//    /**
+//     * 创建签到表
+//     *
+//     * @param basicAttachment
+//     * @param schoolName
+//     * @param examDetail
+//     * @param examStudentList
+//     * @param variablePdfList
+//     * @param printCount
+//     * @param examDetailCourseList
+//     */
+//    public void createSignBook(BasicAttachment basicAttachment, String schoolName, ExamDetail
+//            examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer
+//                                       printCount, List<ExamDetailCourse> examDetailCourseList) throws IOException {
+//        if (Objects.isNull(basicAttachment)) {
+//            throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
+//        }
+//        Map<String, Object> htmlMap = new HashMap<>();
+//        if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
+//            List<String> paperNumbers = examDetailCourseList.stream().map(ExamDetailCourse::getPaperNumber).collect(Collectors.toList());
+//            List<String> courseNames = examDetailCourseList.stream().map(ExamDetailCourse::getCourseName).collect(Collectors.toList());
+//            htmlMap.put("courseName", String.join(", ", courseNames));
+//            htmlMap.put("courseCode", String.join(", ", paperNumbers));
+//        } else {
+//            htmlMap.put("courseName", "");
+//            htmlMap.put("courseCode", "");
+//        }
+//        htmlMap.put("schoolName", schoolName);
+//        htmlMap.put("examRoom", examDetail.getExamRoom());
+//
+//        List<String> extendColumnList = examStudentList.stream().map(ExamStudent::getExtendFields).distinct().collect(Collectors.toList());
+//        Set<String> classTeacher = new HashSet();
+//        if (extendColumnList.size() > 0) {
+//            for (String s : extendColumnList) {
+//                List<Map> mapList = JSONObject.parseArray(s, Map.class);
+//                for (Map map : mapList) {
+//                    if (Objects.equals("classTeacher", map.get("code").toString())) {
+//                        classTeacher.add(map.get("value").toString());
 //                    }
 //                }
-                if (examStudentList1.size() < halfPageSize) {
-                    int examStudentList1Size = examStudentList1.size();
-                    for (int j = 0; j < halfPageSize - examStudentList1Size; j++) {
-                        ExamStudentDto examStudentDto = new ExamStudentDto();
-                        examStudentDto.setIndex(null);
-                        examStudentDto.setSiteNumber("");
-                        examStudentDto.setStudentName("");
-                        examStudentDto.setClazzName("");
-                        examStudentList1.add(examStudentDto);
-                    }
-                }
-                if (examStudentList2.size() < halfPageSize) {
-                    int examStudentList2Size = examStudentList2.size();
-                    for (int j = 0; j < halfPageSize - examStudentList2Size; j++) {
-                        ExamStudentDto examStudentDto = new ExamStudentDto();
-                        examStudentDto.setIndex(null);
-                        examStudentDto.setSiteNumber("");
-                        examStudentDto.setStudentName("");
-                        examStudentDto.setClazzName("");
-                        examStudentList2.add(examStudentDto);
-                    }
-                }
-                subMap.put("studentList1", examStudentList1);
-                subMap.put("studentList2", examStudentList2);
-                subList.add(subMap);
-            }
-            htmlMap.put("subList", subList);
-        } else {
-            int totalCount = examDetail.getPrintCount();
-            List<Map> subList = new ArrayList<>();
-            int pageCount = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
-            for (int i = 0; i < pageCount; i++) {
-                Map subMap = new HashMap();
-                subMap.put("index", i + 1);
-                int studentCount;
-                if (pageCount == 1) {
-                    studentCount = pageSize;
-                } else if (i == pageCount - 1) {
-                    studentCount = totalCount - (pageCount - 1) * pageSize;
-                } else {
-                    studentCount = pageSize;
-                }
-                subMap.put("studentCount", totalCount);
-                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
-                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
-
-                int mod = studentCount % 2;
-                int htmlTableCount = mod == 0 ? studentCount / 2 : studentCount / 2 + 1;
-                for (int j = 0; j < htmlTableCount; j++) {
-                    ExamStudentDto examStudentDto = new ExamStudentDto();
-                    examStudentDto.setIndex(null);
-                    examStudentDto.setStudentName("");
-                    examStudentDto.setClazzName("");
-                    examStudentList1.add(examStudentDto);
-                }
-                for (int j = htmlTableCount; j < studentCount; j++) {
-                    ExamStudentDto examStudentDto = new ExamStudentDto();
-                    examStudentDto.setIndex(null);
-                    examStudentDto.setStudentName("");
-                    examStudentDto.setClazzName("");
-                    examStudentList2.add(examStudentDto);
-                }
-                if (examStudentList1.size() < halfPageSize) {
-                    for (int j = 0; j < halfPageSize - examStudentList1.size(); j++) {
-                        ExamStudentDto examStudentDto = new ExamStudentDto();
-                        examStudentDto.setIndex(null);
-                        examStudentDto.setSiteNumber("");
-                        examStudentDto.setStudentName("");
-                        examStudentDto.setClazzName("");
-                        examStudentList1.add(examStudentDto);
-                    }
-                }
-                if (examStudentList2.size() < halfPageSize) {
-                    for (int j = 0; j < halfPageSize - examStudentList2.size(); j++) {
-                        ExamStudentDto examStudentDto = new ExamStudentDto();
-                        examStudentDto.setIndex(null);
-                        examStudentDto.setSiteNumber("");
-                        examStudentDto.setStudentName("");
-                        examStudentDto.setClazzName("");
-                        examStudentList2.add(examStudentDto);
-                    }
-                }
-                subMap.put("studentList1", examStudentList1);
-                subMap.put("studentList2", examStudentList2);
-                subList.add(subMap);
-            }
-            htmlMap.put("subList", subList);
-        }
-        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
-        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
-        htmlMap.computeIfAbsent("printCount", v -> printCount);
-        htmlMap.computeIfAbsent("sequence", v -> 2);
-        htmlMap.computeIfAbsent("examDetail", v -> examDetail);
-        htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.SIGN);
-        freemarkerUtil.createSignBook(htmlMap);
-    }
+//            }
+//        }
+//        htmlMap.put("classTeacher", String.join(",", classTeacher));
+//        htmlMap.put("startTime", DateUtil.format(new Date(examDetail.getExamStartTime()), SystemConstant.DEFAULT_DATE_PATTERN));
+//        htmlMap.put("endTime", DateUtil.format(new Date(examDetail.getExamEndTime()), SystemConstant.DEFAULT_DATE_PATTERN));
+//        htmlMap.put("paperCode", examDetail.getPackageCode());
+//        htmlMap.put("paperCodeImg", GoogleBarCodeUtil.createBarCode(examDetail.getPackageCode(), false));
+//
+//        int pageSize = 60;
+//        int halfPageSize = pageSize / 2;
+//
+//        if (examStudentList.size() > 0) {
+//            int totalCount = examStudentList.size();
+//            List<Map> subList = new ArrayList<>();
+//            int pageCount = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
+//            for (int i = 0; i < pageCount; i++) {
+//                Map subMap = new HashMap();
+//                subMap.put("index", i + 1);
+//                int studentCount;
+//                List<ExamStudentCourseDto> subStudents;
+//                if (pageCount == 1) {
+//                    studentCount = totalCount;
+//                    subStudents = examStudentList;
+//                } else if (i == pageCount - 1) {
+//                    studentCount = totalCount - (pageCount - 1) * pageSize;
+//                    subStudents = examStudentList.subList(pageSize * i, examStudentList.size());
+//                } else {
+//                    studentCount = pageSize;
+//                    subStudents = examStudentList.subList(pageSize * i, pageSize * (i + 1));
+//                }
+//                subMap.put("studentCount", totalCount);
+//                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
+//                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
+//
+//                Gson gson = new Gson();
+//                int mod = subStudents.size() % 2;
+//                int htmlTableCount = mod == 0 ? subStudents.size() / 2 : subStudents.size() / 2 + 1;
+//                for (int j = 0; j < htmlTableCount; j++) {
+//                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+//                    examStudentDto.setIndex(j + 1);
+//                    String clazzName = getClassName(examStudentDto);
+//                    examStudentDto.setClazzName(clazzName);
+//                    examStudentList1.add(examStudentDto);
+//                }
+//                for (int j = htmlTableCount; j < subStudents.size(); j++) {
+//                    ExamStudentDto examStudentDto = gson.fromJson(gson.toJson(subStudents.get(j)), ExamStudentDto.class);
+//                    examStudentDto.setIndex(j + 1);
+//                    String clazzName = getClassName(examStudentDto);
+//                    examStudentDto.setClazzName(clazzName);
+//                    examStudentList2.add(examStudentDto);
+//                }
+////                if (examStudentList1.size() > examStudentList2.size()) {
+////                    for (int j = subStudents.size() - htmlTableCount; j < examStudentList1.size(); j++) {
+////                        examStudentList2.add(new ExamStudentDto());
+////                    }
+////                }
+//                if (examStudentList1.size() < halfPageSize) {
+//                    int examStudentList1Size = examStudentList1.size();
+//                    for (int j = 0; j < halfPageSize - examStudentList1Size; j++) {
+//                        ExamStudentDto examStudentDto = new ExamStudentDto();
+//                        examStudentDto.setIndex(null);
+//                        examStudentDto.setSiteNumber("");
+//                        examStudentDto.setStudentName("");
+//                        examStudentDto.setClazzName("");
+//                        examStudentList1.add(examStudentDto);
+//                    }
+//                }
+//                if (examStudentList2.size() < halfPageSize) {
+//                    int examStudentList2Size = examStudentList2.size();
+//                    for (int j = 0; j < halfPageSize - examStudentList2Size; j++) {
+//                        ExamStudentDto examStudentDto = new ExamStudentDto();
+//                        examStudentDto.setIndex(null);
+//                        examStudentDto.setSiteNumber("");
+//                        examStudentDto.setStudentName("");
+//                        examStudentDto.setClazzName("");
+//                        examStudentList2.add(examStudentDto);
+//                    }
+//                }
+//                subMap.put("studentList1", examStudentList1);
+//                subMap.put("studentList2", examStudentList2);
+//                subList.add(subMap);
+//            }
+//            htmlMap.put("subList", subList);
+//        } else {
+//            int totalCount = examDetail.getPrintCount();
+//            List<Map> subList = new ArrayList<>();
+//            int pageCount = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
+//            for (int i = 0; i < pageCount; i++) {
+//                Map subMap = new HashMap();
+//                subMap.put("index", i + 1);
+//                int studentCount;
+//                if (pageCount == 1) {
+//                    studentCount = pageSize;
+//                } else if (i == pageCount - 1) {
+//                    studentCount = totalCount - (pageCount - 1) * pageSize;
+//                } else {
+//                    studentCount = pageSize;
+//                }
+//                subMap.put("studentCount", totalCount);
+//                List<ExamStudentDto> examStudentList1 = new ArrayList<>();
+//                List<ExamStudentDto> examStudentList2 = new ArrayList<>();
+//
+//                int mod = studentCount % 2;
+//                int htmlTableCount = mod == 0 ? studentCount / 2 : studentCount / 2 + 1;
+//                for (int j = 0; j < htmlTableCount; j++) {
+//                    ExamStudentDto examStudentDto = new ExamStudentDto();
+//                    examStudentDto.setIndex(null);
+//                    examStudentDto.setStudentName("");
+//                    examStudentDto.setClazzName("");
+//                    examStudentList1.add(examStudentDto);
+//                }
+//                for (int j = htmlTableCount; j < studentCount; j++) {
+//                    ExamStudentDto examStudentDto = new ExamStudentDto();
+//                    examStudentDto.setIndex(null);
+//                    examStudentDto.setStudentName("");
+//                    examStudentDto.setClazzName("");
+//                    examStudentList2.add(examStudentDto);
+//                }
+//                if (examStudentList1.size() < halfPageSize) {
+//                    for (int j = 0; j < halfPageSize - examStudentList1.size(); j++) {
+//                        ExamStudentDto examStudentDto = new ExamStudentDto();
+//                        examStudentDto.setIndex(null);
+//                        examStudentDto.setSiteNumber("");
+//                        examStudentDto.setStudentName("");
+//                        examStudentDto.setClazzName("");
+//                        examStudentList1.add(examStudentDto);
+//                    }
+//                }
+//                if (examStudentList2.size() < halfPageSize) {
+//                    for (int j = 0; j < halfPageSize - examStudentList2.size(); j++) {
+//                        ExamStudentDto examStudentDto = new ExamStudentDto();
+//                        examStudentDto.setIndex(null);
+//                        examStudentDto.setSiteNumber("");
+//                        examStudentDto.setStudentName("");
+//                        examStudentDto.setClazzName("");
+//                        examStudentList2.add(examStudentDto);
+//                    }
+//                }
+//                subMap.put("studentList1", examStudentList1);
+//                subMap.put("studentList2", examStudentList2);
+//                subList.add(subMap);
+//            }
+//            htmlMap.put("subList", subList);
+//        }
+//        htmlMap.computeIfAbsent("basicAttachment", v -> basicAttachment);
+//        htmlMap.computeIfAbsent("variablePdfList", v -> variablePdfList);
+//        htmlMap.computeIfAbsent("printCount", v -> printCount);
+//        htmlMap.computeIfAbsent("sequence", v -> 2);
+//        htmlMap.computeIfAbsent("examDetail", v -> examDetail);
+//        htmlMap.computeIfAbsent("printType", v -> ClassifyEnum.SIGN);
+//        freemarkerUtil.createSignBook(htmlMap);
+//    }
 
     /**
      * 创建签到表
@@ -649,8 +650,9 @@ public class CreatePdfUtil {
      * @param variablePdfList
      * @param printCount
      * @param examDetailCourseList
+     * @param fileTempList
      */
-    public void createSignBook(Long templateId, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount, List<ExamDetailCourse> examDetailCourseList) {
+    public void createSignBook(Long templateId, String schoolName, ExamDetail examDetail, List<ExamStudentCourseDto> examStudentList, List<PdfDto> variablePdfList, Integer printCount, List<ExamDetailCourse> examDetailCourseList, List<File> fileTempList) {
         BasicTemplate basicTemplate = basicTemplateService.getById(templateId);
         if (Objects.isNull(basicTemplate)) {
             throw ExceptionResultEnum.ERROR.exception("印品数据有误");
@@ -766,7 +768,7 @@ public class CreatePdfUtil {
         }
         pdfFillDto.setStudentPlate(studentPlate);
 
-        printCommonService.saveAttachmentSignPdf(pdfFillDto, examDetail, variablePdfList, printCount);
+        printCommonService.saveAttachmentSignPdf(pdfFillDto, examDetail, variablePdfList, printCount, fileTempList);
     }
 
     /**
@@ -907,8 +909,9 @@ public class CreatePdfUtil {
      *
      * @param paperType      抽取的试卷型(多个用,分隔)
      * @param examTaskDetail 命题任务上传试卷信息
+     * @param fileTempList
      */
-    public List<PaperPdfDto> getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws Exception {
+    public List<PaperPdfDto> getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail, List<File> fileTempList) throws Exception {
         String[] paperTypes = paperType.split(",");
         List<PaperPdfDto> paperPdfDtoList = new ArrayList<>();
         PaperPdfDto paperPdfDto = null;
@@ -925,7 +928,7 @@ public class CreatePdfUtil {
                 // 返回抽中的试卷
                 for (String type : paperTypes) {
                     if (Objects.equals(name.toUpperCase(), type.toUpperCase())) {
-                        File file = teachcloudCommonService.getFile(basicAttachment.getPath(), false);
+                        File file = teachcloudCommonService.getFile(basicAttachment.getPath(), false, fileTempList);
                         int pages = (int) object.get("pages");
 
                         PageSizeEnum pageSizeEnum = PageSizeEnum.valueOf((String) jsonObject.get("pageSize"));
@@ -1047,17 +1050,18 @@ public class CreatePdfUtil {
     /**
      * 合并A3 pdf
      *
+     * @param fileTempList
      * @param list
      * @return
      * @throws IOException
      */
-    public String mergeA3Pdf(List<PdfDto>... list) throws IOException {
+    public String mergeA3Pdf(List<File> fileTempList, List<PdfDto>... list) throws IOException {
         List<PdfDto> mergePdfA3List = new ArrayList<>();
         for (int i = 0; i < list.length; i++) {
             mergePdfA3List.addAll(list[i]);
         }
         List<String> pathA3List = mergePdfA3List.stream().map(PdfDto::getPath).collect(Collectors.toList());
-        return PdfUtil.mergePdf(pathA3List.toArray(new String[mergePdfA3List.size()]), null);
+        return PdfUtil.mergePdf(pathA3List.toArray(new String[mergePdfA3List.size()]), null, fileTempList);
     }
 
     /**
@@ -1067,39 +1071,36 @@ public class CreatePdfUtil {
      * @return
      * @throws IOException
      */
-    public String mergeA4Pdf(List<PdfDto>... list) throws IOException {
+    public String mergeA4Pdf(List<File> fileTempList, List<PdfDto>... list) throws IOException {
         List<PdfDto> mergePdfA4List = new ArrayList<>();
         for (int i = 0; i < list.length; i++) {
             mergePdfA4List.addAll(list[i]);
         }
         List<String> pathA4List = mergePdfA4List.stream().map(PdfDto::getPath).collect(Collectors.toList());
-        return PdfUtil.mergePdf(pathA4List.toArray(new String[mergePdfA4List.size()]), null);
+        return PdfUtil.mergePdf(pathA4List.toArray(new String[mergePdfA4List.size()]), null, fileTempList);
     }
 
     /**
      * 合并pdf后保存数据库
      *
-     * @param dirNameA4
      * @param dirNamePaper
      * @param dirNameCardA3
      * @param tbTask
      * @param userId
      * @param examDetail
      * @param basicExam
-     * @param mergePdfDeleteList
+     * @param fileTempList
      * @return
      * @throws IOException
      */
     @Transactional
-    public BasicAttachment mergePdfSaveDb(String dirNameA4,
-                                          String dirNamePaper,
+    public BasicAttachment mergePdfSaveDb(String dirNamePaper,
                                           String dirNameCardA3,
                                           TBTask tbTask,
                                           Long userId,
                                           ExamDetail examDetail,
                                           BasicExam basicExam,
-                                          List<PdfDto> mergePdfDeleteList) throws Exception {
-        boolean oss = dictionaryConfig.sysDomain().isOss();
+                                          List<File> fileTempList) throws Exception {
         File localA4PdfFile = null, localPaperPdfFile = null, localA3PdfCardFile = null;
         BasicAttachment basicAttachment = null;
         // 试卷+题卡
@@ -1152,10 +1153,11 @@ public class CreatePdfUtil {
      * @param basicCardRule      题卡规则
      */
     public BasicAttachment examStudentHtml(String studentContent, ExamStudent examStudent, String
-            paperType, ExamDetail examDetail, ExamDetailCourse examDetailCourse, Long
-                                                   userId, List<PdfDto> examStudentPdfList, BasicCardRule basicCardRule) throws IOException {
+            paperType, ExamDetail examDetail, ExamDetailCourse examDetailCourse,
+                                           Long userId, List<PdfDto> examStudentPdfList, BasicCardRule basicCardRule,
+                                           List<File> fileTempList) throws IOException {
         String studentHtml = studentContent;
-            /*if (Objects.nonNull(examStudent.getExtendFields())) {
+        /*if (Objects.nonNull(examStudent.getExtendFields())) {
                 JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(examStudent.getExtendFields());//扩展字段
                 if (Objects.nonNull(jsonObjectExtend)) {
                     int i = 0;
@@ -1196,7 +1198,7 @@ public class CreatePdfUtil {
             studentHtml = studentHtml.replaceAll("\\$\\{paperNumber\\}", examDetailCourse.getPaperNumber());*/
 
         //学生题卡
-        BasicAttachment examStudentAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode() + (examStudent != null && examStudent.getTicketNumber() != null ? "|" + examStudent.getTicketNumber() : ""), studentHtml, userId, examStudentPdfList);
+        BasicAttachment examStudentAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode() + (examStudent != null && examStudent.getTicketNumber() != null ? "|" + examStudent.getTicketNumber() : ""), studentHtml, userId, examStudentPdfList, fileTempList);
         if (examStudent != null) {
             examStudent.setAttachmentId(examStudentAttachment.getId());
         }
@@ -1307,8 +1309,9 @@ public class CreatePdfUtil {
      * @param userId           当前用户ID
      * @param cardPdfList      备用题卡集合
      * @param basicCardRule    题卡规则对象
+     * @param fileTempList
      */
-    public BasicAttachment cardHtml(String sequence, String cardContent, ExamDetail examDetail, ExamDetailCourse examDetailCourse, String paperType, JSONArray jsonArray, Long userId, List<PdfDto> cardPdfList, BasicCardRule basicCardRule) throws
+    public BasicAttachment cardHtml(String sequence, String cardContent, ExamDetail examDetail, ExamDetailCourse examDetailCourse, String paperType, JSONArray jsonArray, Long userId, List<PdfDto> cardPdfList, BasicCardRule basicCardRule, List<File> fileTempList) throws
             IOException {
         //通用题卡
         String cardTemp = cardContent;
@@ -1359,7 +1362,7 @@ public class CreatePdfUtil {
             cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-A4 page-box-0 page-box-less\">", packageCodeDiv);
         }
 
-        BasicAttachment cardAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode(), cardTemp, userId, cardPdfList);
+        BasicAttachment cardAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode(), cardTemp, userId, cardPdfList, fileTempList);
         JSONObject object = new JSONObject();
         object.put("name", paperType);
         object.put("examDetailCourseId", examDetailCourse.getId());

+ 152 - 152
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -1,153 +1,153 @@
-package com.qmth.distributed.print.business.util;
-
-import com.alibaba.fastjson.JSONObject;
-import com.qmth.distributed.print.business.bean.dto.PdfDto;
-import com.qmth.distributed.print.business.entity.ExamDetail;
-import com.qmth.distributed.print.business.service.PrintCommonService;
-import com.qmth.teachcloud.common.config.DictionaryConfig;
-import com.qmth.teachcloud.common.contant.SystemConstant;
-import com.qmth.teachcloud.common.entity.BasicAttachment;
-import com.qmth.teachcloud.common.enums.ClassifyEnum;
-import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
-import com.qmth.teachcloud.common.enums.UploadFileEnum;
-import com.qmth.teachcloud.common.util.FileStoreUtil;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.stereotype.Component;
-import org.springframework.util.ResourceUtils;
-
-import javax.annotation.Resource;
-import java.io.*;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.StringJoiner;
-
-/**
- * @Description: freemarker util
- * @Param:
- * @return:
- * @Author: wangliang
- * @Date: 2020/6/11
- */
-@Component
-public class FreemarkerUtil {
-    private final static Logger log = LoggerFactory.getLogger(FreemarkerUtil.class);
-
-    @Resource
-    DictionaryConfig dictionaryConfig;
-
+//package com.qmth.distributed.print.business.util;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.qmth.distributed.print.business.bean.dto.PdfDto;
+//import com.qmth.distributed.print.business.entity.ExamDetail;
+//import com.qmth.distributed.print.business.service.PrintCommonService;
+//import com.qmth.teachcloud.common.config.DictionaryConfig;
+//import com.qmth.teachcloud.common.contant.SystemConstant;
+//import com.qmth.teachcloud.common.entity.BasicAttachment;
+//import com.qmth.teachcloud.common.enums.ClassifyEnum;
+//import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+//import com.qmth.teachcloud.common.enums.UploadFileEnum;
+//import com.qmth.teachcloud.common.util.FileStoreUtil;
+//import freemarker.template.Configuration;
+//import freemarker.template.Template;
+//import org.apache.commons.codec.digest.DigestUtils;
+//import org.apache.commons.lang3.StringUtils;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.context.annotation.Lazy;
+//import org.springframework.stereotype.Component;
+//import org.springframework.util.ResourceUtils;
+//
+//import javax.annotation.Resource;
+//import java.io.*;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.Objects;
+//import java.util.StringJoiner;
+//
+///**
+// * @Description: freemarker util
+// * @Param:
+// * @return:
+// * @Author: wangliang
+// * @Date: 2020/6/11
+// */
+//@Component
+//public class FreemarkerUtil {
+//    private final static Logger log = LoggerFactory.getLogger(FreemarkerUtil.class);
+//
 //    @Resource
-//    OssUtil ossUtil;
-
-    @Resource
-    @Lazy
-    PrintCommonService printCommonService;
-
-    @Resource
-    FileStoreUtil fileStoreUtil;
-
-    /**
-     * 单独生成签到表
-     *
-     * @param dataMap
-     * @throws IOException
-     */
-    public void createSignBook(Map<String, Object> dataMap) throws IOException {
-        if (Objects.isNull(dataMap) || dataMap.size() == 0) {
-            throw ExceptionResultEnum.ERROR.exception("签到表数据为空");
-        }
-        this.createSignBookAndPaperPackageHtml(dataMap);
-    }
-
-    /**
-     * 单独生成签到表
-     *
-     * @param dataMap
-     * @throws IOException
-     */
-    public void createPaperPackage(Map<String, Object> dataMap) throws IOException {
-        if (Objects.isNull(dataMap) || dataMap.size() == 0) {
-            throw ExceptionResultEnum.ERROR.exception("卷袋贴数据为空");
-        }
-        this.createSignBookAndPaperPackageHtml(dataMap);
-    }
-
-    /**
-     * 创建签到表
-     *
-     * @param dataMap
-     * @throws IOException
-     */
-    private void createSignBookAndPaperPackageHtml(Map<String, Object> dataMap) throws IOException {
-        Writer out = null;
-        try {
-            BasicAttachment basicAttachment = (BasicAttachment) dataMap.get("basicAttachment");
-            ExamDetail examDetail = (ExamDetail) dataMap.get("examDetail");
-            ClassifyEnum classifyEnum = (ClassifyEnum) dataMap.get("printType");
-            JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
-            String path = (String) jsonObject.get(SystemConstant.PATH);
-            int last = path.lastIndexOf("/") == -1 ? path.lastIndexOf("\\") : path.lastIndexOf("/");
-            String ftlPath = path.substring(0, last);
-            String ftlName = path.substring(last + 1, path.lastIndexOf("."));
-
-            Configuration configuration = new Configuration(Configuration.VERSION_2_3_29);
-            File templates = null;
-            if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig()) && ftlPath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-                templates = ResourceUtils.getFile(dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + ftlPath);
-            } else {
-                File file = new File(dictionaryConfig.fssPublicDomain().getConfig(), ftlPath);
-                templates = ResourceUtils.getFile(file.getPath());
-            }
-            configuration.setDirectoryForTemplateLoading(templates);
-            // step1 加载模版文件
-            Template template = configuration.getTemplate(ftlName + SystemConstant.FTL_PREFIX);
-            // step2 生成数据
-            boolean oss = dictionaryConfig.sysDomain().isOss();
-            StringJoiner stringJoiner = new StringJoiner("");
-            if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-                stringJoiner.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
-            } else {
-                stringJoiner.add(dictionaryConfig.fssPublicDomain().getConfig()).add(File.separator);
-            }
-            StringJoiner htmlStringJoiner = SystemConstant.getDirName(UploadFileEnum.HTML, true);
-            htmlStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.HTML_PREFIX);
-            File htmlFile = new File(stringJoiner.toString() + htmlStringJoiner.toString());
-            if (!htmlFile.getParentFile().exists()) {
-                htmlFile.getParentFile().mkdirs();
-                htmlFile.createNewFile();
-            }
-            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile)));
-            // step3 输出文件
-            template.process(dataMap, out);
-            out.flush();
-
-            if (oss) {
-                String htmlStringJoinerStr = htmlStringJoiner.toString().replace("\\", "/");
-                jsonObject.put(SystemConstant.HTML_PATH, htmlStringJoinerStr);
-                fileStoreUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)), fileStoreUtil.getUploadEnumByPath(htmlStringJoinerStr).getFssType());
-            } else {
-                jsonObject.put(SystemConstant.HTML_PATH, htmlFile.getPath());
-            }
-            jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
-                    UploadFileEnum.FILE,
-                    UploadFileEnum.HTML
-            });
-            basicAttachment.setPath(jsonObject.toJSONString());
-            printCommonService.saveAttachmentPdf(classifyEnum, examDetail, basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"), (Integer) dataMap.get("sequence"));
-
-//            htmlFile.delete();
-        } catch (Exception e) {
-            log.error(SystemConstant.LOG_ERROR, e);
-        } finally {
-            if (Objects.nonNull(out)) {
-                out.close();
-            }
-        }
-    }
-}
+//    DictionaryConfig dictionaryConfig;
+//
+////    @Resource
+////    OssUtil ossUtil;
+//
+//    @Resource
+//    @Lazy
+//    PrintCommonService printCommonService;
+//
+//    @Resource
+//    FileStoreUtil fileStoreUtil;
+//
+//    /**
+//     * 单独生成签到表
+//     *
+//     * @param dataMap
+//     * @throws IOException
+//     */
+//    public void createSignBook(Map<String, Object> dataMap) throws IOException {
+//        if (Objects.isNull(dataMap) || dataMap.size() == 0) {
+//            throw ExceptionResultEnum.ERROR.exception("签到表数据为空");
+//        }
+//        this.createSignBookAndPaperPackageHtml(dataMap);
+//    }
+//
+//    /**
+//     * 单独生成签到表
+//     *
+//     * @param dataMap
+//     * @throws IOException
+//     */
+//    public void createPaperPackage(Map<String, Object> dataMap) throws IOException {
+//        if (Objects.isNull(dataMap) || dataMap.size() == 0) {
+//            throw ExceptionResultEnum.ERROR.exception("卷袋贴数据为空");
+//        }
+//        this.createSignBookAndPaperPackageHtml(dataMap);
+//    }
+//
+//    /**
+//     * 创建签到表
+//     *
+//     * @param dataMap
+//     * @throws IOException
+//     */
+//    private void createSignBookAndPaperPackageHtml(Map<String, Object> dataMap) throws IOException {
+//        Writer out = null;
+//        try {
+//            BasicAttachment basicAttachment = (BasicAttachment) dataMap.get("basicAttachment");
+//            ExamDetail examDetail = (ExamDetail) dataMap.get("examDetail");
+//            ClassifyEnum classifyEnum = (ClassifyEnum) dataMap.get("printType");
+//            JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
+//            String path = (String) jsonObject.get(SystemConstant.PATH);
+//            int last = path.lastIndexOf("/") == -1 ? path.lastIndexOf("\\") : path.lastIndexOf("/");
+//            String ftlPath = path.substring(0, last);
+//            String ftlName = path.substring(last + 1, path.lastIndexOf("."));
+//
+//            Configuration configuration = new Configuration(Configuration.VERSION_2_3_29);
+//            File templates = null;
+//            if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig()) && ftlPath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
+//                templates = ResourceUtils.getFile(dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + ftlPath);
+//            } else {
+//                File file = new File(dictionaryConfig.fssPublicDomain().getConfig(), ftlPath);
+//                templates = ResourceUtils.getFile(file.getPath());
+//            }
+//            configuration.setDirectoryForTemplateLoading(templates);
+//            // step1 加载模版文件
+//            Template template = configuration.getTemplate(ftlName + SystemConstant.FTL_PREFIX);
+//            // step2 生成数据
+//            boolean oss = dictionaryConfig.sysDomain().isOss();
+//            StringJoiner stringJoiner = new StringJoiner("");
+//            if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
+//                stringJoiner.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
+//            } else {
+//                stringJoiner.add(dictionaryConfig.fssPublicDomain().getConfig()).add(File.separator);
+//            }
+//            StringJoiner htmlStringJoiner = SystemConstant.getDirName(UploadFileEnum.HTML, true);
+//            htmlStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.HTML_PREFIX);
+//            File htmlFile = new File(stringJoiner.toString() + htmlStringJoiner.toString());
+//            if (!htmlFile.getParentFile().exists()) {
+//                htmlFile.getParentFile().mkdirs();
+//                htmlFile.createNewFile();
+//            }
+//            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile)));
+//            // step3 输出文件
+//            template.process(dataMap, out);
+//            out.flush();
+//
+//            if (oss) {
+//                String htmlStringJoinerStr = htmlStringJoiner.toString().replace("\\", "/");
+//                jsonObject.put(SystemConstant.HTML_PATH, htmlStringJoinerStr);
+//                fileStoreUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)), fileStoreUtil.getUploadEnumByPath(htmlStringJoinerStr).getFssType());
+//            } else {
+//                jsonObject.put(SystemConstant.HTML_PATH, htmlFile.getPath());
+//            }
+//            jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
+//                    UploadFileEnum.FILE,
+//                    UploadFileEnum.HTML
+//            });
+//            basicAttachment.setPath(jsonObject.toJSONString());
+//            printCommonService.saveAttachmentPdf(classifyEnum, examDetail, basicAttachment, (List<PdfDto>) dataMap.get("variablePdfList"), (Integer) dataMap.get("printCount"), (Integer) dataMap.get("sequence"));
+//
+////            htmlFile.delete();
+//        } catch (Exception e) {
+//            log.error(SystemConstant.LOG_ERROR, e);
+//        } finally {
+//            if (Objects.nonNull(out)) {
+//                out.close();
+//            }
+//        }
+//    }
+//}

+ 3 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java

@@ -42,8 +42,9 @@ public class PdfUtil {
      *
      * @param files
      * @param outputPath
+     * @param fileTempList
      */
-    public static String mergePdf(String[] files, String outputPath) {
+    public static String mergePdf(String[] files, String outputPath, List<File> fileTempList) {
         Document document = null;
         PdfCopy copy = null;
         StringJoiner dirName = new StringJoiner("");
@@ -53,6 +54,7 @@ public class PdfUtil {
                 document = new Document(new PdfReader(ByteArray.fromFile(new File(files[0])).value()).getPageSize(1));
                 if (Objects.isNull(outputPath)) {
                     pdfFileTemp = SystemConstant.getFileTempVar(SystemConstant.PDF_PREFIX);
+                    fileTempList.add(pdfFileTemp);
                     dirName.add(pdfFileTemp.getPath());
                     outputPath = dirName.toString();
                 }

+ 17 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -863,10 +863,26 @@ public class SystemConstant {
      */
     public static File getFileTempVar(String suffix) throws IOException {
         File file = File.createTempFile(SystemConstant.TEMP, suffix);
-        System.out.println("getFileTempVar absolutePath:" + file.getAbsolutePath());
+        System.out.println("getFileTempVar_absolutePath:" + file.getAbsolutePath());
         return file;
     }
 
+    /**
+     * 获取临时文件
+     *
+     * @param suffix
+     * @param fileTemp
+     * @return
+     * @throws IOException
+     */
+    public static List<File> getFileTempVar(String suffix, List<File> fileTemp) throws IOException {
+        File file = File.createTempFile(SystemConstant.TEMP, suffix);
+        System.out.println("getFileTempVar_absolutePath:" + file.getAbsolutePath());
+        fileTemp.add(file);
+        return fileTemp;
+    }
+
+
     /**
      * 获取dirname
      *

+ 1 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/BasicAttachmentService.java

@@ -5,6 +5,7 @@ import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.List;
 

+ 2 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TeachcloudCommonService.java

@@ -154,9 +154,10 @@ public interface TeachcloudCommonService {
      *
      * @param path
      * @param pdf
+     * @param fileTempList
      * @return
      */
-    public File getFile(String path, boolean pdf) throws Exception;
+    public File getFile(String path, boolean pdf, List<File> fileTempList) throws Exception;
 
     /**
      * 下载文件到本地

+ 4 - 5
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicAttachmentServiceImpl.java

@@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.FileCopyUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -76,7 +75,8 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 pdfStringJoiner.add(dictionaryConfig.fssLocalPdfDomain().getConfig()).add(File.separator);
             }
             pdfStringJoiner = SystemConstant.getDirName(pdfStringJoiner, UploadFileEnum.PDF, true);
-            pdfStringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.PDF_PREFIX);
+            String pdfName = SystemConstant.getNanoId() + SystemConstant.PDF_PREFIX;
+            pdfStringJoiner.add(pdfName);
 
             String pdfDirName = pdfStringJoiner.toString().replaceAll("\\\\", "/");
             String pdfFileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
@@ -88,15 +88,14 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 fileStoreUtil.ossUpload(pdfDirName, pdfFile, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
             } else {
                 if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
-                    File file = new File(pdfStringJoiner.toString());
-                    FileCopyUtils.copy(file, pdfFile);
+                    fileStoreUtil.localUpload(pdfDirName, new FileInputStream(pdfFile), pdfFileMd5, LocalCatalogEnum.LOCAL_PDF);
                 } else {
                     fileStoreUtil.ossUpload(pdfDirName, pdfFile, pdfFileMd5, fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
                 }
                 jsonPdf.put(SystemConstant.TYPE, SystemConstant.LOCAL);
             }
             jsonPdf.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.PDF);
-            basicAttachment = new BasicAttachment(jsonPdf.toJSONString(), pdfFile.getName(), SystemConstant.PDF_PREFIX, new BigDecimal(pdfFile.length()), pdfFileMd5, userId);
+            basicAttachment = new BasicAttachment(jsonPdf.toJSONString(), pdfName, SystemConstant.PDF_PREFIX, new BigDecimal(pdfFile.length()), pdfFileMd5, userId);
             save(basicAttachment);
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);

+ 8 - 11
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -592,11 +592,12 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
      *
      * @param path
      * @param pdf
+     * @param fileTempList
      * @return
      * @throws IOException
      */
     @Override
-    public File getFile(String path, boolean pdf) throws Exception {
+    public File getFile(String path, boolean pdf, List<File> fileTempList) throws Exception {
         File file = null;
         JSONObject jsonObject = JSONObject.parseObject(path);
         String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
@@ -606,14 +607,10 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class, (String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
         StringJoiner localPath = new StringJoiner("");
         if (Objects.equals(attachmentType, SystemConstant.OSS)) {
-            if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig()) && !filePath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-                localPath = localPath.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator).add(filePath);
-            } else {
-                String suffix = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
-                File fileTemp = SystemConstant.getFileTempVar(suffix);
-                localPath = localPath.add(fileTemp.getPath());
-            }
-            file = fileStoreUtil.ossDownload(filePath, localPath.toString(), uploadType.getFssType());
+            String suffix = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
+            File fileTemp = SystemConstant.getFileTempVar(suffix);
+            fileTempList.add(fileTemp);
+            file = fileStoreUtil.ossDownload(filePath, fileTemp, uploadType.getFssType());
         } else {
             if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig()) && !filePath.contains(dictionaryConfig.fssLocalFileDomain().getConfig())) {
                 localPath = localPath.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator).add(filePath);
@@ -621,8 +618,8 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
             } else {
                 String suffix = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
                 File fileTemp = SystemConstant.getFileTempVar(suffix);
-                localPath = localPath.add(fileTemp.getPath());
-                file = fileStoreUtil.ossDownload(filePath, localPath.toString(), uploadType.getFssType());
+                fileTempList.add(fileTemp);
+                file = fileStoreUtil.ossDownload(filePath, fileTemp, uploadType.getFssType());
             }
         }
         return file;

+ 14 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/FileStoreUtil.java

@@ -158,6 +158,20 @@ public class FileStoreUtil {
         return this.saveLocal(fileService.getFileStore(type).read(dirName), localPath);
     }
 
+    /**
+     * 从文件存储上下载文件到本地
+     *
+     * @param dirName   文件地址
+     * @param localFile 本地路径
+     * @param type      fileStore类型
+     * @throws Exception 异常
+     */
+    public File ossDownload(String dirName, File localFile, String type) throws Exception {
+        log.info("ossDownload is come in");
+        InputStream inputStream = fileService.getFileStore(type).read(dirName);
+        FileUtils.copyInputStreamToFile(inputStream, localFile);
+        return localFile;
+    }
 
     /**
      * 从文件存储上下载文件到byte[]