Sfoglia il codice sorgente

3.2.0-印品生成bug修复

xiaof 2 anni fa
parent
commit
911d6f529d

+ 2 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/PrintCommonService.java

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.itextpdf.text.DocumentException;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
@@ -310,5 +311,5 @@ public interface PrintCommonService {
 
     void saveAttachmentPackagePdf(PdfPackageDto pdfPackageDto, ExamDetail examDetail, List<PdfDto> variablePdfList, Integer printCount);
 
-    String uploadPdfFile(File pdfFile);
+    JSONObject uploadPdfFile(File pdfFile, ClassifyEnum classifyEnum);
 }

+ 4 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicTemplateServiceImpl.java

@@ -228,15 +228,15 @@ public class BasicTemplateServiceImpl extends ServiceImpl<BasicTemplateMapper, B
         // 签到表
         if (ClassifyEnum.SIGN.equals(classifyEnum)) {
             if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
-                String json = PdfFillUtils.parseSignTempData(basicTemplate.getDisplayRange(), destUrl);
-                basicTemplate.setPreviewPath(json);
+                JSONObject json = PdfFillUtils.parseSignTempData(basicTemplate.getDisplayRange(), destUrl);
+                basicTemplate.setPreviewPath(JSON.toJSONString(json));
                 basicTemplateMapper.updateById(basicTemplate);
             }
             return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());
         } else if (ClassifyEnum.PACKAGE.equals(classifyEnum)) {
             if (StringUtils.isBlank(basicTemplate.getPreviewPath())) {
-                String json = PdfFillUtils.packageTempData(basicTemplate.getDisplayRange(), destUrl);
-                basicTemplate.setPreviewPath(json);
+                JSONObject json = PdfFillUtils.packageTempData(basicTemplate.getDisplayRange(), destUrl);
+                basicTemplate.setPreviewPath(JSON.toJSONString(json));
                 basicTemplateMapper.updateById(basicTemplate);
             }
             return basicTemplate.getPreviewPath() == null ? null : teachcloudCommonService.filePreview(basicTemplate.getPreviewPath());

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ClientServiceImpl.java

@@ -636,7 +636,7 @@ public class ClientServiceImpl implements ClientService {
 //                vMap.put("htmlUrl", teachcloudCommonService.filePreviewByPathAndType(path.get("htmlPath").toString(), path.get("type").toString(), false));
 //                vMap.put("htmlMd5", path.get("htmlMd5"));
                 vMap.put("pdfUrl", teachcloudCommonService.filePreviewByPathAndType(path.get("pdfPath").toString(), path.get("type").toString(), false));
-                vMap.put("pdfMd5", path.get("pdfMd5"));
+                vMap.put("pdfMd5", path.get("pdfMd5").toString().toLowerCase());
             }
         }
         if (vMap.size() > 1) {

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamDetailServiceImpl.java

@@ -178,7 +178,7 @@ public class ExamDetailServiceImpl extends ServiceImpl<ExamDetailMapper, ExamDet
                 JSONObject object = jsonArray.getJSONObject(i);
                 JSONObject jsonObject = new JSONObject();
                 jsonObject.put("type", Objects.nonNull(object.get("printType")) ? PdfTypeEnum.valueOf((String) object.get("printType")) : null);
-                jsonObject.put("url", Objects.nonNull(object.get("pdfPath")) ? teachcloudCommonService.filePreviewByPathAndType((String) object.get("pdfPath"), (String) object.get("type"), false) : null);
+                jsonObject.put("url", Objects.nonNull(object.get(SystemConstant.PDF_PATH)) ? teachcloudCommonService.filePreviewByPathAndType((String) object.get(SystemConstant.PDF_PATH), (String) object.get("type"), false) : null);
                 list.add(jsonObject);
             }
         }

+ 8 - 5
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceImpl.java

@@ -314,10 +314,11 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 pdfFile.getParentFile().mkdirs();
                 pdfFile.createNewFile();
             }
+            PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
+
             byte[] data = ByteArray.fromFile(pdfFile).value();
             String md5 = ByteArray.md5(data).toHexString();
             InputStream ins = new ByteArrayInputStream(data);
-            PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
             if (oss) {//上传至oss
                 fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
                 ins.close();
@@ -337,7 +338,6 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 object.put(SystemConstant.TYPE, SystemConstant.OSS);
             }
             object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
-                    UploadFileEnum.HTML,
                     UploadFileEnum.PDF
             });
             jsonArray.add(object);
@@ -1375,10 +1375,11 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 pdfFile.getParentFile().mkdirs();
                 pdfFile.createNewFile();
             }
+            PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
+
             byte[] data = ByteArray.fromFile(pdfFile).value();
             String md5 = ByteArray.md5(data).toHexString();
             InputStream ins = new ByteArrayInputStream(data);
