xiaof il y a 3 ans
Parent
commit
b04d3d86da

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

@@ -909,6 +909,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         zipFile.getParentFile().mkdirs();
                         zipFile.createNewFile();
                     }
+
+                    boolean oss = dictionaryConfig.sysDomain().isOss();
+
                     List<File> sourceFiles = new ArrayList<>();
                     for (BasicAttachment basicAttachment : basicAttachmentList) {
                         JSONObject jsonObject = JSONObject.parseObject(basicAttachment.getPath());
@@ -917,8 +920,13 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                         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(fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString(), uploadFileEnum.getFssType()));
+                        File htmlFile = null;
+                        if (oss) {
+                            htmlFile = fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), stringJoinerPdf.toString(), uploadFileEnum.getFssType());
+                        } else {
+                            htmlFile = new File((String) jsonObject.get(SystemConstant.PATH));
+                        }
+                        sourceFiles.add(htmlFile);
                     }
                     FileUtil.doZip(zipFile, sourceFiles);
                     String ossDirName = dirName.toString().replaceAll("\\\\", "/");
@@ -969,6 +977,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
             zipFile.createNewFile();
         }
 
+        boolean oss = dictionaryConfig.sysDomain().isOss();
+
         // 跟文件路径
         String zipLocalRootPath = SystemConstant.TEMP_FILES_DIR + File.separator + System.currentTimeMillis();
         Long[] ids = (Long[]) map.get("ids");
@@ -1005,8 +1015,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     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);
-                    fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath, uploadFileEnum.getFssType());
+                    if (oss) {
+                        fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath, uploadFileEnum.getFssType());
+                    } else {
+                        FileUtil.copyFile(jsonObject.getString(SystemConstant.PATH), paperPath);
+                    }
                     count++;
                 }
             }
@@ -1027,8 +1040,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     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);
-                    fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath, uploadFileEnum.getFssType());
+                    if (oss) {
+                        fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), confirmPath, uploadFileEnum.getFssType());
+                    } else {
+                        FileUtil.copyFile(jsonObject.getString(SystemConstant.PATH), confirmPath);
+                    }
                     count++;
                 }
             }
@@ -1052,8 +1068,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 JSONObject jsonObject = JSONObject.parseObject(cardAttachment.getPath());
                 String cardPath = firstPath + File.separator + "题卡" + File.separator + cardAttachment.getName() + cardAttachment.getType();
                 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());
+
+                if (oss) {
+                    fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), cardPath, uploadFileEnum.getFssType());
+                } else {
+                    FileUtil.copyFile(jsonObject.getString(SystemConstant.PATH), cardPath);
+                }
             } else {
                 List<ExamCardDetail> examCardDetailList = examCardDetailService.list(new QueryWrapper<ExamCardDetail>().lambda().eq(ExamCardDetail::getCardId, cardId));
                 if (examCardDetailList.size() != 1) {
@@ -1105,6 +1125,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         // 根文件路径
         String zipLocalRootPath = SystemConstant.TEMP_FILES_DIR + 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()));
@@ -1126,8 +1148,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             String paperPath = zipLocalRootPath + File.separator + examTask.getPaperNumber() + File.separator + "试卷" + "_" + examTask.getPaperNumber() + "_" + name + attachment.getType();
                             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());
+                            if (oss) {
+                                fileStoreUtil.ossDownload((String) jsonObject.get(SystemConstant.PATH), paperPath, uploadFileEnum.getFssType());
+                            } else {
+                                FileUtil.copyFile(jsonObject.getString(SystemConstant.PATH), paperPath);
+                            }
                         }
                     }
                 }
@@ -1177,7 +1202,6 @@ public class TaskLogicServiceImpl implements TaskLogicService {
         }
 
         ZipUtil.zip(zipLocalRootPath, zipFile.getPath(), false);
-//        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);
@@ -1788,6 +1812,8 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                     }
                 }
 
+                boolean oss = dictionaryConfig.sysDomain().isOss();
+
                 if (Objects.isNull(paperFileDownloadContent)) {
                     continue;
                 }
@@ -1822,7 +1848,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             paperName = paperName + "-" + examTaskPaperFileDto.getPaperType();
                             String paperLocalPath = filePath + paperName + examTaskPaperFileDto.getPaperSuffix();
                             String paperPath = examTaskPaperFileDto.getPaperPath();
-                            fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
+                            if (oss) {
+                                fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
+                            } else {
+                                FileUtil.copyFile(paperPath, paperLocalPath);
+                            }
                             courseCount = 1;
                         }
                         break;
@@ -1854,7 +1884,12 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             paperName = paperName + "-" + examTaskPaperFileDto.getPaperType();
                             String paperLocalPath = filePath + paperName + examTaskPaperFileDto.getPaperSuffix();
                             String paperPath = examTaskPaperFileDto.getPaperPath();
-                            fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
+
+                            if (oss) {
+                                fileStoreUtil.ossDownload(paperPath, paperLocalPath, fileStoreUtil.getUploadEnumByPath(paperPath).getFssType());
+                            } else {
+                                FileUtil.copyFile(paperPath, paperLocalPath);
+                            }
                             courseCount = 1;
                         }
                         break;

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

@@ -9,6 +9,7 @@ import com.qmth.distributed.print.business.bean.dto.CardRuleDto;
 import com.qmth.distributed.print.business.entity.BasicCardRule;
 import com.qmth.distributed.print.business.service.BasicCardRuleService;
 import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import io.swagger.annotations.Api;
@@ -82,7 +83,10 @@ public class BasicCardRuleController {
      */
     @ApiOperation(value = "查询单个")
     @RequestMapping(value = "/get_one", method = RequestMethod.POST)
-    public Result getOne(@RequestParam(value = "id", required = true) Long id) {
+    public Result getOne(@RequestParam(value = "id", required = false) Long id) {
+        if(id == null){
+            throw ExceptionResultEnum.ERROR.exception("");
+        }
         BasicCardRule cardRule = basicCardRuleService.getById(id);
         return ResultUtil.ok(cardRule);
     }

+ 26 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/util/FileUtil.java

@@ -2,6 +2,7 @@ package com.qmth.teachcloud.common.util;
 
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import org.apache.commons.io.FileUtils;
 import org.apache.tomcat.util.http.fileupload.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -541,4 +542,29 @@ public class FileUtil {
             log.error(SystemConstant.LOG_ERROR, e);
         }
     }
+
+    /**
+     * 复制文件
+     *
+     * @param sourceFileName 源文件
+     * @param destFileName   目标文件
+     */
+    public static void copyFile(String sourceFileName, String destFileName) {
+        try {
+            File sourceFile = new File(sourceFileName);
+            if (!sourceFile.exists()) {
+                throw ExceptionResultEnum.ERROR.exception("源文件" + sourceFileName + "不存在");
+            }
+
+            File desFile = new File(destFileName);
+            if (!desFile.exists()) {
+                desFile.getParentFile().mkdirs(); //目标文件目录不存在的话需要创建目录
+                desFile.createNewFile();
+            }
+
+            FileUtils.copyFile(sourceFile, desFile);
+        } catch (IOException e) {
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
+        }
+    }
 }