Prechádzať zdrojové kódy

Merge branch 'dev'
merge

wangliang 4 rokov pred
rodič
commit
a0949f0c96

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

@@ -341,7 +341,7 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
             for (TBTask tbTask : tbTasks) {
                 if (tbTask.getResetCount() < dictionaryConfig.sysDomain().getAutoCreatePdfResetMaxCount()) {
                     Map<String, Object> map = new HashMap<>();
-                    tbTask.setVersion(new AtomicInteger(tbTask.getVersion()).incrementAndGet());
+//                    tbTask.setVersion(new AtomicInteger(tbTask.getVersion()).incrementAndGet());
                     if (Objects.nonNull(tbTask.getRemark())) {
                         JSONArray jsonArray = JSONArray.parseArray(tbTask.getRemark());
                         ArraysParams arraysParams = new ArraysParams(jsonArray.toArray(new Long[jsonArray.size()]));

+ 4 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/execute/AsyncCreatePdfTempleteService.java

@@ -61,10 +61,10 @@ public class AsyncCreatePdfTempleteService extends AsyncCreateTaskTemplete {
             log.error("请求出错", e);
             stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), EXCEPTION_TITLE, EXCEPTION_DATA, e.getMessage()));
             tbTask.setResult(TaskResultEnum.ERROR);
-            TBTask dbTask = tbTaskService.getById(tbTask.getId());
-            if (tbTask.getVersion() == dbTask.getVersion()) {
-                tbTask.setResetCount(new AtomicInteger(tbTask.getResetCount()).incrementAndGet());
-            }
+//            TBTask dbTask = tbTaskService.getById(tbTask.getId());
+//            if (tbTask.getVersion() == dbTask.getVersion()) {
+//                tbTask.setResetCount(new AtomicInteger(tbTask.getResetCount()).incrementAndGet());
+//            }
             if (e instanceof ApiException) {
                 ResultUtil.error((ApiException) e, e.getMessage());
             } else {

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

@@ -140,10 +140,10 @@ public abstract class AsyncImportTaskTemplete {
             stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), EXCEPTION_CREATE_TXT_TITLE, EXCEPTION_DATA, e.getMessage()));
             tbTask.setSummary(stringJoinerSummary.toString());
             tbTask.setResult(TaskResultEnum.ERROR);
-            TBTask dbTask = tbTaskService.getById(tbTask.getId());
-            if (tbTask.getVersion() == dbTask.getVersion()) {
-                tbTask.setResetCount(new AtomicInteger(tbTask.getResetCount()).incrementAndGet());
-            }
+//            TBTask dbTask = tbTaskService.getById(tbTask.getId());
+//            if (tbTask.getVersion() == dbTask.getVersion()) {
+//                tbTask.setResetCount(new AtomicInteger(tbTask.getResetCount()).incrementAndGet());
+//            }
             if (e instanceof ApiException) {
                 ResultUtil.error((ApiException) e, e.getMessage());
             } else {

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

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.itextpdf.text.DocumentException;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.annotation.ExcelDBFieldDesc;
 import com.qmth.distributed.print.business.bean.dto.*;
@@ -160,6 +161,179 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return map;
     }
 
