From 62deae273c927c03fb4fc70bb7e7f545ab509673 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Tue, 18 Jul 2023 23:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.0=E3=80=91=E3=80=90sys=E3=80=91?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=A7=92=E8=89=B2=E5=AF=B9=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modular/role/service/SysRoleService.java | 9 ++++++++ .../role/service/impl/SysRoleServiceImpl.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/SysRoleService.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/SysRoleService.java index f1853c3eb..d85dc20b0 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/SysRoleService.java +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/SysRoleService.java @@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.sys.modular.role.service; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.sys.api.SysRoleServiceApi; +import cn.stylefeng.roses.kernel.sys.api.enums.permission.DataScopeTypeEnum; import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRole; import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleRequest; import com.baomidou.mybatisplus.extension.service.IService; @@ -100,4 +101,12 @@ public interface SysRoleService extends IService, SysRoleServiceApi { */ void updateRoleDataScopeType(Long roleId, Integer dataScopeType); + /** + * 获取角色对应的数据范围,如果是多个角色,则取最大类型的数据范围 + * + * @author fengshuonan + * @since 2023/7/18 23:19 + */ + DataScopeTypeEnum getRoleDataScope(List roleIds); + } \ No newline at end of file diff --git a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleServiceImpl.java b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleServiceImpl.java index cad0ab625..76648aed8 100644 --- a/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleServiceImpl.java +++ b/kernel-s-system/system-business-permission/src/main/java/cn/stylefeng/roses/kernel/sys/modular/role/service/impl/SysRoleServiceImpl.java @@ -145,6 +145,27 @@ public class SysRoleServiceImpl extends ServiceImpl impl this.update(sysRoleLambdaUpdateWrapper); } + @Override + public DataScopeTypeEnum getRoleDataScope(List roleIds) { + + LambdaQueryWrapper sysRoleLambdaQueryWrapper = new LambdaQueryWrapper<>(); + sysRoleLambdaQueryWrapper.in(SysRole::getRoleId, roleIds); + sysRoleLambdaQueryWrapper.select(SysRole::getDataScopeType); + + // 按数据范围降序排列,50-全部数据最大 + sysRoleLambdaQueryWrapper.orderByDesc(SysRole::getDataScopeType); + + SysRole sysRole = this.getOne(sysRoleLambdaQueryWrapper, false); + if (sysRole != null) { + if (sysRole.getDataScopeType() != null) { + return DataScopeTypeEnum.codeToEnum(sysRole.getDataScopeType()); + } + } + + // 如果是查询不到,则直接返回仅本人数据 + return DataScopeTypeEnum.SELF; + } + @Override public List findList(SysRoleRequest sysRoleRequest) { LambdaQueryWrapper wrapper = this.createWrapper(sysRoleRequest);