Ver Fonte

3.0.0-考试模式使用

xiaof há 3 anos atrás
pai
commit
445ce07da2

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

@@ -1151,7 +1151,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             String htmlContent;
             String htmlContent;
             // 通用模板
             // 通用模板
             if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod())) {
             if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod())) {
-                htmlContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
+                htmlContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
             } else {
             } else {
                 BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
                 BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
                 htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
                 htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);

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

@@ -57,6 +57,7 @@ import java.io.*;
 import java.lang.reflect.Field;
 import java.lang.reflect.Field;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.Function;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
@@ -169,7 +170,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     PrintCommonService printCommonService;
     PrintCommonService printCommonService;
 
 
     @Resource
     @Resource
-    private BasicPrintConfigService basicPrintConfigService;
+    private BasicExamService basicExamService;
 
 
     /**
     /**
      * 创建pdf前置条件
      * 创建pdf前置条件
@@ -216,18 +217,14 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
 
     /**
     /**
      * 创建pdf核心逻辑
      * 创建pdf核心逻辑
-     *
      * @param examDetailCourseList
      * @param examDetailCourseList
-     * @param examPrintPlan
-     * @param examDetail
-     * @param sysUser
-     * @param paperTypeParam
-     * @param basicAttachmentList
+     * @param examPrintPlan 印刷计划
+     * @param examDetail 考场对象
+     * @param sysUser 当前用户
+     * @param paperTypeParam 试卷类型
+     * @param basicAttachmentList 附件集合
      * @param attachmentIds
      * @param attachmentIds
      * @param list
      * @param list
-     * @return
-     * @throws IOException
-     * @throws DocumentException
      */
      */
     @Transactional
     @Transactional
     public List<BasicAttachment> createPdfCoreLogic(List<ExamDetailCourse> examDetailCourseList,
     public List<BasicAttachment> createPdfCoreLogic(List<ExamDetailCourse> examDetailCourseList,
@@ -242,32 +239,27 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
         if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
             Map<Long, BasicCardRule> basicCardRuleMap = new HashMap<>();
             Map<Long, BasicCardRule> basicCardRuleMap = new HashMap<>();
             for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
             for (ExamDetailCourse examDetailCourse : examDetailCourseList) {
-                List<PdfDto> paperPdfTempList = new ArrayList<>();//所有试卷
-                List<PdfDto> examStudentTempPdfList = new ArrayList<>();//所有题卡
-                List<PdfDto> backupPaperTempPdfList = new ArrayList<>();//备份试卷
-                List<PdfDto> cardPdfTempList = new ArrayList<>();//备份题卡
+                List<PdfDto> studentPaperPdfList = new ArrayList<>();//所有试卷
+                List<PdfDto> studentCardPdfList = new ArrayList<>();//所有题卡
+                List<PdfDto> backupPaperPdfList = new ArrayList<>();//备份试卷
+                List<PdfDto> backupCardPdfList = new ArrayList<>();//备份题卡
 
 
                 String printContent = examPrintPlan.getPrintContent();
                 String printContent = examPrintPlan.getPrintContent();
                 if (StringUtils.isBlank(printContent)) {
                 if (StringUtils.isBlank(printContent)) {
                     return null;
                     return null;
                 }
                 }
                 //查询试卷
                 //查询试卷
-                List<ExamTask> examTaskList = examTaskService.findByFlowStatus(sysUser.getSchoolId()
-                        , examDetailCourse.getCourseCode()
-                        , examDetailCourse.getCourseName()
-                        , examDetailCourse.getPaperNumber()
-                        , FlowStatusEnum.FINISH);
+                List<ExamTask> examTaskList = examTaskService.findByFlowStatus(sysUser.getSchoolId(), examDetailCourse.getCourseCode(), examDetailCourse.getCourseName(), examDetailCourse.getPaperNumber(), FlowStatusEnum.FINISH);
                 if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
                 if (Objects.isNull(examTaskList) || examTaskList.size() == 0) {
                     throw ExceptionResultEnum.EXAM_TASK_IS_NULL.exception();
                     throw ExceptionResultEnum.EXAM_TASK_IS_NULL.exception();
                 }
                 }
                 Set<Long> examTaskIds = examTaskList.stream().map(ExamTask::getId).collect(Collectors.toSet());
                 Set<Long> examTaskIds = examTaskList.stream().map(ExamTask::getId).collect(Collectors.toSet());
-                Map<Long, ExamTask> examTaskMap = examTaskList.stream().collect(
-                        Collectors.toMap(ExamTask::getId, Function.identity(), (dto1, dto2) -> dto1));
+                Map<Long, ExamTask> examTaskMap = examTaskList.stream().collect(Collectors.toMap(ExamTask::getId, Function.identity(), (dto1, dto2) -> dto1));
 
 
                 QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
                 QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
-                examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds)
-                        .eq(ExamTaskDetail::getEnable, true);
+                examTaskDetailQueryWrapper.lambda().in(ExamTaskDetail::getExamTaskId, examTaskIds).eq(ExamTaskDetail::getEnable, true);
                 List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
                 List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.list(examTaskDetailQueryWrapper);
+
                 JSONObject jsonObject = new JSONObject();
                 JSONObject jsonObject = new JSONObject();
                 JSONArray jsonArray = new JSONArray();
                 JSONArray jsonArray = new JSONArray();
                 for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
                 for (ExamTaskDetail examTaskDetail : examTaskDetailList) {
@@ -277,28 +269,27 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         throw ExceptionResultEnum.EXAM_CARD_IS_NULL.exception();
                         throw ExceptionResultEnum.EXAM_CARD_IS_NULL.exception();
                     }
                     }
 
 
