Bladeren bron

Merge branch 'dev_v2.2.0' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev_v2.2.0

xiaof 3 jaren geleden
bovenliggende
commit
0cf2df0bcc
21 gewijzigde bestanden met toevoegingen van 320 en 111 verwijderingen
  1. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamCardService.java
  2. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskService.java
  3. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamCardServiceImpl.java
  4. 1 1
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamTaskServiceImpl.java
  5. 15 15
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceServiceImpl.java
  6. 6 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/export/AsyncExportTaskTemplete.java
  7. 6 16
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java
  8. 2 2
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/TaskLogicService.java
  9. 34 15
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java
  10. 21 12
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java
  11. 8 4
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java
  12. 1 1
      distributed-print/src/main/java/com/qmth/distributed/print/api/ExamCardController.java
  13. 1 1
      distributed-print/src/main/java/com/qmth/distributed/print/api/ExamTaskController.java
  14. 42 3
      distributed-print/src/test/java/com/qmth/distributed/print/FssTest.java
  15. 12 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/config/DictionaryConfig.java
  16. 34 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/FssPrivateDomain.java
  17. 34 0
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/FssPublicDomain.java
  18. 4 4
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TeachcloudCommonService.java
  19. 9 8
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicAttachmentServiceImpl.java
  20. 47 19
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java
  21. 40 4
      teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/FileStoreUtil.java

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamCardService.java

@@ -36,7 +36,7 @@ public interface ExamCardService extends IService<ExamCard> {
 
     List<ExamCard> listSelectCard(String courseCode, Long cardRuleId, String paperType);
 
-    void downloadFiles(HttpServletResponse response, ArraysParams arraysParams);
+    void downloadFiles(HttpServletResponse response, ArraysParams arraysParams) throws Exception;
 
     List<SyncExamCardDto> listSyncCardByCourseCodeAndPaperNumber(Long schoolId, String courseCode, String paperNumber);
 }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamTaskService.java

@@ -103,7 +103,7 @@ public interface ExamTaskService extends IService<ExamTask> {
      */
     IPage<WorkResult> queryByMyWorkSubmit(IPage<Map> iPage, Long userId, Long schoolId, ExamStatusEnum status);
 
-    void paperDownload(HttpServletResponse response, Long examTaskId);
+    void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception;
 
     ExamTask getByCourseCodeAndPaperNumber(Long schoolId, String courseCode, String paperNumber);
 

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

@@ -223,7 +223,7 @@ public class ExamCardServiceImpl extends ServiceImpl<ExamCardMapper, ExamCard> i
     }
 
     @Override
