mirror of https://gitee.com/stylefeng/roses
!47 【7.3.3】获取数据范围:补充用户id集合,并增加通过用户id直接获取用户数据范围方法
Merge pull request !47 from 夜星/dev-7.3.3pull/48/MERGE v7.3.3
commit
2081c19ad4
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,6 +272,21 @@ public class SysUserController {
|
|||
return new SuccessResponseData<>(sysUserService.selector(sysUserRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户下拉列表,用户权限下用户
|
||||
* <p>
|
||||
* 本接口不查询超级管理员
|
||||
*
|
||||
* @param sysUserRequest 请求参数:name 姓名(可选)
|
||||
* @return 返回除超级管理员外的用户列表
|
||||
* @author yx
|
||||
* @date 2023/02/21 09:49
|
||||
*/
|
||||
@GetResource(name = "系统用户_选择器(权限)", path = "/sysUser/selectorByAuthority", requiredPermission = false)
|
||||
public ResponseData<List<SimpleDict>> selectorByAuthority(SysUserRequest sysUserRequest) {
|
||||
return new SuccessResponseData<>(sysUserService.selectorByAuthority(sysUserRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户下拉列表,可以根据姓名搜索
|
||||
* <p>
|
||||
|
|
|
@ -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 {
|
||||
|
||||
/**
|
||||
* 新增
|
||||
|
|
|
@ -230,6 +230,13 @@ public interface SysUserService extends IService<SysUser>, UserServiceApi {
|
|||
*/
|
||||
List<SimpleDict> selector(SysUserRequest sysUserRequest);
|
||||
|
||||
/**
|
||||
* 用户下拉列表选择-根据当前用户权限获取管理的用户信息
|
||||
* 可以获取指定用户的管理用户
|
||||
* 支持通过用户姓名模糊查询
|
||||
*/
|
||||
List<SimpleDict> selectorByAuthority(SysUserRequest request);
|
||||
|
||||
/**
|
||||
* 查询所有用户下拉列表(含管理员)
|
||||
*
|
||||
|
|
|
@ -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) {
|
||||
|
||||
// 先从缓存获取用户绑定的角色
|
||||
|
|
|
@ -91,6 +91,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -601,6 +602,34 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return this.selectUserList(sysUserRequest, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SimpleDict> selectorByAuthority(SysUserRequest request) {
|
||||
//获取用户数据权限
|
||||
Long userId = ObjectUtil.isNull(request.getUserId()) ? LoginContext.me().getLoginUser().getUserId() : request.getUserId();
|
||||
DataScopeDTO dataScope = dataScopeApi.getDataScope(userId);
|
||||
// 塞入用户数据范围
|
||||
request.setUserScopeIds(dataScope.getUserIds());
|
||||
LambdaQueryWrapper<SysUser> wrapper = this.createWrapper(request);
|
||||
|
||||
// 排除超级管理员
|
||||
wrapper.ne(SysUser::getSuperAdminFlag, YesOrNotEnum.Y.getCode());
|
||||
|
||||
// 查询id name account
|
||||
wrapper.select(SysUser::getRealName, SysUser::getUserId, SysUser::getAccount);
|
||||
List<SysUser> list = this.list(wrapper);
|
||||
|
||||
ArrayList<SimpleDict> results = new ArrayList<>();
|
||||
for (SysUser sysUser : list) {
|
||||
SimpleDict simpleDict = new SimpleDict();
|
||||
simpleDict.setId(sysUser.getUserId());
|
||||
simpleDict.setName(sysUser.getRealName());
|
||||
simpleDict.setCode(sysUser.getAccount());
|
||||
results.add(simpleDict);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SimpleDict> selectorWithAdmin(SysUserRequest sysUserRequest) {
|
||||
return this.selectUserList(sysUserRequest, true);
|
||||
|
@ -1046,11 +1075,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
queryWrapper.eq(ObjectUtil.isNotEmpty(sysUserRequest.getUserId()), SysUser::getUserId, sysUserRequest.getUserId());
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(sysUserRequest.getAccount()), SysUser::getAccount, sysUserRequest.getAccount());
|
||||
queryWrapper.like(ObjectUtil.isNotEmpty(sysUserRequest.getRealName()), SysUser::getRealName, sysUserRequest.getRealName());
|
||||
queryWrapper.in(CollectionUtils.isNotEmpty(sysUserRequest.getUserScopeIds()), SysUser::getUserId, sysUserRequest.getUserScopeIds());
|
||||
|
||||
// 根据text查询
|
||||
if (ObjectUtil.isNotEmpty(sysUserRequest.getSearchText())) {
|
||||
queryWrapper.like(SysUser::getAccount, sysUserRequest.getSearchText()).or().like(SysUser::getRealName, sysUserRequest.getSearchText()).or()
|
||||
.like(SysUser::getNickName, sysUserRequest.getSearchText());
|
||||
queryWrapper.and(wrapper -> wrapper.like(SysUser::getAccount, sysUserRequest.getSearchText())
|
||||
// 姓名
|
||||
.or().like(SysUser::getRealName, sysUserRequest.getSearchText())
|
||||
// 昵称
|
||||
.or().like(SysUser::getNickName, sysUserRequest.getSearchText())
|
||||
// 手机号
|
||||
.or().like(SysUser::getPhone, sysUserRequest.getSearchText()));
|
||||
}
|
||||
|
||||
return queryWrapper;
|
||||
|
|
Loading…
Reference in New Issue