Browse Source

下载管理修改

wangliang 2 years ago
parent
commit
cb8b1a25ff

+ 4 - 8
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/DownloadService.java

@@ -1,15 +1,10 @@
 package com.qmth.distributed.print.business.service;
 package com.qmth.distributed.print.business.service;
 
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.service.IService;
-import com.qmth.distributed.print.business.bean.dto.BasicExamDto;
 import com.qmth.distributed.print.business.bean.dto.ExamTaskDetailDto;
 import com.qmth.distributed.print.business.bean.dto.ExamTaskDetailDto;
 import com.qmth.distributed.print.business.bean.dto.ExamTaskPaperDto;
 import com.qmth.distributed.print.business.bean.dto.ExamTaskPaperDto;
-import com.qmth.distributed.print.business.bean.dto.ExamTaskPaperFileDto;
-import com.qmth.teachcloud.common.entity.BasicExam;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
-import java.util.List;
 import java.util.Set;
 import java.util.Set;
 
 
 /**
 /**
@@ -24,11 +19,12 @@ public interface DownloadService {
 
 
     /**
     /**
      * 查找要下载的试卷文件内容
      * 查找要下载的试卷文件内容
+     *
      * @param semesterId 学期id
      * @param semesterId 学期id
-     * @param examId 考试id
-     * @param orgId 机构id
+     * @param examId     考试id
+     * @param orgId      机构id
      * @param courseName 课程名称
      * @param courseName 课程名称
-     * @param idSet 命题任务idSet
+     * @param idSet      命题任务idSet
      * @return 要下载的试卷文件内容集合
      * @return 要下载的试卷文件内容集合
      */
      */
     ExamTaskPaperDto findDownloadContent(Long schoolId, Long semesterId, Long examId, Long orgId, String courseName, Set<Long> idSet);
     ExamTaskPaperDto findDownloadContent(Long schoolId, Long semesterId, Long examId, Long orgId, String courseName, Set<Long> idSet);

+ 72 - 67
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DownloadServiceImpl.java

@@ -27,8 +27,12 @@ import com.qmth.teachcloud.common.service.AttachmentCommonService;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.SysOrgService;
 import com.qmth.teachcloud.common.service.SysOrgService;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
