|
@@ -1017,10 +1017,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
ResultUtil.error(e.getMessage());
|
|
|
}
|
|
|
} finally {
|
|
|
- if (!CollectionUtils.isEmpty(sourceFileList)) {
|
|
|
- for (File file : sourceFileList) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
+ if (Objects.nonNull(zipLocalRootPath)) {
|
|
|
+ ConvertUtil.delFolder(zipLocalRootPath);
|
|
|
}
|
|
|
if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss() && Objects.nonNull(zipFile)) {
|
|
|
zipFile.delete();
|
|
@@ -1262,105 +1260,139 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> executeExportPaperAndCardLogic(Map<String, Object> map) throws Exception {
|
|
|
- TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
- String yyyyMMddHH24mmss = DateUtil.format(new Date(), "yyyyMMddHHmmss");
|
|
|
- BasicSchool basicSchool = commonCacheService.schoolCache(tbTask.getSchoolId());
|
|
|
- LocalDateTime nowTime = LocalDateTime.now();
|
|
|
- StringJoiner zipJoiner = new StringJoiner("")
|
|
|
- .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
|
|
|
- StringJoiner dirName = new StringJoiner("")
|
|
|
- .add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
- .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
- .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
- .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
- .add(File.separator)
|
|
|
- .add(yyyyMMddHH24mmss).add("_").add(basicSchool.getName()).add("_").add("试卷导出文件").add(SystemConstant.ZIP_PREFIX);
|
|
|
- String dirNameTmp = dirName.toString().replaceAll("\\\\", "/");
|
|
|
-
|
|
|
- // 根文件路径
|
|
|
- String zipLocalRootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + System.currentTimeMillis();
|
|
|
-
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
-
|
|
|
- List<ExamTaskDetailDto> examTasks = (List<ExamTaskDetailDto>) map.get("examTasks");
|
|
|
- for (ExamTaskDetailDto examTask : examTasks) {
|
|
|
- ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(Long.valueOf(examTask.getId()));
|
|
|
-
|
|
|
- // 试卷
|
|
|
- String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
|
|
|
- if (StringUtils.isNotBlank(paperAttachmentIds)) {
|
|
|
- List<Map> paperInfo = JSONObject.parseArray(paperAttachmentIds, Map.class);
|
|
|
- if (Objects.isNull(paperInfo)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
|
|
|
- }
|
|
|
- for (Map paperMap : paperInfo) {
|
|
|
- if (Objects.nonNull(paperMap.get("attachmentId")) && String.valueOf(paperMap.get("attachmentId")).length() > 0 && !String.valueOf(paperMap.get("attachmentId")).equals("null")) {
|
|
|
- String name = paperMap.get("name").toString();
|
|
|
- Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
|
|
|
- BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
- if (Objects.nonNull(attachment)) {
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
|
|
|
- String paperPath = zipLocalRootPath + File.separator + examTask.getPaperNumber() + File.separator + "试卷" + "_" + examTask.getPaperNumber() + "_" + name + attachment.getType();
|
|
|
- UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
-
|
|
|
- if (oss) {
|
|
|
- fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath, uploadFileEnum.getFssType());
|
|
|
- } else {
|
|
|
- FileUtil.copyFile(jsonObject.getString(SystemConstant.PATH), paperPath);
|
|
|
+ String zipLocalRootPath = null;
|
|
|
+ File zipFile = null;
|
|
|
+ try {
|
|
|
+ TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
|
|
|
+ String yyyyMMddHH24mmss = DateUtil.format(new Date(), "yyyyMMddHHmmss");
|
|
|
+ BasicSchool basicSchool = commonCacheService.schoolCache(tbTask.getSchoolId());
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ StringJoiner zipJoiner = new StringJoiner("")
|
|
|
+ .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
|
|
|
+ StringJoiner dirName = new StringJoiner("")
|
|
|
+ .add(UploadFileEnum.FILE.getTitle()).add(File.separator)
|
|
|
+ .add(String.valueOf(nowTime.getYear())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
|
|
|
+ .add(String.format("%02d", nowTime.getDayOfMonth()))
|
|
|
+ .add(File.separator)
|
|
|
+ .add(yyyyMMddHH24mmss).add("_").add(basicSchool.getName()).add("_").add("试卷导出文件").add(SystemConstant.ZIP_PREFIX);
|
|
|
+ String dirNameTmp = dirName.toString().replaceAll("\\\\", "/");
|
|
|
+
|
|
|
+ // 根文件路径
|
|
|
+ Long time = System.currentTimeMillis();
|
|
|
+ zipLocalRootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + time;
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+
|
|
|
+ List<ExamTaskDetailDto> examTasks = (List<ExamTaskDetailDto>) map.get("examTasks");
|
|
|
+ for (ExamTaskDetailDto examTask : examTasks) {
|
|
|
+ ExamTaskDetailPdfDownloadDto examTaskDetailPdfDownloadDto = examTaskDetailService.findPdfDownload(Long.valueOf(examTask.getId()));
|
|
|
+
|
|
|
+ StringJoiner dirPath = new StringJoiner("")
|
|
|
+ .add(String.valueOf(time)).add(File.separator)
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getSemesterName()).add(File.separator)
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getExamName()).add(File.separator)
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getCourseNameCode()).add(File.separator)
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getPaperNumber()).add(File.separator)
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getCourseNameCode()).add("-")
|
|
|
+ .add(examTaskDetailPdfDownloadDto.getPaperNumber()).add("-");
|
|
|
+ // 试卷
|
|
|
+ String paperAttachmentIds = examTaskDetailPdfDownloadDto.getPaperAttachmentIds();
|
|
|
+ if (StringUtils.isNotBlank(paperAttachmentIds)) {
|
|
|
+ List<Map> paperInfo = JSONObject.parseArray(paperAttachmentIds, Map.class);
|
|
|
+ if (Objects.isNull(paperInfo)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
|
|
|
+ }
|
|
|
+ for (Map paperMap : paperInfo) {
|
|
|
+ if (Objects.nonNull(paperMap.get("attachmentId")) && String.valueOf(paperMap.get("attachmentId")).length() > 0 && !String.valueOf(paperMap.get("attachmentId")).equals("null")) {
|
|
|
+ String name = paperMap.get("name").toString();
|
|
|
+ Long attachmentId = Long.valueOf(String.valueOf(paperMap.get("attachmentId")));
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
+ if (Objects.nonNull(attachment)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
|
|
|
+ String paperPath = dirPath.toString() + "试卷" + "-" + name + attachment.getType();
|
|
|
+ UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
|
|
|
+ File file = null;
|
|
|
+ StringJoiner stringJoinerPdf = new StringJoiner("")
|
|
|
+ .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator)
|
|
|
+ .add(paperPath);
|
|
|
+ if (oss) {
|
|
|
+ file = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString(), uploadFileEnum.getFssType());
|
|
|
+ } else {
|
|
|
+ file = new File(paperPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
|
|
|
+ file.createNewFile();
|
|
|
+ }
|
|
|
+ IOUtils.copy(new FileInputStream((String) jsonObject.get(SystemConstant.PATH)), new FileOutputStream(file));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ ExamCard examCard = examCardService.getById(Long.parseLong((String) paperMap.get("cardId")));
|
|
|
+ if (Objects.isNull(examCard)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("找不到答题卡");
|
|
|
+ }
|
|
|
+ MakeMethodEnum makeMethodEnum = examCard.getMakeMethod();
|
|
|
+
|
|
|
+ String cardHtmlPath = dirPath.toString() + "题卡" + "-" +paperMap.get("name") + SystemConstant.HTML_PREFIX;
|
|
|
+ String cardPdfPath = dirPath.toString() + "题卡" + "-" + paperMap.get("name") + SystemConstant.PDF_PREFIX;
|
|
|
+ // 通用题卡
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
|
|
|
+ String htmlContent;
|
|
|
+ if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
|
|
|
+ htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
+ } else {
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
+ }
|
|
|
+ // html
|
|
|
+ File localFile = new File(cardHtmlPath);
|
|
|
+ if (!localFile.getParentFile().exists()) {
|
|
|
+ localFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ // 生成html文件
|
|
|
+ FileCopyUtils.copy(htmlContent.getBytes(), localFile);
|
|
|
+ // 转pdf文件
|
|
|
+ File file = new File(cardPdfPath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.createNewFile();
|
|
|
+ }
|
|
|
+ HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
|
|
|
}
|
|
|
- ExamCard examCard = examCardService.getById(Long.parseLong((String) paperMap.get("cardId")));
|
|
|
- if (Objects.isNull(examCard)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("找不到答题卡");
|
|
|
- }
|
|
|
- MakeMethodEnum makeMethodEnum = examCard.getMakeMethod();
|
|
|
-
|
|
|
- String cardPath = zipLocalRootPath + File.separator + examTask.getPaperNumber();
|
|
|
- String cardHtmlPath = cardPath + File.separator + "题卡" + paperMap.get("name") + "_" + examTask.getPaperNumber() + SystemConstant.HTML_PREFIX;
|
|
|
- String cardPdfPath = cardPath + File.separator + "题卡" + paperMap.get("name") + "_" + examTask.getPaperNumber() + SystemConstant.PDF_PREFIX;
|
|
|
- // 通用题卡
|
|
|
- ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
|
|
|
- String htmlContent;
|
|
|
- if (MakeMethodEnum.SELECT.equals(makeMethodEnum)) {
|
|
|
- htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
- } else {
|
|
|
- BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
|
|
|
- htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
- }
|
|
|
- // html
|
|
|
- File localFile = new File(cardHtmlPath);
|
|
|
- if (!localFile.getParentFile().exists()) {
|
|
|
- localFile.getParentFile().mkdirs();
|
|
|
- }
|
|
|
- // 生成html文件
|
|
|
- FileCopyUtils.copy(htmlContent.getBytes(), localFile);
|
|
|
- // 转pdf文件
|
|
|
- File file = new File(cardPdfPath);
|
|
|
- if (!file.exists()) {
|
|
|
- file.createNewFile();
|
|
|
- }
|
|
|
- HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- File zipFile = new File(zipJoiner.toString() + dirNameTmp);
|
|
|
- Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipLocalRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- if (oss) {//上传至oss
|
|
|
- fileStoreUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))), fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
|
|
|
- jsonObject.put(SystemConstant.PATH, dirNameTmp);
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- zipFile.delete();
|
|
|
- } else {
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- jsonObject.put(SystemConstant.PATH, zipFile.getPath());
|
|
|
+ zipFile = new File(zipJoiner.toString() + dirNameTmp);
|
|
|
+ if (!zipFile.getParentFile().exists()) {
|
|
|
+ zipFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipLocalRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ if (oss) {//上传至oss
|
|
|
+ fileStoreUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))), fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
|
|
|
+ jsonObject.put(SystemConstant.PATH, dirNameTmp);
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ } else {
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ jsonObject.put(SystemConstant.PATH, zipFile.getPath());
|
|
|
+ }
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
+ tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
|
+ map.put(SystemConstant.DATA_COUNT, examTasks.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(zipLocalRootPath)) {
|
|
|
+ ConvertUtil.delFolder(zipLocalRootPath);
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss() && Objects.nonNull(zipFile)) {
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
}
|
|
|
- jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
- tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
|
- ConvertUtil.delFolder(zipLocalRootPath);
|
|
|
- map.put(SystemConstant.DATA_COUNT, examTasks.size());
|
|
|
return map;
|
|
|
}
|
|
|
|