|
@@ -545,28 +545,34 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
|
|
|
List<ExamTaskPaperExportDto> examTaskPaperExportDtoList = new ArrayList<>();
|
|
|
for (ExamTaskDetailDto examTaskDetailDto : examTaskDetailDtoList) {
|
|
|
ExamTaskPaperExportDto examTaskPaperExportDto = new ExamTaskPaperExportDto(examTaskDetailDto);
|
|
|
- examTaskPaperExportDtoList.add(examTaskPaperExportDto);
|
|
|
- List<PaperInfoVo> paperInfoVoList = ExamTaskUtil.parsePaperAttachmentPath(examTaskDetailDto.getPaperAttachmentIds());
|
|
|
+ List<ExamTaskDetail> examTaskDetailList = examTaskDetailService.listByExamTaskId(examTaskDetailDto.getId());
|
|
|
+ if (CollectionUtils.isEmpty(examTaskDetailList)) {
|
|
|
+ examTaskPaperExportDto.setResult("未找到试卷,下载失败");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ examTaskPaperExportDto.setPaperType(examTaskDetailList.stream().map(m -> String.valueOf(m.getSerialNumber())).collect(Collectors.joining(",")));
|
|
|
+ examTaskPaperExportDto.setExposedPaperType(examTaskDetailList.stream().filter(m -> m.getExposed()).map(m -> String.valueOf(m.getSerialNumber())).collect(Collectors.joining(",")));
|
|
|
+ examTaskPaperExportDto.setUnexposedPaperType(examTaskDetailList.stream().filter(m -> !m.getExposed()).map(m -> String.valueOf(m.getSerialNumber())).collect(Collectors.joining(",")));
|
|
|
+
|
|
|
+ List<ExamTaskDetail> examTaskDetails = examTaskDetailList.stream().collect(Collectors.toList());
|
|
|
// 选择曝光卷型
|
|
|
if (PaperFileDownloadExposureStatusEnum.EXPOSED_PAPER.equals(paperFileDownloadExposureStatus)) {
|
|
|
- if (StringUtils.isBlank(examTaskDetailDto.getExposedPaperType())) {
|
|
|
+ examTaskDetails = examTaskDetailList.stream().filter(m -> m.getExposed()).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(examTaskDetails)) {
|
|
|
examTaskPaperExportDto.setResult("没有曝光卷型,下载失败");
|
|
|
continue;
|
|
|
- } else {
|
|
|
- paperInfoVoList = ExamTaskUtil.parsePaperAttachmentPath(examTaskDetailDto.getPaperAttachmentIds(), examTaskDetailDto.getExposedPaperType());
|
|
|
}
|
|
|
}
|
|
|
// 选择未曝光卷型
|
|
|
if (PaperFileDownloadExposureStatusEnum.UNEXPOSED_PAPER.equals(paperFileDownloadExposureStatus)) {
|
|
|
+ examTaskDetails = examTaskDetailList.stream().filter(m -> !m.getExposed()).collect(Collectors.toList());
|
|
|
if (StringUtils.isBlank(examTaskDetailDto.getUnexposedPaperType())) {
|
|
|
examTaskPaperExportDto.setResult("没有未曝光卷型,下载失败");
|
|
|
continue;
|
|
|
- } else {
|
|
|
- paperInfoVoList = ExamTaskUtil.parsePaperAttachmentPath(examTaskDetailDto.getPaperAttachmentIds(), examTaskDetailDto.getUnexposedPaperType());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(paperInfoVoList)) {
|
|
|
+ if (CollectionUtils.isEmpty(examTaskDetails)) {
|
|
|
examTaskPaperExportDto.setResult("所选试卷状态未查询到上传的试卷信息,下载失败");
|
|
|
continue;
|
|
|
}
|
|
@@ -583,63 +589,68 @@ public class DownloadLogicServiceImpl implements DownloadLogicService {
|
|
|
|
|
|
// 目录规则(课程名称(课程代码)/试卷编号)
|
|
|
String secondPath = examTaskDetailDto.getCourseName() + SystemConstant.HYPHEN + examTaskDetailDto.getCourseCode() + File.separator + examTaskDetailDto.getPaperNumber();
|
|
|
- for (PaperInfoVo paperInfoVo : paperInfoVoList) {
|
|
|
- // 下载试卷
|
|
|
- if (downloadPaper) {
|
|
|
- // 不管什么命名规则,默认都加上卷型前缀
|
|
|
- String paperFileNamePath = "试卷" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
|
|
|
- // 原文件名
|
|
|
- if (namedByOriginalFile) {
|
|
|
- paperFileNamePath = paperFileNamePath + SystemConstant.HYPHEN + paperInfoVo.getFilename();
|
|
|
- } else {
|
|
|
- paperFileNamePath = paperFileNamePath + "." + FilenameUtils.getExtension(paperInfoVo.getFilename());
|
|
|
- }
|
|
|
- Long attachmentId = Long.valueOf(paperInfoVo.getAttachmentId());
|
|
|
- if (Objects.nonNull(attachmentId)) {
|
|
|
- BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
- if (Objects.nonNull(attachment)) {
|
|
|
- String fileName = trimWhiteSpace(zipLocalRootPath + File.separator + secondPath + File.separator + spliceFileName(paperFileNamePath, SystemConstant.PDF_PREFIX));
|
|
|
- fileUploadService.downloadFile(attachment, fileName);
|
|
|
+ for (ExamTaskDetail examTaskDetail : examTaskDetails) {
|
|
|
+ List<PaperInfoVo> paperInfoVoList = JSON.parseArray(examTaskDetail.getPaperAttachmentIds(), PaperInfoVo.class);
|
|
|
+ for (PaperInfoVo paperInfoVo : paperInfoVoList) {
|
|
|
+ // 下载试卷
|
|
|
+ if (downloadPaper) {
|
|
|
+ // 不管什么命名规则,默认都加上卷型前缀
|
|
|
+ String paperFileNamePath = "卷" + examTaskDetail.getSerialNumber() + SystemConstant.HYPHEN + "试卷" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
|
|
|
+ // 原文件名
|
|
|
+ if (namedByOriginalFile) {
|
|
|
+ paperFileNamePath = paperFileNamePath + SystemConstant.HYPHEN + paperInfoVo.getFilename();
|
|
|
+ } else {
|
|
|
+ paperFileNamePath = paperFileNamePath + "." + FilenameUtils.getExtension(paperInfoVo.getFilename());
|
|
|
+ }
|
|
|
+ Long attachmentId = Long.valueOf(paperInfoVo.getAttachmentId());
|
|
|
+ if (Objects.nonNull(attachmentId)) {
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
+ if (Objects.nonNull(attachment)) {
|
|
|
+ String fileName = trimWhiteSpace(zipLocalRootPath + File.separator + secondPath + File.separator + spliceFileName(paperFileNamePath, SystemConstant.PDF_PREFIX));
|
|
|
+ fileUploadService.downloadFile(attachment, fileName);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- // 下载题卡
|
|
|
- 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 + "题卡" + SystemConstant.HYPHEN + paperInfoVo.getName() + SystemConstant.HYPHEN + fileNamePath;
|
|
|
- String cardPdfPath = zipLocalRootPath + File.separator + secondPath + File.separator + "题卡" + 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);
|
|
|
- }
|
|
|
+ // 下载题卡
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
- // 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, PageSizeEnum.A3);
|
|
|
}
|
|
|
- HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
|
|
|
+ examTaskPaperExportDto.setResult("下载成功");
|
|
|
}
|
|
|
- examTaskPaperExportDto.setResult("下载成功");
|
|
|
}
|
|
|
+
|
|
|
+ examTaskPaperExportDtoList.add(examTaskPaperExportDto);
|
|
|
}
|
|
|
|
|
|
// 导出文件excel
|