Pārlūkot izejas kodu

卷库查询下载pdf名称修改

wangliang 2 gadi atpakaļ
vecāks
revīzija
04e2f25c64

+ 58 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/ExamTaskDetailPdfDownloadDto.java

@@ -0,0 +1,58 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+import com.qmth.distributed.print.business.entity.ExamTaskDetail;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: examTaskDetail pdf dto
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2022/10/13
+ */
+public class ExamTaskDetailPdfDownloadDto extends ExamTaskDetail {
+
+    @ApiModelProperty(value = "学期名称")
+    private String semesterName;
+
+    @ApiModelProperty(value = "考试名称")
+    private String examName;
+
+    @ApiModelProperty(value = "课程名(课程代码)")
+    private String courseNameCode;
+
+    @ApiModelProperty(value = "试卷编号")
+    private String paperNumber;
+
+    public String getSemesterName() {
+        return semesterName;
+    }
+
+    public void setSemesterName(String semesterName) {
+        this.semesterName = semesterName;
+    }
+
+    public String getExamName() {
+        return examName;
+    }
+
+    public void setExamName(String examName) {
+        this.examName = examName;
+    }
+
+    public String getCourseNameCode() {
+        return courseNameCode;
+    }
+
+    public void setCourseNameCode(String courseNameCode) {
+        this.courseNameCode = courseNameCode;
+    }
+
+    public String getPaperNumber() {
+        return paperNumber;
+    }
+
+    public void setPaperNumber(String paperNumber) {
+        this.paperNumber = paperNumber;
+    }
+}

+ 9 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamTaskDetailMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 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.ExamTaskDetailPdfDownloadDto;
 import com.qmth.distributed.print.business.entity.ExamTaskDetail;
 import com.qmth.distributed.print.business.entity.ExamTaskDetail;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
@@ -30,4 +31,12 @@ public interface ExamTaskDetailMapper extends BaseMapper<ExamTaskDetail> {
      * @return
      * @return
      */
      */
     List<ExamTaskDetail> getExamTaskDetailByCardIdJson(@Param("cardId") Long cardId);
     List<ExamTaskDetail> getExamTaskDetailByCardIdJson(@Param("cardId") Long cardId);
+
+    /**
+     * 根据examTaskId下载pdf
+     *
+     * @param examTaskId
+     * @return
+     */
+    ExamTaskDetailPdfDownloadDto findPdfDownload(@Param("examTaskId") Long examTaskId);
 }
 }

+ 9 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskDetailService.java

@@ -3,6 +3,7 @@ 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.baomidou.mybatisplus.extension.service.IService;
 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.ExamTaskDetailPdfDownloadDto;
 import com.qmth.distributed.print.business.bean.params.RelatePaperParam;
 import com.qmth.distributed.print.business.bean.params.RelatePaperParam;
 import com.qmth.distributed.print.business.entity.ExamCard;
 import com.qmth.distributed.print.business.entity.ExamCard;
 import com.qmth.distributed.print.business.entity.ExamTaskDetail;
 import com.qmth.distributed.print.business.entity.ExamTaskDetail;
@@ -46,4 +47,12 @@ public interface ExamTaskDetailService extends IService<ExamTaskDetail> {
      * @return
      * @return
      */
      */
     List<ExamTaskDetail> getExamTaskDetailByCardIdJson(Long cardId);
     List<ExamTaskDetail> getExamTaskDetailByCardIdJson(Long cardId);
+
+    /**
+     * 根据examTaskId下载pdf
+     *
+     * @param examTaskId
+     * @return
+     */
+    ExamTaskDetailPdfDownloadDto findPdfDownload(Long examTaskId);
 }
 }

+ 13 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskDetailServiceImpl.java

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 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.ExamTaskDetailPdfDownloadDto;
 import com.qmth.distributed.print.business.bean.params.RelatePaperParam;
 import com.qmth.distributed.print.business.bean.params.RelatePaperParam;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
 import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
@@ -282,7 +283,7 @@ public class ExamTaskDetailServiceImpl extends ServiceImpl<ExamTaskDetailMapper,
 //        updateWrapper.lambda().set(ExamTaskDetail::getCardId, examCard.getId()).set(ExamTaskDetail::getMakeMethod, examCard.getMakeMethod().name()).eq(ExamTaskDetail::getExamTaskId, examTaskId);
 //        updateWrapper.lambda().set(ExamTaskDetail::getCardId, examCard.getId()).set(ExamTaskDetail::getMakeMethod, examCard.getMakeMethod().name()).eq(ExamTaskDetail::getExamTaskId, examTaskId);
 //        this.update(updateWrapper);
 //        this.update(updateWrapper);
         List<ExamTaskDetail> examTaskDetails = new ArrayList<>();
         List<ExamTaskDetail> examTaskDetails = new ArrayList<>();
