mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
列出文件夹树
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建文件夹
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<NetDiskEntity, NetDiskRepository
|
||||
|
||||
public NetDiskTreeDto tree(IdRequest request) {
|
||||
|
||||
handlerRootDir(request);
|
||||
|
||||
if (StringUtils.isEmpty(request.getId())) {
|
||||
return this.mapper.toTreeDto(findRoot());
|
||||
}
|
||||
|
||||
NetDiskEntity entity = get(request.getId());
|
||||
|
||||
return this.mapper.toTreeDto(entity);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private EntityManager entityManager;
|
||||
|
||||
public NetDiskTreeDto dirTree(IdRequest request) {
|
||||
|
||||
|
||||
|
||||
// NetDiskEntity entity = get(request.getId());
|
||||
|
||||
Integer dirDepth = this.repository.dirDepth(request.getId());
|
||||
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.append("select r0 from NetDiskEntity r0 where r0.id = '")
|
||||
.append(request.getId())
|
||||
.append("'");
|
||||
|
||||
sb.append("\n");
|
||||
|
||||
for(int i = 1; i < dirDepth; i++) {
|
||||
|
||||
sb.append(" join fetch r").append(i - 1).append(".children as r").append(i).append("\n");
|
||||
|
||||
}
|
||||
|
||||
NetDiskEntity fullRoot = (NetDiskEntity) entityManager.createQuery(sb.toString()).getSingleResult();
|
||||
|
||||
|
||||
return this.mapper.toTreeDto(fullRoot);
|
||||
}
|
||||
|
||||
|
||||
public List<NetDiskDto> idToPath2(IdRequest request) {
|
||||
|
||||
String id = request.getId();
|
||||
|
||||
Reference in New Issue
Block a user