浏览代码

Merge branch 'dev' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev

xiaof 4 年之前
父节点
当前提交
82634144ca

+ 47 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PaperPdfDto.java

@@ -0,0 +1,47 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.File;
+import java.io.Serializable;
+
+/**
+ * @Description: 试卷pdf dto
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/4/26
+ */
+public class PaperPdfDto implements Serializable {
+
+    @ApiModelProperty(name = "文件")
+    File file;
+
+    @ApiModelProperty(name = "页面大小")
+    int pages;
+
+    public PaperPdfDto() {
+
+    }
+
+    public PaperPdfDto(File file, int pages) {
+        this.file = file;
+        this.pages = pages;
+    }
+
+    public File getFile() {
+        return file;
+    }
+
+    public void setFile(File file) {
+        this.file = file;
+    }
+
+    public int getPages() {
+        return pages;
+    }
+
+    public void setPages(int pages) {
+        this.pages = pages;
+    }
+}

+ 5 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java

@@ -58,6 +58,11 @@ public class PdfDto {
         this.tag = tag;
     }
 
+    public PdfDto(PageSizeEnum pageSize, Integer pageCount) {
+        this.pageSize = pageSize;
+        this.pageCount = pageCount;
+    }
+
     public PdfDto(PageSizeEnum pageSize, Integer pageCount, Integer actualPageCount) {
         this.pageSize = pageSize;
         this.pageCount = pageCount;

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

@@ -8,10 +8,7 @@ import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.annotation.ExcelDBFieldDesc;
-import com.qmth.distributed.print.business.bean.dto.ExaminationExportDto;
-import com.qmth.distributed.print.business.bean.dto.ExaminationImportDto;
-import com.qmth.distributed.print.business.bean.dto.FieldsDto;
-import com.qmth.distributed.print.business.bean.dto.PdfDto;
+import com.qmth.distributed.print.business.bean.dto.*;
 import com.qmth.distributed.print.business.bean.params.ArraysParams;
 import com.qmth.distributed.print.business.bean.params.SerialNumberParams;
 import com.qmth.distributed.print.business.entity.*;
@@ -237,8 +234,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             String paperType = Objects.nonNull(paperTypeParam) ? paperTypeParam : createPdfUtil.getPaperType(examPrintPlan, examTaskDetail, examDetail, examDetailCourse);
                             examTaskDetail.setRelatePaperType(paperType);
 
+                            PaperPdfDto paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
+
                             //获取试卷pdf
-                            PdfDto pdfDto = createPdfUtil.getPaperPdf(paperType, examTaskDetail, examPrintPlan.getBackupCount(), null, backupPaperTempPdfList);
+                            PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, examPrintPlan.getBackupCount(), backupPaperTempPdfList);
                             examDetailCourse.setPaperPagesA3(Objects.nonNull(pdfDto) ? pdfDto.getPageCount() : examDetailCourse.getPaperPagesA3());
                             backupPaperPdfList.addAll(backupPaperTempPdfList);
 
@@ -290,11 +289,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                 });
 
                                 for (ExamStudent t : examStudentList) {
-                                    createPdfUtil.getPaperPdf(paperType, examTaskDetail, 1, paperPdfTempList, null);
-                                    paperPdfList.addAll(paperPdfTempList);
-
+                                    createPdfUtil.getExamStudentPaperPdf(paperPdfDto, paperPdfTempList);
                                     basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, paperType, examCard, sysUser.getId(), examStudentTempPdfList));
                                 }
+                                paperPdfList.addAll(paperPdfTempList);
                                 examStudentPdfList.addAll(examStudentTempPdfList);
                                 examStudentService.saveOrUpdateBatch(examStudentList);
                                 jsonObject.put("card", jsonArray);
@@ -664,19 +662,17 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
             // 处理试卷样品
             List<Map> paperInfo = JSONObject.parseArray(examTaskDetail.getPaperAttachmentIds(), Map.class);