-    public void downloadFiles(HttpServletResponse response, ArraysParams arraysParams) {
+    public void downloadFiles(HttpServletResponse response, ArraysParams arraysParams) throws Exception {
         // 路径规则:download-temp/{time}/{schoolId}/{courseCode}-{couseName}/{paperNumber}/{fileName}
         long time = System.nanoTime();
         String rootPath = SystemConstant.TEMP_FILES_DIR + File.separator + time;

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

@@ -977,7 +977,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
     }
 
     @Override
-    public void paperDownload(HttpServletResponse response, Long examTaskId) {
+    public void paperDownload(HttpServletResponse response, Long examTaskId) throws Exception {
         String schoolId = ServletUtil.getRequestHeaderSchoolId().toString();
         QueryWrapper<ExamTaskDetail> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(ExamTaskDetail::getExamTaskId, examTaskId);

+ 15 - 15
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/PrintCommonServiceServiceImpl.java

@@ -11,12 +11,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.itextpdf.text.DocumentException;
 import com.itextpdf.text.pdf.PdfReader;
 import com.qmth.boot.api.exception.ApiException;
-import com.qmth.boot.core.fss.service.FileService;
-import com.qmth.boot.core.fss.store.FileStore;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.entity.*;
 import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
-import com.qmth.distributed.print.business.enums.ExamStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.distributed.print.business.templete.execute.AsyncCreatePdfTempleteService;
@@ -62,8 +59,8 @@ import java.util.*;
 public class PrintCommonServiceServiceImpl implements PrintCommonService {
     private final static Logger log = LoggerFactory.getLogger(PrintCommonServiceServiceImpl.class);
 
-    @Resource
-    OssUtil ossUtil;
+//    @Resource
+//    OssUtil ossUtil;
 
     @Autowired
     private DictionaryConfig dictionaryConfig;
@@ -116,7 +113,7 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
     TFFlowApproveService tfFlowApproveService;
 
     @Resource
-    private FileService fileService;
+    private FileStoreUtil fileStoreUtil;
 
 
     /**
@@ -149,8 +146,8 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
                 filePath = (String) jsonObject.get(SystemConstant.PATH);
                 url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
                 UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
-//                htmlFile = convertUtil.saveLocal(fileService.getFileStore(uploadType.getFssType()).read(filePath),url);
-                htmlFile = ossUtil.ossDownload(filePath, url);
+//                htmlFile = ossUtil.ossDownload(filePath, url);
+                htmlFile = fileStoreUtil.ossDownload(filePath, url,uploadType.getFssType());
             }
             LocalDateTime nowTime = LocalDateTime.now();
             StringJoiner pdfStringJoiner = new StringJoiner("");
@@ -179,7 +176,8 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
             PdfDto pdfDto = null;
             if (oss) {//上传至oss
                 pdfDto = PdfUtil.addPdfPage(pdfFile);
-                ossUtil.ossUpload(pdfDirNameStr, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(pdfFileMd5)));
+//                ossUtil.ossUpload(pdfDirNameStr, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(pdfFileMd5)));
+                fileStoreUtil.ossUpload(pdfDirNameStr, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(pdfFileMd5)),fileStoreUtil.getUploadEnumByPath(pdfDirNameStr).getFssType());
 //                htmlFile.delete();
             }
             JSONObject attachmentPath = JSONObject.parseObject(examDetail.getAttachmentPath());
@@ -249,11 +247,13 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
             String fileMd5 = null;
             if (oss) {//上传至oss
                 String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
-                ossUtil.ossUpload(dirName, htmlContent);
+//                ossUtil.ossUpload(dirName, htmlContent);
+                fileStoreUtil.ossUpload(dirName,htmlContent,fileStoreUtil.getUploadEnumByPath(dirName).getFssType());
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
                 jsonObject.put(SystemConstant.PATH, dirName);
                 String url = SystemConstant.TEMP_FILES_DIR + File.separator + dirName;
-                File localHtmlFile = ossUtil.ossDownload(dirName, url);
+//                File localHtmlFile = ossUtil.ossDownload(dirName, url);
+                File localHtmlFile = fileStoreUtil.ossDownload(dirName, url,fileStoreUtil.getUploadEnumByPath(dirName).getFssType());
                 StringJoiner pdfStringJoiner = new StringJoiner("");
                 pdfStringJoiner.add(UploadFileEnum.PDF.getTitle()).add(File.separator);
                 pdfStringJoiner.add(String.valueOf(nowTime.getYear())).add(File.separator)
@@ -275,7 +275,8 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
                 pdfDto = PdfUtil.addPdfPage(pdfFile);
                 localFileList.add(new PdfDto(pdfFile.getPath(), PageSizeEnum.A3, pdfDto.getPageCount()));
                 fileMd5 = DigestUtils.md5Hex(new FileInputStream(pdfFile));
-                ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
+//                ossUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)));
+                fileStoreUtil.ossUpload(pdfDirName, pdfFile, BinaryUtil.toBase64String(HexUtils.decodeHex(fileMd5)),fileStoreUtil.getUploadEnumByPath(pdfDirName).getFssType());
 //                localHtmlFile.delete();
                 jsonObject.put(SystemConstant.PDF_PATH, pdfDirName);
                 // htmlMd5
@@ -386,9 +387,8 @@ public class PrintCommonServiceServiceImpl implements PrintCommonService {
             stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(format);
             if (oss) {//上传至oss\
                 String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
-                ossUtil.ossUpload(dirName, file.getInputStream(), BinaryUtil.toBase64String(HexUtils.decodeHex(md5)));
-//                FileStore fileStore = fileService.getFileStore(type.getFssType());
-//                fileStore.write(dirName,file.getInputStream(),DigestUtils.md5Hex(file.getInputStream()));
+                fileStoreUtil.ossUpload(dirName,file.getInputStream(),md5,type.getFssType());
+
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
                 jsonObject.put(SystemConstant.PATH, dirName);
             } else {//上传至服务器

+ 6 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/export/AsyncExportTaskTemplete.java

@@ -12,9 +12,10 @@ import com.qmth.teachcloud.common.enums.TaskResultEnum;
 import com.qmth.teachcloud.common.enums.TaskStatusEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.service.TBTaskService;
-import com.qmth.teachcloud.common.util.OssUtil;
+import com.qmth.teachcloud.common.util.FileStoreUtil;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
+import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,7 +61,8 @@ public abstract class AsyncExportTaskTemplete {
      * @param tbTask
      */
     public void createTxt(TBTask tbTask) {
-        OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
+//        OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
+        FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
         TBTaskService tbTaskService = SpringContextHolder.getBean(TBTaskService.class);
         ByteArrayOutputStream out = null;
         InputStream inputStream = null;
@@ -80,7 +82,8 @@ public abstract class AsyncExportTaskTemplete {
             if (Objects.equals(type, SystemConstant.OSS)) {//上传至oss
                 path = path.substring(0, path.lastIndexOf("/") + 1);
                 stringJoiner.add(path).add(SystemConstant.getUuid()).add(TXT_PREFIX).toString();
-                ossUtil.ossUpload(stringJoiner.toString(), inputStream, null);
+//                ossUtil.ossUpload(stringJoiner.toString(), inputStream, null);
+                fileStoreUtil.ossUpload(stringJoiner.toString(), inputStream, DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)), fileStoreUtil.getUploadEnumByPath(stringJoiner.toString()).getFssType());
             } else {//上传至服务器
                 path = path.substring(0, path.lastIndexOf(File.separator) + 1);
                 stringJoiner.add(path).add(SystemConstant.getUuid()).add(TXT_PREFIX).toString();

+ 6 - 16
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -3,8 +3,6 @@ package com.qmth.distributed.print.business.templete.importData;
 import cn.hutool.core.date.DateUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.api.exception.ApiException;
-import com.qmth.boot.core.fss.service.FileService;
-import com.qmth.boot.core.fss.store.FileStore;
 import com.qmth.teachcloud.common.contant.SpringContextHolder;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.TBTask;
@@ -13,8 +11,7 @@ import com.qmth.teachcloud.common.enums.TaskStatusEnum;
 import com.qmth.teachcloud.common.enums.TaskTypeEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.service.TBTaskService;
-import com.qmth.teachcloud.common.util.ConvertUtil;
-import com.qmth.teachcloud.common.util.OssUtil;
+import com.qmth.teachcloud.common.util.FileStoreUtil;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -68,19 +65,14 @@ public abstract class AsyncImportTaskTemplete {
      * @throws IOException
      */
     public InputStream getUploadFileInputStream(TBTask tbTask) throws Exception {
-        OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
-//        FileService fileService = SpringContextHolder.getBean(FileService.class);
-//        ConvertUtil convertUtil = SpringContextHolder.getBean(ConvertUtil.class);
+        FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
         JSONObject jsonObject = JSONObject.parseObject(tbTask.getImportFilePath());
         String path = (String) jsonObject.get(SystemConstant.PATH);
         String type = (String) jsonObject.get(SystemConstant.TYPE);
         UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
         InputStream inputStream = null;
         if (Objects.equals(type, SystemConstant.OSS)) {
-            byte[] data = ossUtil.ossDownload(path);
-            inputStream = new ByteArrayInputStream(data);
-//            FileStore fileStore = fileService.getFileStore(uploadType.getFssType());
-//            inputStream = fileStore.read(path);
+            inputStream = fileStoreUtil.ossDownloadIs(path,uploadType.getFssType());
         } else {
             StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(path);
             inputStream = new FileInputStream(new File(localPath.toString()));
@@ -94,7 +86,7 @@ public abstract class AsyncImportTaskTemplete {
      * @param tbTask
      */
     public void createTxt(TBTask tbTask) {
-        OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
+//        OssUtil ossUtil = SpringContextHolder.getBean(OssUtil.class);
         TBTaskService tbTaskService = SpringContextHolder.getBean(TBTaskService.class);
         ByteArrayOutputStream out = null;
         InputStream inputStream = null;
@@ -128,10 +120,8 @@ public abstract class AsyncImportTaskTemplete {
             if (Objects.equals(type, SystemConstant.OSS)) {//上传至oss
                 path = path.substring(0, path.lastIndexOf("/") + 1);
                 stringJoiner.add(path).add(SystemConstant.getUuid()).add(TXT_PREFIX).toString();
-                ossUtil.ossUpload(stringJoiner.toString(), inputStream, null);
-//                FileService fileService = SpringContextHolder.getBean(FileService.class);
-//                FileStore fileStore = fileService.getFileStore(uploadType.getFssType());
-//                fileStore.write(stringJoiner.toString(),inputStream, DigestUtils.md5Hex(inputStream));
+                FileStoreUtil fileStoreUtil = SpringContextHolder.getBean(FileStoreUtil.class);
+                fileStoreUtil.ossUpload(stringJoiner.toString(),inputStream,DigestUtils.md5Hex(new ByteArrayInputStream(bookByteAry)),uploadType.getFssType());
             } else {//上传至服务器
                 File finalFile = new File(stringJoiner.toString());
                 if (!finalFile.exists()) {

+ 2 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/TaskLogicService.java

@@ -53,7 +53,7 @@ public interface TaskLogicService {
      * @param map
      * @return
      */
-    public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws IOException;
+    public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws Exception;
 
     /**
      * 导出试卷、题卡pdf
@@ -61,7 +61,7 @@ public interface TaskLogicService {
      * @param map
      * @return
      */
-    Map<String, Object> executeExportPaperAndCardLogic(Map<String, Object> map) throws IOException;
+    Map<String, Object> executeExportPaperAndCardLogic(Map<String, Object> map) throws Exception;
 
     /**
      * 处理导入考生数据

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

@@ -105,8 +105,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     ExamDetailService examDetailService;
 
-    @Resource
-    OssUtil ossUtil;
+//    @Resource
+//    OssUtil ossUtil;
 
     @Resource
     CommonCacheService commonCacheService;
@@ -150,6 +150,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     @Resource
     SysUserService sysUserService;
 
+    @Resource
+    FileStoreUtil fileStoreUtil;
+
 
     /**
      * 创建pdf前置条件
@@ -218,7 +221,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                                     List<BasicAttachment> basicAttachmentList,
                                                     Set<Long> attachmentIds,
                                                     List<PdfDto>... list
-    ) throws IOException {
+    ) throws Exception {
         if (Objects.nonNull(examDetailCourseList) && examDetailCourseList.size() > 0) {
             String printContent = examPrintPlan.getPrintContent();
             if (StringUtils.isBlank(printContent)) {
@@ -368,7 +371,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
      * @throws DocumentException
      */
     @Transactional
-    public void createA4File(ExamPrintPlan examPrintPlan, ExamDetail examDetail, BasicSchool basicSchool, Set<File> ftlList, List<ExamDetailCourse> examDetailCourseList, List<PdfDto>... list) throws IOException, DocumentException {
+    public void createA4File(ExamPrintPlan examPrintPlan, ExamDetail examDetail, BasicSchool basicSchool, Set<File> ftlList, List<ExamDetailCourse> examDetailCourseList, List<PdfDto>... list) throws Exception {
         List<Long> examDetailCourseListIds = examDetailCourseList.stream().map(s -> s.getId()).collect(Collectors.toList());
         if (Objects.nonNull(examPrintPlan.getOrdinaryContent())) {
             //获取普通印品
@@ -557,7 +560,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
         String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
 
-        ossUtil.ossUpload(dirName, in, null);
+//        ossUtil.ossUpload(dirName, in, null);
+        fileStoreUtil.ossUpload(dirName, in,DigestUtils.md5Hex(new ByteArrayInputStream(outputStream.toByteArray())), fileStoreUtil.getUploadEnumByPath(dirName).getFssType());
         jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
         jsonObject.put(SystemConstant.PATH, dirName);
         jsonObject.put(SystemConstant.UPLOAD_TYPE, UploadFileEnum.FILE);
@@ -806,13 +810,17 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     List<File> sourceFiles = new ArrayList<>();
                     for (BasicAttachment basicAttachment : basicAttachmentList) {
                         JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
+                        UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
                         StringJoiner stringJoinerPdf = new StringJoiner("")
                                 .add(SystemConstant.TEMP_FILES_DIR).add(File.separator)
                                 .add((String) jsonObject.get(SystemConstant.PATH));
-                        sourceFiles.add(ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString()));
+//                        sourceFiles.add(ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString()));
+                        sourceFiles.add(fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString(),uploadFileEnum.getFssType()));
                     }
                     FileUtil.doZip(zipFile, sourceFiles);
-                    ossUtil.ossUpload(dirName.toString(), zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
+//                    ossUtil.ossUpload(dirName.toString(), zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
+                    fileStoreUtil.ossUpload(dirName.toString(), zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))),fileStoreUtil.getUploadEnumByPath(dirName.toString()).getFssType());
                     JSONObject jsonObject = new JSONObject();
                     jsonObject.put(SystemConstant.PATH, dirName.toString());
                     jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
@@ -838,7 +846,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
 
     @Override
     @Transactional
-    public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws IOException {
+    public Map<String, Object> executeExportSampleLogic(Map<String, Object> map) throws Exception {
         int count = 0;
         TBTask tbTask = (TBTask) map.get(SystemConstant.TASK);
         LocalDateTime nowTime = LocalDateTime.now();
@@ -892,8 +900,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 List<BasicAttachment> paperAttachmentList = basicAttachmentService.listByIds(attPaperIds);
                 for (BasicAttachment paperAttachment : paperAttachmentList) {
                     JSONObject jsonObject = JSONObject.parseObject(paperAttachment.getPath());
+                    UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
                     String paperPath = firstPath + File.separator + "试卷" + File.separator + paperAttachment.getName() + paperAttachment.getType();
-                    ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
+//                    ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
+                    fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath,uploadFileEnum.getFssType());
                     count++;
                 }
             }
@@ -913,8 +923,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 List<BasicAttachment> confirmAttachmentList = basicAttachmentService.listByIds(attConfirmIds);
                 for (BasicAttachment confirmAttachment : confirmAttachmentList) {
                     JSONObject jsonObject = JSONObject.parseObject(confirmAttachment.getPath());
+                    UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
                     String confirmPath = firstPath + File.separator + "审核样本" + File.separator + confirmAttachment.getName() + confirmAttachment.getType();
-                    ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath);
+//                    ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath);
+                    fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath,uploadFileEnum.getFssType());
                     count++;
                 }
             }
@@ -945,7 +957,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 }
                 JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
                 String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
-                ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath);
+                UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+//                ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath);
+                fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath,uploadFileEnum.getFssType());
             } else {
                 List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId, cardId));
                 if (examCardDetailList.size() != 1) {
@@ -964,7 +978,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             count++;
         }
         ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), false);
-        ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
+//        ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
+        fileStoreUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))),fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
         JSONObject jsonObject = new JSONObject();
         jsonObject.put(SystemConstant.PATH, dirNameTmp);
         jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
