Explorar o código

卷库下载-bug修改

xiaof %!s(int64=3) %!d(string=hai) anos
pai
achega
c1ea4b0951

+ 28 - 36
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -19,6 +19,7 @@ import com.qmth.distributed.print.business.mapper.ExamTaskMapper;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
 import com.qmth.distributed.print.business.templete.execute.AsyncPaperReviewPdfExportService;
+import com.qmth.distributed.print.business.util.CreatePdfUtil;
 import com.qmth.distributed.print.business.util.HtmlToPdfUtil;
 import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
 import com.qmth.teachcloud.common.bean.dto.MqDto;
@@ -40,6 +41,7 @@ import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.FileCopyUtils;
 import org.springframework.util.LinkedMultiValueMap;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -174,6 +176,9 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Resource
     TExamTaskFlowService tExamTaskFlowService;
 
+    @Resource
+    CreatePdfUtil createPdfUtil;
+
     @Override
     public List<ExamTask> listByCourseCode(Long schoolId, String code) {
         QueryWrapper<ExamTask> queryWrapper = new QueryWrapper<>();
@@ -1127,47 +1132,34 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             ExamCard examCard = examCardService.getById(cardId);
 
             String cardPath = rootPath + File.separator + examTask.getPaperNumber();
+            String cardHtmlPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.HTML_PREFIX;
+            String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.PDF_PREFIX;
+
+            ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
+            String htmlContent;
             // 通用模板
             if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod())) {
-                if (examCard.getTemplateId() != null) {
-                    BasicTemplate basicTemplate = basicTemplateService.getById(examCard.getTemplateId());
-                    if (basicTemplate == null) {
-                        throw ExceptionResultEnum.ERROR.exception("题卡文件异常");
-                    }
-                    BasicAttachment attachment = basicAttachmentService.getById(basicTemplate.getAttachmentId());
-                    String fileName = "题卡" + "_" + examTask.getPaperNumber() + attachment.getType();
-                    File file = teachcloudCommonService.copyFile(cardPath, fileName, attachment);
-                    fileList.add(file);
-
-                    String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.PDF_PREFIX;
-                    // 转pdf文件
-                    File file1 = new File(cardPdfPath);
-                    if (!file1.exists()) {
-                        file1.createNewFile();
-                    }
-                    HtmlToPdfUtil.convert(file.getPath(), cardPdfPath, PageSizeEnum.A3);
-                    fileList.add(file1);
-                }
+                htmlContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
+            } else {
+                BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
+                htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
             }
-            // 自制题卡或者客服制卡
-            else {
-                ExamCardDetail examCardDetail = examCardDetailService.getByCardId(cardId);
-                if (StringUtils.isBlank(examCardDetail.getHtmlContent())) {
-                    throw ExceptionResultEnum.ERROR.exception("题卡内容有误");
-                }
-                String fileName = "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.HTML_PREFIX;
-                File file = basicAttachmentService.saveAttachmentHtml(cardPath, fileName, examCardDetail.getHtmlContent());
-                fileList.add(file);
 
-                String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + SystemConstant.PDF_PREFIX;
-                // 转pdf文件
-                File file1 = new File(cardPdfPath);
-                if (!file1.exists()) {
-                    file1.createNewFile();
-                }
-                HtmlToPdfUtil.convert(file.getPath(), cardPdfPath, PageSizeEnum.A3);
-                fileList.add(file1);
+            // html
+            File htmlFile = new File(cardHtmlPath);
+            if (!htmlFile.getParentFile().exists()) {
+                htmlFile.getParentFile().mkdirs();
+            }
+            // 生成html文件
+            FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
+            fileList.add(htmlFile);
+            // 转pdf文件
+            File pdfFile = new File(cardPdfPath);
+            if (!pdfFile.exists()) {
+                pdfFile.createNewFile();
             }
+            HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
+            fileList.add(pdfFile);
         }
         if (fileList.size() == 0) {
             throw ExceptionResultEnum.ERROR.exception("没有可导出文件");