Parcourir la source

更新 file-service disk 模块

reghao il y a 4 jours
Parent
commit
1248117056

+ 0 - 9
file/file-service/src/main/java/cn/reghao/tnb/file/app/zdisk/db/mapper/DiskFileMapper.java

@@ -4,7 +4,6 @@ import cn.reghao.jutil.jdk.web.db.BaseMapper;
 import cn.reghao.jutil.jdk.web.db.Page;
 import cn.reghao.tnb.file.app.zdisk.model.po.DiskFile;
 import cn.reghao.tnb.file.app.zdisk.model.query.DiskQuery;
-import cn.reghao.tnb.file.app.zdisk.model.vo.DiskFileCount;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -21,16 +20,8 @@ public interface DiskFileMapper extends BaseMapper<DiskFile> {
     void updateDeleteDiskFiles(List<String> fileIds);
     void updateDeleteByPathPrefix(@Param("owner") long owner, @Param("pathPrefix") String pathPrefix);
 
-    List<DiskFileCount> findFileTypeCountByGroup(long owner);
     int countByDiskQuery(DiskQuery diskQuery);
     List<DiskFile> findDiskQueryByPage(@Param("page") Page page, @Param("diskQuery") DiskQuery diskQuery);
     List<DiskFile> findByFileIds(List<String> list);
-    List<DiskFile> findByParentIds(List<String> list);
     DiskFile findRoot();
-
-    List<String> countSha256sumGroupByDiskQuery(@Param("fileType") int fileType, @Param("userId") long userId);
-    List<DiskFile> findSha256sumGroupByPage(@Param("page") Page page,
-                                            @Param("fileType") int fileType,
-                                            @Param("userId") long userId);
-    List<DiskFile> findSha256sumGroup(List<String> sha256sumList);
 }

+ 0 - 19
file/file-service/src/main/java/cn/reghao/tnb/file/app/zdisk/model/vo/DiskFileCount.java

@@ -1,19 +0,0 @@
-package cn.reghao.tnb.file.app.zdisk.model.vo;
-
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-
-/**
- * @author reghao
- * @date 2025-08-21 21:44:21
- */
-@AllArgsConstructor
-@NoArgsConstructor
-@Setter
-@Getter
-public class DiskFileCount {
-    private int fileType;
-    private long total;
-}

+ 17 - 139
file/file-service/src/main/java/cn/reghao/tnb/file/app/zdisk/service/DiskFileService.java

@@ -8,7 +8,6 @@ import cn.reghao.jutil.jdk.converter.DateTimeConverter;
 import cn.reghao.jutil.jdk.web.db.Page;
 import cn.reghao.jutil.jdk.web.db.PageList;
 import cn.reghao.jutil.jdk.web.result.Result;
-import cn.reghao.tnb.file.app.zdisk.model.vo.DiskFileCount;
 import cn.reghao.tnb.file.app.zdisk.model.vo.DiskFileDetail;
 import cn.reghao.tnb.file.app.zdisk.model.vo.FileInfo;
 import cn.reghao.tnb.file.app.zdisk.model.vo.NamePath;