+    /**
+     * 创建pdf核心逻辑
+     *
+     * @param examDetailCourseList
+     * @param examPrintPlan
+     * @param examDetail
+     * @param sysUser
+     * @param paperTypeParam
+     * @param basicAttachmentList
+     * @param attachmentIds
+     * @param ftlList
+     * @param basicSchool
+     * @param list
+     * @return
+     * @throws IOException
+     * @throws DocumentException
+     */
+    @Transactional
+    public List<BasicAttachment> createPdfCoreLogic(List<ExamDetailCourse> examDetailCourseList,
+                                                    ExamPrintPlan examPrintPlan,
+                                                    ExamDetail examDetail,
+                                                    SysUser sysUser,
+                                                    String paperTypeParam,
+                                                    List<BasicAttachment> basicAttachmentList,
+                                                    Set<Long> attachmentIds,
+                                                    Set<File> ftlList,
+                                                    BasicSchool basicSchool,
+                                                    List<PdfDto>... list
+    ) throws IOException, DocumentException {
+        if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
+            for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
+                if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
+                    //获取普通印品
+                    JSONArray jsonArrayOrdinary = JSONArray.parseArray(examPrintPlan.getOrdinaryContent());
+                    for (int i = 0; i < jsonArrayOrdinary.size(); i++) {
+                        JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
+                        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"));
+                        }
+                    }
+                }
+
+                List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
+                List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
+                List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
+                List<PdfDto> cardPdfTempList = new ArrayList<>();//备份题卡
+
+                //查询试卷
+                QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
+                examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
+                        .eq(ExamTask::getCourseCode, examDetailCourse.getCourseCode())
+                        .eq(ExamTask::getCourseName, examDetailCourse.getCourseName())
+                        .eq(ExamTask::getPaperNumber, examDetailCourse.getPaperNumber())
+                        .eq(ExamTask::getEnable, true)
+                        .eq(ExamTask::getStatus, ExamStatusEnum.FINISH)
+                        .orderByAsc(ExamTask::getPaperNumber);
+                List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
+                if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
+                    throw ExceptionResultEnum.ERROR.exception("命题任务为空");
+                }
+                Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
+
+                QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
+                examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
+                        .eq(ExamTaskDetail::getEnable, true);
+                List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
+                JSONObject jsonObject = new JSONObject();
+                JSONArray jsonArray = new JSONArray();
+                for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
+                    //查询题卡
+                    ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
+                    if (Objects.isNull(examCard)) {
+                        throw ExceptionResultEnum.ERROR.exception("题卡为空");
+                    }
+                    QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
+                    examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
+                    List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
+
+                    //拼装key
+                    String key = examDetail.getSchoolId()
+                            + "_" + examDetail.getExamStartTime()
+                            + "_" + examDetail.getExamEndTime()
+                            + "_" + examDetailCourse.getCourseCode()
+                            + "_" + examDetailCourse.getPaperNumber();
+                    String paperType = null;
+                    if (Objects.nonNull(paperTypeParam)) {
+                        paperType = paperTypeParam;
+                        CreatePdfCacheUtil.setPaperType(key, paperType);
+                    } else {
+                        paperType = createPdfUtil.getPaperType(examPrintPlan, examTaskDetail, key);//抽取卷型
+                    }
+                    examTaskDetail.setRelatePaperType(paperType);
+                    examDetailCourse.setPaperType(paperType);
+
+                    PaperPdfDto paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
+
+                    //获取试卷pdf
+                    PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, examPrintPlan.getBackupCount(), backupPaperTempPdfList);
+                    examDetailCourse.setPaperPagesA3(Objects.nonNull(pdfDto) ? pdfDto.getPageCount() : examDetailCourse.getPaperPagesA3());
+                    list[1].addAll(backupPaperTempPdfList);
+
+                    basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
+                    for (ExamCardDetail examCardDetail : examCardDetailList) {
+                        createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
+
+                        //把模板页面上的 ${} 替换成实际内容
+                        String cardContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
+                        String studentContent = cardContent;
+
+                        for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
+                            BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList);
+                            examDetailCourse.setCardPagesA3(basicAttachment.getPages());
+                            basicAttachmentList.add(basicAttachment);
+                        }
+                        list[2].addAll(cardPdfTempList);
+
+                        //查询考生
+                        QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
+                        examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
+                                .eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
+                        List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
+
+                        if (Objects.nonNull(examPrintPlan.getVariableContent())) {
+                            //获取变量印品
+                            JSONArray jsonArrayVariable = JSONArray.parseArray(examPrintPlan.getVariableContent());
+                            for (int i = 0; i < jsonArrayVariable.size(); i++) {
+                                JSONObject jsonObjectVariable = jsonArrayVariable.getJSONObject(i);
+                                String type = (String) jsonObjectVariable.get("type");
+                                if (Objects.nonNull(jsonObjectVariable.get("attachmentId")) && !Objects.equals("", jsonObjectVariable.get("attachmentId"))) {
+                                    Long attachmentId = Long.parseLong((String) jsonObjectVariable.get("attachmentId"));
+                                    BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
+                                    ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
+                                    if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
+                                        createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, list[3], (Integer) jsonObjectVariable.get("backupCount"));
+                                    } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAGE")) {//卷袋贴
+                                        if (Objects.nonNull(pdfDto)) {
+                                            createPdfUtil.createPaperPackage(pdfDto.isTag(), basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, list[3], (Integer) jsonObjectVariable.get("backupCount"));
+                                        }
+                                    }
+                                }
+                            }
+                        }
+
+                        Collections.sort(list[3], new Comparator<PdfDto>() {
+                            @Override
+                            public int compare(PdfDto o1, PdfDto o2) {
+                                return o1.getSequence() > o2.getSequence() ? 1 : -1;
+                            }
+                        });
+
+                        for (ExamStudent t : examStudentList) {
+                            if (Objects.nonNull(pdfDto)) {
+                                createPdfUtil.getExamStudentPaperPdf(paperPdfDto, paperPdfTempList);
+                            }
+                            basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, examDetail, examDetailCourse, sysUser.getId(), examStudentTempPdfList));
+                        }
+                        list[4].addAll(paperPdfTempList);
+                        list[5].addAll(examStudentTempPdfList);
+                        examStudentService.saveOrUpdateBatch(examStudentList);
+                        jsonObject.put("card", jsonArray);
+                        examCardDetail.setAttachmentId(jsonObject.toJSONString());
+                    }
+                    examCardDetailService.saveOrUpdateBatch(examCardDetailList);
+                }
+                examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
+            }
+            detailCourseService.saveOrUpdateBatch(examDetailCourseList);
+        }
+        return basicAttachmentList;
+    }
+
     /**
      * 创建pdf逻辑
      *
@@ -167,7 +341,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @return
      */
     @Override
