|
@@ -36,6 +36,7 @@ import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.*;
|
|
|
import com.qmth.teachcloud.common.util.excel.ExcelError;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
@@ -1934,251 +1935,262 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
orgId = requestUser.getOrgId();
|
|
|
}
|
|
|
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- String zipJoiner = null, zipLocalRootPath = null;
|
|
|
- if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
- zipJoiner = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator;
|
|
|
- zipLocalRootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + time;
|
|
|
- } else {
|
|
|
- zipJoiner = dictionaryConfig.fssPublicDomain().getConfig() + File.separator;
|
|
|
- zipLocalRootPath = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + time;
|
|
|
- }
|
|
|
- StringJoiner stringJoiner = SystemConstant.getDirName(UploadFileEnum.FILE, true);
|
|
|
- stringJoiner.add(SystemConstant.getNanoId()).add(SystemConstant.ZIP_PREFIX);
|
|
|
- String dirNameTmp = stringJoiner.toString().replaceAll("\\\\", SystemConstant.ORG_SPLIT);
|
|
|
- File zipFile = new File(zipJoiner + dirNameTmp);
|
|
|
- if (!zipFile.getParentFile().exists()) {
|
|
|
- zipFile.getParentFile().mkdirs();
|
|
|
-// boolean cf = zipFile.createNewFile();
|
|
|
- }
|
|
|
+ File zipFile = null;
|
|
|
+ String zipLocalRootPath = null;
|
|
|
+ try {
|
|
|
+ boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("");
|
|
|
+ if (!oss && Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
+ stringJoiner.add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator);
|
|
|
+ }
|
|
|
+ stringJoiner = SystemConstant.getDirName(stringJoiner, UploadFileEnum.FILE, true);
|
|
|
+ stringJoiner.add("下载管理_批量下载_" + System.currentTimeMillis()).add(SystemConstant.ZIP_PREFIX);
|
|
|
|
|
|
- ExamTaskPaperDto examTaskPaperDto = downloadService.findDownloadContent(schoolId, semesterId, examId, orgId, courseName, idSet);
|
|
|
- // 导出文件excel
|
|
|
- List<ExamTaskPaperExportDto> examTaskPaperExportDtoList = examTaskPaperDto.getExamTaskPaperExportDtoList();
|
|
|
+ String dirNameTmp = stringJoiner.toString().replaceAll("\\\\", SystemConstant.ORG_SPLIT);
|
|
|
+ zipFile = SystemConstant.getFileTempDirVar(SystemConstant.getNanoId(), SystemConstant.ZIP_PREFIX);
|
|
|
+ zipLocalRootPath = zipFile.getParent() + File.separator + System.currentTimeMillis();
|
|
|
|
|
|
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
- ExcelUtil.excelMake(ExamTaskPaperExportDto.class, examTaskPaperExportDtoList, outputStream);
|
|
|
- InputStream in = new ByteArrayInputStream(outputStream.toByteArray());
|
|
|
+ ExamTaskPaperDto examTaskPaperDto = downloadService.findDownloadContent(schoolId, semesterId, examId, orgId, courseName, idSet);
|
|
|
+ // 导出文件excel
|
|
|
+ List<ExamTaskPaperExportDto> examTaskPaperExportDtoList = examTaskPaperDto.getExamTaskPaperExportDtoList();
|
|
|
|
|
|
- String excelName = "试卷使用清单";
|
|
|
- if (Objects.nonNull(paperFileDownloadExposureStatus)) {
|
|
|
- excelName = excelName + paperFileDownloadExposureStatus.getDesc();
|
|
|
- }
|
|
|
- String excelLocalPath = zipLocalRootPath + File.separator + excelName + "." + SystemConstant.XLSX;
|
|
|
- convertUtil.saveLocal(in, excelLocalPath);
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ ExcelUtil.excelMake(ExamTaskPaperExportDto.class, examTaskPaperExportDtoList, outputStream);
|
|
|
+ InputStream in = new ByteArrayInputStream(outputStream.toByteArray());
|
|
|
|
|
|
- // 所有试卷信息
|
|
|
- List<ExamTaskPaperFileDto> examTaskPaperFileDtoList = examTaskPaperDto.getExamTaskPaperFileDtoList();
|
|
|
- if (examTaskPaperFileDtoList.size() == 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("没有找到任何试卷信息");
|
|
|
- }
|
|
|
- // 二级路径 课程
|
|
|
- Set<String> courseSet = examTaskPaperFileDtoList.stream().map(e -> e.getCourseName() + SystemConstant.HYPHEN + e.getCourseCode()).collect(Collectors.toSet());
|
|
|
- // 文件数以一级目录文件为准(初始1是excel)
|
|
|
- int count = 1;
|
|
|
- for (String course : courseSet) {
|
|
|
- // 三级路径 课程代码-课程名称/试卷编号
|
|
|
- int courseCount = 0;
|
|
|
- Set<String> paperNumberSet = examTaskPaperFileDtoList
|
|
|
- .stream()
|
|
|
- .filter(e -> course.equals(e.getCourseName() + SystemConstant.HYPHEN + e.getCourseCode()))
|
|
|
- .map(ExamTaskPaperFileDto::getPaperNumber)
|
|
|
- .collect(Collectors.toSet());
|
|
|
- for (String paperNumber : paperNumberSet) {
|
|
|
- // 试卷下文件集
|
|
|
- List<ExamTaskPaperFileDto> paperCellList = examTaskPaperFileDtoList
|
|
|
+ String excelName = "试卷使用清单";
|
|
|
+ if (Objects.nonNull(paperFileDownloadExposureStatus)) {
|
|
|
+ excelName = excelName + paperFileDownloadExposureStatus.getDesc();
|
|
|
+ }
|
|
|
+ String excelLocalPath = zipLocalRootPath + File.separator + excelName + "." + SystemConstant.XLSX;
|
|
|
+ FileUtils.copyInputStreamToFile(in, new File(excelLocalPath));
|
|
|
+
|
|
|
+ // 所有试卷信息
|
|
|
+ List<ExamTaskPaperFileDto> examTaskPaperFileDtoList = examTaskPaperDto.getExamTaskPaperFileDtoList();
|
|
|
+ if (examTaskPaperFileDtoList.size() == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到任何试卷信息");
|
|
|
+ }
|
|
|
+ // 二级路径 课程
|
|
|
+ Set<String> courseSet = examTaskPaperFileDtoList.stream().map(e -> e.getCourseName() + SystemConstant.HYPHEN + e.getCourseCode()).collect(Collectors.toSet());
|
|
|
+ // 文件数以一级目录文件为准(初始1是excel)
|
|
|
+ int count = 1;
|
|
|
+ for (String course : courseSet) {
|
|
|
+ // 三级路径 课程代码-课程名称/试卷编号
|
|
|
+ int courseCount = 0;
|
|
|
+ Set<String> paperNumberSet = examTaskPaperFileDtoList
|
|
|
.stream()
|
|
|
- .filter(e -> paperNumber.equals(e.getPaperNumber()))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 文件路径
|
|
|
- String filePath = zipLocalRootPath + File.separator + course + File.separator + paperNumber + File.separator;
|
|
|
-
|
|
|
- // 试卷文件曝光度筛选
|
|
|
- if (Objects.nonNull(paperFileDownloadExposureStatus)) {
|
|
|
- switch (paperFileDownloadExposureStatus) {
|
|
|
- case EXPOSED_PAPER: // 曝光的
|
|
|
- paperCellList = paperCellList.stream().filter(ExamTaskPaperFileDto::getExposureStatus).collect(Collectors.toList());
|
|
|
- if (paperCellList.size() > 0) {
|
|
|
- specialSuccessMessage = "";
|
|
|
- }
|
|
|
- break;
|
|
|
- case UNEXPOSED_PAPER: // 未曝光的
|
|
|
- paperCellList = paperCellList.stream().filter(e -> !e.getExposureStatus()).collect(Collectors.toList());
|
|
|
- if (paperCellList.size() > 0) {
|
|
|
- specialSuccessMessage = "";
|
|
|
- }
|
|
|
- break;
|
|
|
- case ALL_PAPER: // 全部试卷
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ .filter(e -> course.equals(e.getCourseName() + SystemConstant.HYPHEN + e.getCourseCode()))
|
|
|
+ .map(ExamTaskPaperFileDto::getPaperNumber)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ for (String paperNumber : paperNumberSet) {
|
|
|
+ // 试卷下文件集
|
|
|
+ List<ExamTaskPaperFileDto> paperCellList = examTaskPaperFileDtoList
|
|
|
+ .stream()
|
|
|
+ .filter(e -> paperNumber.equals(e.getPaperNumber()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 文件路径
|
|
|
+ String filePath = zipLocalRootPath + File.separator + course + File.separator + paperNumber + File.separator;
|
|
|
+
|
|
|
+ // 试卷文件曝光度筛选
|
|
|
+ if (Objects.nonNull(paperFileDownloadExposureStatus)) {
|
|
|
+ switch (paperFileDownloadExposureStatus) {
|
|
|
+ case EXPOSED_PAPER: // 曝光的
|
|
|
+ paperCellList = paperCellList.stream().filter(ExamTaskPaperFileDto::getExposureStatus).collect(Collectors.toList());
|
|
|
+ if (paperCellList.size() > 0) {
|
|
|
+ specialSuccessMessage = "";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case UNEXPOSED_PAPER: // 未曝光的
|
|
|
+ paperCellList = paperCellList.stream().filter(e -> !e.getExposureStatus()).collect(Collectors.toList());
|
|
|
+ if (paperCellList.size() > 0) {
|
|
|
+ specialSuccessMessage = "";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case ALL_PAPER: // 全部试卷
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
-
|
|
|
- if (Objects.isNull(paperFileDownloadContent)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- switch (paperFileDownloadContent) {
|
|
|
- case ONLY_CARD: // 只下载题卡
|
|
|
- for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
|
|
|
- Long examCardId = examTaskPaperFileDto.getExamCardId();
|
|
|
- Long cardRuleId = examTaskPaperFileDto.getCardRuleId();
|
|
|
- ExamCard examCard = examCardService.getById(examCardId);
|
|
|
- ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCardId);
|
|
|
- String htmlContent;
|
|
|
- if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
|
|
|
- htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
- } else {
|
|
|
- BasicCardRule basicCardRule = basicCardRuleService.getById(cardRuleId);
|
|
|
- htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
- }
|
|
|
+ if (Objects.isNull(paperFileDownloadContent)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ switch (paperFileDownloadContent) {
|
|
|
+ case ONLY_CARD: // 只下载题卡
|
|
|
+ for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
|
|
|
+ Long examCardId = examTaskPaperFileDto.getExamCardId();
|
|
|
+ Long cardRuleId = examTaskPaperFileDto.getCardRuleId();
|
|
|
+ ExamCard examCard = examCardService.getById(examCardId);
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCardId);
|
|
|
+ String htmlContent;
|
|
|
+ if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
|
|
|
+ htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
+ } else {
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(cardRuleId);
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
+ }
|
|
|
|
|
|
- byte[] bytes = htmlContent.getBytes();
|
|
|
- String cardName = "题卡-";
|
|
|
- if (namedByCourseInfo) {
|
|
|
- cardName = cardName + course;
|
|
|
- }
|
|
|
- if (namedByPaperNumber) {
|
|
|
- cardName = cardName + paperNumber;
|
|
|
- }
|
|
|
- if (namedByOriginalFile) {
|
|
|
- cardName = cardName + examCardService.getById(examCardId).getTitle();
|
|
|
- }
|
|
|
- cardName = cardName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
- String cardLocalHtmlPath = filePath + cardName + SystemConstant.HTML_PREFIX;
|
|
|
- String cardLocalPdfPath = filePath + cardName + SystemConstant.PDF_PREFIX;
|
|
|
+ byte[] bytes = htmlContent.getBytes();
|
|
|
+ String cardName = "题卡-";
|
|
|
+ if (namedByCourseInfo) {
|
|
|
+ cardName = cardName + course;
|
|
|
+ }
|
|
|
+ if (namedByPaperNumber) {
|
|
|
+ cardName = cardName + paperNumber;
|
|
|
+ }
|
|
|
+ if (namedByOriginalFile) {
|
|
|
+ cardName = cardName + examCardService.getById(examCardId).getTitle();
|
|
|
+ }
|
|
|
+ cardName = cardName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
+ String cardLocalHtmlPath = filePath + cardName + SystemConstant.HTML_PREFIX;
|
|
|
+ String cardLocalPdfPath = filePath + cardName + SystemConstant.PDF_PREFIX;
|
|
|
|
|
|
- File localFile = new File(cardLocalHtmlPath);
|
|
|
- if (!localFile.getParentFile().exists()) {
|
|
|
- boolean mkr = localFile.getParentFile().mkdirs();
|
|
|
- }
|
|
|
- FileCopyUtils.copy(bytes, localFile);
|
|
|
+ File localFile = new File(cardLocalHtmlPath);
|
|
|
+ if (!localFile.getParentFile().exists()) {
|
|
|
+ boolean mkr = localFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ FileCopyUtils.copy(bytes, localFile);
|
|
|
|
|
|
- File pdfFile = new File(cardLocalPdfPath);
|
|
|
- if (!pdfFile.exists()) {
|
|
|
- boolean cf = pdfFile.createNewFile();
|
|
|
- }
|
|
|
- HtmlToPdfUtil.convert(cardLocalHtmlPath, cardLocalPdfPath, PageSizeEnum.A3);
|
|
|
- specialSuccessMessage = "";
|
|
|
- courseCount = 1;
|
|
|
- }
|
|
|
- break;
|
|
|
- case ONLY_PAPER: // 只下载试卷
|
|
|
- for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
|
|
|
- String paperName = "试卷-";
|
|
|
- if (namedByCourseInfo) {
|
|
|
- paperName = paperName + course;
|
|
|
- }
|
|
|
- if (namedByPaperNumber) {
|
|
|
- paperName = paperName + paperNumber;
|
|
|
- }
|
|
|
- if (namedByOriginalFile) {
|
|
|
- paperName = paperName + examTaskPaperFileDto.getPaperName();
|
|
|
- }
|
|
|
- paperName = paperName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
- String paperLocalPath = filePath + paperName + examTaskPaperFileDto.getPaperSuffix();
|
|
|
- String paperPath = examTaskPaperFileDto.getPaperPath();
|
|
|
- if (oss) {
|
|
|
- fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
|
|
|
- } else {
|
|
|
- FileUtil.copyFile(paperPath, paperLocalPath);
|
|
|
+ File pdfFile = new File(cardLocalPdfPath);
|
|
|
+ if (!pdfFile.exists()) {
|
|
|
+ boolean cf = pdfFile.createNewFile();
|
|
|
+ }
|
|
|
+ HtmlToPdfUtil.convert(cardLocalHtmlPath, cardLocalPdfPath, PageSizeEnum.A3);
|
|
|
+ specialSuccessMessage = "";
|
|
|
+ courseCount = 1;
|
|
|
}
|
|
|
- courseCount = 1;
|
|
|
- }
|
|
|
- break;
|
|
|
- case PAPER_AND_CARD: // 全部下载
|
|
|
- for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
|
|
|
- // 题卡
|
|
|
- Long examCardId = examTaskPaperFileDto.getExamCardId();
|
|
|
- Long cardRuleId = examTaskPaperFileDto.getCardRuleId();
|
|
|
- ExamCard examCard = examCardService.getById(examCardId);
|
|
|
- ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCardId);
|
|
|
- String htmlContent;
|
|
|
- if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
|
|
|
- htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
- } else {
|
|
|
- BasicCardRule basicCardRule = basicCardRuleService.getById(cardRuleId);
|
|
|
- htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
+ break;
|
|
|
+ case ONLY_PAPER: // 只下载试卷
|
|
|
+ for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
|
|
|
+ String paperName = "试卷-";
|
|
|
+ if (namedByCourseInfo) {
|
|
|
+ paperName = paperName + course;
|
|
|
+ }
|
|
|
+ if (namedByPaperNumber) {
|
|
|
+ paperName = paperName + paperNumber;
|
|
|
+ }
|
|
|
+ if (namedByOriginalFile) {
|
|
|
+ paperName = paperName + examTaskPaperFileDto.getPaperName();
|
|
|
+ }
|
|
|
+ paperName = paperName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
+ String paperLocalPath = filePath + paperName + examTaskPaperFileDto.getPaperSuffix();
|
|
|
+ String paperPath = examTaskPaperFileDto.getPaperPath();
|
|
|
+ if (oss) {
|
|
|
+ fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
+ FileUtil.copyFile(paperPath, paperLocalPath);
|
|
|
+ } else {
|
|
|
+ fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ courseCount = 1;
|
|
|
}
|
|
|
+ break;
|
|
|
+ case PAPER_AND_CARD: // 全部下载
|
|
|
+ for (ExamTaskPaperFileDto examTaskPaperFileDto : paperCellList) {
|
|
|
+ // 题卡
|
|
|
+ Long examCardId = examTaskPaperFileDto.getExamCardId();
|
|
|
+ Long cardRuleId = examTaskPaperFileDto.getCardRuleId();
|
|
|
+ ExamCard examCard = examCardService.getById(examCardId);
|
|
|
+ ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCardId);
|
|
|
+ String htmlContent;
|
|
|
+ if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
|
|
|
+ htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
|
|
|
+ } else {
|
|
|
+ BasicCardRule basicCardRule = basicCardRuleService.getById(cardRuleId);
|
|
|
+ htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
|
|
|
+ }
|
|
|
|
|
|
- byte[] bytes = htmlContent.getBytes();
|
|
|
- String cardName = "题卡-";
|
|
|
- if (namedByCourseInfo) {
|
|
|
- cardName = cardName + course;
|
|
|
- }
|
|
|
- if (namedByPaperNumber) {
|
|
|
- cardName = cardName + paperNumber;
|
|
|
- }
|
|
|
- if (namedByOriginalFile) {
|
|
|
- cardName = cardName + examCardService.getById(examCardId).getTitle();
|
|
|
- }
|
|
|
- cardName = cardName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
- String cardLocalHtmlPath = filePath + cardName + SystemConstant.HTML_PREFIX;
|
|
|
- String cardLocalPdfPath = filePath + cardName + SystemConstant.PDF_PREFIX;
|
|
|
- File localCardFile = new File(cardLocalHtmlPath);
|
|
|
- if (!localCardFile.getParentFile().exists()) {
|
|
|
- boolean mkr = localCardFile.getParentFile().mkdirs();
|
|
|
- }
|
|
|
- FileCopyUtils.copy(bytes, localCardFile);
|
|
|
+ byte[] bytes = htmlContent.getBytes();
|
|
|
+ String cardName = "题卡-";
|
|
|
+ if (namedByCourseInfo) {
|
|
|
+ cardName = cardName + course;
|
|
|
+ }
|
|
|
+ if (namedByPaperNumber) {
|
|
|
+ cardName = cardName + paperNumber;
|
|
|
+ }
|
|
|
+ if (namedByOriginalFile) {
|
|
|
+ cardName = cardName + examCardService.getById(examCardId).getTitle();
|
|
|
+ }
|
|
|
+ cardName = cardName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
+ String cardLocalHtmlPath = filePath + cardName + SystemConstant.HTML_PREFIX;
|
|
|
+ String cardLocalPdfPath = filePath + cardName + SystemConstant.PDF_PREFIX;
|
|
|
+ File localCardFile = new File(cardLocalHtmlPath);
|
|
|
+ if (!localCardFile.getParentFile().exists()) {
|
|
|
+ boolean mkr = localCardFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ FileCopyUtils.copy(bytes, localCardFile);
|
|
|
|
|
|
- File cardPdfFile = new File(cardLocalPdfPath);
|
|
|
- if (!cardPdfFile.exists()) {
|
|
|
- boolean cf = cardPdfFile.createNewFile();
|
|
|
- }
|
|
|
- HtmlToPdfUtil.convert(cardLocalHtmlPath, cardLocalPdfPath, PageSizeEnum.A3);
|
|
|
+ File cardPdfFile = new File(cardLocalPdfPath);
|
|
|
+ if (!cardPdfFile.exists()) {
|
|
|
+ boolean cf = cardPdfFile.createNewFile();
|
|
|
+ }
|
|
|
+ HtmlToPdfUtil.convert(cardLocalHtmlPath, cardLocalPdfPath, PageSizeEnum.A3);
|
|
|
|
|
|
- // 试卷
|
|
|
- String paperName = "试卷-";
|
|
|
- if (namedByCourseInfo) {
|
|
|
- paperName = paperName + course;
|
|
|
- }
|
|
|
- if (namedByPaperNumber) {
|
|
|
- paperName = paperName + paperNumber;
|
|
|
- }
|
|
|
- if (namedByOriginalFile) {
|
|
|
- paperName = paperName + examTaskPaperFileDto.getPaperName();
|
|
|
- }
|
|
|
- paperName = paperName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
- String paperLocalPath = filePath + paperName + examTaskPaperFileDto.getPaperSuffix();
|
|
|
- String paperPath = examTaskPaperFileDto.getPaperPath();
|
|
|
-
|
|
|
- if (oss) {
|
|
|
- fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
|
|
|
- } else {
|
|
|
- FileUtil.copyFile(paperPath, paperLocalPath);
|
|
|
+ // 试卷
|
|
|
+ String paperName = "试卷-";
|
|
|
+ if (namedByCourseInfo) {
|
|
|
+ paperName = paperName + course;
|
|
|
+ }
|
|
|
+ if (namedByPaperNumber) {
|
|
|
+ paperName = paperName + paperNumber;
|
|
|
+ }
|
|
|
+ if (namedByOriginalFile) {
|
|
|
+ paperName = paperName + examTaskPaperFileDto.getPaperName();
|
|
|
+ }
|
|
|
+ paperName = paperName + SystemConstant.HYPHEN + examTaskPaperFileDto.getPaperType();
|
|
|
+ String paperLocalPath = filePath + paperName + examTaskPaperFileDto.getPaperSuffix();
|
|
|
+ String paperPath = examTaskPaperFileDto.getPaperPath();
|
|
|
+
|
|
|
+ if (oss) {
|
|
|
+ fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
|
|
|
+ FileUtil.copyFile(paperPath, paperLocalPath);
|
|
|
+ } else {
|
|
|
+ fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ courseCount = 1;
|
|
|
}
|
|
|
- courseCount = 1;
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
+ count = count + courseCount;
|
|
|
}
|
|
|
- count = count + courseCount;
|
|
|
- }
|
|
|
- Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipLocalRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
+ Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipLocalRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
|
|
|
|
|
|
- boolean oss = dictionaryConfig.sysDomain().isOss();
|
|
|
- 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 jsonObject = new JSONObject();
|
|
|
jsonObject.put(SystemConstant.PATH, dirNameTmp);
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
- } else {
|
|
|
- jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
- jsonObject.put(SystemConstant.PATH, zipJoiner.toString() + dirNameTmp.toString());
|
|
|
- }
|
|
|
- jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
- tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
|
- ConvertUtil.delFolder(zipLocalRootPath);
|
|
|
- if (oss) {
|
|
|
- zipFile.delete();
|
|
|
+ String zipFileMd5 = DigestUtils.md5Hex(new FileInputStream(zipFile));
|
|
|
+ if (oss) {//上传至oss
|
|
|
+ fileStoreUtil.ossUpload(dirNameTmp, zipFile, zipFileMd5, fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
|
|
|
+ } else {
|
|
|
+ if (Objects.nonNull(dictionaryConfig.fssLocalPdfDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalPdfDomain().getConfig())) {
|
|
|
+ fileStoreUtil.localUpload(dirNameTmp, new FileInputStream(zipFile), zipFileMd5, LocalCatalogEnum.LOCAL_PDF);
|
|
|
+ } else {
|
|
|
+ fileStoreUtil.ossUpload(dirNameTmp, zipFile, zipFileMd5, fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
|
|
|
+ }
|
|
|
+ jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
|
|
|
+ }
|
|
|
+ jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
|
|
|
+ tbTask.setResultFilePath(jsonObject.toJSONString());
|
|
|
+ map.put("count", count);
|
|
|
+ map.put("specialSuccessMessage", specialSuccessMessage);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(zipFile)) {
|
|
|
+ zipFile.delete();
|
|
|
+ }
|
|
|
+ ConvertUtil.delFolder(zipLocalRootPath);
|
|
|
}
|
|
|
- map.put("count", count);
|
|
|
- map.put("specialSuccessMessage", specialSuccessMessage);
|
|
|
return map;
|
|
|
}
|
|
|
|