Kaynağa Gözat

试卷下载md5修改

wangliang 4 yıl önce
ebeveyn
işleme
423c3f45e4

+ 14 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamPaperServiceImpl.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.aliyun.oss.common.utils.BinaryUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.cache.RedisKeyHelper;
 import com.qmth.themis.business.cache.bean.ExamPaperCacheBean;
@@ -20,6 +21,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 
@@ -104,7 +106,19 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
         ret.setTotalObjectiveScore(ep.getTotalObjectiveScore());
         ret.setTotalSubjectiveScore(ep.getTotalSubjectiveScore());
         ret.setPaperPath(ep.getPaperPath());
+        if (Objects.isNull(ep.getPaperMd5())) {
+            try {
+                ep.setPaperMd5(BinaryUtil.encodeMD5(ossUtil.download(false, ep.getPaperPath())));
+                if (Objects.isNull(ep.getStructMd5())) {
+                    ep.setStructMd5(BinaryUtil.encodeMD5(ossUtil.download(false, ep.getStructPath())));
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        ret.setPaperMd5(ep.getPaperMd5());
         ret.setStructPath(ep.getStructPath());
+        ret.setStructMd5(ep.getStructMd5());
         ret.setAnswerPath(ep.getAnswerPath());
         ret.setDecryptSecret(ep.getDecryptSecret());
         ret.setDecryptVector(ep.getDecryptVector());

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

@@ -42,7 +42,6 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.math.BigDecimal;
-import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.regex.Matcher;
@@ -1231,9 +1230,9 @@ public class TEExamServiceImpl extends ServiceImpl<TEExamMapper, TEExam> impleme
         }
         ExamPaperDownloadBean ret = new ExamPaperDownloadBean();
         ret.setPaperUrl(ossUtil.getPrivateUrl(ep.getPaperPath()));
-        ret.setPaperMd5(BinaryUtil.encodeMD5(ossUtil.download(false, ep.getPaperPath())));
+        ret.setPaperMd5(ep.getPaperMd5());
         ret.setStructUrl(ossUtil.getPrivateUrl(ep.getStructPath()));
-        ret.setStructMd5(BinaryUtil.encodeMD5(ossUtil.download(false, ep.getStructPath())));
+        ret.setStructMd5(ep.getStructMd5());
         return ret;
     }
 

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

@@ -399,8 +399,8 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
         paper.setPaperMd5(BinaryUtil.encodeMD5(FileUtil.fileConvertToByteArray(encryptZip)));
         ossUtil.upload(false, filePath, encryptZip);
     }
-
-    private void disposeStruct(String rootDir, TEExamPaper paper, File paperFile) {
+    
+    private void disposeStruct(String rootDir, TEExamPaper paper, File paperFile) throws IOException {
         BigDecimal obTotal = new BigDecimal(0);
         BigDecimal subTotal = new BigDecimal(0);
         if (paperFile == null) {
@@ -446,9 +446,9 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
                 }
             }
         }
-
         String filePath = sdf.format(new Date()) + "/" + uuid() + ".json";
         paper.setStructPath(filePath);
+        paper.setStructMd5(BinaryUtil.encodeMD5(FileUtil.fileConvertToByteArray(new File(filePath))));
         paper.setTotalObjectiveScore(obTotal.doubleValue());
         paper.setTotalSubjectiveScore(subTotal.doubleValue());
         ossUtil.upload(false, filePath, paperJson.toJSONString());