-    @Transactional
+//    @Transactional
     public Map<String, Object> executeCreatePdfLogic(Map<String, Object> map) throws IOException {
         List<BasicAttachment> basicAttachmentList = null;
         try {
@@ -179,11 +353,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             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;
 
-            //这里为保存附件html的逻辑
-            //查询题卡详情是否有附件id,有的话则把以前的附件删除
-            Set<Long> attachmentIds = null;
-            Set<File> ftlList = null;
-
             //查询printPlan
             ExamPrintPlan examPrintPlan = examPrintPlanService.getById(tbTask.getPrintPlanId());
             if (Objects.isNull(examPrintPlan)) {
@@ -209,8 +378,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             if (Objects.isNull(examDetailList) || examDetailList.size() == 0) {
                 throw ExceptionResultEnum.ERROR.exception("考务计划为空");
             }
-            attachmentIds = Objects.isNull(attachmentIds) ? attachmentIds = new HashSet<>() : attachmentIds;
-            ftlList = Objects.isNull(ftlList) ? ftlList = new HashSet<>() : ftlList;
+            Set<Long> attachmentIds = new HashSet<>();
+            Set<File> ftlList = new HashSet<>();
             for (ExamDetail examDetail : examDetailList) {
                 tbTask.setObjName(examDetail.getExamRoom() + "-" + examDetail.getExamPlace());
                 //查询examDetailCourse
@@ -221,161 +390,33 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     examDetailCourseQueryWrapper.lambda().eq(ExamDetailCourse::getExamDetailId, examDetail.getId());
                 }
                 List<ExamDetailCourse> examDetailCourseList = detailCourseService.list(examDetailCourseQueryWrapper);
-                if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
-                    List<PdfDto> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
-                    List<PdfDto> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
-                    List<PdfDto> paperPdfList = new ArrayList<>();//所有试卷
-                    List<PdfDto> examStudentPdfList = new ArrayList<>();//所有题卡
-                    List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
-                    List<PdfDto> cardPdfList = new ArrayList<>();//备份题卡
-
-                    for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
-                        if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
-                            //获取普通印品
-                            JSONArray jsonArrayOrdinary = JSONArray.parseArray(examPrintPlan.getOrdinaryContent());
-                            for (int i = 0; i < jsonArrayOrdinary.size(); i++) {
-                                JSONObject jsonObjectOrdinary = jsonArrayOrdinary.getJSONObject(i);
-                                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, ordinaryPdfList, (Integer) jsonObjectOrdinary.get("backupCount"));
-                                }
-                            }
-                        }
-
-                        List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
-                        List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
-                        List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
-                        List<PdfDto> cardPdfTempList = new ArrayList<>();//备份题卡
-
-                        //查询试卷
-                        QueryWrapper<ExamTask> examTaskQueryWrapper = new QueryWrapper<>();
-                        examTaskQueryWrapper.lambda().eq(ExamTask::getSchoolId, sysUser.getSchoolId())
-                                .eq(ExamTask::getCourseCode, examDetailCourse.getCourseCode())
-                                .eq(ExamTask::getCourseName, examDetailCourse.getCourseName())
-                                .eq(ExamTask::getPaperNumber, examDetailCourse.getPaperNumber())
-                                .eq(ExamTask::getEnable, true)
-                                .eq(ExamTask::getStatus, ExamStatusEnum.FINISH)
-                                .orderByAsc(ExamTask::getPaperNumber);
-                        List<ExamTask> examTaskList = examTaskService.list(examTaskQueryWrapper);
-                        if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
-                            throw ExceptionResultEnum.ERROR.exception("命题任务为空");
-                        }
-                        Set<Long> examTaskIds = examTaskList.stream().map(s -> s.getId()).collect(Collectors.toSet());
-
-                        QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
-                        examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
-                                .eq(ExamTaskDetail::getEnable, true);
-                        List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
-                        JSONObject jsonObject = new JSONObject();
-                        JSONArray jsonArray = new JSONArray();
-                        for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
-                            //查询题卡
-                            ExamCard examCard = examCardService.getById(examTaskDetail.getCardId());
-                            if (Objects.isNull(examCard)) {
-                                throw ExceptionResultEnum.ERROR.exception("题卡为空");
-                            }
-                            QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
-                            examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
-                            List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
-
-                            //拼装key
-                            String key = examDetail.getSchoolId()
-                                    + "_" + examDetail.getExamStartTime()
-                                    + "_" + examDetail.getExamEndTime()
-                                    + "_" + examDetailCourse.getCourseCode()
-                                    + "_" + examDetailCourse.getPaperNumber();
-                            String paperType = null;
-                            if (Objects.nonNull(paperTypeParam)) {
-                                paperType = paperTypeParam;
-                                CreatePdfCacheUtil.setPaperType(key, paperType);
-                            } else {
-                                paperType = createPdfUtil.getPaperType(examPrintPlan, examTaskDetail, key);//抽取卷型
-                            }
-                            examTaskDetail.setRelatePaperType(paperType);
-                            examDetailCourse.setPaperType(paperType);
-
-                            PaperPdfDto paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
-
-                            //获取试卷pdf
-                            PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, examPrintPlan.getBackupCount(), backupPaperTempPdfList);
-                            examDetailCourse.setPaperPagesA3(Objects.nonNull(pdfDto) ? pdfDto.getPageCount() : examDetailCourse.getPaperPagesA3());
-                            backupPaperPdfList.addAll(backupPaperTempPdfList);
-
-                            basicAttachmentList = Objects.isNull(basicAttachmentList) ? basicAttachmentList = new ArrayList<>() : basicAttachmentList;
-                            for (ExamCardDetail examCardDetail : examCardDetailList) {
-                                createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
-
-                                //把模板页面上的 ${} 替换成实际内容
-                                String cardContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
-                                String studentContent = cardContent;
-
-                                for (int i = 1; i <= examPrintPlan.getBackupCount(); i++) {
-                                    BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList);
-                                    examDetailCourse.setCardPagesA3(basicAttachment.getPages());
-                                    basicAttachmentList.add(basicAttachment);
-                                }
-                                cardPdfList.addAll(cardPdfTempList);
-
-                                //查询考生
-                                QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
-                                examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
-                                        .eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
-                                List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
-
-                                if (Objects.nonNull(examPrintPlan.getVariableContent())) {
-                                    //获取变量印品
-                                    JSONArray jsonArrayVariable = JSONArray.parseArray(examPrintPlan.getVariableContent());
-                                    for (int i = 0; i < jsonArrayVariable.size(); i++) {
-                                        JSONObject jsonObjectVariable = jsonArrayVariable.getJSONObject(i);
-                                        String type = (String) jsonObjectVariable.get("type");
-                                        if (Objects.nonNull(jsonObjectVariable.get("attachmentId")) && !Objects.equals("", jsonObjectVariable.get("attachmentId"))) {
-                                            Long attachmentId = Long.parseLong((String) jsonObjectVariable.get("attachmentId"));
-                                            BasicAttachment basicAttachment = basicAttachmentService.getById(attachmentId);
-                                            ftlList.add(commonService.getFile(basicAttachment.getPath(), false));
-                                            if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "SIGN")) {//签到表
-                                                createPdfUtil.createSignBook(basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
-                                            } else if (Objects.nonNull(type) && Objects.equals(type.toUpperCase(), "PACKAGE")) {//卷袋贴
-                                                if (Objects.nonNull(pdfDto)) {
-                                                    createPdfUtil.createPaperPackage(pdfDto.isTag(), basicAttachment, basicSchool.getName(), examDetail, examDetailCourse, examStudentList, variablePdfList, (Integer) jsonObjectVariable.get("backupCount"));
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-
-                                Collections.sort(variablePdfList, new Comparator<PdfDto>() {
-                                    @Override
-                                    public int compare(PdfDto o1, PdfDto o2) {
-                                        return o1.getSequence() > o2.getSequence() ? 1 : -1;
-                                    }
-                                });
-
-                                for (ExamStudent t : examStudentList) {
-                                    if (Objects.nonNull(pdfDto)) {
-                                        createPdfUtil.getExamStudentPaperPdf(paperPdfDto, paperPdfTempList);
-                                    }
-                                    basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, examDetail, examDetailCourse, sysUser.getId(), examStudentTempPdfList));
-                                }
-                                paperPdfList.addAll(paperPdfTempList);
-                                examStudentPdfList.addAll(examStudentTempPdfList);
-                                examStudentService.saveOrUpdateBatch(examStudentList);
-                                jsonObject.put("card", jsonArray);
-                                examCardDetail.setAttachmentId(jsonObject.toJSONString());
-                            }
-                            examCardDetailService.saveOrUpdateBatch(examCardDetailList);
-                        }
-                        examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
-                    }
-                    detailCourseService.saveOrUpdateBatch(examDetailCourseList);
-                    //合并pdf
-                    basicAttachmentList.add(createPdfUtil.mergePdf(basicExamRule, tbTask, examDetail, sysUser.getId(), schoolId, variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
-                }
-            }
-            if (PrintMethodEnum.AUTO == basicExamRule.getPrintMethod()) {
-                examPrintPlan.setStatus(PrintPlanStatusEnum.PRINTING);
-                examPrintPlanService.updateById(examPrintPlan);
+                List<PdfDto> variablePdfList = new ArrayList<>();//变量印品(签到表、卷袋贴)
+                List<PdfDto> ordinaryPdfList = new ArrayList<>();//普通印品(登记表)
+                List<PdfDto> paperPdfList = new ArrayList<>();//所有试卷
+                List<PdfDto> examStudentPdfList = new ArrayList<>();//所有题卡
+                List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
+                List<PdfDto> cardPdfList = new ArrayList<>();//备份题卡
+
+                //创建pdf核心逻辑
+                basicAttachmentList = createPdfCoreLogic(examDetailCourseList,
+                        examPrintPlan,
+                        examDetail,
+                        sysUser,
+                        paperTypeParam,
+                        basicAttachmentList,
+                        attachmentIds,
+                        ftlList,
+                        basicSchool,
+                        ordinaryPdfList,
+                        backupPaperPdfList,
+                        cardPdfList,
+                        variablePdfList,
+                        paperPdfList,
+                        examStudentPdfList);
+                //合并pdf
+                basicAttachmentList.add(createPdfUtil.mergePdf(basicExamRule, tbTask, examDetail, sysUser.getId(), variablePdfList, ordinaryPdfList, paperPdfList, examStudentPdfList, backupPaperPdfList, cardPdfList));
             }