-                    //查询题卡规则
                     ExamTask examTask = examTaskMap.get(examTaskDetail.getExamTaskId());
                     ExamTask examTask = examTaskMap.get(examTaskDetail.getExamTaskId());
+
+                    //查询题卡规则
                     BasicCardRule basicCardRule = null;
                     BasicCardRule basicCardRule = null;
-                    if (Objects.nonNull(examTask)) {
-                        if (!basicCardRuleMap.containsKey(examTask.getCardRuleId())) {
-                            basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
-                            BasicCardRule finalBasicCardRule = basicCardRule;
-                            basicCardRuleMap.computeIfAbsent(examTask.getCardRuleId(), v -> finalBasicCardRule);
-                        } else {
-                            basicCardRule = basicCardRuleMap.get(examTask.getCardRuleId());
-                        }
+                    if (!basicCardRuleMap.containsKey(examTask.getCardRuleId())) {
+                        basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
+                        BasicCardRule finalBasicCardRule = basicCardRule;
+                        basicCardRuleMap.computeIfAbsent(examTask.getCardRuleId(), v -> finalBasicCardRule);
+                    } else {
+                        basicCardRule = basicCardRuleMap.get(examTask.getCardRuleId());
                     }
                     }
-                    QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
-                    examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
-                    List<ExamCardDetail> examCardDetailList = examCardDetailService.list(examCardDetailQueryWrapper);
 
 
                     //拼装key
                     //拼装key
