Quellcode durchsuchen

分片上传接口加上事务控制

lijie vor 3 Jahren
Ursprung
Commit
c2a7d72d27

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

@@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.common.utils.ResourceUtil;
 import com.persagy.dmp.file.constant.FileCommonConst;
 import com.persagy.dmp.file.context.OldFileAppContext;
@@ -22,6 +23,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.SneakyThrows;
 import org.springframework.core.io.Resource;
 import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -257,6 +259,7 @@ public class CompatibleOldFileController {
      */
     @PostMapping(value = "/common/register_multipart_upload")
     @ResponseBody
+    @Transactional(rollbackFor = BusinessException.class)
     public String registerMultipartUpload() {
         if (StrUtil.isBlank(OldFileAppContext.getContext().getSystemId())
             || StrUtil.isBlank(OldFileAppContext.getContext().getKey())){
@@ -287,6 +290,7 @@ public class CompatibleOldFileController {
     @SneakyThrows
     @RequestMapping(value = "/common/multipart_upload",consumes = {MediaType.MULTIPART_FORM_DATA})
     @ResponseBody
+    @Transactional(rollbackFor = BusinessException.class)
     public String multipartUpload(@RequestParam(value = "file",required = false) MultipartFile file,
                                   @RequestParam(value = "uploadId",required = false) String uploadId,
                                   @RequestParam(value = "chunkNumber",required = false) Integer chunkNumber,
@@ -351,6 +355,7 @@ public class CompatibleOldFileController {
     @SneakyThrows
     @RequestMapping(value = "/common/merge_multipart")
     @ResponseBody
+    @Transactional(rollbackFor = BusinessException.class)
     public String mergeMultipart() {
         if (StrUtil.isBlank(OldFileAppContext.getContext().getUploadId())){
             return INCORRECT_PARAMETERS;