mirror of https://gitee.com/stylefeng/roses
【8.0】【role】更新获取角色的数据权限详情
parent
797c36d9a7
commit
e8b52f312b
|
@ -8,10 +8,13 @@ import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
|||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.sys.api.constants.PermissionCodeConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRole;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindDataScopeRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindPermissionRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindDataScopeResponse;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindPermissionResponse;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.PermissionAssignService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleDataScopeService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -36,6 +39,9 @@ public class PermissionAssignController {
|
|||
@Resource
|
||||
private PermissionAssignService permissionAssignService;
|
||||
|
||||
@Resource
|
||||
private SysRoleDataScopeService sysRoleDataScopeService;
|
||||
|
||||
/**
|
||||
* 获取所有角色列表
|
||||
* <p>
|
||||
|
@ -81,4 +87,17 @@ public class PermissionAssignController {
|
|||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色的数据权限详情
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/16 23:15
|
||||
*/
|
||||
@GetResource(name = "获取角色的数据权限详情", path = "/permission/getRoleBindDataScope")
|
||||
public ResponseData<RoleBindDataScopeResponse> getRoleBindDataScope(
|
||||
@Validated(BaseRequest.detail.class) RoleBindDataScopeRequest roleBindDataScopeRequest) {
|
||||
RoleBindDataScopeResponse roleBindDataScopeResponse = sysRoleDataScopeService.getRoleBindDataScope(roleBindDataScopeRequest);
|
||||
return new SuccessResponseData<>(roleBindDataScopeResponse);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.modular.role.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色绑定数据权限的请求
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/16 23:16
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class RoleBindDataScopeRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@NotNull(message = "角色id不能为空", groups = {detail.class})
|
||||
@ChineseDescription("角色id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,40-指定部门数据,50-全部数据
|
||||
*/
|
||||
@ChineseDescription("数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,40-指定部门数据,50-全部数据")
|
||||
private Integer dataScopeType;
|
||||
|
||||
/**
|
||||
* 用户拥有的指定部门的组织机构信息id集合
|
||||
*/
|
||||
@ChineseDescription("用户拥有的指定部门的组织机构信息id集合")
|
||||
private List<Long> orgIdList;
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.sys.modular.role.pojo.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色绑定数据范围的响应
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/16 23:17
|
||||
*/
|
||||
@Data
|
||||
public class RoleBindDataScopeResponse {
|
||||
|
||||
/**
|
||||
* 数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,40-指定部门数据,50-全部数据
|
||||
*/
|
||||
@ChineseDescription("数据范围类型:10-仅本人数据,20-本部门数据,30-本部门及以下数据,40-指定部门数据,50-全部数据")
|
||||
private Integer dataScopeType;
|
||||
|
||||
/**
|
||||
* 用户拥有的指定部门的组织机构信息id集合
|
||||
*/
|
||||
@ChineseDescription("用户拥有的指定部门的组织机构信息id集合")
|
||||
private List<Long> orgIdList;
|
||||
|
||||
}
|
|
@ -2,7 +2,9 @@ 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.modular.role.entity.SysRoleDataScope;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindDataScopeRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleDataScopeRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindDataScopeResponse;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -15,7 +17,7 @@ import java.util.List;
|
|||
*/
|
||||
public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
||||
|
||||
/**
|
||||
/**
|
||||
* 新增
|
||||
*
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
|
@ -24,7 +26,7 @@ public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
|||
*/
|
||||
void add(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||
|
||||
/**
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
|
@ -33,7 +35,7 @@ public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
|||
*/
|
||||
void del(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||
|
||||
/**
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
|
@ -42,7 +44,7 @@ public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
|||
*/
|
||||
void edit(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||
|
||||
/**
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
|
@ -51,24 +53,32 @@ public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
|||
*/
|
||||
SysRoleDataScope detail(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
* @return List<SysRoleDataScope> 返回结果
|
||||
* @author fengshuonan
|
||||
* @date 2023/06/10 21:29
|
||||
*/
|
||||
List<SysRoleDataScope> findList(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取列表(带分页)
|
||||
*
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
* @param sysRoleDataScopeRequest 请求参数
|
||||
* @return PageResult<SysRoleDataScope> 返回结果
|
||||
* @author fengshuonan
|
||||
* @date 2023/06/10 21:29
|
||||
*/
|
||||
PageResult<SysRoleDataScope> findPage(SysRoleDataScopeRequest sysRoleDataScopeRequest);
|
||||
|
||||
/**
|
||||
* 获取角色绑定的数据权限
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/16 23:26
|
||||
*/
|
||||
RoleBindDataScopeResponse getRoleBindDataScope(RoleBindDataScopeRequest roleBindDataScopeRequest);
|
||||
|
||||
}
|
|
@ -80,4 +80,14 @@ public interface SysRoleService extends IService<SysRole>, SysRoleServiceApi {
|
|||
*/
|
||||
PageResult<SysRole> findPage(SysRoleRequest sysRoleRequest);
|
||||
|
||||
/**
|
||||
* 获取角色的数据范围类型
|
||||
*
|
||||
* @param roleId 角色id
|
||||
* @return 数据范围类型
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/16 23:28
|
||||
*/
|
||||
Integer getRoleDataScopeType(Long roleId);
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
|
@ -10,15 +11,21 @@ import cn.stylefeng.roses.kernel.sys.api.callback.RemoveRoleCallbackApi;
|
|||
import cn.stylefeng.roses.kernel.sys.modular.role.entity.SysRoleDataScope;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.enums.exception.SysRoleDataScopeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.mapper.SysRoleDataScopeMapper;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindDataScopeRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.SysRoleDataScopeRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindDataScopeResponse;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleDataScopeService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 角色数据范围业务实现层
|
||||
|
@ -27,7 +34,11 @@ import java.util.Set;
|
|||
* @date 2023/06/10 21:29
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMapper, SysRoleDataScope> implements SysRoleDataScopeService, RemoveRoleCallbackApi {
|
||||
public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMapper, SysRoleDataScope> implements SysRoleDataScopeService,
|
||||
RemoveRoleCallbackApi {
|
||||
|
||||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Override
|
||||
public void add(SysRoleDataScopeRequest sysRoleDataScopeRequest) {
|
||||
|
@ -67,6 +78,33 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
|||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleBindDataScopeResponse getRoleBindDataScope(RoleBindDataScopeRequest roleBindDataScopeRequest) {
|
||||
|
||||
RoleBindDataScopeResponse roleBindDataScopeResponse = new RoleBindDataScopeResponse();
|
||||
roleBindDataScopeResponse.setOrgIdList(new ArrayList<>());
|
||||
|
||||
// 获取角色的数据范围类型
|
||||
Integer dataScopeType = sysRoleService.getRoleDataScopeType(roleBindDataScopeRequest.getRoleId());
|
||||
roleBindDataScopeResponse.setDataScopeType(dataScopeType);
|
||||
|
||||
// 如果是指定部门,则获取指定部门的orgId集合
|
||||
if (DataScopeTypeEnum.DEFINE.getCode().equals(dataScopeType)) {
|
||||
|
||||
LambdaQueryWrapper<SysRoleDataScope> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysRoleDataScope::getRoleId, roleBindDataScopeRequest.getRoleId());
|
||||
wrapper.select(SysRoleDataScope::getOrganizationId);
|
||||
List<SysRoleDataScope> sysRoleDataScopes = this.list(wrapper);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(sysRoleDataScopes)) {
|
||||
List<Long> scopeOrgIdList = sysRoleDataScopes.stream().map(SysRoleDataScope::getOrganizationId).collect(Collectors.toList());
|
||||
roleBindDataScopeResponse.setOrgIdList(scopeOrgIdList);
|
||||
}
|
||||
}
|
||||
|
||||
return roleBindDataScopeResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateHaveRoleBind(Set<Long> beRemovedRoleIdList) {
|
||||
// none
|
||||
|
|
|
@ -108,6 +108,29 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
return PageResultFactory.createPageResult(sysRolePage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRoleDataScopeType(Long roleId) {
|
||||
|
||||
// 角色id为空,返回仅本人数据
|
||||
if (ObjectUtil.isEmpty(roleId)) {
|
||||
return DataScopeTypeEnum.SELF.getCode();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<SysRole> sysRoleLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysRoleLambdaQueryWrapper.eq(SysRole::getRoleId, roleId);
|
||||
sysRoleLambdaQueryWrapper.select(SysRole::getDataScopeType);
|
||||
SysRole sysRole = this.getOne(sysRoleLambdaQueryWrapper, false);
|
||||
|
||||
if (sysRole != null) {
|
||||
Integer dataScopeType = sysRole.getDataScopeType();
|
||||
if (dataScopeType != null) {
|
||||
return dataScopeType;
|
||||
}
|
||||
}
|
||||
|
||||
return DataScopeTypeEnum.SELF.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRole> findList(SysRoleRequest sysRoleRequest) {
|
||||
LambdaQueryWrapper<SysRole> wrapper = this.createWrapper(sysRoleRequest);
|
||||
|
|
Loading…
Reference in New Issue