Browse Source

fix:试卷文件批量下载-题卡优化

caozixuan 3 năm trước cách đây
mục cha
commit
1b53b6f07a

+ 11 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExamTaskPaperFileDto.java

@@ -64,6 +64,9 @@ public class ExamTaskPaperFileDto {
     @ApiModelProperty(value = "该命题任务id")
     private Long examCardId;
 
+    @ApiModelProperty(value = "题卡规则id")
+    private Long cardRuleId;
+
     public Long getExamTaskId() {
         return examTaskId;
     }
@@ -175,4 +178,12 @@ public class ExamTaskPaperFileDto {
     public void setExamCardId(Long examCardId) {
         this.examCardId = examCardId;
     }
+
+    public Long getCardRuleId() {
+        return cardRuleId;
+    }
+
+    public void setCardRuleId(Long cardRuleId) {
+        this.cardRuleId = cardRuleId;
+    }
 }

+ 2 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DownloadServiceImpl.java

@@ -198,6 +198,7 @@ public class DownloadServiceImpl implements DownloadService {
                 String courseName = examTaskDetailDto.getCourseName();
                 String paperNumber = examTaskDetailDto.getPaperNumber();
                 Long examCardId= examTaskDetailDto.getExamCardId();
+                Long cardRuleId = SystemConstant.convertIdToLong(examTaskDetailDto.getCardRuleId());
 
                 // 生成导出对象
                 ExamTaskPaperExportDto examTaskPaperExportDto = new ExamTaskPaperExportDto();
@@ -255,6 +256,7 @@ public class DownloadServiceImpl implements DownloadService {
                     cell.setPaperNumber(paperNumber);
                     // 题卡
                     cell.setExamCardId(examCardId);
+                    cell.setCardRuleId(cardRuleId);
                     // 试卷
                     cell.setPaperType(paperType);
                     cell.setExposureStatus(exposureStatus);

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

@@ -1720,18 +1720,35 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 String filePath = zipLocalRootPath + File.separator + course + File.separator + paperNumber + File.separator;
 
                 Long examCardId = paperCellList.get(0).getExamCardId();
+                Long cardRuleId = paperCellList.get(0).getCardRuleId();
+                ExamCard examCard = examCardService.getById(examCardId);
                 ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCardId);
-                String htmlContent = examCardDetail.getHtmlContent();
+                String htmlContent;
+                if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
+                    htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
+                } else {
+                    BasicCardRule basicCardRule = basicCardRuleService.getById(cardRuleId);
+                    htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
+                }
+
+
                 byte[] bytes = htmlContent.getBytes();
-                String cardLocalPath = filePath + "题卡-" + examCardService.getById(examCardId).getTitle() + SystemConstant.HTML_PREFIX;
+                String cardLocalHtmlPath = filePath + "题卡-" + examCardService.getById(examCardId).getTitle() + SystemConstant.HTML_PREFIX;
+                String cardLocalPdfPath = filePath + "题卡-" + examCardService.getById(examCardId).getTitle() + SystemConstant.PDF_PREFIX;
 
                 switch (paperFileDownloadContent) {
                     case ONLY_CARD: // 只下载题卡
-                        File localFile = new File(cardLocalPath);
+                        File localFile = new File(cardLocalHtmlPath);
                         if (!localFile.getParentFile().exists()) {
                             boolean mkr = localFile.getParentFile().mkdirs();
                         }
                         FileCopyUtils.copy(bytes, localFile);
+
+                        File pdfFile = new File(cardLocalPdfPath);
+                        if (!pdfFile.exists()) {
+                            boolean cf = pdfFile.createNewFile();
+                        }
+                        HtmlToPdfUtil.convert(cardLocalHtmlPath, cardLocalPdfPath, PageSizeEnum.A3);
                         break;
                     case ONLY_PAPER: // 只下载试卷
                         for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
@@ -1752,11 +1769,17 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         break;
                     case PAPER_AND_CARD: // 全部下载
                         // 题卡
-                        File localCardFile = new File(cardLocalPath);
+                        File localCardFile = new File(cardLocalHtmlPath);
                         if (!localCardFile.getParentFile().exists()) {
                             boolean mkr = localCardFile.getParentFile().mkdirs();
                         }
                         FileCopyUtils.copy(bytes, localCardFile);
+
+                        File cardPdfFile = new File(cardLocalPdfPath);
+                        if (!cardPdfFile.exists()) {
+                            boolean cf = cardPdfFile.createNewFile();
+                        }
+                        HtmlToPdfUtil.convert(cardLocalHtmlPath, cardLocalPdfPath, PageSizeEnum.A3);
                         // 试卷
                         for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
                             String paperName = "试卷-";
@@ -1778,7 +1801,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             }
         }
         ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), false);
-//        ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
         fileStoreUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))), fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
         JSONObject jsonObject = new JSONObject();
         jsonObject.put(SystemConstant.PATH, dirNameTmp);

+ 1 - 0
distributed-print-business/src/main/resources/mapper/ExamTaskMapper.xml

@@ -1344,6 +1344,7 @@
             resultType="com.qmth.distributed.print.business.bean.dto.ExamTaskDetailDto">
         SELECT
             a.id,
+            a.card_rule_id cardRuleId,
             be.name examName,
             bs.name semesterName,
             a.course_code courseCode,