+import com.qmth.teachcloud.common.util.ConvertUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.FileCopyUtils;
 import org.springframework.util.FileCopyUtils;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -38,6 +42,7 @@ import java.util.*;
 
 
 @Service
 @Service
 public class DownloadServiceImpl implements DownloadService {
 public class DownloadServiceImpl implements DownloadService {
+    private final static Logger log = LoggerFactory.getLogger(DownloadServiceImpl.class);
 
 
     @Resource
     @Resource
     TeachcloudCommonService teachcloudCommonService;
     TeachcloudCommonService teachcloudCommonService;
@@ -105,87 +110,87 @@ public class DownloadServiceImpl implements DownloadService {
             throw ExceptionResultEnum.ERROR.exception("没有未曝光试卷,无法下载");
             throw ExceptionResultEnum.ERROR.exception("没有未曝光试卷,无法下载");
         }
         }
         String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
         String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
-        List<JSONObject> jsonObjectList = JSONObject.parseArray(paperAttachmentIds, JSONObject.class);
 
 
         // 收集处理试卷和题卡
         // 收集处理试卷和题卡
         // 本地存储目录
         // 本地存储目录
+        File fileTemp = null;
         String rootPath = null;
         String rootPath = null;
-        if (Objects.nonNull(dictionaryConfig.fssLocalFileDomain()) && !StringUtils.isBlank(dictionaryConfig.fssLocalFileDomain().getConfig())) {
-            rootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + System.currentTimeMillis();
-        } else {
-            rootPath = dictionaryConfig.fssPublicDomain().getConfig() + File.separator + System.currentTimeMillis();
-        }
-        List<File> fileList = new ArrayList<>();
-
-        List<String> unexposedPaperTypes = Arrays.asList(unexposedPaperType.split(","));
-        List<ExamPaperInfoDto> paperInfoDtoList = JSONObject.parseArray(paperAttachmentIds, ExamPaperInfoDto.class);
-        if (Objects.isNull(paperInfoDtoList)) {
-            throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
-        }
-        for (ExamPaperInfoDto paperInfo : paperInfoDtoList) {
-            String paperType = paperInfo.getName();
-            if (!unexposedPaperTypes.contains(paperType)) {
-                continue;
+        try {
+            fileTemp = SystemConstant.getFileTempVar(SystemConstant.ZIP_PREFIX);
+            rootPath = fileTemp.getParent() + File.separator + System.currentTimeMillis();
+            List<File> fileList = new ArrayList<>();
+            List<String> unexposedPaperTypes = Arrays.asList(unexposedPaperType.split(","));
+            List<ExamPaperInfoDto> paperInfoDtoList = JSONObject.parseArray(paperAttachmentIds, ExamPaperInfoDto.class);
+            if (CollectionUtils.isEmpty(paperInfoDtoList)) {
+                throw ExceptionResultEnum.ERROR.exception("试卷信息不存在");
             }
             }
 
 
-            // 试卷附件id
-            Long attachmentId = paperInfo.getAttachmentId();
-            if (attachmentId == null) {
-                throw ExceptionResultEnum.ERROR.exception("命题任务没有上传试卷,无法下载");
-            }
-            // 题卡id
-            Long cardId = paperInfo.getCardId();
+            for (ExamPaperInfoDto paperInfo : paperInfoDtoList) {
+                String paperType = paperInfo.getName();
+                if (!unexposedPaperTypes.contains(paperType)) {
+                    continue;
+                }
 
 
-            // 试卷
-            BasicAttachment attachment = basicAttachmentMapper.selectById(attachmentId);
-            if (attachment == null) {
-                throw ExceptionResultEnum.ERROR.exception("附件数据异常");
-            }
-            String paperPath = rootPath + File.separator + examTask.getCourseName() + SystemConstant.HYPHEN + examTask.getCourseCode() + File.separator + examTask.getPaperNumber();
-            String fileName = "试卷" + "_" + attachment.getName() + "_" + paperType + attachment.getType();
-            fileList.add(attachmentCommonService.downloadFile(paperPath, fileName, attachment));
-
-            // 题卡
-            if (cardId != null) {
-                ExamCard examCard = examCardMapper.selectById(cardId);
-
-                String cardPath = rootPath + File.separator + examTask.getCourseName() + SystemConstant.HYPHEN + examTask.getCourseCode() + File.separator + examTask.getPaperNumber();
-                String cardHtmlPath = cardPath + File.separator + "题卡" + "_" + examTask.getCourseName() + "_" + paperType + SystemConstant.HTML_PREFIX;
-                String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getCourseName() + "_" + paperType + SystemConstant.PDF_PREFIX;
-
-                ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
-                String htmlContent;
-                // 通用模板
-                if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
-                    htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
-                } else {
-                    BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
-                    htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
+                // 试卷附件id
+                Long attachmentId = paperInfo.getAttachmentId();
+                if (attachmentId == null) {
+                    throw ExceptionResultEnum.ERROR.exception("命题任务没有上传试卷,无法下载");
                 }
                 }
+                // 题卡id
+                Long cardId = paperInfo.getCardId();
 
 
-                // html
-                File htmlFile = new File(cardHtmlPath);
-                if (!htmlFile.getParentFile().exists()) {
-                    htmlFile.getParentFile().mkdirs();
+                // 试卷
+                BasicAttachment attachment = basicAttachmentMapper.selectById(attachmentId);
+                if (attachment == null) {
+                    throw ExceptionResultEnum.ERROR.exception("附件数据异常");
                 }
                 }
-                // 生成html文件
-                FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
-                fileList.add(htmlFile);
-                // 转pdf文件
-                File pdfFile = new File(cardPdfPath);
-                if (!pdfFile.exists()) {
-                    pdfFile.createNewFile();
+                String paperPath = rootPath + File.separator + examTask.getCourseName() + SystemConstant.HYPHEN + examTask.getCourseCode() + File.separator + examTask.getPaperNumber();
+                String fileName = "试卷" + "_" + attachment.getName() + "_" + paperType + attachment.getType();
+                fileList.add(attachmentCommonService.downloadFile(paperPath, fileName, attachment));
+
+                // 题卡
+                if (cardId != null) {
+                    ExamCard examCard = examCardMapper.selectById(cardId);
+
+                    String cardPath = rootPath + File.separator + examTask.getCourseName() + SystemConstant.HYPHEN + examTask.getCourseCode() + File.separator + examTask.getPaperNumber();
+                    String cardHtmlPath = cardPath + File.separator + "题卡" + "_" + examTask.getCourseName() + "_" + paperType + SystemConstant.HTML_PREFIX;
+                    String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getCourseName() + "_" + paperType + SystemConstant.PDF_PREFIX;
+
+                    ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
+                    String htmlContent;
+                    // 通用模板
+                    if (MakeMethodEnum.SELECT.equals(examCard.getMakeMethod()) && CardCreateMethodEnum.UPLOAD.equals(examCard.getCreateMethod())) {
+                        htmlContent = createPdfUtil.resetHtmlTemplateBar(examCardDetail.getHtmlContent());
+                    } else {
+                        BasicCardRule basicCardRule = basicCardRuleService.getById(examTask.getCardRuleId());
+                        htmlContent = createPdfUtil.replaceHtmlCard(examCardDetail, basicCardRule);
+                    }
+
+                    // html
+                    File htmlFile = new File(cardHtmlPath);
+                    // 生成html文件
+                    FileCopyUtils.copy(htmlContent.getBytes(), htmlFile);
+                    fileList.add(htmlFile);
+                    // 转pdf文件
+                    File pdfFile = new File(cardPdfPath);
+                    HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
+                    fileList.add(pdfFile);
                 }
                 }
-                HtmlToPdfUtil.convert(cardHtmlPath, cardPdfPath, PageSizeEnum.A3);
-                fileList.add(pdfFile);
             }
             }
-        }
 
 
-        if (fileList.size() == 0) {
-            throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
+            if (fileList.size() == 0) {
+                throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
+            }
+            String zipName = examTask.getCourseName() + "未曝光试卷" + SystemConstant.ZIP_PREFIX;
+            attachmentCommonService.zipFiles(response, rootPath, zipName, fileList);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+        } finally {
+            if (Objects.nonNull(fileTemp)) {
+                fileTemp.delete();
+            }
+            ConvertUtil.delFolder(rootPath);
         }
         }
