【8.0】【sys】获取角色对应的数据范围

pull/57/head
fengshuonan 2023-07-18 23:27:10 +08:00
parent 8a0485b07a
commit 62deae273c
2 changed files with 30 additions and 0 deletions

View File

@ -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<SysRole>, SysRoleServiceApi {
*/
void updateRoleDataScopeType(Long roleId, Integer dataScopeType);
/**
*
*
* @author fengshuonan
* @since 2023/7/18 23:19
*/
DataScopeTypeEnum getRoleDataScope(List<Long> roleIds);
}

View File

@ -145,6 +145,27 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
this.update(sysRoleLambdaUpdateWrapper);
}
@Override
public DataScopeTypeEnum getRoleDataScope(List<Long> roleIds) {
LambdaQueryWrapper<SysRole> 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<SysRole> findList(SysRoleRequest sysRoleRequest) {
LambdaQueryWrapper<SysRole> wrapper = this.createWrapper(sysRoleRequest);