-            if (Objects.isNull(paperInfo)) {
-                throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
-            }
             System.out.println("paperInfo = " + JSON.toJSONString(paperInfo));
             Set<Long> attPaperIds = new HashSet<>();
             for (Map paperMap : paperInfo) {
-                if (Objects.nonNull(paperMap.get("attachmentId")) && String.valueOf(paperMap.get("attachmentId")).length() > 0 && !String.valueOf(paperMap.get("attachmentId")).equals("null")) {
-                    Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
-                    attPaperIds.add(attachmentId);
+                if (Objects.isNull(paperMap.get("attachmentId"))) {
+                    throw ExceptionResultEnum.ERROR.exception("未找到附件id");
                 }
+                Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
+                attPaperIds.add(attachmentId);
             }
-            if (attPaperIds.size() > 0) {
-                List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
+            List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
+            if (Objects.nonNull(paperAttachmentList)) {
                 for (BasicAttachment paperAttachment : paperAttachmentList) {
                     JSONObject jsonObject = JSONObject.parseObject(paperAttachment.getPath());
                     String paperPath = firstPath + File.separator + "试卷" + File.separator + paperAttachment.getName() + paperAttachment.getType();
@@ -696,8 +692,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 Long attachmentId = Long.valueOf(String.valueOf(confirmMap.get("attachmentId")));
                 attConfirmIds.add(attachmentId);
             }
-            if (attConfirmIds.size() > 0) {
-                List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
+            List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
+            if (Objects.nonNull(confirmAttachmentList)) {
                 for (BasicAttachment confirmAttachment : confirmAttachmentList) {
                     JSONObject jsonObject = JSONObject.parseObject(confirmAttachment.getPath());
                     String confirmPath = firstPath + File.separator + "审核样本" + File.separator + confirmAttachment.getName() + confirmAttachment.getType();
@@ -733,6 +729,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
                 String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
                 ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath);
+                count++;
             } else {
                 List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId, cardId));
                 if (examCardDetailList.size() != 1) {
@@ -747,8 +744,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     localFile.getParentFile().mkdirs();
                 }
                 FileCopyUtils.copy(bytes, localFile);
+                count++;
             }
-            count++;
         }
         ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), true);
         ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));

+ 49 - 20
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.Gson;
 import com.itextpdf.text.DocumentException;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
+import com.qmth.distributed.print.business.bean.dto.PaperPdfDto;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.cache.CreatePdfCacheUtil;
 import com.qmth.distributed.print.business.entity.*;
@@ -295,16 +296,55 @@ public class CreatePdfUtil {
     /**
      * 获取试卷pdf
      *
-     * @param paperType
-     * @param examTaskDetail
+     * @param paperPdfDto
+     * @param pdfList
+     * @return
+     * @throws IOException
+     */
+    public PdfDto getExamStudentPaperPdf(PaperPdfDto paperPdfDto, List<PdfDto> pdfList) throws IOException {
+        if (Objects.nonNull(paperPdfDto)) {
+            int pages = paperPdfDto.getPages();
+            PdfDto pdfDto = PdfUtil.addPdfPage(paperPdfDto.getFile());
+            pdfList.add(new PdfDto(paperPdfDto.getFile().getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
+            return new PdfDto(PageSizeEnum.A3, pages);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * 获取试卷pdf
+     *
+     * @param paperPdfDto
      * @param backupCount
      * @param pdfList
      * @return
      * @throws IOException
      */
-    public PdfDto getPaperPdf(String paperType, ExamTaskDetail examTaskDetail, Integer backupCount, List<PdfDto>... pdfList) throws IOException {
-        boolean tag = true;
-        int pages = 0;
+    public PdfDto getPaperPdf(PaperPdfDto paperPdfDto, Integer backupCount, List<PdfDto> pdfList) throws IOException {
+        if (Objects.nonNull(paperPdfDto)) {
+            int pages = paperPdfDto.getPages();
+            boolean tag = pages > 2 ? true : false;
+            PdfDto pdfDto = PdfUtil.addPdfPage(paperPdfDto.getFile());
+            for (int j = 1; j <= backupCount; j++) {
+                pdfList.add(new PdfDto(paperPdfDto.getFile().getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
+            }
+            return new PdfDto(PageSizeEnum.A3, pages, tag);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * 获取考试试卷
+     *
+     * @param paperType
+     * @param examTaskDetail
+     * @return
+     * @throws IOException
+     */
+    public PaperPdfDto getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws IOException {
+        PaperPdfDto paperPdfDto = null;
         JSONArray jsonArrayPaper = JSONArray.parseArray(examTaskDetail.getPaperAttachmentIds());
         for (int i = 0; i < jsonArrayPaper.size(); i++) {
             JSONObject object = (JSONObject) jsonArrayPaper.get(i);
@@ -317,24 +357,13 @@ public class CreatePdfUtil {
                 String name = (String) object.get("name");
                 if (Objects.equals(name.toUpperCase(), paperType.toUpperCase())) {
                     File file = commonService.getFile(basicAttachment.getPath(), false);
-                    pages = (int) object.get("pages");
-                    tag = pages > 2 ? true : false;
-                    PdfDto pdfDto = PdfUtil.addPdfPage(file);
-                    if (Objects.nonNull(pdfList[0])) {
-                        pdfList[0].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
-                    }
-                    if (Objects.nonNull(pdfList[1])) {
-                        for (int j = 1; j <= backupCount; j++) {
-                            pdfList[1].add(new PdfDto(file.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
-                        }
-                    }
+                    int pages = (int) object.get("pages");
+                    paperPdfDto = new PaperPdfDto(file, pages);
+                    break;
                 }
-                return new PdfDto(PageSizeEnum.A3, pages, tag);
-            } else {
-                return null;
             }
         }
-        return null;
+        return paperPdfDto;
     }
 
     /**