|
@@ -26,6 +26,7 @@ import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.templete.execute.AsyncPaperReviewPdfExportService;
|
|
|
import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
import com.qmth.distributed.print.business.util.PdfUtil;
|
|
|
+import com.qmth.distributed.print.business.util.pdf.CreatePdfNewUtil;
|
|
|
import com.qmth.teachcloud.common.bean.dto.AssignTeacherDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.DataPermissionRule;
|
|
@@ -67,6 +68,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -137,12 +139,16 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
@Resource
|
|
|
ExamTaskService examTaskService;
|
|
|
@Resource
|
|
|
+ ExamTaskPaperDataService examTaskPaperDataService;
|
|
|
+ @Resource
|
|
|
ExamStudentService examStudentService;
|
|
|
@Resource
|
|
|
TFFlowJoinService tfFlowJoinService;
|
|
|
@Resource
|
|
|
CreatePdfUtil createPdfUtil;
|
|
|
@Resource
|
|
|
+ CreatePdfNewUtil createPdfNewUtil;
|
|
|
+ @Resource
|
|
|
BasicPrintConfigService basicPrintConfigService;
|
|
|
@Resource
|
|
|
TFFlowLogService tfFlowLogService;
|
|
@@ -889,39 +895,40 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception {
|
|
|
- ExamTask examTask = this.getById(examTaskId);
|
|
|
+ public void paperDownload(HttpServletResponse response, Long examTaskId) {
|
|
|
ExamTaskDetailPdfDownloadDto examTaskDetailPdfDownloadDto = examTaskDetailService.findPdfDownload(examTaskId);
|
|
|
Optional.ofNullable(examTaskDetailPdfDownloadDto).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("数据异常"));
|
|
|
|
|
|
- File tempFile = null;
|
|
|
String rootPath = null;
|
|
|
try {
|
|
|
// 本地保存目录
|
|
|
- tempFile = SystemConstant.getFileTempDirVar(System.currentTimeMillis() + File.separator + SystemConstant.getNanoId(), SystemConstant.TEMP_PREFIX);
|
|
|
- rootPath = tempFile.getParent();
|
|
|
+ File tempFile = SystemConstant.getFileTempParentDirVar(SystemConstant.TEMP_PREFIX);
|
|
|
+ rootPath = tempFile.getPath() + File.separator + SystemConstant.getNanoId();
|
|
|
+
|
|
|
+ // 下载文件保存目录(用uuid命名)
|
|
|
+ String downloadFilePath = rootPath + File.separator + SystemConstant.getNanoId();
|
|
|
+ File downloadPathFile = new File(downloadFilePath);
|
|
|
+ if (!downloadPathFile.exists()) {
|
|
|
+ downloadPathFile.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
StringJoiner dirPath = new StringJoiner("");
|
|
|
- dirPath = dirPath.add(rootPath).add(File.separator)
|
|
|
+ dirPath = dirPath.add(downloadFilePath).add(File.separator)
|
|
|
.add(examTaskDetailPdfDownloadDto.getSemesterName()).add(File.separator)
|
|
|
.add(examTaskDetailPdfDownloadDto.getExamName()).add(File.separator)
|
|
|
.add(examTaskDetailPdfDownloadDto.getCourseNameCode().replaceAll(" ", "")).add(File.separator)
|
|
|
- .add(examTaskDetailPdfDownloadDto.getPaperNumber()).add(File.separator)
|
|
|
- .add(examTaskDetailPdfDownloadDto.getCourseNameCode().replaceAll(" ", "")).add(SystemConstant.HYPHEN)
|
|
|
- .add(examTaskDetailPdfDownloadDto.getPaperNumber()).add(SystemConstant.HYPHEN);
|
|
|
- List<File> fileList = new ArrayList<>();
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getPaperNumber()).add(File.separator);
|
|
|
List<PaperInfoVo> paperInfoVoList = ExamTaskUtil.parsePaperAttachmentPath(examTaskDetailPdfDownloadDto.getPaperAttachmentIds());
|
|
|
// 试卷
|
|
|
for (PaperInfoVo paperInfoVo : paperInfoVoList) {
|
|
|
+ String originalFileName = paperInfoVo.getFilename().substring(0, paperInfoVo.getFilename().lastIndexOf("."));
|
|
|
Long attachmentId = Long.valueOf(paperInfoVo.getAttachmentId());
|
|
|
String name = paperInfoVo.getName();
|
|
|
if (Objects.nonNull(attachmentId)) {
|
|
|
BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
Optional.ofNullable(attachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("附件数据异常"));
|
|
|
- String fileName = dirPath + "试卷" + SystemConstant.HYPHEN + name + attachment.getType();
|
|
|
- File file = fileUploadService.downloadFile(attachment, fileName);
|
|
|
- if (Objects.nonNull(file)) {
|
|
|
- fileList.add(file);
|
|
|
- }
|
|
|
+ String fileName = dirPath + "试卷" + SystemConstant.HYPHEN + name + SystemConstant.HYPHEN + originalFileName + attachment.getType();
|
|
|
+ fileUploadService.downloadFile(attachment, fileName);
|
|
|
}
|
|
|
|
|
|
// 题卡
|
|
@@ -929,18 +936,10 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
if (cardId != null) {
|
|
|
ExamCard examCard = examCardService.getById(cardId);
|
|
|
|
|
|
- String cardHtmlPath = dirPath + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.HTML_PREFIX;
|
|
|
- String cardPdfPath = dirPath + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.PDF_PREFIX;
|
|
|
-
|
|
|
- String htmlContent;
|
|
|
- // 通用模板
|
|
|
- if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod())) {
|
|
|
- htmlContent = createPdfUtil.resetHtmlTemplateBar(examCard.getHtmlContent());
|
|
|
- } else {
|
|
|
- BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
- htmlContent = createPdfUtil.replaceHtmlCard(examCard, basicCardRule);
|
|
|
- }
|
|
|
+ String cardHtmlPath = dirPath + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.HYPHEN + examCard.getTitle() + SystemConstant.HTML_PREFIX;
|
|
|
+ String cardPdfPath = dirPath + "题卡" + SystemConstant.HYPHEN + name + SystemConstant.HYPHEN + examCard.getTitle() + SystemConstant.PDF_PREFIX;
|
|
|
|
|
|
+ String htmlContent = createPdfNewUtil.replaceBlankHtmlContent(examCard.getHtmlContent());
|
|
|
// html
|
|
|
File htmlFile = new File(cardHtmlPath);
|
|
|
if (!htmlFile.exists()) {
|
|
@@ -948,8 +947,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
htmlFile.createNewFile();
|
|
|
}
|
|
|
// 生成html文件
|
|
|
- FileCopyUtils.copy(htmlContent.getBytes(StandardCharsets.UTF_8), htmlFile);
|
|
|
- fileList.add(htmlFile);
|
|
|
+ FileUtil.writeContent(htmlFile, htmlContent);
|
|
|
// 转pdf文件
|
|
|
File pdfFile = new File(cardPdfPath);
|
|
|
if (!pdfFile.exists()) {
|
|
@@ -957,24 +955,15 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
pdfFile.createNewFile();
|
|
|
}
|
|
|
HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
|
|
|
- fileList.add(pdfFile);
|
|
|
}
|
|
|
}
|
|
|
- if (fileList.size() == 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
|
|
|
- }
|
|
|
- if (Objects.nonNull(tempFile)) {
|
|
|
- tempFile.delete();
|
|
|
- }
|
|
|
- teachcloudCommonService.downloadFileAndZip(response, rootPath, rootPath, null);
|
|
|
+ String zipFileName = downloadPathFile.getName() + SystemConstant.ZIP_PREFIX;
|
|
|
+ FileUtil.downloadEncryptZip(response, downloadPathFile, zipFileName);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("文件下载失败");
|
|
|
} finally {
|
|
|
- if (Objects.nonNull(tempFile)) {
|
|
|
- tempFile.delete();
|
|
|
- }
|
|
|
if (Objects.nonNull(rootPath)) {
|
|
|
- ConvertUtil.delFolder(rootPath);
|
|
|
+ FileUtil.deleteDirectory(rootPath);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1278,6 +1267,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
examCardService.update(updateWrapper);
|
|
|
}
|
|
|
|
|
|
+ // 更新题库试卷表
|
|
|
+ for (PaperInfoVo paperInfoVo : paperInfoVoList) {
|
|
|
+ if (StringUtils.isNotBlank(paperInfoVo.getUuid())) {
|
|
|
+ UpdateWrapper<ExamTaskPaperData> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamTaskPaperData::getPaperNumber, examTask.getPaperNumber())
|
|
|
+ .eq(ExamTaskPaperData::getExamId, examTask.getExamId())
|
|
|
+ .eq(ExamTaskPaperData::getPaperNumber, paperInfoVo.getUuid())
|
|
|
+ .eq(ExamTaskPaperData::getPaperId, paperInfoVo.getPaperId())
|
|
|
+ .eq(ExamTaskPaperData::getUuid, paperInfoVo.getUuid());
|
|
|
+ examTaskPaperDataService.update(updateWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
BasicExam basicExam = basicExamService.getById(examTask.getExamId());
|
|
|
if (ExamModelEnum.MODEL1.equals(basicExam.getExamModel()) || ExamModelEnum.MODEL2.equals(basicExam.getExamModel())) {
|
|
|
// 创建印刷计划
|
|
@@ -2148,32 +2150,42 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, String> getTikuPaperData(Long examId, Long paperId) {
|
|
|
+ public Map<String, Object> getTikuPaperData(Long examId, Long paperId, String uuid) {
|
|
|
Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
try {
|
|
|
File paperDataFile = tikuUtils.getTikuPaperData(schoolId, paperId);
|
|
|
- ExamTaskPaperData examTaskPaperData = saveTikuPaperData(examId, paperId, paperDataFile);
|
|
|
+ ExamTaskPaperData examTaskPaperData = saveTikuPaperData(examId, paperId, uuid, paperDataFile);
|
|
|
map.put("uuid", examTaskPaperData.getUuid());
|
|
|
map.put("answerJson", examTaskPaperData.getAnswerJson());
|
|
|
+ map.put("attachmentId", examTaskPaperData.getPaperPdfAttachmentId());
|
|
|
return map;
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ExamTaskPaperData saveTikuPaperData(Long examId, Long paperId, File zipFile) {
|
|
|
+ private ExamTaskPaperData saveTikuPaperData(Long examId, Long paperId, String uuid, File zipFile) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
String zipDestPath = null;
|
|
|
try {
|
|
|
zipDestPath = zipFile.getParent() + File.separator + System.nanoTime();
|
|
|
Zip4jUtil.unzip(zipFile.getPath(), zipDestPath);
|
|
|
|
|
|
- ExamTaskPaperData examTaskPaperData = new ExamTaskPaperData();
|
|
|
- examTaskPaperData.setExamId(examId);
|
|
|
- // 系统自动生成唯一码,命题任务提交时,根据唯一码反向更新真实的试卷编号
|
|
|
- examTaskPaperData.setPaperNumber("0");
|
|
|
- examTaskPaperData.setUuid(SystemConstant.getNanoId());
|
|
|
- examTaskPaperData.setPaperId(paperId);
|
|
|
+ ExamTaskPaperData examTaskPaperData = examTaskPaperDataService.selectByMultiId(new ExamTaskPaperData(examId, uuid, paperId));
|
|
|
+ if (examTaskPaperData == null) {
|
|
|
+ examTaskPaperData = new ExamTaskPaperData();
|
|
|
+ examTaskPaperData.setExamId(examId);
|
|
|
+ // 系统自动生成唯一码,命题任务提交时,根据唯一码反向更新真实的试卷编号
|
|
|
+ uuid = SystemConstant.getNanoId();
|
|
|
+ examTaskPaperData.setPaperNumber(uuid);
|
|
|
+ examTaskPaperData.setUuid(uuid);
|
|
|
+ examTaskPaperData.setPaperId(paperId);
|
|
|
+ }
|
|
|
+ // data.zip
|
|
|
+ String zipPdfName = PdfUtil.md5FileName(examTaskPaperData.getUuid() + "data" + paperId + SystemConstant.ZIP_PREFIX);
|
|
|
+ FilePathVo filePathVoZip = fileUploadService.uploadFile(zipFile, UploadFileEnum.FILE, zipPdfName);
|
|
|
+ examTaskPaperData.setDataPacketPath(JSON.toJSONString(filePathVoZip));
|
|
|
// paper.json
|
|
|
String paperJson = FileUtils.readFileToString(new File(zipDestPath + File.separator + "paper.json"), StandardCharsets.UTF_8);
|
|
|
examTaskPaperData.setPaperJson(paperJson);
|
|
@@ -2181,13 +2193,20 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
String answerJson = FileUtils.readFileToString(new File(zipDestPath + File.separator + "answer.json"), StandardCharsets.UTF_8);
|
|
|
examTaskPaperData.setAnswerJson(answerJson);
|
|
|
// paper.pdf
|
|
|
- String paperPdfName = PdfUtil.md5FileName(examTaskPaperData.getUuid() + "paper" + SystemConstant.PDF_PREFIX);
|
|
|
- FilePathVo filePathVoPaper = fileUploadService.uploadFile(new File(zipDestPath + File.separator + "paper.pdf"), UploadFileEnum.PDF, paperPdfName);
|
|
|
- examTaskPaperData.setPaperPdf(JSON.toJSONString(filePathVoPaper));
|
|
|
+ String paperPdfName = PdfUtil.md5FileName(examTaskPaperData.getUuid() + "paper" + paperId + SystemConstant.PDF_PREFIX);
|
|
|
+ File paperPdfFile = new File(zipDestPath + File.separator + "paper.pdf");
|
|
|
+ FilePathVo filePathVoPaper = fileUploadService.uploadFile(paperPdfFile, UploadFileEnum.PDF, paperPdfName);
|
|
|
+ BasicAttachment paperPdfBasicAttachment = new BasicAttachment(JSON.toJSONString(filePathVoPaper), paperPdfName, SystemConstant.PDF_PREFIX, new BigDecimal(paperPdfFile.length()), filePathVoPaper.getMd5(), sysUser.getId());
|
|
|
+ basicAttachmentService.save(paperPdfBasicAttachment);
|
|
|
+ examTaskPaperData.setPaperPdfAttachmentId(paperPdfBasicAttachment.getId());
|
|
|
// answer.pdf
|
|
|
- String answerPdfName = PdfUtil.md5FileName(examTaskPaperData.getUuid() + "answer" + SystemConstant.PDF_PREFIX);
|
|
|
- FilePathVo filePathVoAnswer = fileUploadService.uploadFile(new File(zipDestPath + File.separator + "answer.pdf"), UploadFileEnum.PDF, answerPdfName);
|
|
|
- examTaskPaperData.setAnswerPdf(JSON.toJSONString(filePathVoAnswer));
|
|
|
+ String answerPdfName = PdfUtil.md5FileName(examTaskPaperData.getUuid() + "answer" + paperId + SystemConstant.PDF_PREFIX);
|
|
|
+ File answerPdfFile = new File(zipDestPath + File.separator + "answer.pdf");
|
|
|
+ FilePathVo filePathVoAnswer = fileUploadService.uploadFile(answerPdfFile, UploadFileEnum.PDF, answerPdfName);
|
|
|
+ BasicAttachment answerBasicAttachment = new BasicAttachment(JSON.toJSONString(filePathVoAnswer), answerPdfName, SystemConstant.PDF_PREFIX, new BigDecimal(answerPdfFile.length()), filePathVoAnswer.getMd5(), sysUser.getId());
|
|
|
+ basicAttachmentService.save(answerBasicAttachment);
|
|
|
+ examTaskPaperData.setAnswerPdfAttachmentId(answerBasicAttachment.getId());
|
|
|
+ examTaskPaperDataService.saveOrUpdateByMultiId(examTaskPaperData);
|
|
|
return examTaskPaperData;
|
|
|
} catch (Exception e) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("获取试卷包数据失败");
|