Browse Source

3.4.2 update-1224 无试卷下载报错

xiaofei 5 months ago
parent
commit
c5114e461b

+ 3 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DownloadServiceImpl.java

@@ -112,9 +112,8 @@ public class DownloadServiceImpl implements DownloadService {
                     if (StringUtils.isNotBlank(attachmentId)) {
                         // 试卷
                         BasicAttachment attachment = basicAttachmentMapper.selectById(attachmentId);
-                        if (attachment == null) {
-                            throw ExceptionResultEnum.ERROR.exception("附件数据异常");
-                        }
+                        Optional.ofNullable(attachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未查询到试卷"));
+
                         String paperPath = rootPath + File.separator + examTask.getCourseName().replaceAll(" ", "") + SystemConstant.HYPHEN + examTask.getCourseCode() + File.separator + examTask.getPaperNumber();
                         String fileName = "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "试卷" + SystemConstant.HYPHEN + attachment.getName() + SystemConstant.HYPHEN + paperType + attachment.getType();
                         fileList.add(attachmentCommonService.downloadFile(paperPath, fileName, attachment));
@@ -125,6 +124,7 @@ public class DownloadServiceImpl implements DownloadService {
                     // 题卡
                     if (StringUtils.isNotBlank(cardId)) {
                         ExamCard examCard = examCardMapper.selectById(cardId);
+                        Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未查询到题卡"));
 
                         String cardPath = rootPath + File.separator + examTask.getCourseName().replaceAll(" ", "") + SystemConstant.HYPHEN + examTask.getCourseCode() + File.separator + examTask.getPaperNumber();
                         String cardHtmlPath = cardPath + File.separator + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + examTask.getCourseName() + SystemConstant.HYPHEN + paperType + SystemConstant.HTML_PREFIX;

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

@@ -1026,19 +1026,23 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                 List<PaperInfoVo> paperInfoVoList = ExamTaskUtil.parsePaperAttachmentPath(examTaskDetail.getPaperAttachmentIds());
                 // 试卷
                 for (PaperInfoVo paperInfoVo : paperInfoVoList) {
-                    Long attachmentId = Long.valueOf(paperInfoVo.getAttachmentId());
                     String name = paperInfoVo.getName();
-                    if (Objects.nonNull(attachmentId)) {
+
+                    // 试卷
+                    String attachmentId = paperInfoVo.getAttachmentId();
+                    if (StringUtils.isNotBlank(attachmentId)) {
                         BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
-                        Optional.ofNullable(attachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("附件数据异常"));
+                        Optional.ofNullable(attachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未查询到试卷"));
+
                         String fileName = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "试卷" + SystemConstant.HYPHEN + name + attachment.getType();
                         fileUploadService.downloadFile(attachment, fileName);
                     }
 
                     // 题卡
-                    Long cardId = Long.valueOf(paperInfoVo.getCardId());
-                    if (cardId != null) {
+                    String cardId = paperInfoVo.getCardId();
+                    if (StringUtils.isNotBlank(cardId)) {
                         ExamCard examCard = examCardService.getById(cardId);
+                        Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未查询到题卡"));
 
                         String cardHtmlPath = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.HTML_PREFIX;
                         String cardPdfPath = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.PDF_PREFIX;

+ 66 - 58
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/DownloadLogicServiceImpl.java

@@ -292,41 +292,45 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
                             throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
                         }
                         for (PaperInfoVo paperInfoVo : paperInfoVoList) {
-                            Long attachmentId = Long.valueOf(paperInfoVo.getAttachmentId());
                             String name = paperInfoVo.getName();
-                            if (Objects.nonNull(attachmentId)) {
+                            String attachmentId = paperInfoVo.getAttachmentId();
+                            if (StringUtils.isNotBlank(attachmentId)) {
                                 BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
+                                Optional.ofNullable(attachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("课程[" + examTask.getCourseName() + "(" + examTask.getCourseCode() + ")]、试卷编号[" + examTask.getPaperNumber() + "]命题任务未查询到卷型[" + paperInfoVo.getName() + "]试卷"));
+
                                 if (Objects.nonNull(attachment)) {
                                     String fileName = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "试卷" + SystemConstant.HYPHEN + name + attachment.getType();
                                     File paperFile = fileUploadService.downloadFile(attachment, fileName);
                                     sourceFileList.add(paperFile);
                                 }
                             }
-                            Long cardId = Long.valueOf(paperInfoVo.getCardId());
-                            ExamCard examCard = examCardService.getById(cardId);
-                            Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("找不到答题卡"));
-
-                            String cardHtmlPath = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.HTML_PREFIX;
-                            String cardPdfPath = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.PDF_PREFIX;
-                            // 通用题卡
-                            String htmlContent = createPdfUtil.replaceBlankHtmlContent(examCard.getHtmlContent(), examCard.getCourseId());
-                            // html
-                            File localFile = new File(cardHtmlPath);
-                            if (!localFile.exists()) {
-                                localFile.getParentFile().mkdirs();
-                                localFile.createNewFile();
-                            }
-                            // 生成html文件
-                            FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), localFile);
-                            sourceFileList.add(localFile);
-                            // 转pdf文件
-                            File file = new File(cardPdfPath);
-                            if (!file.exists()) {
-                                file.getParentFile().mkdirs();
-                                file.createNewFile();
+                            String cardId = paperInfoVo.getCardId();
+                            if (StringUtils.isNotBlank(cardId)) {
+                                ExamCard examCard = examCardService.getById(cardId);
+                                Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("课程[" + examTask.getCourseName() + "(" + examTask.getCourseCode() + ")]、试卷编号[" + examTask.getPaperNumber() + "]命题任务未查询到卷型[" + paperInfoVo.getName() + "]题卡"));
+
+                                String cardHtmlPath = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.HTML_PREFIX;
+                                String cardPdfPath = dirPath + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.PDF_PREFIX;
+                                // 通用题卡
+                                String htmlContent = createPdfUtil.replaceBlankHtmlContent(examCard.getHtmlContent(), examCard.getCourseId());
+                                // html
+                                File localFile = new File(cardHtmlPath);
+                                if (!localFile.exists()) {
+                                    localFile.getParentFile().mkdirs();
+                                    localFile.createNewFile();
+                                }
+                                // 生成html文件
+                                FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), localFile);
+                                sourceFileList.add(localFile);
+                                // 转pdf文件
+                                File file = new File(cardPdfPath);
+                                if (!file.exists()) {
+                                    file.getParentFile().mkdirs();
+                                    file.createNewFile();
+                                }
+                                HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, "8K".equals(examCard.getPageSize()) ? PageSizeEnum.K8 : PageSizeEnum.valueOf(examCard.getPageSize()));
+                                sourceFileList.add(file);
                             }
-                            HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, "8K".equals(examCard.getPageSize()) ? PageSizeEnum.K8 : PageSizeEnum.valueOf(examCard.getPageSize()));
-                            sourceFileList.add(file);
                         }
                     }
                 }
@@ -607,9 +611,11 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
                             } else {
                                 paperFileNamePath = paperFileNamePath + "." + FilenameUtils.getExtension(paperInfoVo.getFilename());
                             }
