瀏覽代碼

创建pdf题卡修改

wangliang 2 年之前
父節點
當前提交
8fad03ae1f

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

@@ -387,58 +387,63 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     // 题卡数据组装
                     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);
+                        for (String s : paperTypes) {
+                            examCard = examCardMap.get(s);
+                            Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("卷型" + s + "题卡不存在"));
 
-                        createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
+                            QueryWrapper<ExamCardDetail> examCardDetailQueryWrapper = new QueryWrapper<>();
+                            examCardDetailQueryWrapper.lambda().eq(ExamCardDetail::getCardId, examCard.getId());
+                            ExamCardDetail examCardDetail = examCardDetailService.getOne(examCardDetailQueryWrapper);
 
-                        //把模板页面上的 ${} 替换成实际内容
-                        String cardContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
+                            createPdfUtil.getCardAttachmentId(examCardDetail, attachmentIds);
 
-                        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);
+                            //把模板页面上的 ${} 替换成实际内容
+                            String cardContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
 
-                        if (examStudentList != null && examStudentList.size() > 0) {
-                            for (ExamStudent t : examStudentList) {
-                                // 用带条码的模板
-                                basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetail.getHtmlContent(), t, paperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
+                            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);
                             }
-                        } 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);
+                            // 备用题卡
+                            list[1].addAll(backupCardPdfList);
+
+                            if (examStudentList != null && examStudentList.size() > 0) {
+                                for (ExamStudent t : examStudentList) {
+                                    // 用带条码的模板
+                                    basicAttachmentList.add(createPdfUtil.examStudentHtml(examCardDetail.getHtmlContent(), t, paperType, examDetail, examDetailCourse, sysUser.getId(), studentCardPdfList, basicCardRule));
                                 }
-                                i++;
+                            } 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++;
+                                }
+                            } else {
+                                throw ExceptionResultEnum.ERROR.exception("数据错误:未找到考生或者印刷数量");
                             }
-                        } else {
-                            throw ExceptionResultEnum.ERROR.exception("数据错误:未找到考生或者印刷数量");
+                            // 题卡
+                            list[3].addAll(studentCardPdfList);
+                            jsonObject.put("card", jsonArray);
+                            examDetailCourse.setAttachmentId(jsonObject.toJSONString());
+                            examDetailCourse.setCommonAttachmentId(stuJsonArray.toJSONString());
                         }
-                        // 题卡
-                        list[3].addAll(studentCardPdfList);
-                        jsonObject.put("card", jsonArray);
-                        examDetailCourse.setAttachmentId(jsonObject.toJSONString());
-                        examDetailCourse.setCommonAttachmentId(stuJsonArray.toJSONString());
                     }
                     examStudentService.saveOrUpdateBatch(examStudentList);
                 }
@@ -1022,10 +1027,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 Long attachmentId = paperInfo.getAttachmentId();
                 Long cardId = paperInfo.getCardId();
                 String paperType = paperInfo.getName();
-                if (SystemConstant.longNotNull(attachmentId)){
+                if (SystemConstant.longNotNull(attachmentId)) {
                     attPaperIds.add(attachmentId);
                 }
-                if (SystemConstant.longNotNull(cardId)){
+                if (SystemConstant.longNotNull(cardId)) {
                     ExamCardDto examCardDto = new ExamCardDto();
                     examCardDto.setCardId(cardId);
                     examCardDto.setPaperType(paperType);
@@ -1094,7 +1099,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
                     // 题卡路径
                     String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
-                    if (SystemConstant.strNotNull(paperType)){
+                    if (SystemConstant.strNotNull(paperType)) {
                         cardPath = cardPath + "(" + paperType + ")";
                     }
                     UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
@@ -1115,7 +1120,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
                     // 题卡路径
                     String cardPath = firstPath + File.separator + "题卡" + File.separator + examCard.getTitle();
-                    if (SystemConstant.strNotNull(paperType)){
+                    if (SystemConstant.strNotNull(paperType)) {
                         cardPath = cardPath + "(" + paperType + ")";
                     }
                     cardPath = cardPath + SystemConstant.HTML_PREFIX;