Browse Source

试卷下载md5修改

wangliang 4 years ago
parent
commit
6b17480331

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

@@ -36,11 +36,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
+import java.io.*;
 import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -399,7 +397,7 @@ 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) throws IOException {
         BigDecimal obTotal = new BigDecimal(0);
         BigDecimal subTotal = new BigDecimal(0);
@@ -448,7 +446,20 @@ 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))));
+        ByteArrayOutputStream out = null;
+        try {
+            out = new ByteArrayOutputStream();
+            out.write(paperJson.toJSONString().getBytes(StandardCharsets.UTF_8));
+            byte[] bookByteAry = out.toByteArray();
+            paper.setStructMd5(BinaryUtil.encodeMD5(bookByteAry));
+        } catch (Exception e) {
+            log.error("请求出错", e);
+        } finally {
+            if (Objects.nonNull(out)) {
+                out.flush();
+                out.close();
+            }
+        }
         paper.setTotalObjectiveScore(obTotal.doubleValue());
         paper.setTotalSubjectiveScore(subTotal.doubleValue());
         ossUtil.upload(false, filePath, paperJson.toJSONString());