瀏覽代碼

认证通后台【云资料库】上传文件夹功能开发

JiangChongBo 2 年之前
父節點
當前提交
cf7fddd90d

+ 22 - 0
src/main/java/com/caimei/controller/admin/data/DatabaseApi.java

@@ -262,4 +262,26 @@ public class DatabaseApi {
         databaseService.uploadDictionary(multipartFiles);
         return ResponseJson.success();
     }
+
+    @PostMapping("/upload/dictionary")
+    public ResponseJson uploadPackage(@CurrentUser SysUser sysUser,@RequestBody String params){
+        if (null == sysUser) {
+            return ResponseJson.error("用户信息异常", null);
+        }
+        // 获取供应商用户id
+        Integer userIdentity = sysUser.getUserIdentity();
+        Integer authUserId = 2 == userIdentity ? sysUser.getId() : 3 == userIdentity ? sysUser.getParentId() : null;
+        if (null == authUserId) {
+            return ResponseJson.error("供应商用户id不能为空", null);
+        }
+        JSONObject parseObject = JSONObject.parseObject(params);
+        String fileName = parseObject.getString("fileName");
+        String ossName = parseObject.getString("ossName");
+        String ossUrl = parseObject.getString("ossUrl");
+        String fileSize = parseObject.getString("fileSize");
+        Integer parentId = parseObject.getInteger("parentId");
+        String mime = parseObject.getString("mime");
+        String filePath=parseObject.getString("filePath");
+        return databaseService.uploadPackage(authUserId, fileName, ossName, ossUrl, fileSize, parentId,mime,filePath);
+    }
 }

+ 4 - 0
src/main/java/com/caimei/mapper/cmMapper/FileMapper.java

@@ -80,4 +80,8 @@ public interface FileMapper {
     void updateFileByArticleId(FileTreeVo fileTreeVo);
 
     FileTreeVo findFileByArticleId(Integer id);
+
+    List<Integer> findDictionaryById(Integer fileId);
+
+    List<Integer> getNewestInfoById();
 }

+ 2 - 0
src/main/java/com/caimei/service/data/DatabaseService.java

@@ -39,4 +39,6 @@ public interface DatabaseService {
     ResponseJson<FileTreeVo> getFileDetail(Integer fileId, Integer authUserId);
 
     ResponseJson uploadDictionary(MultipartFile[] multipartFile);
+
+    ResponseJson uploadPackage(Integer authUserId,String fileName, String ossName, String ossUrl, String fileSize,Integer parentId,String mime,String filePath);
 }

+ 42 - 0
src/main/java/com/caimei/service/data/impl/DatabaseServiceImpl.java

@@ -1,10 +1,14 @@
 package com.caimei.service.data.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.IAcsClient;
 import com.aliyuncs.profile.DefaultProfile;
+import com.aliyuncs.utils.StringUtils;
+import com.caimei.annotation.CurrentUser;
 import com.caimei.mapper.cmMapper.FileMapper;
 import com.caimei.model.ResponseJson;
+import com.caimei.model.po.SysUser;
 import com.caimei.model.vo.FileTreeVo;
 import com.caimei.service.async.AsyncService;
 import com.caimei.service.data.DatabaseService;
@@ -15,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
@@ -418,4 +423,41 @@ public class DatabaseServiceImpl implements DatabaseService {
         }
         return filenames;
     }
+
+    @Override
+    public ResponseJson uploadPackage(Integer authUserId,String fileName, String ossName, String ossUrl, String fileSize,Integer parentId,String mime,String filePath){
+        //如果文件夹没有文件则直接返回
+        if(StringUtils.isNotEmpty(filePath)){
+            if(!filePath.contains(".")){
+                ResponseJson.error("-1","文件夹为空");
+            }
+            String[] filePathArr = filePath.split("/");
+            for (int i=0 ;i<filePathArr.length;i++){
+                if(filePathArr[i].contains(".")){
+                    //新增文件
+                    getOssUploadResult(authUserId,fileName,ossName,ossUrl,fileSize,parentId,mime);
+                    System.out.println("文件---------"+filePathArr[i]);
+                }else{
+                    //创建文件夹
+                    //判断文件夹是否存在(不存在则新建,存在则跳过)
+                    List<Integer> dictionaryById = fileMapper.findDictionaryById(parentId);
+                    if(null!=dictionaryById&&dictionaryById.size()>0){
+                        continue;
+                    }else{
+                        //不存在创建文件夹
+                        fileMapper.creatPackage(authUserId, parentId, filePathArr[i]);
+                        //查询最新文件夹id作为下一次的父id
+                        List<Integer> newestInfoById = fileMapper.getNewestInfoById();
+                        if(null!=newestInfoById&&newestInfoById.size()>0){
+                            parentId = newestInfoById.get(0);
+                        }
+                    }
+                    System.out.println("文件夹---------"+filePathArr[i]);
+                }
+            }
+        }else{
+            ResponseJson.error("-1","文件夹为空");
+        }
+        return ResponseJson.success();
+    }
 }

+ 10 - 0
src/main/resources/mapper/FileMapper.xml

@@ -324,4 +324,14 @@
         from cm_tree_file
         where articleId = #{id}
     </select>
+    <select id="findDictionaryById" resultType="java.lang.Integer">
+        select id
+        from cm_tree_file
+        where id = #{fileId}
+    </select>
+    <select id="getNewestInfoById" resultType="java.lang.Integer">
+        select id
+        from cm_tree_file
+        order by id desc
+    </select>
 </mapper>