yangdamao 2 年之前
父节点
当前提交
23afa58ea8

+ 2 - 1
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -122,7 +122,8 @@ public class CommonController extends BaseController {
         if (ToFile.createNewFile()) {
             FileUploadUtils.merge(bo.getFileMd5(), path, ToFile.getPath());
             //校验文件MD5值
-            if (!bo.getFileMd5().equals(FileUtils.md5HashCode(ToFile.getPath()))) {
+            String content = FileUtils.md5HashCode(ToFile.getPath());
+            if (!bo.getFileMd5().equals(content)) {
                 //文件不一致,删除文件
                 ToFile.delete();
                 //删除分片资源

+ 6 - 2
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/file/FileUtils.java

@@ -22,6 +22,7 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.security.MessageDigest;
 import java.util.Comparator;
+import java.util.Formatter;
 import java.util.UUID;
 import java.util.stream.Stream;
 
@@ -278,8 +279,11 @@ public class FileUtils extends org.apache.commons.io.FileUtils
             fis.close();
             //转换并返回包含16个元素字节数组,返回数值范围为-128到127
             byte[] md5Bytes = md.digest();
-            BigInteger bigInt = new BigInteger(1, md5Bytes);
-            return bigInt.toString(16);
+            Formatter formatter = new Formatter();
+            for (byte md5Byte : md5Bytes) {
+                formatter.format("%02x", md5Byte);
+            }
+            return formatter.toString();
         } catch (Exception e) {
             e.printStackTrace();
             return "";

+ 1 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/config/SecurityConfig.java

@@ -136,6 +136,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/common/rollback/period").anonymous()
                 .antMatchers("/common/decompression").anonymous()
                 .antMatchers("/common/merge/file").anonymous()
+                .antMatchers("/common/delete/file").anonymous()
                 .antMatchers("/course/handouts/**").anonymous()
                 .antMatchers("/common/get/goods").anonymous()
                 .antMatchers("/common/get/goods/studyUrl").anonymous()