@@ -977,7 +992,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
     }
 
     @Override
-    public Map<String, Object> executeExportPaperAndCardLogic(Map<String, Object> map) throws IOException {
+    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());
@@ -1015,7 +1030,10 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         if (Objects.nonNull(attachment)) {
                             JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
                             String paperPath = zipLocalRootPath + File.separator + examTask.getPaperNumber() + File.separator + "试卷" + "_" + examTask.getPaperNumber() + "_" + name + attachment.getType();
-                            ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
+                            UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
+//                            ossUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath);
+                            fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath,uploadFileEnum.getFssType());
                         }
                     }
                 }
@@ -1065,7 +1083,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         }
 
         ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), false);
-        ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
+//        ossUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))));
+        fileStoreUtil.ossUpload(dirNameTmp, zipFile, BinaryUtil.toBase64String(HexUtils.decodeHex(DigestUtils.md5Hex(new FileInputStream(zipFile)))),fileStoreUtil.getUploadEnumByPath(dirNameTmp).getFssType());
         JSONObject jsonObject = new JSONObject();
         jsonObject.put(SystemConstant.PATH, dirNameTmp);
         jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);

+ 21 - 12
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -5,30 +5,31 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.Gson;
-import com.itextpdf.text.DocumentException;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentCourseDto;
 import com.qmth.distributed.print.business.bean.dto.ExamStudentDto;
 import com.qmth.distributed.print.business.bean.dto.PaperPdfDto;
 import com.qmth.distributed.print.business.bean.dto.PdfDto;
 import com.qmth.distributed.print.business.cache.CreatePdfCacheUtil;
 import com.qmth.distributed.print.business.entity.*;