-                            Long attachmentId = Long.valueOf(paperInfoVo.getAttachmentId());
-                            if (Objects.nonNull(attachmentId)) {
+                            String attachmentId = paperInfoVo.getAttachmentId();
+                            if (StringUtils.isNotBlank(attachmentId)) {
                                 BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
+                                Optional.ofNullable(attachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("课程[" + examTaskDetailDto.getCourseName() + "(" + examTaskDetailDto.getCourseCode() + ")]、试卷编号[" + examTaskDetailDto.getPaperNumber() + "]命题任务未查询到卷型[" + paperInfoVo.getName() + "]试卷"));
+
                                 if (Objects.nonNull(attachment)) {
                                     String fileName = trimWhiteSpace(zipLocalRootPath + File.separator + secondPath + File.separator + spliceFileName(paperFileNamePath, SystemConstant.PDF_PREFIX));
                                     fileUploadService.downloadFile(attachment, fileName);
@@ -618,38 +624,40 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
                         }
                         // 下载题卡
                         if (downloadCard) {
-                            Long cardId = Long.valueOf(paperInfoVo.getCardId());
-                            ExamCard examCard = examCardService.getById(cardId);
-                            Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("课程[" + examTaskDetailDto.getCourseName() + "(" + examTaskDetailDto.getCourseCode() + ")]、试卷编号[" + examTaskDetailDto.getPaperNumber() + "]命题任务未找到卷型[" + paperInfoVo.getName() + "]题卡"));
-
-                            String cardHtmlPath = zipLocalRootPath + File.separator + secondPath + File.separator + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
-                            String cardPdfPath = zipLocalRootPath + File.separator + secondPath + File.separator + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
-                            // 原文件名
-                            if (namedByOriginalFile) {
-                                cardHtmlPath = trimWhiteSpace(cardHtmlPath + SystemConstant.HYPHEN + examCard.getTitle() + SystemConstant.HTML_PREFIX);
-                                cardPdfPath = trimWhiteSpace(cardPdfPath + SystemConstant.HYPHEN + examCard.getTitle() + SystemConstant.PDF_PREFIX);
-                            } else {
-                                cardHtmlPath = trimWhiteSpace(cardHtmlPath + SystemConstant.HTML_PREFIX);
-                                cardPdfPath = trimWhiteSpace(cardPdfPath + SystemConstant.PDF_PREFIX);
-                            }
+                            String cardId = paperInfoVo.getCardId();
+                            if (StringUtils.isNotBlank(cardId)) {
+                                ExamCard examCard = examCardService.getById(cardId);
+                                Optional.ofNullable(examCard).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("课程[" + examTaskDetailDto.getCourseName() + "(" + examTaskDetailDto.getCourseCode() + ")]、试卷编号[" + examTaskDetailDto.getPaperNumber() + "]命题任务未查询到卷型[" + paperInfoVo.getName() + "]题卡"));
+
+                                String cardHtmlPath = zipLocalRootPath + File.separator + secondPath + File.separator + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
+                                String cardPdfPath = zipLocalRootPath + File.separator + secondPath + File.separator + "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "题卡" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
+                                // 原文件名
+                                if (namedByOriginalFile) {
+                                    cardHtmlPath = trimWhiteSpace(cardHtmlPath + SystemConstant.HYPHEN + examCard.getTitle() + SystemConstant.HTML_PREFIX);
+                                    cardPdfPath = trimWhiteSpace(cardPdfPath + SystemConstant.HYPHEN + examCard.getTitle() + SystemConstant.PDF_PREFIX);
+                                } else {
+                                    cardHtmlPath = trimWhiteSpace(cardHtmlPath + SystemConstant.HTML_PREFIX);
+                                    cardPdfPath = trimWhiteSpace(cardPdfPath + SystemConstant.PDF_PREFIX);
+                                }
 
-                            // html
-                            File localFile = new File(cardHtmlPath);
-                            if (!localFile.exists()) {
-                                localFile.getParentFile().mkdirs();
-                                localFile.createNewFile();
-                            }
-                            // 通用题卡
-                            String htmlContent = createPdfUtil.replaceBlankHtmlContent(examCard.getHtmlContent(), examCard.getCourseId());
-                            // 生成html文件
-                            FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), localFile);
-                            // 转pdf文件
-                            File file = new File(cardPdfPath);
-                            if (!file.exists()) {
-                                file.getParentFile().mkdirs();
-                                file.createNewFile();
+                                // html
+                                File localFile = new File(cardHtmlPath);
+                                if (!localFile.exists()) {
+                                    localFile.getParentFile().mkdirs();
+                                    localFile.createNewFile();
+                                }
+                                // 通用题卡
+                                String htmlContent = createPdfUtil.replaceBlankHtmlContent(examCard.getHtmlContent(), examCard.getCourseId());
+                                // 生成html文件
+                                FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), localFile);
+                                // 转pdf文件
+                                File file = new File(cardPdfPath);
+                                if (!file.exists()) {
+                                    file.getParentFile().mkdirs();
+                                    file.createNewFile();
+                                }
+                                HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, "8K".equals(examCard.getPageSize()) ? PageSizeEnum.K8 : PageSizeEnum.valueOf(examCard.getPageSize()));
                             }
-                            HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, "8K".equals(examCard.getPageSize()) ? PageSizeEnum.K8 : PageSizeEnum.valueOf(examCard.getPageSize()));
                         }
                         examTaskPaperExportDto.setResult("下载成功");
                     }