-            PdfDto pdfDto = PdfUtil.addPdfPage(pdfFile);
             if (oss) {//上传至oss
                 fileStoreUtil.ossUpload(pdfDirNameStr, ins, md5, fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
                 ins.close();
@@ -1424,7 +1425,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
      * @return
      */
     @Override
-    public String uploadPdfFile(File pdfFile) {
+    public JSONObject uploadPdfFile(File pdfFile, ClassifyEnum classifyEnum) {
         try {
             boolean oss = dictionaryConfig.sysDomain().isOss();
             String pdfDirName = pdfFile.getPath();
@@ -1440,6 +1441,8 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 ins.close();
             }
             JSONObject object = new JSONObject();
+            object.put("printType", classifyEnum);
+            object.put("pdfMd5", md5);
             if (!oss) {
                 object.put(SystemConstant.PATH, pdfDirName);
                 object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
@@ -1448,7 +1451,7 @@ public class PrintCommonServiceImpl implements PrintCommonService {
                 object.put(SystemConstant.TYPE, SystemConstant.OSS);
             }
             object.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.PDF);
-            return JSON.toJSONString(object);
+            return object;
         } catch (Exception e) {
             log.error(SystemConstant.LOG_ERROR, e);
             if (e instanceof ApiException) {

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

@@ -492,7 +492,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         if (StringUtils.isNotBlank(variableContent)) {
             List<Long> examDetailCourseListIds = examDetailCourseList.stream().map(BaseEntity::getId).collect(Collectors.toList());
             List<ExamStudentCourseDto> examStudentCourseDtoList = examStudentService.queryBySchoolIdAndExamDetailCourseIds(basicSchool.getId(), examDetailCourseListIds);
-            int count = (int) examStudentCourseDtoList.stream().filter(s -> s.getPaperPageA3() != null && s.getPaperPageA3() > 2).count();
             //获取变量印品
             JSONArray jsonArrayVariable = JSONArray.parseArray(variableContent);
             for (int i = 0; i < jsonArrayVariable.size(); i++) {

+ 25 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 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;
 import com.qmth.distributed.print.business.entity.*;
@@ -131,14 +132,36 @@ public class CreatePdfUtil {
 //            String url = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + filePath;
             UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
 
-//            File localFile = ossUtil.ossDownload(filePath, url);
+            JSONObject attachmentPath = JSONObject.parseObject(examDetail.getAttachmentPath());
+            attachmentPath = Objects.isNull(attachmentPath) ? new JSONObject() : attachmentPath;
+            JSONArray jsonArray = (JSONArray) attachmentPath.get(SystemConstant.PATH);
+            jsonArray = Objects.isNull(jsonArray) ? new JSONArray() : jsonArray;
+
+            JSONObject object = new JSONObject();
+            object.put("printType", ClassifyEnum.CHECK_IN.name());
             File localFile;
-            if (SystemConstant.LOCAL.equals((String) jsonObject.get(SystemConstant.TYPE))) {
+            if (SystemConstant.LOCAL.equals(jsonObject.get(SystemConstant.TYPE))) {
                 localFile = new File(filePath);
+                object.put(SystemConstant.PDF_PATH, localFile.getPath());
+                object.put(SystemConstant.TYPE, SystemConstant.LOCAL);
             } else {
                 localFile = fileStoreUtil.ossDownload(filePath, filePath, uploadFileEnum.getFssType());
+                object.put(SystemConstant.PDF_PATH, localFile.getPath());
+                object.put(SystemConstant.TYPE, SystemConstant.OSS);
             }
+            object.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
+                    UploadFileEnum.PDF
+            });
             PdfDto pdfDto = PdfUtil.addPdfPage(localFile);
+
+            byte[] data = ByteArray.fromFile(localFile).value();
+            String md5 = ByteArray.md5(data).toHexString();
+            object.put("pdfMd5", md5);
+
+            jsonArray.add(object);
+            attachmentPath.put(SystemConstant.PATH, jsonArray);
+            examDetail.setAttachmentPath(attachmentPath.toJSONString());
+
             for (int i = 0; i < printCount; i++) {
                 ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount()));
             }

+ 28 - 14
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePrintPdfUtil.java

@@ -1,15 +1,14 @@
 package com.qmth.distributed.print.business.util;
 
+import com.alibaba.fastjson.JSONObject;
 import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.*;
 import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
 import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
 import com.qmth.distributed.print.business.service.PrintCommonService;
-import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SpringContextHolder;
-import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.enums.ClassifyEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
-import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -18,7 +17,6 @@ import org.springframework.stereotype.Component;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.time.LocalDateTime;
 import java.util.List;
 import java.util.*;
 
@@ -35,16 +33,18 @@ public class CreatePrintPdfUtil {
      * @param pdfFillDto   签到表数据
      * @param destFileName 文件名
      */
-    public String createSignPdf(PdfSignDto pdfFillDto, String destFileName) throws Exception {
+    public File createSignPdf(PdfSignDto pdfFillDto, String destFileName) throws Exception {
 
         // 1:建立Document对象实例
         Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
 //        ByteArrayOutputStream baos = new ByteArrayOutputStream();
         File file = createFolder(destFileName);
+        FileOutputStream fos = null;
+        PdfWriter pdfWriter = null;
         try {
             // 2:建立一个PDF 写入器与document对象关联通过书写器(Writer)可以将文档写入到磁盘中
-            FileOutputStream fos = new FileOutputStream(file);
-            PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
+            fos = new FileOutputStream(file);
+            pdfWriter = PdfWriter.getInstance(document, fos);
 
             //3、设置pdf页眉和页脚和水印
             MyHeaderFooter headerFooter = new MyHeaderFooter();
@@ -60,9 +60,15 @@ public class CreatePrintPdfUtil {
 
         } catch (DocumentException e) {
             e.printStackTrace();
+        } finally {
+            if (fos != null) {
+                fos.close();
+            }
+            if (pdfWriter != null) {
+                pdfWriter.close();
+            }
         }
-        PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
-        return dictionaryConfig.uploadPdfFile(file);
+        return file;
     }
 
     /**
@@ -71,16 +77,18 @@ public class CreatePrintPdfUtil {
      * @param pdfPackageDto 卷袋贴参数
      * @param destFileName  保存文件名
      */
-    public String createPackagePdf(PdfPackageDto pdfPackageDto, String destFileName) throws Exception {
+    public File createPackagePdf(PdfPackageDto pdfPackageDto, String destFileName) throws Exception {
 
         // 1:建立Document对象实例
         Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
 //        ByteArrayOutputStream baos = new ByteArrayOutputStream();
         File file = createFolder(destFileName);
+        FileOutputStream fos = null;
+        PdfWriter pdfWriter = null;
         try {
             // 2:建立一个PDF 写入器与document对象关联通过书写器(Writer)可以将文档写入到磁盘中
-            FileOutputStream fos = new FileOutputStream(file);
-            PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
+            fos = new FileOutputStream(file);
+            pdfWriter = PdfWriter.getInstance(document, fos);
             // 3:打开文档
             document.open();
             //生成pdf
@@ -89,10 +97,16 @@ public class CreatePrintPdfUtil {
             document.close();
         } catch (DocumentException e) {
             e.printStackTrace();
+        } finally {
+            if (fos != null) {
+                fos.close();
+            }
+            if (pdfWriter != null) {
+                pdfWriter.close();
+            }
         }
 
-        PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
-        return dictionaryConfig.uploadPdfFile(file);
+        return file;
     }
 
     /**

+ 12 - 8
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfFillUtils.java

@@ -7,13 +7,13 @@ import com.itextpdf.text.*;
 import com.itextpdf.text.pdf.*;
 import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
 import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
+import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
+import com.qmth.teachcloud.common.enums.ClassifyEnum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
 import java.util.List;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -58,7 +58,7 @@ public class PdfFillUtils {
      * @param data     数据内容
      * @param fileName 文件名
      */
-    public static String parseSignTempData(String data, String fileName) {
+    public static JSONObject parseSignTempData(String data, String fileName) {
         PdfSignDto pdfFillDto = new PdfSignDto();
         pdfFillDto.setTitle("签到表样例");
         pdfFillDto.setPackageNumber("123456789");
@@ -102,7 +102,9 @@ public class PdfFillUtils {
         pdfFillDto.setStudentPlate(studentPlate);
         try {
             CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
-            return createPrintPdfUtil.createSignPdf(pdfFillDto, fileName);
+            File file = createPrintPdfUtil.createSignPdf(pdfFillDto, fileName);
+            PrintCommonService printCommonService = SpringContextHolder.getBean(PrintCommonService.class);
+            return printCommonService.uploadPdfFile(file, ClassifyEnum.SIGN);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -115,7 +117,7 @@ public class PdfFillUtils {
      *
      * @param data data
      */
-    public static String packageTempData(String data, String fileName) {
+    public static JSONObject packageTempData(String data, String fileName) {
         PdfPackageDto pdfPackageDto = new PdfPackageDto();
         pdfPackageDto.setTitle("卷袋贴样例");
         pdfPackageDto.setPackageNumber("123456789");
@@ -135,7 +137,9 @@ public class PdfFillUtils {
 
         try {
             CreatePrintPdfUtil createPrintPdfUtil = new CreatePrintPdfUtil();
-            return createPrintPdfUtil.createPackagePdf(pdfPackageDto, fileName);
+            File file = createPrintPdfUtil.createPackagePdf(pdfPackageDto, fileName);
+            PrintCommonService printCommonService = SpringContextHolder.getBean(PrintCommonService.class);
+            return printCommonService.uploadPdfFile(file, ClassifyEnum.PACKAGE);
         } catch (Exception e) {
             e.printStackTrace();
         }