支持多个root节点

This commit is contained in:
2023-08-26 22:48:03 +08:00
parent 3d3d7814d3
commit 2af416ff7e
4 changed files with 14 additions and 8 deletions

View File

@@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RequestMapping("/resource")
@RestController
@SysLog(module = "资源管理")
@@ -22,12 +24,12 @@ public class ResourceController extends BaseController{
@PostMapping("/apiTree")
@SysLog(action = "获取接口树")
public ResourceTreeDto apiTree() {
public List<ResourceTreeDto> apiTree() {
return this.service.apiTree();
}
@PostMapping("/menuTree")
@SysLog(action = "获取菜单树")
public ResourceTreeDto menuTree() {
public List<ResourceTreeDto> menuTree() {
return this.service.menuTree();
}

View File

@@ -4,10 +4,12 @@ import cn.lihongjie.coal.entity.ResourceEntity;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ResourceRepository extends BaseRepository<ResourceEntity> {
@EntityGraph(attributePaths = {"children"})
ResourceEntity findByTypeAndParentIsNull(String type);
List<ResourceEntity> findAllByTypeAndParentIsNull(String type);
}

View File

@@ -11,6 +11,8 @@ import org.mapstruct.MappingConstants;
import org.mapstruct.MappingTarget;
import org.mapstruct.control.DeepClone;
import java.util.List;
@Mapper(
componentModel = MappingConstants.ComponentModel.SPRING,
uses = {CommonMapper.class},
@@ -25,5 +27,5 @@ public interface ResourceMapper {
void updateEntity(@MappingTarget ResourceEntity entity, UpdateResourceDto dto);
ResourceTreeDto toTreeDto(ResourceEntity byTypeAndParentIsNull);
List<ResourceTreeDto> toTreeDto(List<ResourceEntity> byTypeAndParentIsNull);
}

View File

@@ -184,13 +184,13 @@ public class ResourceService extends BaseService<ResourceEntity, ResourceReposit
return urls;
}
public ResourceTreeDto menuTree() {
public List<ResourceTreeDto> menuTree() {
return this.mapper.toTreeDto(this.repository.findByTypeAndParentIsNull("0"));
return this.mapper.toTreeDto(this.repository.findAllByTypeAndParentIsNull("0"));
}
public ResourceTreeDto apiTree() {
return this.mapper.toTreeDto(this.repository.findByTypeAndParentIsNull("3"));
public List<ResourceTreeDto> apiTree() {
return this.mapper.toTreeDto(this.repository.findAllByTypeAndParentIsNull("3"));
}
}