mirror of https://gitee.com/stylefeng/roses
【7.1.3】【user】用户列表增加数据范围的控制
parent
3624d54973
commit
be77382df1
|
@ -38,6 +38,7 @@ import javax.validation.constraints.NotBlank;
|
|||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 系统用户参数
|
||||
|
@ -179,6 +180,16 @@ public class SysUserRequest extends BaseRequest {
|
|||
@ChineseDescription("用户id集合(用在批量删除)")
|
||||
private List<Long> userIds;
|
||||
|
||||
/**
|
||||
* 部门的数据范围集合
|
||||
*/
|
||||
private Set<Long> scopeOrgIds;
|
||||
|
||||
/**
|
||||
* 用户id的数据范围集合
|
||||
*/
|
||||
private Set<Long> userScopeIds;
|
||||
|
||||
/**
|
||||
* 参数校验分组:修改密码
|
||||
*/
|
||||
|
|
|
@ -35,6 +35,19 @@
|
|||
<if test="sysUserRequest.orgId != null and sysUserRequest.orgId != ''">
|
||||
and suorg.org_id in (select org_id from hr_organization where org_pids like CONCAT('%$[',#{sysUserRequest.orgId},'$]%') escape '$' or org_id=#{sysUserRequest.orgId} )
|
||||
</if>
|
||||
<if test="sysUserRequest.scopeOrgIds != null and sysUserRequest.scopeOrgIds.size() > 0">
|
||||
and suorg.org_id in
|
||||
<foreach item="item" collection="sysUserRequest.scopeOrgIds" index="index" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="sysUserRequest.userScopeIds != null and sysUserRequest.userScopeIds.size() > 0">
|
||||
and suser.user_id in
|
||||
<foreach item="item" collection="sysUserRequest.userScopeIds" index="index" open="(" separator="," close=")">
|
||||
#{item}
|
||||
</foreach>
|
||||
</if>
|
||||
|
||||
and suser.del_flag = 'N'
|
||||
order by suser.create_time desc
|
||||
</where>
|
||||
|
|
|
@ -30,6 +30,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
|
@ -393,6 +394,40 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
@Override
|
||||
public PageResult<SysUserDTO> findPage(SysUserRequest sysUserRequest) {
|
||||
|
||||
LoginUser loginUser = LoginContext.me().getLoginUser();
|
||||
|
||||
// 获取当前用户数据范围的枚举
|
||||
Set<DataScopeTypeEnum> dataScopeTypeEnums = loginUser.getDataScopeTypeEnums();
|
||||
|
||||
// 获取当前用户数绑定的组织机构范围
|
||||
Set<Long> dataScopeOrganizationIds = loginUser.getDataScopeOrganizationIds();
|
||||
|
||||
// 获取当前用户绑定的用户数据范围
|
||||
Set<Long> dataScopeUserIds = loginUser.getDataScopeUserIds();
|
||||
|
||||
// 如果包含了全部数据
|
||||
if (dataScopeTypeEnums.contains(DataScopeTypeEnum.ALL)) {
|
||||
sysUserRequest.setScopeOrgIds(null);
|
||||
sysUserRequest.setUserScopeIds(null);
|
||||
}
|
||||
// 如果是按部门数据划分
|
||||
else if (dataScopeTypeEnums.contains(DataScopeTypeEnum.DEPT)
|
||||
|| dataScopeTypeEnums.contains(DataScopeTypeEnum.DEPT_WITH_CHILD)
|
||||
|| dataScopeTypeEnums.contains(DataScopeTypeEnum.DEFINE)) {
|
||||
sysUserRequest.setScopeOrgIds(null);
|
||||
sysUserRequest.setUserScopeIds(dataScopeUserIds);
|
||||
}
|
||||
// 如果包含了仅有自己的数据
|
||||
else if (dataScopeTypeEnums.contains(DataScopeTypeEnum.SELF)) {
|
||||
sysUserRequest.setScopeOrgIds(dataScopeOrganizationIds);
|
||||
sysUserRequest.setUserScopeIds(dataScopeUserIds);
|
||||
}
|
||||
// 其他情况,没有设置数据范围,则查所有
|
||||
else {
|
||||
sysUserRequest.setScopeOrgIds(null);
|
||||
sysUserRequest.setUserScopeIds(null);
|
||||
}
|
||||
|
||||
Page<SysUserDTO> userPage = this.baseMapper.findUserPage(PageFactory.defaultPage(), sysUserRequest);
|
||||
|
||||
return PageResultFactory.createPageResult(userPage);
|
||||
|
|
Loading…
Reference in New Issue