mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-08 12:57:13 +08:00
feat(system/role): 新增查询角色权限树列表接口(替换角色分配权限的菜单树列表接口)
This commit is contained in:
@@ -116,15 +116,15 @@ public class SaTokenConfiguration {
|
||||
if (AopUtils.isAopProxy(bean)) {
|
||||
clazz = AopProxyUtils.ultimateTargetClass(bean);
|
||||
}
|
||||
// 使用 @CrudRequestMapping 的 Controller,如果使用了 @SaIgnore 注解,则表示忽略认证和权限校验
|
||||
CrudRequestMapping crudRequestMapping = AnnotationUtils.findAnnotation(clazz, CrudRequestMapping.class);
|
||||
SaIgnore saIgnore = AnnotationUtils.findAnnotation(clazz, SaIgnore.class);
|
||||
if (crudRequestMapping != null) {
|
||||
// 缓存权限前缀
|
||||
CrudApiPermissionPrefixCache.put(clazz, crudRequestMapping.value());
|
||||
// 使用 @CrudRequestMapping 的 Controller,如果使用了 @SaIgnore 注解,则表示忽略认证和权限校验
|
||||
if (saIgnore != null) {
|
||||
return crudRequestMapping.value() + StringConstants.PATH_PATTERN;
|
||||
}
|
||||
// 缓存权限前缀
|
||||
CrudApiPermissionPrefixCache.put(clazz, crudRequestMapping.value());
|
||||
}
|
||||
return null;
|
||||
}).filter(Objects::nonNull).toList();
|
||||
|
@@ -17,17 +17,14 @@
|
||||
package top.continew.admin.system.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.continew.admin.common.base.controller.BaseController;
|
||||
import top.continew.admin.common.config.TenantExtensionProperties;
|
||||
import top.continew.admin.common.constant.CacheConstants;
|
||||
import top.continew.admin.system.model.query.MenuQuery;
|
||||
import top.continew.admin.system.model.req.MenuReq;
|
||||
@@ -40,11 +37,8 @@ import top.continew.starter.core.util.validation.ValidationUtils;
|
||||
import top.continew.starter.extension.crud.annotation.CrudApi;
|
||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
|
||||
import top.continew.starter.extension.crud.enums.Api;
|
||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 菜单管理 API
|
||||
@@ -55,12 +49,10 @@ import java.util.List;
|
||||
@Tag(name = "菜单管理 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@CrudRequestMapping(value = "/system/menu", api = {Api.TREE, Api.GET, Api.CREATE, Api.UPDATE, Api.BATCH_DELETE, Api.DICT_TREE})
|
||||
@CrudRequestMapping(value = "/system/menu", api = {Api.TREE, Api.GET, Api.CREATE, Api.UPDATE, Api.BATCH_DELETE,
|
||||
Api.DICT_TREE})
|
||||
public class MenuController extends BaseController<MenuService, MenuResp, MenuResp, MenuQuery, MenuReq> {
|
||||
|
||||
private final MenuService menuService;
|
||||
private final TenantExtensionProperties tenantExtensionProperties;
|
||||
|
||||
@Operation(summary = "清除缓存", description = "清除缓存")
|
||||
@SaCheckPermission("system:menu:clearCache")
|
||||
@DeleteMapping("/cache")
|
||||
@@ -88,14 +80,4 @@ public class MenuController extends BaseController<MenuService, MenuResp, MenuRe
|
||||
req.setComponent(StrUtil.removePrefix(req.getComponent(), StringConstants.SLASH));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Operation(summary = "查询树列表", description = "查询树列表")
|
||||
public List<Tree<Long>> tree(@Valid MenuQuery query, @Valid SortQuery sortQuery) {
|
||||
if (TenantContextHolder.isTenantEnabled() && !tenantExtensionProperties.isDefaultTenant()) {
|
||||
query.setExcludeMenuIdList(menuService.listExcludeTenantMenu());
|
||||
}
|
||||
return super.tree(query, sortQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package top.continew.admin.system.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
@@ -32,8 +34,10 @@ import top.continew.admin.system.model.query.RoleUserQuery;
|
||||
import top.continew.admin.system.model.req.RoleReq;
|
||||
import top.continew.admin.system.model.req.RoleUpdatePermissionReq;
|
||||
import top.continew.admin.system.model.resp.role.RoleDetailResp;
|
||||
import top.continew.admin.system.model.resp.role.RolePermissionResp;
|
||||
import top.continew.admin.system.model.resp.role.RoleResp;
|
||||
import top.continew.admin.system.model.resp.role.RoleUserResp;
|
||||
import top.continew.admin.system.service.MenuService;
|
||||
import top.continew.admin.system.service.RoleService;
|
||||
import top.continew.admin.system.service.UserRoleService;
|
||||
import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
|
||||
@@ -53,10 +57,20 @@ import java.util.List;
|
||||
@Validated
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@CrudRequestMapping(value = "/system/role", api = {Api.LIST, Api.GET, Api.CREATE, Api.UPDATE, Api.BATCH_DELETE, Api.DICT})
|
||||
@CrudRequestMapping(value = "/system/role", api = {Api.LIST, Api.GET, Api.CREATE, Api.UPDATE, Api.BATCH_DELETE,
|
||||
Api.DICT})
|
||||
public class RoleController extends BaseController<RoleService, RoleResp, RoleDetailResp, RoleQuery, RoleReq> {
|
||||
|
||||
private final UserRoleService userRoleService;
|
||||
private final MenuService menuService;
|
||||
|
||||
@Operation(summary = "查询角色权限树列表", description = "查询角色权限树列表")
|
||||
@SaCheckPermission("system:role:updatePermission")
|
||||
@GetMapping("/permission/tree")
|
||||
public List<RolePermissionResp> listPermissionTree() {
|
||||
List<Tree<Long>> treeList = menuService.tree(null, null, false);
|
||||
return BeanUtil.copyToList(treeList, RolePermissionResp.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改权限", description = "修改角色的功能权限")
|
||||
@SaCheckPermission("system:role:updatePermission")
|
||||
|
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.admin.system.model.resp.role;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.admin.system.enums.MenuTypeEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色权限树响应参数
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2025/7/27 10:57
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "角色权限树响应参数")
|
||||
public class RolePermissionResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@Schema(description = "ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
@Schema(description = "标题", example = "用户管理")
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 上级菜单 ID
|
||||
*/
|
||||
@Schema(description = "上级菜单 ID", example = "1000")
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
@Schema(description = "类型", example = "2")
|
||||
private MenuTypeEnum type;
|
||||
|
||||
/**
|
||||
* 权限标识
|
||||
*/
|
||||
@Schema(description = "权限标识", example = "system:user:list")
|
||||
private String permission;
|
||||
|
||||
/**
|
||||
* 子菜单列表
|
||||
*/
|
||||
@Schema(description = "子菜单")
|
||||
private List<RolePermissionResp> children;
|
||||
}
|
@@ -27,6 +27,7 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import top.continew.admin.common.base.service.BaseServiceImpl;
|
||||
import top.continew.admin.common.config.TenantExtensionProperties;
|
||||
import top.continew.admin.common.constant.CacheConstants;
|
||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
||||
import top.continew.admin.common.enums.RoleCodeEnum;
|
||||
@@ -44,6 +45,7 @@ import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.core.util.CollUtils;
|
||||
import top.continew.starter.core.util.validation.CheckUtils;
|
||||
import top.continew.starter.extension.crud.model.query.SortQuery;
|
||||
import top.continew.starter.extension.tenant.context.TenantContextHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -59,12 +61,17 @@ import java.util.Set;
|
||||
@RequiredArgsConstructor
|
||||
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, MenuDO, MenuResp, MenuResp, MenuQuery, MenuReq> implements MenuService {
|
||||
|
||||
private final TenantExtensionProperties tenantExtensionProperties;
|
||||
@Lazy
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@Override
|
||||
public List<Tree<Long>> tree(MenuQuery query, SortQuery sortQuery, boolean isSimple) {
|
||||
if (TenantContextHolder.isTenantEnabled() && !tenantExtensionProperties.isDefaultTenant()) {
|
||||
query = query == null ? new MenuQuery() : query;
|
||||
query.setExcludeMenuIdList(this.listExcludeTenantMenu());
|
||||
}
|
||||
return this.tree(query, sortQuery, isSimple, true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user