|
@@ -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("下载成功");
|
|
|
}
|