+            updateExamPrintPlan(basicExamRule, examPrintPlan);
             map.computeIfAbsent("size", v -> examDetailList.size());
             //最后一步删除附件
 //            createPdfUtil.deleteAttachment(attachmentIds, ftlList);
@@ -391,6 +432,20 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         return map;
     }
 
+    /**
+     * 更新考试计划
+     *
+     * @param basicExamRule
+     * @param examPrintPlan
+     */
+    @Transactional
+    public void updateExamPrintPlan(BasicExamRule basicExamRule, ExamPrintPlan examPrintPlan) {
+        if (PrintMethodEnum.AUTO == basicExamRule.getPrintMethod()) {
+            examPrintPlan.setStatus(PrintPlanStatusEnum.PRINTING);
+            examPrintPlanService.updateById(examPrintPlan);
+        }
+    }
+
     @Transactional(rollbackFor = Exception.class)
     @Override
     public Map<String, Object> executeExaminationLogic(Map<String, Object> map) throws Exception {

+ 27 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -21,6 +21,7 @@ import org.apache.commons.codec.digest.DigestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.File;
@@ -450,13 +451,11 @@ public class CreatePdfUtil {
      * @param tbTask
      * @param examDetail
      * @param userId
-     * @param schoolId
      * @param list
      * @return
      * @throws IOException
      */
-    public BasicAttachment mergePdf(BasicExamRule basicExamRule, TBTask tbTask, ExamDetail examDetail, Long userId, Long schoolId, List<PdfDto>... list) throws IOException {
-        StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
+    public BasicAttachment mergePdf(BasicExamRule basicExamRule, TBTask tbTask, ExamDetail examDetail, Long userId, List<PdfDto>... list) throws IOException {
         List<PdfDto> mergePdfA3List = new ArrayList<>();
         List<PdfDto> mergePdfA4List = new ArrayList<>();
         List<PdfDto> mergePdfDeleteList = new ArrayList<>();
@@ -478,6 +477,31 @@ public class CreatePdfUtil {
         List<String> pathA3List = mergePdfA3List.stream().map(PdfDto::getPath).collect(Collectors.toList());
         String dirNameA4 = PdfUtil.mergePdf(pathA4List.toArray(new String[mergePdfA4List.size()]), null);
         String dirNameA3 = PdfUtil.mergePdf(pathA3List.toArray(new String[mergePdfA3List.size()]), null);
+        return mergePdfSaveDb(dirNameA4, dirNameA3, tbTask, userId, examDetail, basicExamRule, mergePdfDeleteList);
+    }
+
+    /**
+     * 合并pdf后保存数据库
+     *
+     * @param dirNameA4
+     * @param dirNameA3
+     * @param tbTask
+     * @param userId
+     * @param examDetail
+     * @param basicExamRule
+     * @param mergePdfDeleteList
+     * @return
+     * @throws IOException
+     */
+    @Transactional
+    public BasicAttachment mergePdfSaveDb(String dirNameA4,
+                                          String dirNameA3,
+                                          TBTask tbTask,
+                                          Long userId,
+                                          ExamDetail examDetail,
+                                          BasicExamRule basicExamRule,
+                                          List<PdfDto> mergePdfDeleteList) throws IOException {
+        StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
         // oss上只认"/",windows生成的路径分隔符全部替换为"/"
         File localA4PdfFile = null, localA3PdfFile = null;
         BasicAttachment basicAttachment = null;

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/TBTaskController.java

@@ -82,7 +82,7 @@ public class TBTaskController {
     public Result resetCreatePdf(@ApiParam(value = "任务id", required = true) @RequestParam String id) throws IOException {
         Long taskId = Long.parseLong(id);
         TBTask tbTask = tbTaskService.getById(taskId);
-        tbTask.setVersion(new AtomicInteger(tbTask.getVersion()).incrementAndGet());
+//        tbTask.setVersion(new AtomicInteger(tbTask.getVersion()).incrementAndGet());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         Map<String, Object> map = new HashMap<>();
         if (Objects.nonNull(tbTask.getRemark())) {