Browse Source

Merge remote-tracking branch 'origin/dev' into dev

wangliang 4 years ago
parent
commit
5e5a9cdef1

+ 2 - 2
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEOpenServiceImpl.java

@@ -88,8 +88,8 @@ public class TEOpenServiceImpl implements TEOpenService {
             String anwserPath = paper.getAnswerPath();
             File paperFile = new File(dir + uuid() + ".json");
             File anwserFile = new File(dir + uuid() + ".json");
-            FileUtil.saveUrlAsFile(ossUtil.getAliYunOssPrivateDomain().getPrivateUrl() + "/" + paperPath, paperFile);
-            FileUtil.saveUrlAsFile(ossUtil.getAliYunOssPrivateDomain().getPrivateUrl() + "/" + anwserPath, anwserFile);
+            ossUtil.download(false, paperPath, paperFile.getAbsolutePath());
+            ossUtil.download(false, anwserPath, anwserFile.getAbsolutePath());
             JSONObject answerJson = JSONObject.parseObject(FileUtil.readFileContent(anwserFile));
             JSONArray answerdetails = answerJson.getJSONArray("details");
             JSONObject structJson = JSONObject.parseObject(FileUtil.readFileContent(paperFile));

+ 1 - 5
themis-business/src/main/java/com/qmth/themis/business/templete/TaskImportCommon.java

@@ -108,11 +108,7 @@ public class TaskImportCommon {
                     .add(this.path);
             file = new File(localPath.toString());
         } else {
-            try {
-                file = this.ossUtil.download(false, this.path, this.path);
-            } catch (IOException e) {
-                log.error("请求出错", e);
-            }
+            file = this.ossUtil.download(false, this.path, this.path);
         }
         return file;
     }

+ 28 - 20
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamPaperImportTemplete.java

@@ -1,6 +1,29 @@
 package com.qmth.themis.business.templete.impl;
 
-import cn.hutool.core.date.DateUtil;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.UUID;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.qmth.themis.business.constant.SystemConstant;
@@ -25,22 +48,9 @@ import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.FileUtil;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import sun.misc.BASE64Decoder;
 
-import javax.annotation.Resource;
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
-import java.util.*;
+import cn.hutool.core.date.DateUtil;
+import sun.misc.BASE64Decoder;
 
 /**
  * @Description: 试卷导入
@@ -278,9 +288,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
                 structFile = paperFile;
             } else {
                 String structPath = paper.getStructPath();
-                String url = ossUtil.getPrivateUrl(structPath);
                 structFile = new File(rootDir + uuid() + ".json");
-                FileUtil.saveUrlAsFile(url, structFile);
+                ossUtil.download(false, structPath, structFile.getAbsolutePath());
             }
             disposeAnswer(rootDir, paper, answerFile, structFile, attachmentDir);
         }
@@ -659,11 +668,10 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
                     throw new BusinessException("科目 " + courseCode + " 试卷 " + paperCode + " 没有试卷信息,不能先导入答案");
                 }
                 String structPath = paper.getStructPath();
-                String url = ossUtil.getPrivateUrl(structPath);
                 String name = structPath.substring(structPath.lastIndexOf("/") + 1);
                 File structFile = new File(rootDir + name);
                 try {
-                    FileUtil.saveUrlAsFile(url, structFile);
+                    ossUtil.download(false, structPath, structFile.getAbsolutePath());
                     compareAnswerAndPaper(courseCode, paperCode, answerFile, structFile);
                 } finally {
                     if (structFile.exists()) {

+ 1 - 1
themis-business/src/main/java/com/qmth/themis/business/util/OssUtil.java

@@ -147,7 +147,7 @@ public class OssUtil {
      * @param localPath
      * @throws IOException
      */
-    public File download(boolean isPublic, String objectName, String localPath) throws IOException {
+    public File download(boolean isPublic, String objectName, String localPath){
         log.info("oss Download is come in");
         String bucket = isPublic ? aliYunOssPublicDomain.getPublicBucket() : aliYunOssPrivateDomain.getPrivateBucket();
         OSS client = isPublic ? publicClient : privateClient;