Jelajahi Sumber

fix bug:使用旧接口进行断点续传时存在bucket的名称不合法并且合并时无法获取文件md5值

lijie 3 tahun lalu
induk
melakukan
a822666f0b

+ 11 - 11
dmp-cloud/dmp-file/src/main/java/com/persagy/dmp/file/controller/CompatibleOldFileController.java

@@ -264,8 +264,8 @@ public class CompatibleOldFileController {
             return INCORRECT_PARAMETERS;
         }
         // 1.如果非覆盖且文件信息已存在则直接返回文件已存在
-        if (!OldFileAppContext.getContext().getOverwrite() &&
-                null!=fileService.load(OldFileAppContext.getContext().getKey())){
+        FileInfo fileInfo = fileService.load(OldFileAppContext.getContext().getKey());
+        if (!OldFileAppContext.getContext().getOverwrite() && null!=fileInfo){
             return FILE_EXISTED;
         }
         String uploadId = compatibleOldFileService.registerMultipartUpload();
@@ -317,14 +317,6 @@ public class CompatibleOldFileController {
         jsonObj.put("TotalCount", 0);
         // 1.根据文件md5判断是否已经存在
         FileMd5 fileMd5 = fileMd5Service.queryFileMd5ByFileMd5(md5);
-        if (ObjectUtil.isNotEmpty(fileMd5) && FileCommonConst.UPLOAD_SUCCESS.equals(fileMd5.getUploadStatus())){
-            // MD5文件已存在
-            jsonObj.put("TotalCount", totalChunks);
-            return jsonObj.toJSONString();
-        }
-        // 1.先上传分片信息
-        IFileStorageService service = FileStorageFactory.getService();
-        service.uploadChuck(service.getChuckBucketName(null),md5,file.getInputStream(),totalChunks,chunkNumber);
         // 2.更新fileInfo
         if (StrUtil.isBlank(fileInfo.getFileMd5())){
             fileInfo.setFileMd5(md5);
@@ -333,7 +325,15 @@ public class CompatibleOldFileController {
             }
             fileService.updateById(fileInfo);
         }
-        // 3.如果MD5信息没有的话则创建一个
+        if (ObjectUtil.isNotEmpty(fileMd5) && FileCommonConst.UPLOAD_SUCCESS.equals(fileMd5.getUploadStatus())){
+            // MD5文件已存在
+            jsonObj.put("TotalCount", totalChunks);
+            return jsonObj.toJSONString();
+        }
+        // 3.先上传分片信息
+        IFileStorageService service = FileStorageFactory.getService();
+        service.uploadChuck(service.getChuckBucketName(null),md5,file.getInputStream(),totalChunks,chunkNumber);
+        // 4.如果MD5信息没有的话则创建一个
         if (ObjectUtil.isEmpty(fileMd5)){
             FileMd5 fileMd5Create = FileMd5Creator.of(fileInfo.getCreator(), md5, FileCommonConst.UPLOAD_PART);
             fileMd5Create.setFileSize(totalSize);

+ 1 - 1
dmp-cloud/dmp-file/src/main/java/com/persagy/dmp/file/service/impl/CompatibleOldFileServiceImpl.java

@@ -258,7 +258,7 @@ public class CompatibleOldFileServiceImpl implements CompatibleOldFileService {
         try {
             fileInfo.setCreator(FileInfoCreator.formatBucket(OldFileAppContext.getContext().getSystemId()));
             fileInfo.setId(OldFileAppContext.getContext().getKey());
-            fileService.save(fileInfo);
+            fileService.saveOrUpdate(fileInfo);
             return fileInfo.getBusinessId();
         }catch (Exception e){
             return null;

+ 7 - 2
dmp-comp/dmp-mybatis/src/main/java/com/persagy/dmp/mybatis/handler/AuditInfoHandler.java

@@ -1,5 +1,6 @@
 package com.persagy.dmp.mybatis.handler;
 
+import cn.hutool.core.util.StrUtil;
 import com.persagy.dmp.common.context.AppContext;
 import com.persagy.dmp.common.lang.PsDateTime;
 import com.persagy.dmp.common.model.entity.AuditableEntity;
@@ -72,11 +73,15 @@ public class AuditInfoHandler implements Interceptor {
         AuditableEntity entity = (AuditableEntity) parameter;
         // 新增 - 创建人、创建时间赋值
         if (isInsert) {
-            entity.setCreator(AppContext.getContext().getAccountId());
+            if (StrUtil.isBlank(entity.getCreator())){
+                entity.setCreator(AppContext.getContext().getAccountId());
+            }
             entity.setCreationTime(new PsDateTime());
         }
         // 修改 - 修改人、修改时间更新 20211013 新增时也给修改时间赋值,解决按最后更新时间排序为空的问题
-        entity.setModifier(AppContext.getContext().getAccountId());
+        if (StrUtil.isBlank(entity.getModifier())){
+            entity.setModifier(AppContext.getContext().getAccountId());
+        }
         entity.setModifiedTime(new PsDateTime());
     }
 }