-import com.qmth.distributed.print.business.enums.*;
-import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.distributed.print.business.enums.DrawRuleEnum;
+import com.qmth.distributed.print.business.enums.ExamDetailStatusEnum;
+import com.qmth.distributed.print.business.enums.PrintMethodEnum;
 import com.qmth.distributed.print.business.service.ExamDetailService;
+import com.qmth.distributed.print.business.service.PrintCommonService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.entity.TBTask;
 import com.qmth.teachcloud.common.enums.ClassifyEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.PageSizeEnum;
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.TeachcloudCommonService;
 import com.qmth.teachcloud.common.util.ConvertUtil;
-import com.qmth.teachcloud.common.util.OssUtil;
+import com.qmth.teachcloud.common.util.FileStoreUtil;
 import com.qmth.teachcloud.common.util.RedisUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.hibernate.validator.internal.util.logging.formatter.CollectionOfClassesObjectFormatter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Lazy;
@@ -54,8 +55,8 @@ import java.util.stream.Collectors;
 public class CreatePdfUtil {
     private final static Logger log = LoggerFactory.getLogger(CreatePdfUtil.class);
 
-    @Resource
-    OssUtil ossUtil;
+//    @Resource
+//    OssUtil ossUtil;
 
     @Resource
     BasicAttachmentService basicAttachmentService;
@@ -76,6 +77,9 @@ public class CreatePdfUtil {
     @Resource
     TeachcloudCommonService teachcloudCommonService;
 
+    @Resource
+    FileStoreUtil fileStoreUtil;
+
     /**
      * 创建登记表
      *
@@ -84,16 +88,20 @@ public class CreatePdfUtil {
      * @param ordinaryPdfList
      * @param printCount
      */
-    public void createCheckIn(ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws IOException, DocumentException {
+    public void createCheckIn(ExamDetail examDetail, BasicAttachment basicAttachment, List<PdfDto> ordinaryPdfList, Integer printCount) throws Exception {
         if (Objects.isNull(basicAttachment)) {
             throw ExceptionResultEnum.ATTACHMENT_IS_NULL.exception();
         }
         String type = basicAttachment.getType();
         JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
+
         if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.PDF_PREFIX)) {
             String filePath = (String) jsonObject.get(SystemConstant.PATH);
             String url = SystemConstant.TEMP_FILES_DIR + File.separator + filePath;
-            File localFile = ossUtil.ossDownload(filePath, url);
+            UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
+//            File localFile = ossUtil.ossDownload(filePath, url);
+            File localFile = fileStoreUtil.ossDownload(filePath, url, uploadFileEnum.getFssType());
             PdfDto pdfDto = PdfUtil.addPdfPage(localFile);
             for (int i = 0; i < printCount; i++) {
                 ordinaryPdfList.add(new PdfDto(localFile.getPath(), PageSizeEnum.A4, pdfDto.getPageCount()));
@@ -455,7 +463,7 @@ public class CreatePdfUtil {
      * @return
      * @throws IOException
      */
-    public List<PaperPdfDto> getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws IOException {
+    public List<PaperPdfDto> getPaperPdfFile(String paperType, ExamTaskDetail examTaskDetail) throws Exception {
         String[] paperTypes = paperType.split(",");
         List<PaperPdfDto> paperPdfDtoList = new ArrayList<>();
         PaperPdfDto paperPdfDto = null;
@@ -636,7 +644,7 @@ public class CreatePdfUtil {
                                           Long userId,
                                           ExamDetail examDetail,
                                           BasicExamRule basicExamRule,
-                                          List<PdfDto> mergePdfDeleteList) throws IOException {
+                                          List<PdfDto> mergePdfDeleteList) throws Exception {
         StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
         // oss上只认"/",windows生成的路径分隔符全部替换为"/"
         File localA4PdfFile = null, localA3PdfFile = null;
@@ -662,7 +670,8 @@ public class CreatePdfUtil {
         }
         detailService.saveOrUpdate(examDetail);
         if (Objects.nonNull(localA3PdfFile)) {
-            ossUtil.ossUpload(dirNameA3, localA3PdfFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfFile)));
+//            ossUtil.ossUpload(dirNameA3, localA3PdfFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfFile)));
+            fileStoreUtil.ossUpload(dirNameA3, localA3PdfFile, DigestUtils.md5Hex(new FileInputStream(localA3PdfFile)),fileStoreUtil.getUploadEnumByPath(dirNameA3).getFssType());
             localA3PdfFile.delete();
         }
         if (Objects.nonNull(localA4PdfFile)) {

+ 8 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FreemarkerUtil.java

@@ -10,7 +10,7 @@ import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.enums.ClassifyEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
-import com.qmth.teachcloud.common.util.OssUtil;
+import com.qmth.teachcloud.common.util.FileStoreUtil;
 import freemarker.template.Configuration;
 import freemarker.template.Template;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -42,13 +42,16 @@ public class FreemarkerUtil {
     @Resource
     DictionaryConfig dictionaryConfig;
 
-    @Resource
-    OssUtil ossUtil;
+//    @Resource
+//    OssUtil ossUtil;
 
     @Resource
     @Lazy
     PrintCommonService printCommonService;
 
+    @Resource
+    FileStoreUtil fileStoreUtil;
+
     /**
      * 单独生成签到表
      *
@@ -119,7 +122,8 @@ public class FreemarkerUtil {
             out.flush();
             if (oss) {
                 String htmlStringJoinerStr = htmlStringJoiner.toString().replace("\\", "/");
-                ossUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)));
+//                ossUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)));
+                fileStoreUtil.ossUpload(htmlStringJoinerStr, htmlFile, DigestUtils.md5Hex(new FileInputStream(htmlFile)),fileStoreUtil.getUploadEnumByPath(htmlStringJoinerStr).getFssType());
                 jsonObject.put(SystemConstant.HTML_PATH, htmlStringJoinerStr);
                 jsonObject.put(SystemConstant.UPLOAD_TYPE, new UploadFileEnum[]{
                         UploadFileEnum.FILE,

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamCardController.java

@@ -130,7 +130,7 @@ public class ExamCardController {
      */
     @ApiOperation(value = "批量下载文件")
     @RequestMapping(value = "/download_files", method = RequestMethod.POST)
-    public void taskPaperDownload(HttpServletResponse response, @RequestBody ArraysParams arraysParams) {
+    public void taskPaperDownload(HttpServletResponse response, @RequestBody ArraysParams arraysParams) throws Exception {
         examCardService.downloadFiles(response, arraysParams);
     }
 

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamTaskController.java

@@ -505,7 +505,7 @@ public class ExamTaskController {
      */
     @ApiOperation(value = "下载")
     @RequestMapping(value = "/paper_download", method = RequestMethod.POST)
-    public void taskPaperDownload(HttpServletResponse response, @RequestParam Long examTaskId) {
+    public void taskPaperDownload(HttpServletResponse response, @RequestParam Long examTaskId) throws Exception {
         examTaskService.paperDownload(response, examTaskId);
     }
 

+ 42 - 3
distributed-print/src/test/java/com/qmth/distributed/print/FssTest.java

@@ -1,11 +1,15 @@
 package com.qmth.distributed.print;
 
 import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.qmth.boot.core.fss.service.FileService;
 import com.qmth.boot.core.fss.store.FileStore;
 import com.qmth.boot.core.fss.utils.FssUtils;
+import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.UploadFileEnum;
+import com.qmth.teachcloud.common.util.FileStoreUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -29,6 +33,10 @@ public class FssTest {
     private final static Logger log = LoggerFactory.getLogger(FssTest.class);
     @Resource
     private FileService fileService;
+    @Resource
+    private FileStoreUtil fileStoreUtil;
+    @Resource
+    private DictionaryConfig dictionaryConfig;
 
     @Test
     public void uploadFile1() throws Exception {
@@ -44,17 +52,48 @@ public class FssTest {
     @Test
     public void uploadFile() throws Exception {
         UploadFileEnum type = UploadFileEnum.FILE;
-        FileStore fileStore = fileService.getFileStore("public");
         File file = new File("C:\\Users\\ASUS\\Desktop\\excel导入临时\\课程导入模板.xlsx");
+//        File file = new File("C:\\Users\\ASUS\\Desktop\\分布式印刷.txt");
         String date = DateUtil.today().replace("-", "/");
         System.out.println(file.getName());
         System.out.println(date);
-        String path = FssUtils.buildPath(type.getTitle(), date, SystemConstant.getUuid() + "." + SystemConstant.XLSX);
+        String path = FssUtils.buildPath(type.getTitle(), date, SystemConstant.getUuid() + SystemConstant.XLSX);
         System.out.println(path);
-        fileStore.write(path, new FileInputStream(file), DigestUtils.md5Hex(new FileInputStream(file)));
+//        fileService.getFileStore("public").write(path, new FileInputStream(file), DigestUtils.md5Hex(new FileInputStream(file)));
+        fileStoreUtil.ossUpload(path,new FileInputStream(file),DigestUtils.md5Hex(new FileInputStream(file)),"public");
     }
 
+    @Test
+    public void findFile(){
+        String path = "{\"path\":\"file/2021/08/18/7faa128fc0104e05b34b32961c221ac2.xlsx\",\"uploadType\":\"FILE\",\"type\":\"oss\"}";
+        JSONObject jsonObject = JSONObject.parseObject(path);
+        String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
+        String filePath = (String) jsonObject.get(SystemConstant.PATH);
+        UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
 
+        String server;
+        String config;
+        if ("public".equals(uploadFileEnum.getFssType())){
+            config = dictionaryConfig.fssPublicDomain().getConfig();
+            server = dictionaryConfig.fssPublicDomain().getServer();
+        }else if ("private".equals(uploadFileEnum.getFssType())){
+            config = dictionaryConfig.fssPrivateDomain().getConfig();
+            server = dictionaryConfig.fssPrivateDomain().getServer();
+        }else {
+            throw ExceptionResultEnum.ERROR.exception("文件存储store类型不存在");
+        }
 
+        String dirPath = server + "/" + filePath;
+        System.out.println(config);
+        System.out.println(server);
+        System.out.println(dirPath);
+    }
 
+    @Test
+    public void findType(){
+        String path = "upload/2021/08/18/7faa128fc0104e05b34b32961c221ac2.xlsx";
+        String target = path.substring(0,path.indexOf('/'));
+        UploadFileEnum type = UploadFileEnum.valueOf(target.toUpperCase());
+        System.out.println(type);
+    }
 }

+ 12 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/config/DictionaryConfig.java

@@ -92,4 +92,16 @@ public class DictionaryConfig {
     public YunMarkDomain yunMarkDomain() {
         return new YunMarkDomain();
     }
+
+    @Bean
+    @ConfigurationProperties(prefix = "com.qmth.fss.public", ignoreUnknownFields = false)
+    public FssPublicDomain fssPublicDomain() {
+        return new FssPublicDomain();
+    }
+
+    @Bean
+    @ConfigurationProperties(prefix = "com.qmth.fss.private", ignoreUnknownFields = false)
+    public FssPrivateDomain fssPrivateDomain() {
+        return new FssPrivateDomain();
+    }
 }

+ 34 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/FssPrivateDomain.java

@@ -0,0 +1,34 @@
+package com.qmth.teachcloud.common.domain;
+
+/**
+ * @Description: 文件存储中心配置-私有
+ * @Author: CaoZixuan
+ * @Date: 2021-08-18
+ */
+public class FssPrivateDomain {
+    private static final long serialVersionUID = 7510626406622200443L;
+
+    private String config;
+
+    private String server;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getConfig() {
+        return config;
+    }
+
+    public void setConfig(String config) {
+        this.config = config;
+    }
+
+    public String getServer() {
+        return server;
+    }
+
+    public void setServer(String server) {
+        this.server = server;
+    }
+}

+ 34 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/FssPublicDomain.java

@@ -0,0 +1,34 @@
+package com.qmth.teachcloud.common.domain;
+
+/**
+ * @Description: 文件存储中心配置-公有
+ * @Author: CaoZixuan
+ * @Date: 2021-08-18
+ */
+public class FssPublicDomain {
+    private static final long serialVersionUID = 7510626406622200443L;
+
+    private String config;
+
+    private String server;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public String getConfig() {
+        return config;
+    }
+
+    public void setConfig(String config) {
+        this.config = config;
+    }
+
+    public String getServer() {
+        return server;
+    }
+
+    public void setServer(String server) {
+        this.server = server;
+    }
+}

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

@@ -157,7 +157,7 @@ public interface TeachcloudCommonService {
      * @param pdf
      * @return
      */
-    public InputStream getFileInputStream(String path, boolean pdf) throws IOException;
+    public InputStream getFileInputStream(String path, boolean pdf) throws Exception;
 
     /**
      * 获取文件byte数据
@@ -166,7 +166,7 @@ public interface TeachcloudCommonService {
      * @param pdf
      * @return
      */
-    public byte[] getFileByte(String path, boolean pdf) throws IOException;
+    public byte[] getFileByte(String path, boolean pdf) throws Exception;
 
     /**
      * 获取文件
@@ -175,7 +175,7 @@ public interface TeachcloudCommonService {
      * @param pdf
      * @return
      */
-    public File getFile(String path, boolean pdf) throws IOException;
+    public File getFile(String path, boolean pdf) throws Exception;
 
     /**
      * 下载文件到本地
@@ -184,7 +184,7 @@ public interface TeachcloudCommonService {
      * @param attachment 附件表对象
      * @return
      */
-    public File copyFile(String rootPath, String fileName, BasicAttachment attachment);
+    public File copyFile(String rootPath, String fileName, BasicAttachment attachment) throws Exception;
 
     /**
      * 下载文件到本地并压缩返回

+ 9 - 8
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/BasicAttachmentServiceImpl.java

@@ -12,7 +12,6 @@ import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import com.qmth.teachcloud.common.mapper.BasicAttachmentMapper;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.util.FileStoreUtil;
-import com.qmth.teachcloud.common.util.OssUtil;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -47,8 +46,8 @@ import java.util.StringJoiner;
 public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMapper, BasicAttachment> implements BasicAttachmentService {
     private final static Logger log = LoggerFactory.getLogger(BasicAttachmentServiceImpl.class);
 
-    @Resource
-    OssUtil ossUtil;
+//    @Resource
+//    OssUtil ossUtil;
 
     @Resource
     private FileStoreUtil fileStoreUtil;
@@ -56,6 +55,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
     @Autowired
     private DictionaryConfig dictionaryConfig;
 
+
     /**
      * 保存html附件
      *
@@ -200,7 +200,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(format);
             if (oss) {//上传至oss\
                 String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
-                fileStoreUtil.ossUpload(dirName,file.getInputStream(),type.getFssType());
+                fileStoreUtil.ossUpload(dirName,file.getInputStream(),DigestUtils.md5Hex(file.getInputStream()),type.getFssType());
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
                 jsonObject.put(SystemConstant.PATH, dirName);
             } else {//上传至服务器
@@ -239,10 +239,11 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
             JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
             String type = String.valueOf(jsonObject.get(SystemConstant.TYPE));
             if (Objects.nonNull(type) && Objects.equals(type, SystemConstant.OSS)) {//删除阿里云附件
-                ossUtil.ossDelete(jsonObject.get(SystemConstant.PATH).toString());
-                if (Objects.nonNull(jsonObject.get(SystemConstant.PDF_PATH))) {
-                    ossUtil.ossDelete(jsonObject.get(SystemConstant.PDF_PATH).toString());
-                }
+                // TODO: 2021/8/18 fss删除逻辑
+//                ossUtil.ossDelete(jsonObject.get(SystemConstant.PATH).toString());
+//                if (Objects.nonNull(jsonObject.get(SystemConstant.PDF_PATH))) {
+//                    ossUtil.ossDelete(jsonObject.get(SystemConstant.PDF_PATH).toString());
+//                }
             } else {//删除服务器附件
                 File file = new File(jsonObject.get(SystemConstant.PATH).toString());
                 file.delete();

+ 47 - 19
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -75,8 +75,8 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
     @Resource
     DictionaryConfig dictionaryConfig;
 
-    @Resource
-    OssUtil ossUtil;
+//    @Resource
+//    OssUtil ossUtil;
 
     @Autowired
     private SysOrgService sysOrgService;
@@ -87,6 +87,9 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
     @Resource
     BasicAttachmentService basicAttachmentService;
 
+    @Resource
+    FileStoreUtil fileStoreUtil;
+
     /**
      * 获取用户菜单
      *
@@ -433,9 +436,11 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
             url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
         } else {
             if (uploadFileEnum == UploadFileEnum.PAPER) {
-                url = ossUtil.getPrivateUrl(filePath);
+//                url = ossUtil.getPrivateUrl(filePath);
+                url = fileStoreUtil.getPrivateUrl(filePath,uploadFileEnum.getFssType());
             } else {
-                url = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
+//                url = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
+                url = fileStoreUtil.getPrivateUrl(filePath,uploadFileEnum.getFssType());
             }
         }
         return url;
@@ -460,9 +465,11 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
             pathUrl = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + path;
         } else {
             if (isExpire) {
-                pathUrl = ossUtil.getPrivateUrl(path);
+//                pathUrl = ossUtil.getPrivateUrl(path);
+                pathUrl = fileStoreUtil.getPrivateUrl(path,fileStoreUtil.getUploadEnumByPath(path).getFssType());
             } else {
-                pathUrl = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + path;
+//                pathUrl = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + path;
+                pathUrl = fileStoreUtil.getPrivateUrl(path,fileStoreUtil.getUploadEnumByPath(path).getFssType());
             }
 
         }
@@ -489,13 +496,17 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         JSONObject jsonObject = JSONObject.parseObject(attachment.getPath());
         String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
         String filePath = (String) jsonObject.get(SystemConstant.PATH);
+        UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
         if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
             pathUrl = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
         } else {
             if (isExpire) {
-                pathUrl = ossUtil.getPrivateUrl(filePath);
+//                pathUrl = ossUtil.getPrivateUrl(filePath);
+                pathUrl = fileStoreUtil.getPrivateUrl(filePath,uploadFileEnum.getFssType());
             } else {
-                pathUrl = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
+//                pathUrl = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
+                pathUrl = fileStoreUtil.getPrivateUrl(filePath,uploadFileEnum.getFssType());
             }
 
         }
@@ -515,13 +526,16 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
         JSONObject object = JSONObject.parseObject(path);
         String filePath = object.getString(SystemConstant.PATH);
         String type = object.getString(SystemConstant.TYPE);
+        UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) object.get(SystemConstant.UPLOAD_TYPE));
+
         if (filePath.endsWith(SystemConstant.HTML_PREFIX) || filePath.endsWith(SystemConstant.FTL_PREFIX)) {
             StringBuffer sb = new StringBuffer();
             try {
                 InputStream fis;
                 if (type.equals(SystemConstant.OSS)) {
-                    byte[] bytes = ossUtil.ossDownload(filePath);
-                    fis = new ByteArrayInputStream(bytes);
+//                    byte[] bytes = ossUtil.ossDownload(filePath);
+//                    fis = new ByteArrayInputStream(bytes);
+                    fis = fileStoreUtil.ossDownloadIs(filePath,uploadType.getFssType());
                 } else {
                     String url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
                     File file = new File(url);
@@ -537,6 +551,8 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
                 }
             } catch (IOException e) {
                 throw ExceptionResultEnum.ERROR.exception("文件读取异常");
+            } catch (Exception e) {
+                e.printStackTrace();
             }
             return sb.toString();
         }
@@ -551,14 +567,17 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
      * @return
      */
     @Override
-    public InputStream getFileInputStream(String path, boolean pdf) throws IOException {
+    public InputStream getFileInputStream(String path, boolean pdf) throws Exception {
         InputStream inputStream = null;
         JSONObject jsonObject = JSONObject.parseObject(path);
         String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
         String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
+        UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
         if (Objects.equals(attachmentType, SystemConstant.OSS)) {
-            byte[] data = ossUtil.ossDownload(filePath);
-            inputStream = new ByteArrayInputStream(data);
+//            byte[] data = ossUtil.ossDownload(filePath);
+//            inputStream = new ByteArrayInputStream(data);
+            inputStream = fileStoreUtil.ossDownloadIs(filePath,uploadType.getFssType());
         } else {
             StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
             inputStream = new FileInputStream(new File(localPath.toString()));
@@ -575,13 +594,16 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
      * @throws IOException
      */
     @Override
-    public byte[] getFileByte(String path, boolean pdf) throws IOException {
+    public byte[] getFileByte(String path, boolean pdf) throws Exception {
         byte[] data = null;
         JSONObject jsonObject = JSONObject.parseObject(path);
         String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
         String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
+        UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
         if (Objects.equals(attachmentType, SystemConstant.OSS)) {
-            data = ossUtil.ossDownload(filePath);
+//            data = ossUtil.ossDownload(filePath);
+            data = fileStoreUtil.ossDownload(filePath,uploadType.getFssType());
         } else {
             StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
             InputStream inputStream = new FileInputStream(new File(localPath.toString()));
@@ -601,14 +623,17 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
      * @throws IOException
      */
     @Override
-    public File getFile(String path, boolean pdf) throws IOException {
+    public File getFile(String path, boolean pdf) throws Exception {
         File file = null;
         JSONObject jsonObject = JSONObject.parseObject(path);
         String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
         String filePath = pdf ? (String) jsonObject.get(SystemConstant.PDF_PATH) : (String) jsonObject.get(SystemConstant.PATH);
+        UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+
         StringJoiner localPath = new StringJoiner("").add(SystemConstant.TEMP_FILES_DIR).add(File.separator).add(filePath);
         if (Objects.equals(attachmentType, SystemConstant.OSS)) {
-            file = ossUtil.ossDownload(filePath, localPath.toString());
+//            file = ossUtil.ossDownload(filePath, localPath.toString());
+            file = fileStoreUtil.ossDownload(filePath, localPath.toString(),uploadType.getFssType());
         } else {
             file = new File(localPath.toString());
         }
@@ -616,14 +641,17 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
     }
 
     @Override
-    public File copyFile(String rootPath, String fileName, BasicAttachment attachment) {
+    public File copyFile(String rootPath, String fileName, BasicAttachment attachment) throws Exception {
         JSONObject object = JSONObject.parseObject(attachment.getPath());
         String filePath = object.getString(SystemConstant.PATH);
         String type = object.getString(SystemConstant.TYPE);
+        UploadFileEnum uploadType = Enum.valueOf(UploadFileEnum.class,(String) object.get(SystemConstant.UPLOAD_TYPE));
+
         if (type.equals(SystemConstant.OSS)) {
             File localPath = new File(rootPath, fileName);
             try {
-                File file = ossUtil.ossDownload(filePath, localPath.getPath());
+//                File file = ossUtil.ossDownload(filePath, localPath.getPath());
+                File file = fileStoreUtil.ossDownload(filePath, localPath.getPath(),uploadType.getFssType());
                 return file;
             } catch (IOException e) {
                 throw ExceptionResultEnum.ERROR.exception("从OSS上下载文件失败");

+ 40 - 4
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/FileStoreUtil.java

@@ -1,6 +1,9 @@
 package com.qmth.teachcloud.common.util;
 
 import com.qmth.boot.core.fss.service.FileService;
+import com.qmth.teachcloud.common.config.DictionaryConfig;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.enums.UploadFileEnum;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
@@ -22,6 +25,9 @@ public class FileStoreUtil {
     @Resource
     private FileService fileService;
 
+    @Resource
+    private DictionaryConfig dictionaryConfig;
+
     /**
      * 上传文件
      *
@@ -29,9 +35,9 @@ public class FileStoreUtil {
      * @param inputStream 流
      * @param type        fileStore类型
      */
-    public void ossUpload(String dirName, InputStream inputStream, String type) throws Exception {
+    public void ossUpload(String dirName, InputStream inputStream,String md5, String type) throws Exception {
         log.info("ossUpload is come in");
-        fileService.getFileStore(type).write(dirName, inputStream, DigestUtils.md5Hex(inputStream));
+        fileService.getFileStore(type).write(dirName, inputStream,md5);
         log.info("dirName:{}", dirName);
     }
 
@@ -42,9 +48,9 @@ public class FileStoreUtil {
      * @param file    文件
      * @param type    fileStore类型
      */
-    public void ossUpload(String dirName, File file, String type) throws Exception {
+    public void ossUpload(String dirName, File file,String md5, String type) throws Exception {
         log.info("ossUpload is come in");
-        fileService.getFileStore(type).write(dirName, new FileInputStream(file), DigestUtils.md5Hex(new FileInputStream(file)));
+        fileService.getFileStore(type).write(dirName, new FileInputStream(file), md5);
         log.info("dirName:{}", dirName);
     }
 
@@ -99,6 +105,36 @@ public class FileStoreUtil {
         return fileService.getFileStore(type).read(objectName);
     }
 
+
+    /**
+     * 获取文件访问url
+     * @param objectPath 文件路径
+     * @param type 文件上传的类型
+     * @return
+     */
+    public String getPrivateUrl(String objectPath, String type) {
+        String server;
+        if ("public".equals(type)){
+            server = dictionaryConfig.fssPublicDomain().getServer();
+        }else if ("private".equals(type)){
+            server = dictionaryConfig.fssPrivateDomain().getServer();
+        }else {
+            throw ExceptionResultEnum.ERROR.exception("文件存储store类型不存在");
+        }
+
+        return server + "/" + objectPath;
+    }
+
+    /**
+     * 根据数据库文件路径判断文件上传类型
+     * @param path 路径
+     * @return 类型
+     */
+    public UploadFileEnum getUploadEnumByPath(String path){
+        String target = path.substring(0,path.indexOf('/'));
+        return UploadFileEnum.valueOf(target.toUpperCase());
+    }
+
     /**
      * 文件存在某本地路径
      *