浏览代码

公共上传接口增加扩展字段,可自定义oss上传路径

dengsixing 3 年之前
父节点
当前提交
b1f9f34d8b

+ 3 - 3
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/SceneEditController.java

@@ -698,7 +698,6 @@ public class SceneEditController extends BaseController {
      * </p>
      * @author dengsixing
      * @date 2022/2/16
-     * @param num
      * @return
      **/
     @PostMapping(value = "/cad/rename")
@@ -849,8 +848,9 @@ public class SceneEditController extends BaseController {
         @RequestParam(value = "bizType",required = false) String bizType,
         @RequestParam(value = "files",required = false) MultipartFile[] files,
         @RequestParam(value = "num",required = false) String num,
-        @RequestParam(value = "type",required = false,defaultValue = "1") Integer type) throws Exception {
-        return sceneUploadService.uploads(base64,fileName,bizType,files,num,type,getToken());
+        @RequestParam(value = "type",required = false,defaultValue = "1") Integer type,
+        @RequestParam(value = "uploadPath",required = false) String uploadPath) throws Exception {
+        return sceneUploadService.uploads(base64,fileName,bizType,files,num,type,getToken(),uploadPath);
     }
 
     /**

+ 2 - 1
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/ISceneUploadService.java

@@ -16,7 +16,8 @@ import org.springframework.web.multipart.MultipartFile;
  */
 public interface ISceneUploadService extends IService<SceneUpload> {
 
-    String uploads(String imgData, String fileName,String blzType,MultipartFile[] files, String sceneCode, Integer type,String token) throws Exception;
+    String uploads(String imgData, String fileName,String blzType,MultipartFile[] files,
+        String sceneCode, Integer type,String token, String uploadPath) throws Exception;
 
     ResultData delete(DeleteFileParamVO param) throws Exception;
 }

+ 6 - 4
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneUploadServiceImpl.java

@@ -67,7 +67,8 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
     private SSOLoginHelper ssoLoginHelper;
 
     @Override
-    public String uploads(String imgData,String fileName,String blzType,MultipartFile[] files,String sceneCode,Integer type,String token) throws Exception{
+    public String uploads(String imgData,String fileName,String blzType,MultipartFile[] files,
+        String sceneCode,Integer type,String token, String uploadPath) throws Exception{
         SSOUser ssoUser = ssoLoginHelper.loginCheck(token);
         Long userId = ssoUser == null ? null :ssoUser.getId();
 
@@ -79,7 +80,7 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
         if(files !=null && files.length >0){
             multipartFiles.addAll(Arrays.asList(files));
         }
-        return this.uploadFiles(fileName,blzType,multipartFiles,sceneCode,type,userId);
+        return this.uploadFiles(fileName,blzType,multipartFiles,sceneCode,type,userId,uploadPath);
     }
 
     @Override
@@ -107,7 +108,8 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
         return ResultData.ok();
     }
 
-    public String uploadFiles(String sendFileName,String bizType,List<MultipartFile> files, String sceneCode, Integer type,Long userId) throws Exception{
+    public String uploadFiles(String sendFileName,String bizType,List<MultipartFile> files,
+        String sceneCode, Integer type,Long userId, String uploadPath) throws Exception{
         if (StrUtil.isEmpty(sceneCode))
             throw new BusinessException(ServerCode.PARAM_REQUIRED, "num");
         if(CollUtil.isEmpty(files))
@@ -129,7 +131,7 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
             if(files.size() ==1 && StringUtils.isNotBlank(sendFileName)){
                 realFileName = sendFileName ;
             }
-            String ossPath = String.format(UploadFilePath.USER_EDIT_PATH ,sceneCode) + realFileName;
+            String ossPath = StrUtil.isNotBlank(uploadPath) ? uploadPath : (String.format(UploadFilePath.USER_EDIT_PATH ,sceneCode) + realFileName);
             try {
                 uploadToOssUtil.upload2(newFile.getPath(),ossPath);
             }catch (Exception e){