feat: 新增系统权限树接口及页面(多级表格展示)

后端:
- PermissionService: 新增 getSystemPermissionTree() 只返回系统管理分支
- PermissionController: 新增 GET /permission/system/tree

前端:
- 新增 getSystemPermissionTreeApi()
- 新增路由 SystemPlatformSystemPermission(系统权限)
- 新增 views/system/system-permission/index.vue 多级表格展示
This commit is contained in:
小蟑螂
2026-04-10 22:57:15 +08:00
parent 25fee35743
commit f531121578
6 changed files with 286 additions and 5 deletions
@@ -14,6 +14,7 @@ import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.PermissionFilt
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.dto.UpdatePermissionDTO;
import top.xyquan.ecomdmbbackend.modules.sys.permission.model.vo.PermissionVO;
import top.xyquan.ecomdmbbackend.modules.sys.permission.service.PermissionService;
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
import java.util.List;
@@ -26,9 +27,11 @@ import java.util.List;
public class PermissionController {
private final PermissionService permissionService;
private final CurrentUserContext currentUserContext;
public PermissionController(PermissionService permissionService) {
public PermissionController(PermissionService permissionService, CurrentUserContext currentUserContext) {
this.permissionService = permissionService;
this.currentUserContext = currentUserContext;
}
@Operation(summary = "创建权限", description = "创建新的权限")
@@ -91,11 +94,11 @@ public class PermissionController {
return ApiResponse.success(tree);
}
@Operation(summary = "获取公司可见的权限树", description = "只返回已分配权限及其祖先节点")
@GetMapping("/tree/company/{companyId}")
@Operation(summary = "获取公司可见的权限树", description = "只返回当前用户所属公司的已分配权限及其祖先节点")
@GetMapping("/tree/company")
@RequirePermission(value = "system:permission:read", description = "获取公司可见权限树", allowSuper = true)
public ApiResponse<List<PermissionVO>> getCompanyVisiblePermissionTree(
@Parameter(description = "公司ID") @PathVariable Long companyId) {
public ApiResponse<List<PermissionVO>> getCompanyVisiblePermissionTree() {
Long companyId = currentUserContext.getCurrentCompanyId();
List<PermissionVO> tree = permissionService.getCompanyVisiblePermissionTree(companyId);
return ApiResponse.success(tree);
}
@@ -108,4 +111,12 @@ public class PermissionController {
List<PermissionVO> tree = permissionService.getPositionVisiblePermissionTree(positionId);
return ApiResponse.success(tree);
}
@Operation(summary = "获取系统权限树", description = "只返回系统管理模块下的权限(平台超管专用)")
@GetMapping("/system/tree")
@RequirePermission(value = "system:permission:read", description = "获取系统权限树", allowSuper = true)
public ApiResponse<List<PermissionVO>> getSystemPermissionTree() {
List<PermissionVO> tree = permissionService.getSystemPermissionTree();
return ApiResponse.success(tree);
}
}
@@ -73,4 +73,9 @@ public interface PermissionService {
* 获取职位可见的权限树(只返回已分配权限及其祖先节点)
*/
List<PermissionVO> getPositionVisiblePermissionTree(Long positionId);
/**
* 获取系统权限树(只返回系统管理模块下的权限,用于平台超管查看)
*/
List<PermissionVO> getSystemPermissionTree();
}
@@ -238,6 +238,30 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
return result;
}
@Override
public List<PermissionVO> getSystemPermissionTree() {
List<PermissionPO> all = permissionMapper.selectAllForTree();
List<PermissionVO> allVO = all.stream().map(this::convertToVO).collect(Collectors.toList());
// 按 parent_id 分组
Map<Long, List<PermissionVO>> byParent = allVO.stream()
.collect(Collectors.groupingBy(
vo -> vo.getParentId() != null ? vo.getParentId() : 0L,
Collectors.toList()));
// 根节点是 id=100 系统管理模块
List<PermissionVO> root = byParent.getOrDefault(0L, Collections.emptyList());
List<PermissionVO> systemRoot = root.stream()
.filter(n -> n.getId() != null && n.getId() == 100)
.collect(Collectors.toList());
// 递归构建子树(复用已有的 buildChildrenRecursive 方法)
for (PermissionVO node : systemRoot) {
buildChildrenRecursive(node, byParent);
}
return systemRoot;
}
private PermissionVO convertToVO(PermissionPO po) {
PermissionVO vo = new PermissionVO();
BeanUtils.copyProperties(po, vo);