mirror of https://gitee.com/stylefeng/roses
【8.0】【sys】更新角色绑定的数据范围列表获取
parent
0696e47724
commit
8f1b102fc6
|
@ -8,6 +8,7 @@ import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindDataScop
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 角色数据范围 服务类
|
||||
|
@ -89,4 +90,12 @@ public interface SysRoleDataScopeService extends IService<SysRoleDataScope> {
|
|||
*/
|
||||
void updateRoleBindDataScope(RoleBindDataScopeRequest roleBindDataScopeRequest);
|
||||
|
||||
/**
|
||||
* 获取角色绑定的组织机构id列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2023/7/18 23:37
|
||||
*/
|
||||
Set<Long> getRoleBindOrgIdList(List<Long> roleIdList);
|
||||
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.event.sdk.publish.BusinessEventPublisher;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserRoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.enums.permission.DataScopeTypeEnum;
|
||||
|
@ -19,10 +22,7 @@ import cn.stylefeng.roses.kernel.sys.modular.role.factory.PermissionAssignFactor
|
|||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.request.RoleBindPermissionRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.pojo.response.RoleBindPermissionItem;
|
||||
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.SysRoleMenuOptionsService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleMenuService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.SysRoleService;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.role.service.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -63,6 +63,12 @@ public class PermissionAssignServiceImpl implements PermissionAssignService {
|
|||
@Resource
|
||||
private SysRoleService sysRoleService;
|
||||
|
||||
@Resource
|
||||
private DbOperatorApi dbOperatorApi;
|
||||
|
||||
@Resource
|
||||
private SysRoleDataScopeService sysRoleDataScopeService;
|
||||
|
||||
@Override
|
||||
public RoleBindPermissionResponse getRoleBindPermission(RoleBindPermissionRequest roleBindPermissionRequest) {
|
||||
|
||||
|
@ -165,7 +171,56 @@ public class PermissionAssignServiceImpl implements PermissionAssignService {
|
|||
|
||||
@Override
|
||||
public Set<Long> currentUserOrgScopeList() {
|
||||
return null;
|
||||
|
||||
// 获取当前用户id
|
||||
Long userId = LoginContext.me().getLoginUser().getUserId();
|
||||
|
||||
// 用户当前组织机构id
|
||||
Long currentOrgId = LoginContext.me().getLoginUser().getCurrentOrgId();
|
||||
|
||||
// 获取当前用户的数据范围类型
|
||||
DataScopeTypeEnum dataScopeTypeEnum = this.currentUserDataScopeType();
|
||||
|
||||
// 如果是只有本人数据
|
||||
if (DataScopeTypeEnum.SELF.equals(dataScopeTypeEnum)) {
|
||||
return CollectionUtil.set(false, userId);
|
||||
}
|
||||
|
||||
// 如果是本部门数据
|
||||
else if (DataScopeTypeEnum.DEPT.equals(dataScopeTypeEnum)) {
|
||||
return CollectionUtil.set(false, currentOrgId);
|
||||
}
|
||||
|
||||
// 如果是本部门及以下部门
|
||||
else if (DataScopeTypeEnum.DEPT_WITH_CHILD.equals(dataScopeTypeEnum)) {
|
||||
|
||||
// 获取指定组织机构下的所有机构id
|
||||
Set<Long> subOrgIdList = dbOperatorApi.findSubListByParentId("sys_hr_organization", "org_pids", "org_id", currentOrgId);
|
||||
if (ObjectUtil.isEmpty(subOrgIdList)) {
|
||||
subOrgIdList = new HashSet<>();
|
||||
}
|
||||
subOrgIdList.add(currentOrgId);
|
||||
return subOrgIdList;
|
||||
}
|
||||
|
||||
// 如果是指定部门数据
|
||||
else if (DataScopeTypeEnum.DEFINE.equals(dataScopeTypeEnum)) {
|
||||
|
||||
// 获取用户的角色列表
|
||||
List<Long> userHaveRoleIds = sysUserRoleServiceApi.getUserRoleIdList(userId);
|
||||
|
||||
// 获取角色指定的所有部门范围
|
||||
return sysRoleDataScopeService.getRoleBindOrgIdList(userHaveRoleIds);
|
||||
}
|
||||
|
||||
// 如果是全部数据
|
||||
else if (DataScopeTypeEnum.ALL.equals(dataScopeTypeEnum)) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 默认返回只有本人数据
|
||||
return CollectionUtil.set(false, userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.role.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
|
@ -24,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -94,15 +97,8 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
|||
}
|
||||
|
||||
// 如果是指定部门,则获取指定部门的orgId集合
|
||||
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);
|
||||
}
|
||||
Set<Long> roleBindOrgIdList = this.getRoleBindOrgIdList(ListUtil.list(false, roleBindDataScopeRequest.getRoleId()));
|
||||
roleBindDataScopeResponse.setOrgIdList(CollectionUtil.list(false, roleBindOrgIdList));
|
||||
|
||||
return roleBindDataScopeResponse;
|
||||
}
|
||||
|
@ -141,6 +137,25 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
|||
this.saveBatch(bindRoleDataScopeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getRoleBindOrgIdList(List<Long> roleIdList) {
|
||||
|
||||
if(ObjectUtil.isEmpty(roleIdList)){
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<SysRoleDataScope> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(SysRoleDataScope::getRoleId, roleIdList);
|
||||
wrapper.select(SysRoleDataScope::getOrganizationId);
|
||||
List<SysRoleDataScope> sysRoleDataScopes = this.list(wrapper);
|
||||
|
||||
if (ObjectUtil.isNotEmpty(sysRoleDataScopes)) {
|
||||
return sysRoleDataScopes.stream().map(SysRoleDataScope::getOrganizationId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
return new HashSet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateHaveRoleBind(Set<Long> beRemovedRoleIdList) {
|
||||
// none
|
||||
|
|
Loading…
Reference in New Issue