From 950942a742f991e524218eef2c09da0c2486fd65 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sun, 27 Jul 2025 12:42:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(system/role):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=A7=92=E8=89=B2=E6=9D=83=E9=99=90=E6=A0=91?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=EF=BC=88=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E5=88=86=E9=85=8D=E6=9D=83=E9=99=90=E7=9A=84?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E6=A0=91=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/satoken/SaTokenConfiguration.java | 6 +- .../system/controller/MenuController.java | 22 +----- .../system/controller/RoleController.java | 16 +++- .../model/resp/role/RolePermissionResp.java | 75 +++++++++++++++++++ .../system/service/impl/MenuServiceImpl.java | 7 ++ 5 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 continew-system/src/main/java/top/continew/admin/system/model/resp/role/RolePermissionResp.java diff --git a/continew-server/src/main/java/top/continew/admin/config/satoken/SaTokenConfiguration.java b/continew-server/src/main/java/top/continew/admin/config/satoken/SaTokenConfiguration.java index 74e13780..49db94e8 100644 --- a/continew-server/src/main/java/top/continew/admin/config/satoken/SaTokenConfiguration.java +++ b/continew-server/src/main/java/top/continew/admin/config/satoken/SaTokenConfiguration.java @@ -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(); diff --git a/continew-system/src/main/java/top/continew/admin/system/controller/MenuController.java b/continew-system/src/main/java/top/continew/admin/system/controller/MenuController.java index 7a86e200..c176ec3e 100644 --- a/continew-system/src/main/java/top/continew/admin/system/controller/MenuController.java +++ b/continew-system/src/main/java/top/continew/admin/system/controller/MenuController.java @@ -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 { - 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> tree(@Valid MenuQuery query, @Valid SortQuery sortQuery) { - if (TenantContextHolder.isTenantEnabled() && !tenantExtensionProperties.isDefaultTenant()) { - query.setExcludeMenuIdList(menuService.listExcludeTenantMenu()); - } - return super.tree(query, sortQuery); - } - } diff --git a/continew-system/src/main/java/top/continew/admin/system/controller/RoleController.java b/continew-system/src/main/java/top/continew/admin/system/controller/RoleController.java index 418e3ce5..72883e5b 100644 --- a/continew-system/src/main/java/top/continew/admin/system/controller/RoleController.java +++ b/continew-system/src/main/java/top/continew/admin/system/controller/RoleController.java @@ -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 { private final UserRoleService userRoleService; + private final MenuService menuService; + + @Operation(summary = "查询角色权限树列表", description = "查询角色权限树列表") + @SaCheckPermission("system:role:updatePermission") + @GetMapping("/permission/tree") + public List listPermissionTree() { + List> treeList = menuService.tree(null, null, false); + return BeanUtil.copyToList(treeList, RolePermissionResp.class); + } @Operation(summary = "修改权限", description = "修改角色的功能权限") @SaCheckPermission("system:role:updatePermission") diff --git a/continew-system/src/main/java/top/continew/admin/system/model/resp/role/RolePermissionResp.java b/continew-system/src/main/java/top/continew/admin/system/model/resp/role/RolePermissionResp.java new file mode 100644 index 00000000..b1738528 --- /dev/null +++ b/continew-system/src/main/java/top/continew/admin/system/model/resp/role/RolePermissionResp.java @@ -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 children; +} diff --git a/continew-system/src/main/java/top/continew/admin/system/service/impl/MenuServiceImpl.java b/continew-system/src/main/java/top/continew/admin/system/service/impl/MenuServiceImpl.java index 228eea19..17d3027b 100644 --- a/continew-system/src/main/java/top/continew/admin/system/service/impl/MenuServiceImpl.java +++ b/continew-system/src/main/java/top/continew/admin/system/service/impl/MenuServiceImpl.java @@ -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 implements MenuService { + private final TenantExtensionProperties tenantExtensionProperties; @Lazy @Resource private RoleService roleService; @Override public List> 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); }