@@ -49,11 +48,16 @@ public class DiskFileService {
 
     public Result addDiskFile(UploadedFile uploadedFile) {
         String pid = uploadedFile.getPid();
-        DiskFile diskFile1 = findByFileId(pid);
-        if (diskFile1 == null) {
-            return Result.fail("folder not exist");
+        String parentPath = "/";
+        if (!"0".equals(pid)) {
+            DiskFile diskFile1 = findByFileId(pid);
+            if (diskFile1 == null) {
+                return Result.fail("folder not exist");
+            }
+
+            parentPath = diskFile1.getPath();
         }
-        String parentPath = diskFile1.getPath();
+
         try {
             int channelCode = uploadedFile.getChannelCode();
             String uploadId = uploadedFile.getUploadId();
@@ -62,7 +66,9 @@ public class DiskFileService {
             String path = FileUtil.getCanonicalPath(String.format("%s/%s", parentPath, filename));
             DiskFile diskFile2 = findByPath(path);
             if (diskFile2 != null) {
-                return Result.fail("file exist");
+                filename = filename + System.currentTimeMillis();
+                path = FileUtil.getCanonicalPath(String.format("%s/%s", parentPath, filename));
+                //return Result.fail("file exist");
             }
 
             long size = objectMeta.getSize();
@@ -122,97 +128,6 @@ public class DiskFileService {
         return Result.success();
     }
 
-    public void restore(List<String> fileIds) {
-        List<DiskFile> list = findByFileIds(fileIds);
-        List<String> files = list.stream()
-                .filter(diskFile -> diskFile.getFileType() != ObjectType.Folder.getCode())
-                .map(DiskFile::getFileId)
-                .collect(Collectors.toList());
-
-        list.stream()
-                .filter(diskFile -> diskFile.getFileType() == ObjectType.Folder.getCode())
-                .map(diskFile1 -> getChildren(diskFile1.getPath()))
-                .flatMap(Collection::stream)
-                .forEach(diskFile -> {
-                    files.add(diskFile.getFileId());
-                });
-
-        if (!files.isEmpty()) {
-            //diskFile1Repository.updateRestoreFiles(files);
-        }
-    }
-
-    public void erase(List<String> fileIds) {
-        List<DiskFile> list = findByFileIds(fileIds);
-        List<String> files = list.stream()
-                .filter(diskFile -> diskFile.getFileType() != ObjectType.Folder.getCode())
-                .map(DiskFile::getFileId)
-                .collect(Collectors.toList());
-
-        list.stream()
-                .filter(diskFile -> diskFile.getFileType() == ObjectType.Folder.getCode())
-                .map(diskFile -> findByPathPrefix(diskFile.getPath()))
-                .flatMap(Collection::stream)
-                .forEach(diskFile -> {
-                    files.add(diskFile.getFileId());
-                });
-
-        if (!files.isEmpty()) {
-            //diskFile1Repository.deleteByFileIds(files);
-        }
-    }
-
-    public Result rename(String fileId, String newFilename, long owner) {
-        DiskQuery diskQuery = new DiskQuery.Builder()
-                .fileId(fileId)
-                .build();
-        Page page = new Page(1, 10);
-        List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
-        DiskFile current = diskFileList.get(0);
-        if (current == null) {
-            String msg = String.format("file %s not exist", fileId);
-            return Result.fail(msg);
-        }
-
-        String parentPath = getParentPath(current.getPath());
-        String newPath = String.format("%s/%s", parentPath, newFilename);
-
-        diskQuery = new DiskQuery.Builder()
-                .owner(owner)
-                .path(newPath)
-                .build();
-        page = new Page(1, 10);
-        diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
-        DiskFile diskFile = diskFileList.get(0);
-        if (diskFile != null) {
-            String msg = String.format("filename %s exist", newFilename);
-            return Result.fail(msg);
-        }
-
-        current.setPath(newPath);
-        current.setFilename(newFilename);
-        List<DiskFile> diskFiles = new ArrayList<>();
-        diskFiles.add(current);
-        if (current.getFileType() == ObjectType.Folder.getCode()) {
-            getChildren(current.getPath()).stream()
-                    .filter(childFile -> !childFile.getFileId().equals(fileId))
-                    .forEach(childFile -> {
-                        String filename = childFile.getFilename();
-                        NamePath namePath = getUniqueNamePath(newPath, filename);
-
-                        childFile.setPath(namePath.getPath());
-                        childFile.setFilename(namePath.getFilename());
-                        diskFiles.add(childFile);
-                    });
-        }
-
-        if (!diskFiles.isEmpty()) {
-            //diskFile1Repository.updateFilenames(diskFileList);
-        }
-
-        return Result.success();
-    }
-
     public Result move(MoveFile moveFile) {
         long owner = UserContext.getUserId();
         String pid = moveFile.getPid();
@@ -224,7 +139,7 @@ public class DiskFileService {
                 .build();
         Page page = new Page(1, 1);
         List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
-        DiskFile parentFile = diskFileList.get(0);
+        DiskFile parentFile = diskFileList.getFirst();
         if (parentFile == null) {
             String msg = "文件被移动/复制到的位置不存在";
             return Result.fail(msg);
@@ -244,7 +159,7 @@ public class DiskFileService {
                     .build();
             page = new Page(1, 10);
             diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
-            pid1 = diskFileList.get(0).getPid();
+            pid1 = diskFileList.getFirst().getPid();
             parents.add(pid1);
         }
 
@@ -261,7 +176,7 @@ public class DiskFileService {
             return Result.fail(msg);
         }
 
-        String currentPid = list.get(0).getPid();
+        String currentPid = list.getFirst().getPid();
         if (currentPid.equals(pid)) {
             String msg = "移动/复制的目的文件夹和当前相同";
             return Result.fail(msg);
@@ -439,11 +354,6 @@ public class DiskFileService {
 
         return path;
     }
-
-    private String getParentPath(String path) {
-        int index = path.lastIndexOf("/");
-        return path.substring(0, index);
-    }
     
     public List<NamePath> getPathList(String path) {
         List<NamePath> pathList = new ArrayList<>();
@@ -472,16 +382,6 @@ public class DiskFileService {
         return pathList;
     }
 
-    public List<DiskFile> findBySha256sum(String sha256sum) {
-        long owner = UserContext.getUserId();
-        DiskQuery diskQuery = new DiskQuery.Builder()
-                .sha256sum(sha256sum)
-                .owner(owner)
-                .build();
-        Page page = new Page(1, 10);
-        return diskFileMapper.findDiskQueryByPage(page, diskQuery);
-    }
-
     public DiskFile findByPath(String path) {
         long owner = UserContext.getUserId();
         DiskQuery diskQuery = new DiskQuery.Builder()
@@ -490,7 +390,7 @@ public class DiskFileService {
                 .build();
         Page page = new Page(1, 1);
         List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
-        return diskFileList.isEmpty() ? null : diskFileList.get(0);
+        return diskFileList.isEmpty() ? null : diskFileList.getFirst();
     }
 
     public DiskFile findByFileId(String fileId) {
@@ -505,7 +405,7 @@ public class DiskFileService {
                 .build();
         Page page = new Page(1, 1);
         List<DiskFile> diskFileList = diskFileMapper.findDiskQueryByPage(page, diskQuery);
-        return diskFileList.isEmpty() ? null : diskFileList.get(0);
+        return diskFileList.isEmpty() ? null : diskFileList.getFirst();
     }
 
     public List<DiskFile> findByFileIds(List<String> fileIds) {
@@ -516,22 +416,6 @@ public class DiskFileService {
         return diskFileMapper.findByFileIds(fileIds);
     }
 
-    public List<DiskFile> findByParentIds(List<String> parentIds) {
-        if (parentIds.isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        return diskFileMapper.findByParentIds(parentIds);
-    }
-
-    public List<DiskFile> findBySha256sumList(List<String> sha256sumList) {
-        if (sha256sumList.isEmpty()) {
-            return Collections.emptyList();
-        }
-
-        return diskFileMapper.findSha256sumGroup(sha256sumList);
-    }
-
     private List<DiskFile> findByPathPrefix(String pathPrefix) {
         long owner = UserContext.getUserId();
         DiskQuery diskQuery = new DiskQuery.Builder()
@@ -595,10 +479,4 @@ public class DiskFileService {
 
         return null;
     }
-
-    public Map<Integer, DiskFileCount> getFileTypeCount() {
-        long loginUser = UserContext.getUserId();
-        List<DiskFileCount> list = diskFileMapper.findFileTypeCountByGroup(loginUser);
-        return list.stream().collect(Collectors.toMap(DiskFileCount::getFileType, k -> k));
-    }
 }

+ 0 - 53
file/file-service/src/main/resources/mapper/disk/DiskFileMapper.xml

@@ -105,13 +105,6 @@
         </where>
         order by file_type,filename
     </select>
-    <select id="findFileTypeCountByGroup" resultType="cn.reghao.tnb.file.app.zdisk.model.vo.DiskFileCount">
-        select file,count(*) as total
-        from disk_file
-        group by file_type
-        order by total desc
-    </select>
-
     <select id="findByFileIds" resultType="cn.reghao.tnb.file.app.zdisk.model.po.DiskFile">
         select *
         from disk_file
@@ -120,14 +113,6 @@
             #{id}
         </foreach>
     </select>
-    <select id="findByParentIds" resultType="cn.reghao.tnb.file.app.zdisk.model.po.DiskFile">
-        select *
-        from disk_file
-        where deleted=0 and pid in
-        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
-            #{id}
-        </foreach>
-    </select>
     <select id="findRoot" resultType="cn.reghao.tnb.file.app.zdisk.model.po.DiskFile">
         select *
         from disk_file
@@ -138,42 +123,4 @@
         from disk_file
         where deleted=0 and file_id!=#{fileId} and `path` like concat(#{pathPrefix})
     </select>
-
-    <select id="countSha256sumGroupByDiskQuery" resultType="java.lang.String">
-        select sha256sum
-        from disk_file
-        where deleted=0 and `owner`=#{userId} and file_type=#{fileType} and sha256sum not in (
-            select sha256sum
-            from my_disk_album_file A
-            where exists (
-                          select album_id
-                          from my_disk_album B
-                          where B.create_by=#{userId} and B.album_id=A.album_id
-                      )
-        )
-        group by sha256sum
-    </select>
-    <select id="findSha256sumGroupByPage" resultType="cn.reghao.tnb.file.app.zdisk.model.po.DiskFile">
-        select *
-        from disk_file
-        where deleted=0 and `owner`=#{userId} and file_type=#{fileType} and sha256sum not in (
-            select sha256sum
-            from my_disk_album_file A
-            where exists (
-                          select album_id
-                          from my_disk_album B
-                          where B.create_by=#{userId} and B.album_id=A.album_id
-                      )
-        )
-        group by sha256sum
-    </select>
-    <select id="findSha256sumGroup" resultType="cn.reghao.tnb.file.app.zdisk.model.po.DiskFile">
-        select *
-        from disk_file
-        where deleted=0 and sha256sum in
-        <foreach collection="list" item="id" index="index" open="(" close=")" separator=",">
-            #{id}
-        </foreach>
-        group by sha256sum
-    </select>
 </mapper>