wangliang 2 жил өмнө
parent
commit
fef136211b

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

@@ -387,6 +387,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     // 题卡数据组装
                     basicAttachmentList = Objects.isNull(basicAttachmentList) ? new ArrayList<>() : basicAttachmentList;
                     if (printContent.contains("CARD")) {
+                        Map<String, ExamCardDetail> examCardDetailMap = new HashMap<>();
+                        Map<String, String> cardContentMap = new HashMap<>();
                         for (String s : paperTypes) {
                             examCard = examCardMap.get(s);
                             Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("卷型" + s + "题卡不存在"));
@@ -407,43 +409,45 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             }
                             // 备用题卡
                             list[1].addAll(backupCardPdfList);
+                            examCardDetailMap.put(s, examCardDetail);
+                            cardContentMap.put(s, cardContent);
+                        }
 
-                            if (examStudentList != null && examStudentList.size() > 0) {
-                                for (ExamStudent t : examStudentList) {
-                                    // 用带条码的模板
-                                    basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetail.getHtmlContent(), t, s, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
-                                }
-                            } else if (examDetail.getPrintCount() != null) {
-                                AtomicInteger atomicInteger = new AtomicInteger(0);
-                                Map<String, BasicAttachment> stringBasicAttachmentMap = new HashMap<>();
-                                int i = 0;
-                                while (i < examDetail.getPrintCount()) {
-                                    int seq = atomicInteger.getAndIncrement();
-                                    int mod = seq % examTaskDetail.getDrawCount();
-                                    String tempPaperType = paperTypes.get(mod);
-                                    BasicAttachment basicAttachment = createPdfUtil.examStudentHtml(cardContent, null, tempPaperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule);
-
-                                    if (!stringBasicAttachmentMap.containsKey(tempPaperType)) {
-                                        stringBasicAttachmentMap.put(tempPaperType, basicAttachment);
-                                        JSONObject object = new JSONObject();
-                                        object.put("name", tempPaperType);
-                                        object.put("attachmentId", basicAttachment.getId());
-                                        stuJsonArray.add(object);
-
-                                        // 用不带条码的模板
-                                        basicAttachmentList.add(basicAttachment);
-                                    }
-                                    i++;
+                        if (examStudentList != null && examStudentList.size() > 0) {
+                            for (ExamStudent t : examStudentList) {
+                                // 用带条码的模板
+                                basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetailMap.get(t.getPaperType()).getHtmlContent(), t, paperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
+                            }
+                        } else if (examDetail.getPrintCount() != null) {
+                            AtomicInteger atomicInteger = new AtomicInteger(0);
+                            Map<String, BasicAttachment> stringBasicAttachmentMap = new HashMap<>();
+                            int i = 0;
+                            while (i < examDetail.getPrintCount()) {
+                                int seq = atomicInteger.getAndIncrement();
+                                int mod = seq % examTaskDetail.getDrawCount();
+                                String tempPaperType = paperTypes.get(mod);
+                                BasicAttachment basicAttachment = createPdfUtil.examStudentHtml(cardContentMap.get(tempPaperType), null, tempPaperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule);
+
+                                if (!stringBasicAttachmentMap.containsKey(tempPaperType)) {
+                                    stringBasicAttachmentMap.put(tempPaperType, basicAttachment);
+                                    JSONObject object = new JSONObject();
+                                    object.put("name", tempPaperType);
+                                    object.put("attachmentId", basicAttachment.getId());
+                                    stuJsonArray.add(object);
+
+                                    // 用不带条码的模板
+                                    basicAttachmentList.add(basicAttachment);
                                 }
-                            } else {
-                                throw ExceptionResultEnum.ERROR.exception("数据错误:未找到考生或者印刷数量");
+                                i++;
                             }
-                            // 题卡
-                            list[3].addAll(studentCardPdfList);
-                            jsonObject.put("card", jsonArray);
-                            examDetailCourse.setAttachmentId(jsonObject.toJSONString());
-                            examDetailCourse.setCommonAttachmentId(stuJsonArray.toJSONString());
+                        } else {
+                            throw ExceptionResultEnum.ERROR.exception("数据错误:未找到考生或者印刷数量");
                         }
+                        // 题卡
+                        list[3].addAll(studentCardPdfList);
+                        jsonObject.put("card", jsonArray);
+                        examDetailCourse.setAttachmentId(jsonObject.toJSONString());
+                        examDetailCourse.setCommonAttachmentId(stuJsonArray.toJSONString());
                     }
                     examStudentService.saveOrUpdateBatch(examStudentList);
                 }