Переглянути джерело

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

xiaof 4 роки тому
батько
коміт
cc8989bee4

+ 0 - 52
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/OrgCenterTypeEnum.java

@@ -1,52 +0,0 @@
-package com.qmth.distributed.print.business.enums;
-
-import com.qmth.distributed.print.business.enums.result.EnumResult;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Description: 机构用户中心机构类别
- * @Author: CaoZixuan
- * @Date: 2021-03-27
- */
-public enum OrgCenterTypeEnum {
-    NETWORK("NETWORK","高校网院"),
-    COLLEGE("COLLEGE","高校教务处"),
-    UNDERGRADUATE("UNDERGRADUATE","本科招办"),
-    POSTGRADUATE("COLLEGE","研究生招办"),
-    MINISTRY("MINISTRY","考试院"),
-    AOPENG("AOPENG","奥鹏"),
-    PARTNER("PARTNER","合作机构"),
-    OTHER("OTHER","其他"),
-    ;
-
-    OrgCenterTypeEnum(String typeCode, String typeName) {
-        this.typeCode = typeCode;
-        this.typeName = typeName;
-    }
-
-    private final String typeCode;
-    private final String typeName;
-
-    public String getTypeCode() {
-        return typeCode;
-    }
-
-    public String getTypeName() {
-        return typeName;
-    }
-    public static List<EnumResult> listTypes() {
-        List<EnumResult> list = new ArrayList<EnumResult>();
-        for (OrgCenterTypeEnum value : OrgCenterTypeEnum.values()) {
-            EnumResult result = new EnumResult();
-            result.setName(value.name());
-            result.setOrdinal(value.ordinal());
-            result.setCode(value.getTypeCode());
-            result.setDesc(value.getTypeName());
-            list.add(result);
-        }
-        return list;
-    }
-
-}

+ 15 - 27
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/OrgCenterDataDisposeServiceImpl.java

@@ -1,22 +1,18 @@
 package com.qmth.distributed.print.business.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.qmth.distributed.print.business.entity.BasicSchool;
-import com.qmth.distributed.print.business.enums.OrgCenterTypeEnum;
 import com.qmth.distributed.print.business.service.BasicSchoolService;
 import com.qmth.distributed.print.business.service.CallApiOrgCenterService;
 import com.qmth.distributed.print.business.service.OrgCenterDataDisposeService;
 import com.qmth.distributed.print.common.contant.SystemConstant;