-        String zipName = examTask.getCourseName() + "未曝光试卷" + SystemConstant.ZIP_PREFIX;
-        attachmentCommonService.zipFiles(response, rootPath, zipName, fileList);
     }
     }
 
 
     @Override
     @Override

+ 236 - 224
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -36,6 +36,7 @@ import com.qmth.teachcloud.common.service.*;
 import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.common.util.excel.ExcelError;
 import com.qmth.teachcloud.common.util.excel.ExcelError;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -1934,251 +1935,262 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             orgId = requestUser.getOrgId();
             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()
                         .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.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;
         return map;
     }
     }
 
 

+ 1 - 1
distributed-print-business/src/main/resources/db/1、init-table.sql

@@ -1,4 +1,4 @@
-SET NAMES utf8mb4mb4;
+SET NAMES utf8mb4;
 
 
 -- ----------------------------
 -- ----------------------------
 -- Table structure for basic_attachment
 -- Table structure for basic_attachment

+ 30 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -21,6 +21,8 @@ import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 import java.io.*;
 import java.io.*;
 import java.lang.reflect.Field;
 import java.lang.reflect.Field;
@@ -40,6 +42,7 @@ import java.util.stream.Collectors;
  * @Date: 2019/10/11
  * @Date: 2019/10/11
  */
  */
 public class SystemConstant {
 public class SystemConstant {
+    private final static Logger log = LoggerFactory.getLogger(SystemConstant.class);
 
 
     /**
     /**
      * 分布式印刷api前缀
      * 分布式印刷api前缀
@@ -172,6 +175,7 @@ public class SystemConstant {
     public static final String SUCCESS = "success";
     public static final String SUCCESS = "success";
     public static final String EXTEND_COLUMN = "extendColumn";
     public static final String EXTEND_COLUMN = "extendColumn";
     public static final String USER_DIR = "user.dir";
     public static final String USER_DIR = "user.dir";
+    public static final String TMP_DIR = "java.io.tmpdir";
     public static final String PDF_TEMP = "pdf-temp";
     public static final String PDF_TEMP = "pdf-temp";
     public static final String FILE_TEMP = "file-temp";
     public static final String FILE_TEMP = "file-temp";
     public static final String TEMP = "temp";
     public static final String TEMP = "temp";
@@ -788,7 +792,32 @@ public class SystemConstant {
      */
      */
     public static File getFileTempVar(String suffix) throws IOException {
     public static File getFileTempVar(String suffix) throws IOException {
         File file = File.createTempFile(SystemConstant.TEMP, suffix);
         File file = File.createTempFile(SystemConstant.TEMP, suffix);
-        System.out.println("getFileTempVar_absolutePath1:" + file.getAbsolutePath());
+        log.info("getFileTempVar_absolutePath:{}", file.getAbsolutePath());
+        return file;
+    }
+
+    /**
+     * 获取临时文件
+     *
+     * @param suffix
+     * @return
+     */
+    public static File getFileTempDirVar(String suffix) {
+        File file = new File(System.getProperty(SystemConstant.TMP_DIR), SystemConstant.getNanoId() + suffix);
+        log.info("getFileTempDirVar_absolutePath:{}", file.getAbsolutePath());
+        return file;
+    }
+
+    /**
+     * 获取临时文件
+     *
+     * @param fileName
+     * @param suffix
+     * @return
+     */
+    public static File getFileTempDirVar(String fileName, String suffix) {
+        File file = new File(System.getProperty(SystemConstant.TMP_DIR), fileName + suffix);
+        log.info("getFileTempDirVar_absolutePath:{}", file.getAbsolutePath());
         return file;
         return file;
     }
     }
 
 

+ 3 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/AttachmentCommonServiceImpl.java

@@ -21,6 +21,7 @@ import java.io.*;
 import java.net.URLEncoder;
 import java.net.URLEncoder;
 import java.util.List;
 import java.util.List;
 import java.util.Objects;
 import java.util.Objects;
+import java.util.Optional;
 
 
 /**
 /**
  * 试卷、题卡下载、预览等操作公共服务service impl
  * 试卷、题卡下载、预览等操作公共服务service impl
@@ -37,9 +38,8 @@ public class AttachmentCommonServiceImpl implements AttachmentCommonService {
 
 
     @Override
     @Override
     public File downloadFile(String rootPath, String fileName, BasicAttachment basicAttachment) throws Exception {
     public File downloadFile(String rootPath, String fileName, BasicAttachment basicAttachment) throws Exception {
-        if (basicAttachment == null) {
-            throw ExceptionResultEnum.ERROR.exception("附件信息不存在");
-        }
+        Optional.ofNullable(basicAttachment).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("附件信息不存在"));
+
         JSONObject object = JSONObject.parseObject(basicAttachment.getPath());
         JSONObject object = JSONObject.parseObject(basicAttachment.getPath());
         String filePath = object.getString(SystemConstant.PATH);
         String filePath = object.getString(SystemConstant.PATH);
         String type = object.getString(SystemConstant.TYPE);
         String type = object.getString(SystemConstant.TYPE);