【8.0】【role】更新获取角色的数据权限详情

pull/57/head
fengshuonan 2023-07-16 23:39:55 +08:00
parent 797c36d9a7
commit e8b52f312b
7 changed files with 226 additions and 9 deletions

View File

@ -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);
}
}

View File

@ -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.
*
* GunsAPACHE 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;
}

View File

@ -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.
*
* GunsAPACHE 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;
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);