From 3f80716092782b3638335a3e577d2952589d6d02 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Thu, 11 Jan 2024 16:41:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E5=87=BA=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../netDisk/controller/NetDiskController.java | 10 +++++ .../netDisk/repository/NetDiskRepository.java | 16 ++++++++ .../coal/netDisk/service/NetDiskService.java | 39 ++++++++++++++++--- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/netDisk/controller/NetDiskController.java b/src/main/java/cn/lihongjie/coal/netDisk/controller/NetDiskController.java index 8ba4d9f5..440198d5 100644 --- a/src/main/java/cn/lihongjie/coal/netDisk/controller/NetDiskController.java +++ b/src/main/java/cn/lihongjie/coal/netDisk/controller/NetDiskController.java @@ -102,6 +102,16 @@ public class NetDiskController { public NetDiskTreeDto tree(@RequestBody IdRequest request) { return this.service.tree(request); } + /** + * 列出文件夹树 + * + * @param request + * @return + */ + @PostMapping("/dirTree") + public NetDiskTreeDto dirTree(@RequestBody IdRequest request) { + return this.service.dirTree(request); + } /** * 创建文件夹 diff --git a/src/main/java/cn/lihongjie/coal/netDisk/repository/NetDiskRepository.java b/src/main/java/cn/lihongjie/coal/netDisk/repository/NetDiskRepository.java index 2953eb77..807e954b 100644 --- a/src/main/java/cn/lihongjie/coal/netDisk/repository/NetDiskRepository.java +++ b/src/main/java/cn/lihongjie/coal/netDisk/repository/NetDiskRepository.java @@ -92,4 +92,20 @@ from tmp2 where index = len """, nativeQuery = true) String pathToId(@Param("path") String path, @Param("organizationId") String organizationId); + + @Query(value = """ + +with recursive tmp as ( + +select 0 as depth, t.id as id from t_net_disk t where t.id = :id +union all +select tmp.depth + 1 as depth, t.id as id from t_net_disk t +inner join tmp on t.parent_id = tmp.id +where t.entry_type = '0' +) + +select max(depth) from tmp + +""", nativeQuery = true) + Integer dirDepth(@Param("id") String id); } diff --git a/src/main/java/cn/lihongjie/coal/netDisk/service/NetDiskService.java b/src/main/java/cn/lihongjie/coal/netDisk/service/NetDiskService.java index f05165e7..ff7d0a87 100644 --- a/src/main/java/cn/lihongjie/coal/netDisk/service/NetDiskService.java +++ b/src/main/java/cn/lihongjie/coal/netDisk/service/NetDiskService.java @@ -19,6 +19,7 @@ import com.aliyun.oss.model.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.persistence.EntityManager; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.Predicate; @@ -901,17 +902,45 @@ public class NetDiskService extends BaseService idToPath2(IdRequest request) { String id = request.getId();