-        if (SystemConstant.strNotNull(examTaskId)){
+        if (SystemConstant.strNotNull(examTaskId)) {
             QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
             QueryWrapper<ExamTaskDetail> examTaskDetailQueryWrapper = new QueryWrapper<>();
             examTaskDetailQueryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, Long.parseLong(examTaskId));
             examTaskDetailQueryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, Long.parseLong(examTaskId));
             examTaskDetails = this.list(examTaskDetailQueryWrapper);
             examTaskDetails = this.list(examTaskDetailQueryWrapper);
@@ -469,6 +470,17 @@ public class ExamTaskDetailServiceImpl extends ServiceImpl<ExamTaskDetailMapper,
         return examTaskDetailMapper.getExamTaskDetailByCardIdJson(cardId);
         return examTaskDetailMapper.getExamTaskDetailByCardIdJson(cardId);
     }
     }
 
 
+    /**
+     * 根据examTaskId下载pdf
+     *
+     * @param examTaskId
+     * @return
+     */
+    @Override
+    public ExamTaskDetailPdfDownloadDto findPdfDownload(Long examTaskId) {
+        return examTaskDetailMapper.findPdfDownload(examTaskId);
+    }
+
     /**
     /**
      * 卷库校验
      * 卷库校验
      *
      *

+ 42 - 27
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java

@@ -965,16 +965,24 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     @Override
     @Override
     public void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception {
     public void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception {
         ExamTask examTask = this.getById(examTaskId);
         ExamTask examTask = this.getById(examTaskId);
-        QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, examTaskId);
-        ExamTaskDetail examTaskDetail = examTaskDetailService.getOne(queryWrapper);
-        if (examTaskDetail == null) {
+        ExamTaskDetailPdfDownloadDto examTaskDetailPdfDownloadDto = examTaskDetailService.findPdfDownload(examTaskId);
+        if (examTaskDetailPdfDownloadDto == null) {
             throw ExceptionResultEnum.ERROR.exception("数据异常");
             throw ExceptionResultEnum.ERROR.exception("数据异常");
         }
         }
-        String paperAttachmentIds = examTaskDetail.getPaperAttachmentIds();
+
+        String paperAttachmentIds = examTaskDetailPdfDownloadDto.getPaperAttachmentIds();
         List<JSONObject> jsonObjectList = JSONObject.parseArray(paperAttachmentIds, JSONObject.class);
         List<JSONObject> jsonObjectList = JSONObject.parseArray(paperAttachmentIds, JSONObject.class);
         // 本地保存目录
         // 本地保存目录
-        String rootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + System.currentTimeMillis();
+        Long time = System.currentTimeMillis();
+        String rootPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + time;
+        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("-");
         List<File> fileList = new ArrayList<>();
         List<File> fileList = new ArrayList<>();
         // 试卷
         // 试卷
         for (JSONObject jsonObject : jsonObjectList) {
         for (JSONObject jsonObject : jsonObjectList) {
@@ -985,10 +993,18 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                 if (attachment == null) {
                 if (attachment == null) {
                     throw ExceptionResultEnum.ERROR.exception("附件数据异常");
                     throw ExceptionResultEnum.ERROR.exception("附件数据异常");
                 }
                 }
-                String paperPath = rootPath + File.separator + examTask.getPaperNumber();
-                String fileName = "试卷" + "_" + examTask.getPaperNumber() + "_" + name + attachment.getType();
-                File file = teachcloudCommonService.copyFile(paperPath, fileName, attachment);
-                fileList.add(file);
+                StringJoiner paperPath = new StringJoiner("")
+                        .add(dictionaryConfig.fssLocalFileDomain().getConfig()).add(File.separator)
+                        .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);
+                String fileName = examTaskDetailPdfDownloadDto.getCourseNameCode() + "-" + examTaskDetailPdfDownloadDto.getPaperNumber() + "-" + "试卷" + "-" + name + attachment.getType();
+                File file = teachcloudCommonService.copyFile(paperPath.toString(), fileName, attachment);
+                if (Objects.nonNull(file)) {
+                    fileList.add(file);
+                }
             }
             }
 
 
             // 题卡
             // 题卡
@@ -996,9 +1012,8 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             if (cardId != null) {
             if (cardId != null) {
                 ExamCard examCard = examCardService.getById(cardId);
                 ExamCard examCard = examCardService.getById(cardId);
 
 
-                String cardPath = rootPath + File.separator + examTask.getPaperNumber();
-                String cardHtmlPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + "_" + name + SystemConstant.HTML_PREFIX;
-                String cardPdfPath = cardPath + File.separator + "题卡" + "_" + examTask.getPaperNumber() + "_" + name + SystemConstant.PDF_PREFIX;
+                String cardHtmlPath = dirPath.toString() + "题卡" + "-" + name + SystemConstant.HTML_PREFIX;
+                String cardPdfPath = dirPath.toString() + "题卡" + "-" + name + SystemConstant.PDF_PREFIX;
 
 
                 ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
                 ExamCardDetail examCardDetail = examCardDetailService.getByCardId(examCard.getId());
                 String htmlContent;
                 String htmlContent;
@@ -1031,7 +1046,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
             throw ExceptionResultEnum.ERROR.exception("没有可导出文件");
         }
         }
 
 
-        teachcloudCommonService.downloadFileAndZip(response, rootPath, fileList);
+        teachcloudCommonService.downloadFileAndZip(response, rootPath, rootPath);
     }
     }
 
 
     @Override
     @Override
@@ -1880,8 +1895,8 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
                 if (!SystemConstant.strNotNull(courseCode)) {
                 if (!SystemConstant.strNotNull(courseCode)) {
                     throw ExceptionResultEnum.ERROR.exception("缺少考试课程编号");
                     throw ExceptionResultEnum.ERROR.exception("缺少考试课程编号");
                 }
                 }
-                BasicCourse basicCourse = basicCourseService.getOne(new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId,schoolId).eq(BasicCourse::getCode,courseCode));
-                if (Objects.isNull(basicCourse)){
+                BasicCourse basicCourse = basicCourseService.getOne(new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId, schoolId).eq(BasicCourse::getCode, courseCode));
+                if (Objects.isNull(basicCourse)) {
                     throw ExceptionResultEnum.ERROR.exception("找不到课程编号对应的课程");
                     throw ExceptionResultEnum.ERROR.exception("找不到课程编号对应的课程");
                 }
                 }
                 Long basicCourseId = basicCourse.getId();
                 Long basicCourseId = basicCourse.getId();
@@ -2036,7 +2051,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         // 导入的excel创建或查询的学生集合
         // 导入的excel创建或查询的学生集合
         List<BasicStudentResult> studentDatasource = basicStudentService.basicStudentList(requestUser.getSchoolId(), null, null, null, null);
         List<BasicStudentResult> studentDatasource = basicStudentService.basicStudentList(requestUser.getSchoolId(), null, null, null, null);
 
 
-        List<ExamStudentImportDto> existStudentList =  examStudentImportDtoList
+        List<ExamStudentImportDto> existStudentList = examStudentImportDtoList
                 .stream()
                 .stream()
                 .filter(e -> studentDatasource.stream().map(BasicStudentResult::getStudentCode).collect(Collectors.toList()).contains(e.getStudentCode()))
                 .filter(e -> studentDatasource.stream().map(BasicStudentResult::getStudentCode).collect(Collectors.toList()).contains(e.getStudentCode()))
                 .collect(Collectors.toList());
                 .collect(Collectors.toList());
@@ -2048,8 +2063,8 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             String impClazzName = examStudentImportDto.getClazzName();
             String impClazzName = examStudentImportDto.getClazzName();
 
 
 
 
-            List<BasicStudentResult> basicStudentList =  studentDatasource.stream().filter(e -> e.getStudentCode().equals(studentCode)).collect(Collectors.toList());
-            if (basicStudentList.size() != 1){
+            List<BasicStudentResult> basicStudentList = studentDatasource.stream().filter(e -> e.getStudentCode().equals(studentCode)).collect(Collectors.toList());
+            if (basicStudentList.size() != 1) {
                 throw ExceptionResultEnum.ERROR.exception("学号为:" + studentCode + "的考生数据异常");
                 throw ExceptionResultEnum.ERROR.exception("学号为:" + studentCode + "的考生数据异常");
             }
             }
             BasicStudentResult basicStudent = basicStudentList.get(0);
             BasicStudentResult basicStudent = basicStudentList.get(0);
@@ -2059,19 +2074,19 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
             String realityClazzName = basicStudent.getClazz();
             String realityClazzName = basicStudent.getClazz();
 
 
             // 学院核对
             // 学院核对
-            if (!impCollegeName.equals(realityCollegeName)){
+            if (!impCollegeName.equals(realityCollegeName)) {
                 throw ExceptionResultEnum.ERROR.exception("导入的考生【" + studentName + "(" + studentCode + ")】所在学院【" + impCollegeName +
                 throw ExceptionResultEnum.ERROR.exception("导入的考生【" + studentName + "(" + studentCode + ")】所在学院【" + impCollegeName +
                         "】与该考生实际所在学院【" + realityCollegeName + "】不符,请检验excel数据是否异常或联系管理员核对");
                         "】与该考生实际所在学院【" + realityCollegeName + "】不符,请检验excel数据是否异常或联系管理员核对");
             }
             }
 
 
             // 专业核对
             // 专业核对
-            if (!impMajorName.equals(realityMajorName)){
+            if (!impMajorName.equals(realityMajorName)) {
                 throw ExceptionResultEnum.ERROR.exception("导入的考生【" + studentName + "(" + studentCode + ")】所在专业【" + impMajorName +
                 throw ExceptionResultEnum.ERROR.exception("导入的考生【" + studentName + "(" + studentCode + ")】所在专业【" + impMajorName +
                         "】与该考生实际所在专业【" + realityMajorName + "】不符,请检验excel数据是否异常或联系管理员核对");
                         "】与该考生实际所在专业【" + realityMajorName + "】不符,请检验excel数据是否异常或联系管理员核对");
             }
             }
 
 
             // 班级核对
             // 班级核对
-            if (!impClazzName.equals(realityClazzName)){
+            if (!impClazzName.equals(realityClazzName)) {
                 throw ExceptionResultEnum.ERROR.exception("导入的考生【" + studentName + "(" + studentCode + ")】所在班级【" + impClazzName +
                 throw ExceptionResultEnum.ERROR.exception("导入的考生【" + studentName + "(" + studentCode + ")】所在班级【" + impClazzName +
                         "】与该考生实际所在班级【" + realityClazzName + "】不符,请检验excel数据是否异常或联系管理员核对");
                         "】与该考生实际所在班级【" + realityClazzName + "】不符,请检验excel数据是否异常或联系管理员核对");
             }
             }
@@ -2102,14 +2117,14 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
         List<BasicStudentResult> basicStudentResultDatasource = basicStudentService.basicStudentList(requestUser.getSchoolId(), null, null, null, studentCodeDatasource);
         List<BasicStudentResult> basicStudentResultDatasource = basicStudentService.basicStudentList(requestUser.getSchoolId(), null, null, null, studentCodeDatasource);
 
 
         // 考试对象键(考点、考场)
         // 考试对象键(考点、考场)
-        List<Map<String,String>> examObjectKeyList = examStudentImportDtoList.stream().flatMap(e -> {
-            Map<String,String> key = new HashMap<>();
-            key.put("examPlace",e.getExamPlace());
-            key.put("examRoom",e.getExamRoom());
+        List<Map<String, String>> examObjectKeyList = examStudentImportDtoList.stream().flatMap(e -> {
+            Map<String, String> key = new HashMap<>();
+            key.put("examPlace", e.getExamPlace());
+            key.put("examRoom", e.getExamRoom());
             return Stream.of(key);
             return Stream.of(key);
         }).distinct().collect(Collectors.toList());
         }).distinct().collect(Collectors.toList());
 
 
-        for (Map<String,String> key : examObjectKeyList) {
+        for (Map<String, String> key : examObjectKeyList) {
             // 考点
             // 考点
             String examPlace = key.get("examPlace");
             String examPlace = key.get("examPlace");
             // 考场
             // 考场

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

@@ -1017,10 +1017,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 ResultUtil.error(e.getMessage());
                 ResultUtil.error(e.getMessage());
             }
             }
         } finally {
         } 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)) {
             if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss() && Objects.nonNull(zipFile)) {
                 zipFile.delete();
                 zipFile.delete();
@@ -1262,105 +1260,139 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
 
     @Override
     @Override
     public Map<String, Object> executeExportPaperAndCardLogic(Map<String, Object> map) throws Exception {
     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;
         return map;
     }
     }
 
 

+ 24 - 0
distributed-print-business/src/main/resources/mapper/ExamTaskDetailMapper.xml

@@ -170,4 +170,28 @@
             </if>
             </if>
         </where>
         </where>
     </select>
     </select>
+
+    <select id="findPdfDownload" resultType="com.qmth.distributed.print.business.bean.dto.ExamTaskDetailPdfDownloadDto">
+        select
+            etd.*,
+            bs.name as semesterName,
+            be.name as examName,
+            GROUP_CONCAT(CONCAT(et.course_name, '(', et.course_code, ')')) as courseNameCode,
+            GROUP_CONCAT(et.paper_number) paperNumber
+        from
+            exam_task_detail etd
+                join exam_task et on
+                et.id = etd.exam_task_id
+                join basic_exam be on
+                be.id = et.exam_id
+                join basic_semester bs on
+                bs.id = be.semester_id
+        <where>
+            <if test="examTaskId != null and examTaskId != ''">
+                etd.exam_task_id = #{examTaskId}
+            </if>
+        </where>
+        GROUP BY
+            etd.id
+    </select>
 </mapper>
 </mapper>

+ 17 - 0
teachcloud-common-api/src/main/java/com/qmth/teachcloud/common/api/api/TSAuthController.java

@@ -1,7 +1,9 @@
 package com.qmth.teachcloud.common.api.api;
 package com.qmth.teachcloud.common.api.api;
 
 
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.core.solar.config.SolarProperties;
 import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
 import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
+import com.qmth.boot.core.solar.service.SolarService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.service.AuthInfoService;
 import com.qmth.teachcloud.common.service.AuthInfoService;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.Result;
@@ -41,6 +43,21 @@ public class TSAuthController {
     @Resource
     @Resource
     AuthInfoService authInfoService;
     AuthInfoService authInfoService;
 
 
+    @Resource
+    SolarService solarService;
+
+    @Resource
+    SolarProperties solarProperties;
+
+    @ApiOperation(value = "同步机构接口")
+    @RequestMapping(value = "/sync/org", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "菜单信息", response = Result.class)})
+    public Result syncOrg() {
+        solarService.update(solarProperties.getAccessKey(), solarProperties.getAccessSecret());
+        authInfoService.appInfoInit();
+        return ResultUtil.ok(true);
+    }
+
     @ApiOperation(value = "导出硬件信息")
     @ApiOperation(value = "导出硬件信息")
     @ApiResponses({@ApiResponse(code = 200, message = "导出硬件信息", response = Object.class)})
     @ApiResponses({@ApiResponse(code = 200, message = "导出硬件信息", response = Object.class)})
     @RequestMapping(value = "/export/device/info", method = RequestMethod.POST)
     @RequestMapping(value = "/export/device/info", method = RequestMethod.POST)

+ 8 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TeachcloudCommonService.java

@@ -175,6 +175,14 @@ public interface TeachcloudCommonService {
      */
      */
     public void downloadFileAndZip(HttpServletResponse response, String filePath, List<File> files);
     public void downloadFileAndZip(HttpServletResponse response, String filePath, List<File> files);
 
 