-                    String key = examDetail.getSchoolId()
-                            + "_" + examDetail.getExamStartTime()
-                            + "_" + examDetail.getExamEndTime()
-                            + "_" + examDetailCourse.getCourseCode()
-                            + "_" + examDetailCourse.getPaperNumber();
+                    StringJoiner stringJoiner = new StringJoiner("_");
+                    stringJoiner.add(String.valueOf(examDetail.getSchoolId()))
+                            .add(String.valueOf(examDetail.getExamStartTime()))
+                            .add(String.valueOf(examDetail.getExamEndTime()))
+                            .add(examDetailCourse.getCourseCode())
+                            .add(examDetailCourse.getPaperNumber());
+                    String key = stringJoiner.toString();
+
                     String paperType;
                     String paperType;
                     if (Objects.nonNull(paperTypeParam)) {
                     if (Objects.nonNull(paperTypeParam)) {
                         paperType = paperTypeParam;
                         paperType = paperTypeParam;
@@ -311,72 +302,139 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
 
                     //查询考生
                     //查询考生
                     QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
                     QueryWrapper<ExamStudent> examStudentQueryWrapper = new QueryWrapper<>();
-                    examStudentQueryWrapper.lambda().eq(ExamStudent::getSchoolId, sysUser.getSchoolId())
-                            .eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
+                    examStudentQueryWrapper.lambda().eq(ExamStudent::getExamDetailCourseId, examDetailCourse.getId());
                     List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
                     List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
 
 
+                    // 查询考试
+                    BasicExam basicExam = basicExamService.getById(examTask.getExamId());
+                    //
                     List<String> paperTypes = Arrays.asList(paperType.split(",")).stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList());
                     List<String> paperTypes = Arrays.asList(paperType.split(",")).stream().sorted(Comparator.comparing(String::valueOf)).collect(Collectors.toList());
-                    int i1 = 0;
-                    for (ExamStudent t : examStudentList) {
-                        int mod = i1 % examTaskDetail.getDrawCount();
-                        String stuPaperType = paperTypes.get(mod);
-                        t.setPaperType(stuPaperType);
-                        i1++;
-                    }
-
-                    List<PaperPdfDto> paperPdfDto = null;
-
                     int backupCount = examPrintPlan.getBackupCount() != null ? examPrintPlan.getBackupCount() : 0;
                     int backupCount = examPrintPlan.getBackupCount() != null ? examPrintPlan.getBackupCount() : 0;
 
 
-                    if (printContent.contains("PAPER")) {
-                        paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
-
-                        //获取试卷pdf
-                        PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperTempPdfList);
-                        if (Objects.nonNull(pdfDto)) {
-                            examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
-                        } else {
-                            examDetailCourse.setPaperPagesA3(examDetailCourse.getPaperPagesA3());
+                    if (examStudentList != null && examStudentList.size() > 0) {
+                        AtomicInteger atomicInteger = new AtomicInteger(0);
+                        for (ExamStudent t : examStudentList) {
+                            int i1 = atomicInteger.getAndIncrement();
+                            int mod = i1 % examTaskDetail.getDrawCount();
+                            t.setPaperType(paperTypes.get(mod));
                         }
                         }
-                        // 备用试卷
-                        list[0].addAll(backupPaperTempPdfList);
 
 
-                        for (ExamStudent t : examStudentList) {
+                        // 试卷
+                        if (printContent.contains("PAPER")) {
+                            List<PaperPdfDto> paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
+
+                            //获取试卷pdf
+                            PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperPdfList);
                             if (Objects.nonNull(pdfDto)) {
                             if (Objects.nonNull(pdfDto)) {
-                                createPdfUtil.getExamStudentPaperPdf(t.getPaperType(), paperPdfDto, paperPdfTempList);
+                                examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
+                            } else {
+                                examDetailCourse.setPaperPagesA3(examDetailCourse.getPaperPagesA3());
+                            }
+                            // 备用试卷
+                            list[0].addAll(backupPaperPdfList);
+
+                            for (ExamStudent t : examStudentList) {
+                                if (Objects.nonNull(pdfDto)) {
+                                    PdfDto stuPdfDto = createPdfUtil.getExamStudentPaperPdf(t.getPaperType(), paperPdfDto, studentPaperPdfList);
+                                }
                             }
                             }
+                            // 考生试卷
+                            list[2].addAll(studentPaperPdfList);
                         }
                         }
-                        // 试卷
-                        list[2].addAll(paperPdfTempList);
-                    }
 
 
-                    basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
-                    if (printContent.contains("CARD")) {
-                        for (ExamCardDetail examCardDetail : examCardDetailList) {
+                        basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
+                        if (printContent.contains("CARD")) {
+                            QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
+                            examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
+                            ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
+
                             createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
                             createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
 
 
                             //把模板页面上的 ${} 替换成实际内容
                             //把模板页面上的 ${} 替换成实际内容
-                            String cardContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
+                            String cardContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
                             String studentContent = examCardDetail.getHtmlContent();
                             String studentContent = examCardDetail.getHtmlContent();
 
 
                             for (int i = 1; i <= backupCount; i++) {
                             for (int i = 1; i <= backupCount; i++) {
-                                BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, examCard, jsonArray, sysUser.getId(), cardPdfTempList, basicCardRule);
+                                BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
                                 examDetailCourse.setCardPagesA3(basicAttachment.getPages());
                                 examDetailCourse.setCardPagesA3(basicAttachment.getPages());
                                 basicAttachmentList.add(basicAttachment);
                                 basicAttachmentList.add(basicAttachment);
                             }
                             }
                             // 备用题卡
                             // 备用题卡
-                            list[1].addAll(cardPdfTempList);
+                            list[1].addAll(backupCardPdfList);
 
 
                             for (ExamStudent t : examStudentList) {
                             for (ExamStudent t : examStudentList) {
-                                basicAttachmentList.add(createPdfUtil.examStudentHtml(attachmentIds, studentContent, t, examDetail, examDetailCourse, sysUser.getId(), examStudentTempPdfList, basicCardRule));
+                                basicAttachmentList.add(createPdfUtil.examStudentHtml(studentContent, t, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
+                            }
+                            // 题卡
+                            list[3].addAll(studentCardPdfList);
+                            jsonObject.put("card", jsonArray);
+                            examDetailCourse.setAttachmentId(jsonObject.toJSONString());
+                        }
+                        examStudentService.saveOrUpdateBatch(examStudentList);
+                    } else if (examDetail.getPrintCount() != null){
+                        // 试卷
+                        if (printContent.contains("PAPER")) {
+                            List<PaperPdfDto> paperPdfDto = createPdfUtil.getPaperPdfFile(paperType, examTaskDetail);
+
+                            //获取试卷pdf
+                            PdfDto pdfDto = createPdfUtil.getPaperPdf(paperPdfDto, backupCount, backupPaperPdfList);
+                            if (Objects.nonNull(pdfDto)) {
+                                examDetailCourse.setPaperPagesA3(pdfDto.getPageCount());
+                            } else {
+                                examDetailCourse.setPaperPagesA3(examDetailCourse.getPaperPagesA3());
                             }
                             }
+                            // 备用试卷
+                            list[0].addAll(backupPaperPdfList);
+
+                            AtomicInteger atomicInteger = new AtomicInteger(0);
+                            int i = 0;
+                            while (i < examDetail.getPrintCount()) {
+                                int i1 = atomicInteger.getAndIncrement();
+                                int mod = i1 % examTaskDetail.getDrawCount();
+                                if (Objects.nonNull(pdfDto)) {
+                                    PdfDto stuPdfDto = createPdfUtil.getExamStudentPaperPdf(paperTypes.get(mod), paperPdfDto, studentPaperPdfList);
+                                }
+                                i++;
+                            }
+
+                            // 考生试卷
+                            list[2].addAll(studentPaperPdfList);
+                        }
+
+                        basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
+                        if (printContent.contains("CARD")) {
+                            QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
+                            examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
+                            ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
+
+                            createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
+
+                            //把模板页面上的 ${} 替换成实际内容
+                            String cardContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
+
+                            for (int i = 1; i <= backupCount; i++) {
+                                BasicAttachment basicAttachment = createPdfUtil.cardHtml(String.format("%02d", i), cardContent, examDetail, examDetailCourse, jsonArray, sysUser.getId(), backupCardPdfList, basicCardRule);
+                                examDetailCourse.setCardPagesA3(basicAttachment.getPages());
+                                basicAttachmentList.add(basicAttachment);
+                            }
+                            // 备用题卡
+                            list[1].addAll(backupCardPdfList);
+
+                            int i = 0;
+                            while (i < examDetail.getPrintCount()) {
+                                ExamStudent student = new ExamStudent();
+                                student.setTicketNumber(Integer.toString(i));
+                                basicAttachmentList.add(createPdfUtil.examStudentHtml(cardContent, student, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
+                                i++;
+                            }
+
                             // 题卡
                             // 题卡
-                            list[3].addAll(examStudentTempPdfList);
+                            list[3].addAll(studentCardPdfList);
                             jsonObject.put("card", jsonArray);
                             jsonObject.put("card", jsonArray);
                             examDetailCourse.setAttachmentId(jsonObject.toJSONString());
                             examDetailCourse.setAttachmentId(jsonObject.toJSONString());
                         }
                         }
+                        examStudentService.saveOrUpdateBatch(examStudentList);
                     }
                     }
-                    examStudentService.saveOrUpdateBatch(examStudentList);
                 }
                 }
                 examDetailCourse.setAttachmentId(jsonObject.toJSONString());
                 examDetailCourse.setAttachmentId(jsonObject.toJSONString());
                 examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
                 examTaskDetailService.saveOrUpdateBatch(examTaskDetailList);