-import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -44,17 +40,17 @@ public class OrgCenterDataDisposeServiceImpl implements OrgCenterDataDisposeServ
         List<Long> needDisable = new ArrayList<>();
         List<Long> needDelete = new ArrayList<>();
         for (Long aLong : oldIdList) {
-            if (!newIdList.contains(aLong)){
+            if (!newIdList.contains(aLong)) {
                 needDisable.add(aLong);
-            }else {
+            } else {
                 needDelete.add(aLong);
             }
         }
-        if (needDisable.size() > 0){
-            basicSchoolService.update(new UpdateWrapper<BasicSchool>().lambda().set(BasicSchool::getEnable,false).in(BasicSchool::getId,needDisable));
+        if (needDisable.size() > 0) {
+            basicSchoolService.update(new UpdateWrapper<BasicSchool>().lambda().set(BasicSchool::getEnable, false).in(BasicSchool::getId, needDisable));
         }
-        if (needDelete.size() > 0){
-            basicSchoolService.remove(new QueryWrapper<BasicSchool>().lambda().in(BasicSchool::getId,needDelete));
+        if (needDelete.size() > 0) {
+            basicSchoolService.remove(new QueryWrapper<BasicSchool>().lambda().in(BasicSchool::getId, needDelete));
         }
 
         for (Map map : result) {
@@ -64,23 +60,15 @@ public class OrgCenterDataDisposeServiceImpl implements OrgCenterDataDisposeServ
             String logo = String.valueOf(map.get("logo"));
             String accessKey = String.valueOf(map.get("accessKey"));
             String accessSecret = String.valueOf(map.get("accessSecret"));
-            Map typeMap = JSONObject.parseObject(String.valueOf(map.get("type")));
-            String typeCode = String.valueOf(typeMap.get("code"));
-            String typeName = String.valueOf(typeMap.get("name"));
-            if (!Arrays.stream(OrgCenterTypeEnum.values()).map(OrgCenterTypeEnum::getTypeCode).collect(Collectors.toList()).contains(typeCode)){
-                throw ExceptionResultEnum.ERROR.exception("机构类型在枚举中不存在 + typeCode = " + typeCode);
-            }
-            if (!OrgCenterTypeEnum.PARTNER.getTypeCode().equals(typeCode)){
-                BasicSchool school = new BasicSchool();
-                school.setId(id);
-                school.setCode(code);
-                school.setName(name);
-                school.setEnable(true);
-                school.setAccessKey(accessKey);
-                school.setAccessSecret(accessSecret);
-                school.setLogo(logo);
-                basicSchoolService.save(school);
-            }
+            BasicSchool school = new BasicSchool();
+            school.setId(id);
+            school.setCode(code);
+            school.setName(name);
+            school.setEnable(true);
+            school.setAccessKey(accessKey);
+            school.setAccessSecret(accessSecret);
+            school.setLogo(logo);
+            basicSchoolService.save(school);
         }
     }
 }

+ 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 {

+ 41 - 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;
@@ -621,6 +645,20 @@ public class CreatePdfUtil {
         if (Objects.nonNull(examDetailCourse.getPaperType())) {
             cardTemp = cardTemp.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(examDetailCourse.getPaperType()), false));
         }
+        Map<String, Object> map = ConvertUtil.analyzeDateAndTime(examDetail.getExamStartTime(), examDetail.getExamEndTime());
+        cardTemp = cardTemp.replaceAll("\\$\\{examDate\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{examTime\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{ticketNumber\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{siteNumber\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{studentCode\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{studentName\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{courseName\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{courseCode\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{examPlace\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{examRoom\\}", "");
+        cardTemp = cardTemp.replaceAll("\\$\\{paperNumber\\}", "");
+
         //通用题卡生成卷袋贴条码
         String packageCode = examDetail.getPackageCode() + sequence;
         String packageCodeImg = null;

+ 4 - 7
distributed-print/src/main/java/com/qmth/distributed/print/api/EnumsController.java

@@ -85,19 +85,16 @@ public class EnumsController {
         } else if (type.equals(EnumType.CARD_REQUIRED_FIELDS.name())) {
             //题卡必选字段
             list = CardRequiredFieldsEnum.listTypes();
-        } else if (type.equals(EnumType.ORG_CENTER_TYPE_ENUM.name())){
-            //机构用户中心类型
-            list = OrgCenterTypeEnum.listTypes();
-        } else if (type.equals(EnumType.PRINT_PLAN_STATUS_ENUM.name())){
+        } else if (type.equals(EnumType.PRINT_PLAN_STATUS_ENUM.name())) {
             //印刷计划状态
             list = PrintPlanStatusEnum.listTypes();
-        } else if (type.equals(EnumType.MAKE_METHOD.name())){
+        } else if (type.equals(EnumType.MAKE_METHOD.name())) {
             // 题卡制作方式
             list = MakeMethodEnum.listTypes();
-        } else if (type.equals(EnumType.CARD_TYPE.name())){
+        } else if (type.equals(EnumType.CARD_TYPE.name())) {
             // 题卡类型
             list = CardTypeEnum.listTypes();
-        } else if (type.equals(EnumType.EXAM_DETAIL_STATUS_ENUM.name())){
+        } else if (type.equals(EnumType.EXAM_DETAIL_STATUS_ENUM.name())) {
             // 考场状态
             list = ExamDetailStatusEnum.listTypes();
         }

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

@@ -1,7 +1,6 @@
 package com.qmth.distributed.print.api;
 
 import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.boot.api.constant.ApiConstant;
@@ -18,7 +17,6 @@ import com.qmth.distributed.print.business.service.TBTaskService;
 import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.contant.SystemConstant;
-import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
 import io.swagger.annotations.*;
@@ -67,7 +65,10 @@ public class TBTaskController {
         if (Objects.nonNull(taskListResultIPage) && Objects.nonNull(taskListResultIPage.getRecords()) && taskListResultIPage.getRecords().size() > 0) {
             List<TaskListResult> taskListResultList = taskListResultIPage.getRecords();
             for (TaskListResult taskListResult : taskListResultList) {
-                if (Objects.equals(taskListResult.getStatus(), TaskStatusEnum.FINISH.getTitle()) && Objects.equals(taskListResult.getResult(), TaskResultEnum.ERROR.getTitle()) && taskListResult.getResetCount() >= dictionaryConfig.sysDomain().getAutoCreatePdfResetMaxCount()) {
+                if (Objects.equals(taskListResult.getStatus(), TaskStatusEnum.FINISH.getTitle()) && Objects.equals(taskListResult.getResult(), TaskResultEnum.ERROR.getTitle())
+//                        && taskListResult.getResetCount() >= dictionaryConfig.sysDomain().getAutoCreatePdfResetMaxCount()
+                        && Objects.equals(taskListResult.getType(), TaskTypeEnum.CREATE_PDF.getTitle())
+                ) {
                     taskListResult.setResetCreatePdf(true);
                 }
             }
@@ -81,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())) {

+ 7 - 7
distributed-print/src/main/java/com/qmth/distributed/print/start/StartRunning.java

@@ -52,13 +52,13 @@ public class StartRunning implements CommandLineRunner {
         quartzService.addJob(TimedSyncSchoolJob.class, JobEnum.TIMED_SYNC_SCHOOL_JOB.name(), JobEnum.TIMED_TASK_JOB_GROUP.name(), "0 0 0 * * ?", schoolJobMap);
         log.info("增加学校信息同步定时任务 end");
 
-        log.info("增加重新生成pdf定时任务 start");
-        Map taskJobMap = new HashMap();
-        schoolJobMap.computeIfAbsent("name", v -> ResetCreatePdfJob.class.getName());
-        quartzService.deleteJob(JobEnum.RESET_CREATE_PDF_JOB.name(), JobEnum.RESET_CREATE_PDF_JOB_GROUP.name());
-        // 每天0点定时任务
-        quartzService.addJob(ResetCreatePdfJob.class, JobEnum.RESET_CREATE_PDF_JOB.name(), JobEnum.RESET_CREATE_PDF_JOB_GROUP.name(), "0 0/1 * * * ?", taskJobMap);
-        log.info("增加重新生成pdf定时任务 end");
+//        log.info("增加重新生成pdf定时任务 start");
+//        Map taskJobMap = new HashMap();
+//        schoolJobMap.computeIfAbsent("name", v -> ResetCreatePdfJob.class.getName());
+//        quartzService.deleteJob(JobEnum.RESET_CREATE_PDF_JOB.name(), JobEnum.RESET_CREATE_PDF_JOB_GROUP.name());
+//         //每天0点定时任务
+//        quartzService.addJob(ResetCreatePdfJob.class, JobEnum.RESET_CREATE_PDF_JOB.name(), JobEnum.RESET_CREATE_PDF_JOB_GROUP.name(), "0 0/1 * * * ?", taskJobMap);
+//        log.info("增加重新生成pdf定时任务 end");
 
 //        log.info("增加任务到期提醒定时任务 start");
 //        Map expireJobMap = new HashMap();