mirror of https://gitee.com/stylefeng/roses
【7.3.3】获取数据范围:补充用户id集合,并增加通过用户id直接获取用户数据范围方法
parent
b5b6a5e0a6
commit
9d4c5511b6
|
@ -52,4 +52,11 @@ public interface DataScopeApi {
|
|||
*/
|
||||
DataScopeDTO getDataScope(Long userId, List<SysRoleDTO> sysRoles);
|
||||
|
||||
/**
|
||||
* 获取用户的数据范围
|
||||
* @param userId 用户id
|
||||
* @return 数据范围内容
|
||||
*/
|
||||
DataScopeDTO getDataScope(Long userId);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package cn.stylefeng.roses.kernel.system.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author: yx
|
||||
* @Date: 2022-12-29 13:27
|
||||
*/
|
||||
public interface SysUserRoleApi {
|
||||
/**
|
||||
* 根据userId查询角色集合
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 用户角色集合
|
||||
* @author chenjinlong
|
||||
* @date 2021/2/3 15:09
|
||||
*/
|
||||
List<Long> findRoleIdsByUserId(Long userId);
|
||||
}
|
|
@ -26,6 +26,8 @@ package cn.stylefeng.roses.kernel.system.api;
|
|||
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.SysUserOrgDTO;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 用户组织机构服务api
|
||||
*
|
||||
|
@ -51,4 +53,11 @@ public interface UserOrgServiceApi {
|
|||
*/
|
||||
SysUserOrgDTO getUserOrgByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取组织下用户id
|
||||
*
|
||||
* @author yx
|
||||
* @date 2020/12/19 22:33
|
||||
*/
|
||||
Set<Long> getUserIdsByOrgIds(Set<Long> organizationIds);
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.organization.service;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.DataScopeApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.*;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.api.exception.enums.organization.DataScopeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.organization.DataScopeDTO;
|
||||
|
@ -64,6 +64,10 @@ public class DataScopeService implements DataScopeApi {
|
|||
@Resource
|
||||
private DbOperatorApi dbOperatorApi;
|
||||
|
||||
@Resource
|
||||
private SysUserRoleApi sysUserRoleApi;
|
||||
|
||||
|
||||
@Override
|
||||
public DataScopeDTO getDataScope(Long userId, List<SysRoleDTO> sysRoles) {
|
||||
|
||||
|
@ -125,11 +129,26 @@ public class DataScopeService implements DataScopeApi {
|
|||
List<Long> userBindDataScope = userServiceApi.getUserBindDataScope(userId);
|
||||
organizationIds.addAll(userBindDataScope);
|
||||
|
||||
// 3. 组装返回结果
|
||||
// 3. 如果userIds为空 organizationIds不为空 则userIds 为organizationIds下所有用户id
|
||||
if (CollectionUtil.isEmpty(userIds) && CollectionUtil.isNotEmpty(organizationIds)) {
|
||||
userIds.addAll(userOrgServiceApi.getUserIdsByOrgIds(organizationIds));
|
||||
}
|
||||
|
||||
// 4. 组装返回结果
|
||||
dataScopeResponse.setUserIds(userIds);
|
||||
dataScopeResponse.setOrganizationIds(organizationIds);
|
||||
|
||||
return dataScopeResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataScopeDTO getDataScope(Long userId) {
|
||||
// 2. 获取用户角色信息
|
||||
List<Long> roleIds = sysUserRoleApi.findRoleIdsByUserId(userId);
|
||||
if (ObjectUtil.isEmpty(roleIds)) {
|
||||
throw new SystemModularException(AuthExceptionEnum.ROLE_IS_EMPTY);
|
||||
}
|
||||
List<SysRoleDTO> roleResponseList = roleServiceApi.getRolesByIds(roleIds);
|
||||
return this.getDataScope(userId, roleResponseList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.system.modular.user.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.api.SysUserRoleApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.request.SysUserRequest;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.request.UserRoleRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserRole;
|
||||
|
@ -37,7 +38,7 @@ import java.util.List;
|
|||
* @author chenjinlong
|
||||
* @date 2021/2/3 15:23
|
||||
*/
|
||||
public interface SysUserRoleService extends IService<SysUserRole> {
|
||||
public interface SysUserRoleService extends IService<SysUserRole> , SysUserRoleApi {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
|
|
|
@ -41,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -80,6 +82,13 @@ public class SysUserOrgServiceServiceImpl extends ServiceImpl<SysUserOrgMapper,
|
|||
return sysUserOrgDTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Long> getUserIdsByOrgIds(Set<Long> organizationIds) {
|
||||
List<SysUserOrg> userOrgs = this.lambdaQuery().in(SysUserOrg::getOrgId, organizationIds).list();
|
||||
return userOrgs.stream().map(SysUserOrg::getUserId).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void add(UserOrgRequest userOrgResponse) {
|
||||
|
|
|
@ -101,7 +101,6 @@ public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUs
|
|||
}
|
||||
|
||||
@Override
|
||||
|
||||
public List<Long> findRoleIdsByUserId(Long userId) {
|
||||
|
||||
// 先从缓存获取用户绑定的角色
|
||||
|
|
Loading…
Reference in New Issue