@@ -1104,7 +1162,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
             ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
             String htmlContent;
             String htmlContent;
             if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
             if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
-                htmlContent = createPdfUtil.replaceHtmlTemplete(examCardDetail);
+                htmlContent = createPdfUtil.replaceHtmlTemplate(examCardDetail);
             } else {
             } else {
                 BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
                 BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
                 htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
                 htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);

+ 85 - 91
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -86,7 +86,7 @@ public class CreatePdfUtil {
 
 
     @Resource
     @Resource
     BasicSchoolService basicSchoolService;
     BasicSchoolService basicSchoolService;
-    
+
     @Resource
     @Resource
     ExamDetailService examDetailService;
     ExamDetailService examDetailService;
 
 
@@ -365,10 +365,9 @@ public class CreatePdfUtil {
     /**
     /**
      * 替换html通用模版
      * 替换html通用模版
      *
      *
-     * @param examCardDetail
-     * @return
+     * @param examCardDetail 题卡详细内容
      */
      */
-    public String replaceHtmlTemplete(ExamCardDetail examCardDetail) {
+    public String replaceHtmlTemplate(ExamCardDetail examCardDetail) {
         String content = examCardDetail.getHtmlContent();
         String content = examCardDetail.getHtmlContent();
         log.info("contentTemp:{}", content);
         log.info("contentTemp:{}", content);
         content = content.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
         content = content.replaceAll("<img src=\"data:image/png;base64,\\$\\{examNumber\\}\">", "");
@@ -441,11 +440,9 @@ public class CreatePdfUtil {
     /**
     /**
      * 获取试卷pdf
      * 获取试卷pdf
      *
      *
-     * @param stuPaperType
-     * @param paperPdfDto
-     * @param pdfList
-     * @return
-     * @throws IOException
+     * @param stuPaperType 考生卷型
+     * @param paperPdfDto  抽取的试卷文件信息
+     * @param pdfList      考生试卷集合
      */
      */
     public PdfDto getExamStudentPaperPdf(String stuPaperType, List<PaperPdfDto> paperPdfDto, List<PdfDto> pdfList) throws IOException {
     public PdfDto getExamStudentPaperPdf(String stuPaperType, List<PaperPdfDto> paperPdfDto, List<PdfDto> pdfList) throws IOException {
         Set<Integer> pagesList = new HashSet<>();
         Set<Integer> pagesList = new HashSet<>();
@@ -468,11 +465,9 @@ public class CreatePdfUtil {
     /**
     /**
      * 获取试卷pdf
      * 获取试卷pdf
      *
      *
-     * @param paperPdfDto
-     * @param backupCount
-     * @param pdfList
-     * @return
-     * @throws IOException
+     * @param paperPdfDto 抽取的试卷文件信息
+     * @param backupCount 备份数量
+     * @param pdfList     备份试卷集合
      */
      */
     public PdfDto getPaperPdf(List<PaperPdfDto> paperPdfDto, Integer backupCount, List<PdfDto> pdfList) throws IOException {
     public PdfDto getPaperPdf(List<PaperPdfDto> paperPdfDto, Integer backupCount, List<PdfDto> pdfList) throws IOException {
         Set<Integer> pagesList = new HashSet<>();
         Set<Integer> pagesList = new HashSet<>();
@@ -497,10 +492,8 @@ public class CreatePdfUtil {
     /**
     /**
      * 获取考试试卷
      * 获取考试试卷
      *
      *
-     * @param paperType
-     * @param examTaskDetail
-     * @return
-     * @throws IOException
+     * @param paperType      抽取的试卷型(多个用,分隔)
+     * @param examTaskDetail 命题任务上传试卷信息
      */
      */
     public List<PaperPdfDto> getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws Exception {
     public List<PaperPdfDto> getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws Exception {
         String[] paperTypes = paperType.split(",");
         String[] paperTypes = paperType.split(",");
@@ -516,6 +509,7 @@ public class CreatePdfUtil {
                     throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
                     throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
                 }
                 }
                 String name = (String) object.get("name");
                 String name = (String) object.get("name");
+                // 返回抽中的试卷
                 for (String type : paperTypes) {
                 for (String type : paperTypes) {
                     if (Objects.equals(name.toUpperCase(), type.toUpperCase())) {
                     if (Objects.equals(name.toUpperCase(), type.toUpperCase())) {
                         File file = teachcloudCommonService.getFile(basicAttachment.getPath(), false);
                         File file = teachcloudCommonService.getFile(basicAttachment.getPath(), false);
@@ -710,10 +704,10 @@ public class CreatePdfUtil {
             dirNameCardA3 = dirNameCardA3.replaceAll("\\\\", "/");
             dirNameCardA3 = dirNameCardA3.replaceAll("\\\\", "/");
             localA3PdfCardFile = new File(stringJoiner.toString() + File.separator + dirNameCardA3);
             localA3PdfCardFile = new File(stringJoiner.toString() + File.separator + dirNameCardA3);
             basicAttachment = basicAttachmentService.saveAttachmentPdf(dirNameCardA3, userId);
             basicAttachment = basicAttachmentService.saveAttachmentPdf(dirNameCardA3, userId);
-            if(StringUtils.isBlank(tbTask.getImportFileName())) {
+            if (StringUtils.isBlank(tbTask.getImportFileName())) {
                 tbTask.setImportFileName(basicAttachment.getName());
                 tbTask.setImportFileName(basicAttachment.getName());
             }
             }
-            if(StringUtils.isBlank(tbTask.getImportFilePath())) {
+            if (StringUtils.isBlank(tbTask.getImportFilePath())) {
                 tbTask.setImportFilePath(basicAttachment.getPath());
                 tbTask.setImportFilePath(basicAttachment.getPath());
             }
             }
             examDetail.setCardAttachmentId(basicAttachment.getId());
             examDetail.setCardAttachmentId(basicAttachment.getId());
@@ -780,66 +774,67 @@ public class CreatePdfUtil {
     /**
     /**
      * 考生题卡html
      * 考生题卡html
      *
      *
-     * @param attachmentIds
-     * @param studentContent
-     * @param t
-     * @param examDetail
-     * @param examDetailCourse
-     * @param userId
-     * @param examStudentPdfList
-     * @return
-     * @throws IOException
+     * @param studentContent     题卡html内容
+     * @param examStudent        考生对象
+     * @param examDetail         考场对象
+     * @param examDetailCourse   考场课程对象
+     * @param userId             当前用户ID
+     * @param examStudentPdfList 考生题卡集合
+     * @param basicCardRule      题卡规则
      */
      */
-    public BasicAttachment examStudentHtml(Set<Long> attachmentIds, String studentContent, ExamStudent t, ExamDetail examDetail, ExamDetailCourse examDetailCourse, Long userId, List<PdfDto> examStudentPdfList, BasicCardRule basicCardRule) throws IOException {
-        if (Objects.nonNull(t.getAttachmentId())) {
-            attachmentIds.add(t.getAttachmentId());
-        }
+    public BasicAttachment examStudentHtml(String studentContent, ExamStudent examStudent, ExamDetail examDetail, ExamDetailCourse examDetailCourse, Long userId, List<PdfDto> examStudentPdfList, BasicCardRule basicCardRule) throws IOException {
         String studentHtml = studentContent;
         String studentHtml = studentContent;
-        if (Objects.nonNull(t.getExtendFields())) {
-            JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(t.getExtendFields());//扩展字段
-            if (Objects.nonNull(jsonObjectExtend)) {
-                for (int i = 0; i < jsonObjectExtend.size(); i++) {
-                    JSONObject object = (JSONObject) jsonObjectExtend.get(i);
-                    studentHtml = studentHtml.replaceAll("\\$\\{" + object.get("code") + "\\}", String.valueOf(object.get("value")));
+        if(examStudent.getId() != null) {
+            if (Objects.nonNull(examStudent.getExtendFields())) {
+                JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(examStudent.getExtendFields());//扩展字段
+                if (Objects.nonNull(jsonObjectExtend)) {
+                    int i = 0;
+                    while (i < jsonObjectExtend.size()) {
+                        JSONObject object = (JSONObject) jsonObjectExtend.get(i);
+                        studentHtml = studentHtml.replaceAll("\\$\\{" + object.get("code") + "\\}", String.valueOf(object.get("value")));
+                        i++;
+                    }
                 }
                 }
             }
             }
+            //生成学生考号条码并将图片转成base64
+            if (Objects.nonNull(examStudent.getTicketNumber())) {
+                studentHtml = studentHtml.replaceAll("\\$\\{examNumber\\}", GoogleBarCodeUtil.createBarCode(examStudent.getTicketNumber(), false));
+            }
+            studentHtml = studentHtml.replaceAll("\\$\\{examNumberStr\\}", examStudent.getTicketNumber());
+            //随机生成学生试卷条码并将图片转成base64
+            if (Objects.nonNull(examStudent.getPaperType())) {
+                studentHtml = studentHtml.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(examStudent.getPaperType()), false));
+            }
+            Map<String, Object> map = ConvertUtil.analyzeDateAndTime(examDetail.getExamStartTime(), examDetail.getExamEndTime());
+            String examDate = Objects.nonNull(map.get("date")) ? (String) map.get("date") : "";
+            String examTime = Objects.nonNull(map.get("time")) ? (String) map.get("time") : "";
+            studentHtml = studentHtml.replaceAll("\\$\\{examDate\\}", examDate);
+            studentHtml = studentHtml.replaceAll("\\$\\{examTime\\}", examTime);
+            studentHtml = studentHtml.replaceAll("\\$\\{ticketNumber\\}", examStudent.getTicketNumber());
+            studentHtml = studentHtml.replaceAll("\\$\\{siteNumber\\}", examStudent.getSiteNumber());
+            if (StringUtils.isNotEmpty(examStudent.getPaperType())) {
+                studentHtml = studentHtml.replaceAll("\\$\\{paperTypeName\\}", examStudent.getPaperType());
+            }
+            studentHtml = studentHtml.replaceAll("\\$\\{studentCode\\}", examStudent.getStudentCode());
+            studentHtml = studentHtml.replaceAll("\\$\\{studentName\\}", examStudent.getStudentName());
+            studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examDetailCourse.getCourseName());
+            studentHtml = studentHtml.replaceAll("\\$\\{courseCode\\}", examDetailCourse.getCourseCode());
+            studentHtml = studentHtml.replaceAll("\\$\\{examPlace\\}", examDetail.getExamPlace());
+            studentHtml = studentHtml.replaceAll("\\$\\{examRoom\\}", examDetail.getExamRoom());
+            studentHtml = studentHtml.replaceAll("\\$\\{paperNumber\\}", examDetailCourse.getPaperNumber());
+
+            List<StudentExtendDto> studentExtendDtos = createExtendObject(examStudent, basicCardRule);
+            for (StudentExtendDto extendDto : studentExtendDtos) {
+                studentHtml = studentHtml.replaceAll("\\$\\{" + extendDto.getFieldName() + "\\}", String.valueOf(extendDto.getValue()));
+            }
+
+            //学生题卡
+            BasicAttachment examStudentAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode() + "|" + examStudent.getTicketNumber(), studentHtml, userId, examStudentPdfList);
+            examStudent.setAttachmentId(examStudentAttachment.getId());
+            return examStudentAttachment;
+        } else {
+            return printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode() + "|" + examStudent.getTicketNumber(), studentHtml, userId, examStudentPdfList);
         }
         }
-        //生成学生考号条码并将图片转成base64
-        if (Objects.nonNull(t.getTicketNumber())) {
-            studentHtml = studentHtml.replaceAll("\\$\\{examNumber\\}", GoogleBarCodeUtil.createBarCode(t.getTicketNumber(), false));
-        }
-        studentHtml = studentHtml.replaceAll("\\$\\{examNumberStr\\}", t.getTicketNumber());
-        //随机生成学生试卷条码并将图片转成base64
-        if (Objects.nonNull(t.getPaperType())) {
-            studentHtml = studentHtml.replaceAll("\\$\\{paperType\\}", GoogleBarCodeUtil.createBarCode(SystemConstant.convertPaperType(t.getPaperType()), false));
-        }
-        Map<String, Object> map = ConvertUtil.analyzeDateAndTime(examDetail.getExamStartTime(), examDetail.getExamEndTime());
-        String examDate = Objects.nonNull(map.get("date")) ? (String) map.get("date") : "";
-        String examTime = Objects.nonNull(map.get("time")) ? (String) map.get("time") : "";
-        studentHtml = studentHtml.replaceAll("\\$\\{examDate\\}", examDate);
-        studentHtml = studentHtml.replaceAll("\\$\\{examTime\\}", examTime);
-        studentHtml = studentHtml.replaceAll("\\$\\{ticketNumber\\}", t.getTicketNumber());
-        studentHtml = studentHtml.replaceAll("\\$\\{siteNumber\\}", t.getSiteNumber());
-        if (StringUtils.isNotEmpty(t.getPaperType())) {
-            studentHtml = studentHtml.replaceAll("\\$\\{paperTypeName\\}", t.getPaperType());
-        }
-        studentHtml = studentHtml.replaceAll("\\$\\{studentCode\\}", t.getStudentCode());
-        studentHtml = studentHtml.replaceAll("\\$\\{studentName\\}", t.getStudentName());
-        studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examDetailCourse.getCourseName());
-        studentHtml = studentHtml.replaceAll("\\$\\{courseCode\\}", examDetailCourse.getCourseCode());
-        studentHtml = studentHtml.replaceAll("\\$\\{examPlace\\}", examDetail.getExamPlace());
-        studentHtml = studentHtml.replaceAll("\\$\\{examRoom\\}", examDetail.getExamRoom());
-        studentHtml = studentHtml.replaceAll("\\$\\{paperNumber\\}", examDetailCourse.getPaperNumber());
-
-        List<StudentExtendDto> studentExtendDtos = createExtendObject(t, basicCardRule);
-        for (StudentExtendDto extendDto : studentExtendDtos) {
-            studentHtml = studentHtml.replaceAll("\\$\\{" + extendDto.getFieldName() + "\\}", String.valueOf(extendDto.getValue()));
-        }
-
-        //学生题卡
-        BasicAttachment examStudentAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, userId, examStudentPdfList);
-        t.setAttachmentId(examStudentAttachment.getId());
-        return examStudentAttachment;
     }
     }
 
 
     /**
     /**
@@ -887,17 +882,16 @@ public class CreatePdfUtil {
     /**
     /**
      * 通用题卡html
      * 通用题卡html
      *
      *
-     * @param cardContent
-     * @param examDetailCourse
-     * @param examCard
-     * @param jsonArray
-     * @param userId
-     * @param cardPdfList
-     * @param basicCardRule
-     * @return
-     * @throws IOException
+     * @param sequence         序号
+     * @param cardContent      题卡内容
+     * @param examDetail       考场对象
+     * @param examDetailCourse 考场课程对象
+     * @param jsonArray        组装json返回
+     * @param userId           当前用户ID
+     * @param cardPdfList      备用题卡集合
+     * @param basicCardRule    题卡规则对象
      */
      */
-    public BasicAttachment cardHtml(String sequence, String cardContent, ExamDetail examDetail, ExamDetailCourse examDetailCourse, ExamCard examCard, JSONArray jsonArray, Long userId, List<PdfDto> cardPdfList, BasicCardRule basicCardRule) throws IOException {
+    public BasicAttachment cardHtml(String sequence, String cardContent, ExamDetail examDetail, ExamDetailCourse examDetailCourse, JSONArray jsonArray, Long userId, List<PdfDto> cardPdfList, BasicCardRule basicCardRule) throws IOException {
         //通用题卡
         //通用题卡
         String cardTemp = cardContent;
         String cardTemp = cardContent;
         cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", examDetailCourse.getPaperType());
         cardTemp = cardTemp.replaceAll("\\$\\{paperTypeName\\}", examDetailCourse.getPaperType());
@@ -908,9 +902,11 @@ public class CreatePdfUtil {
         if (Objects.nonNull(basicCardRule) && Objects.nonNull(basicCardRule.getExtendFields())) {
         if (Objects.nonNull(basicCardRule) && Objects.nonNull(basicCardRule.getExtendFields())) {
             JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(basicCardRule.getExtendFields());//扩展字段
             JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(basicCardRule.getExtendFields());//扩展字段
             if (Objects.nonNull(jsonObjectExtend)) {
             if (Objects.nonNull(jsonObjectExtend)) {
-                for (int i = 0; i < jsonObjectExtend.size(); i++) {
+                int i = 0;
+                while (i < jsonObjectExtend.size()) {
                     JSONObject object = (JSONObject) jsonObjectExtend.get(i);
                     JSONObject object = (JSONObject) jsonObjectExtend.get(i);
                     cardTemp = cardTemp.replaceAll("\\$\\{" + object.get("code") + "\\}", "");
                     cardTemp = cardTemp.replaceAll("\\$\\{" + object.get("code") + "\\}", "");
+                    i++;
                 }
                 }
             }
             }
         }
         }
@@ -929,13 +925,11 @@ public class CreatePdfUtil {
 
 
         //通用题卡生成卷袋贴条码
         //通用题卡生成卷袋贴条码
         String packageCode = examDetail.getPackageCode() + sequence;
         String packageCode = examDetail.getPackageCode() + sequence;
-        String packageCodeImg = null;
-        if (Objects.nonNull(packageCode)) {
-            packageCodeImg = GoogleBarCodeUtil.createBarCode(packageCode, false);
-        }
+        String packageCodeImg = GoogleBarCodeUtil.createBarCode(packageCode, false);
+
         String packageCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 10px;right: 25%;margin-left: -100px;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + packageCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + packageCode + "</p></div>";
         String packageCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 10px;right: 25%;margin-left: -100px;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + packageCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + packageCode + "</p></div>";
         cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", packageCodeDiv);
         cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", packageCodeDiv);
-        BasicAttachment cardAttachment = printCommonService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examDetailCourse.getCourseCode(), cardTemp, userId, cardPdfList);
+        BasicAttachment cardAttachment = printCommonService.saveAttachmentHtml(examDetail.getSchoolId() + "|" + examDetailCourse.getCourseCode(), cardTemp, userId, cardPdfList);
         JSONObject object = new JSONObject();
         JSONObject object = new JSONObject();
         object.put("name", examDetailCourse.getPaperType());
         object.put("name", examDetailCourse.getPaperType());
         object.put("examDetailCourseId", examDetailCourse.getId());
         object.put("examDetailCourseId", examDetailCourse.getId());