+    /**
+     * 下载文件到本地并压缩返回
+     *
+     * @param filePath    文件根目录
+     * @param zipRootPath zip文件根目录
+     */
+    public void downloadFileAndZip(HttpServletResponse response, String filePath, String zipRootPath);
+
     /**
     /**
      * 下载文件到本地并压缩返回
      * 下载文件到本地并压缩返回
      *
      *

+ 31 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -659,6 +659,37 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         }
         }
     }
     }
 
 
+    /**
+     * 下载文件到本地并压缩返回
+     *
+     * @param rootPath    文件根目录
+     * @param zipRootPath zip文件根目录
+     */
+    @Override
+    public void downloadFileAndZip(HttpServletResponse response, String rootPath, String zipRootPath) {
+        String schoolId = ServletUtil.getRequestHeaderSchoolId().toString();
+        long time = System.nanoTime();
+        File rootFile = new File(rootPath);
+        // 创建保存目录
+        if (!rootFile.exists()) {
+            rootFile.mkdirs();
+        }
+        File zipFile = null;
+        try {
+            String zipPath = dictionaryConfig.fssLocalFileDomain().getConfig() + File.separator + schoolId;
+            zipFile = FileUtil.file(zipPath, time + ".zip");
+            Zip4jUtil.zipEncryptFile(zipFile.getPath(), zipRootPath, SystemConstant.ZIP_ENCRYPT_PWD);
+            outputFile(response, zipFile, String.valueOf(time));
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception("下载失败");
+        } finally {
+            // 删除zip文件
+            FileUtil.del(zipFile);
+            // 删除压缩内容
+            FileUtil.del(rootPath);
+        }
+    }
+
     @Override
     @Override
     public void downloadFileAndZip(HttpServletResponse response, String rootPath, long time) {
     public void downloadFileAndZip(HttpServletResponse response, String rootPath, long time) {
         File rootFile = new File(rootPath);
         File rootFile = new File(rootPath);