mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update [重大更新] 重写数据权限实现
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.ruoyi.common.annotation.DataColumn;
|
||||
import com.ruoyi.common.annotation.DataPermission;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -19,6 +21,9 @@ public interface SysDeptMapper extends BaseMapperPlus<SysDept> {
|
||||
* @param dept 部门信息
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id")
|
||||
})
|
||||
List<SysDept> selectDeptList(SysDept dept);
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.annotation.DataColumn;
|
||||
import com.ruoyi.common.annotation.DataPermission;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -14,6 +16,9 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysRoleMapper extends BaseMapperPlus<SysRole> {
|
||||
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id")
|
||||
})
|
||||
Page<SysRole> selectPageRoleList(@Param("page") Page<SysRole> page, @Param("role") SysRole role);
|
||||
|
||||
/**
|
||||
@ -22,6 +27,9 @@ public interface SysRoleMapper extends BaseMapperPlus<SysRole> {
|
||||
* @param role 角色信息
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id")
|
||||
})
|
||||
List<SysRole> selectRoleList(SysRole role);
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.annotation.DataColumn;
|
||||
import com.ruoyi.common.annotation.DataPermission;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.core.mybatisplus.core.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
@ -14,6 +16,10 @@ import java.util.List;
|
||||
*/
|
||||
public interface SysUserMapper extends BaseMapperPlus<SysUser> {
|
||||
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id"),
|
||||
@DataColumn(key = "userName", value = "u.user_id")
|
||||
})
|
||||
Page<SysUser> selectPageUserList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);
|
||||
|
||||
/**
|
||||
@ -22,6 +28,10 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser> {
|
||||
* @param sysUser 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id"),
|
||||
@DataColumn(key = "userName", value = "u.user_id")
|
||||
})
|
||||
List<SysUser> selectUserList(SysUser sysUser);
|
||||
|
||||
/**
|
||||
@ -30,6 +40,10 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser> {
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id"),
|
||||
@DataColumn(key = "userName", value = "u.user_id")
|
||||
})
|
||||
Page<SysUser> selectAllocatedList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);
|
||||
|
||||
/**
|
||||
@ -38,6 +52,10 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser> {
|
||||
* @param user 用户信息
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@DataPermission({
|
||||
@DataColumn(key = "deptName", value = "d.dept_id"),
|
||||
@DataColumn(key = "userName", value = "u.user_id")
|
||||
})
|
||||
Page<SysUser> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param("user") SysUser user);
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
/**
|
||||
* 通用 数据权限 服务
|
||||
*
|
||||
* @author Lion Li
|
||||
*/
|
||||
public interface SysDataScopeService {
|
||||
|
||||
/**
|
||||
* 获取角色自定义权限
|
||||
* @param roleId 角色id
|
||||
* @return 部门id组
|
||||
*/
|
||||
String getRoleCustom(Long roleId);
|
||||
|
||||
/**
|
||||
* 获取部门及以下权限
|
||||
* @param deptId 部门id
|
||||
* @return 部门id组
|
||||
*/
|
||||
String getDeptAndChild(Long deptId);
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
||||
import com.ruoyi.system.service.SysDataScopeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("sdss")
|
||||
public class SysDataScopeServiceImpl implements SysDataScopeService {
|
||||
|
||||
@Autowired
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
@Autowired
|
||||
private SysDeptMapper deptMapper;
|
||||
|
||||
@Override
|
||||
public String getRoleCustom(Long roleId) {
|
||||
List<SysRoleDept> list = roleDeptMapper.selectList(
|
||||
new LambdaQueryWrapper<SysRoleDept>()
|
||||
.select(SysRoleDept::getDeptId)
|
||||
.eq(SysRoleDept::getRoleId, roleId));
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
return list.stream().map(rd -> Convert.toStr(rd.getDeptId())).collect(Collectors.joining(","));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDeptAndChild(Long deptId) {
|
||||
List<SysDept> list = deptMapper.selectList(new LambdaQueryWrapper<SysDept>()
|
||||
.select(SysDept::getDeptId)
|
||||
.eq(SysDept::getDeptId, deptId)
|
||||
.or()
|
||||
.apply("find_in_set({0},ancestors)", deptId));
|
||||
if (CollUtil.isNotEmpty(list)) {
|
||||
return list.stream().map(d -> Convert.toStr(d.getDeptId())).collect(Collectors.joining(","));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
@ -47,8 +46,9 @@ public class SysDeptServiceImpl extends ServicePlusImpl<SysDeptMapper, SysDept,
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysDept> selectDeptList(SysDept dept) {
|
||||
// return baseMapper.selectList();
|
||||
// return baseMapper.selectList(new LambdaQueryWrapper<>());
|
||||
return baseMapper.selectDeptList(dept);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
@ -46,7 +45,6 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole,
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public TableDataInfo<SysRole> selectPageRoleList(SysRole role, PageQuery pageQuery) {
|
||||
Page<SysRole> page = baseMapper.selectPageRoleList(PageUtils.buildPage(pageQuery), role);
|
||||
return PageUtils.buildDataInfo(page);
|
||||
@ -59,7 +57,6 @@ public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole,
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysRole> selectRoleList(SysRole role) {
|
||||
return baseMapper.selectRoleList(role);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
@ -54,7 +53,6 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser,
|
||||
private SysUserPostMapper userPostMapper;
|
||||
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
|
||||
public TableDataInfo<SysUser> selectPageUserList(SysUser user, PageQuery pageQuery) {
|
||||
Page<SysUser> page = baseMapper.selectPageUserList(PageUtils.buildPage(pageQuery), user);
|
||||
return PageUtils.buildDataInfo(page);
|
||||
@ -67,7 +65,6 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser,
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
|
||||
public List<SysUser> selectUserList(SysUser user) {
|
||||
return baseMapper.selectUserList(user);
|
||||
}
|
||||
@ -79,7 +76,6 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser,
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
|
||||
public TableDataInfo<SysUser> selectAllocatedList(SysUser user, PageQuery pageQuery) {
|
||||
Page<SysUser> page = baseMapper.selectAllocatedList(PageUtils.buildPage(pageQuery), user);
|
||||
return PageUtils.buildDataInfo(page);
|
||||
@ -92,7 +88,6 @@ public class SysUserServiceImpl extends ServicePlusImpl<SysUserMapper, SysUser,
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
|
||||
public TableDataInfo<SysUser> selectUnallocatedList(SysUser user, PageQuery pageQuery) {
|
||||
Page<SysUser> page = baseMapper.selectUnallocatedList(PageUtils.buildPage(pageQuery), user);
|
||||
return PageUtils.buildDataInfo(page);
|
||||
|
@ -42,10 +42,10 @@
|
||||
<if test="status != null and status != ''">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
<if test="params.dataScope != null and params.dataScope != ''">
|
||||
AND ( ${params.dataScope} )
|
||||
</if>
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- <if test="params.dataScope != null and params.dataScope != ''">-->
|
||||
<!-- AND ( ${params.dataScope} )-->
|
||||
<!-- </if>-->
|
||||
order by d.parent_id, d.order_num
|
||||
</select>
|
||||
|
||||
|
@ -60,10 +60,10 @@
|
||||
<if test="role.params.endTime != null and role.params.endTime != ''"><!-- 结束时间检索 -->
|
||||
and date_format(r.create_time,'%y%m%d') <= date_format(#{role.params.endTime},'%y%m%d')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
<if test="role.params.dataScope != null and role.params.dataScope != ''">
|
||||
AND ( ${role.params.dataScope} )
|
||||
</if>
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- <if test="role.params.dataScope != null and role.params.dataScope != ''">-->
|
||||
<!-- AND ( ${role.params.dataScope} )-->
|
||||
<!-- </if>-->
|
||||
order by r.role_sort
|
||||
</select>
|
||||
|
||||
@ -88,10 +88,10 @@
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
<if test="params.dataScope != null and params.dataScope != ''">
|
||||
AND ( ${params.dataScope} )
|
||||
</if>
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- <if test="params.dataScope != null and params.dataScope != ''">-->
|
||||
<!-- AND ( ${params.dataScope} )-->
|
||||
<!-- </if>-->
|
||||
order by r.role_sort
|
||||
</select>
|
||||
|
||||
|
@ -108,10 +108,10 @@
|
||||
AND (u.dept_id = #{user.deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{user.deptId},
|
||||
ancestors) ))
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
<if test="user.params.dataScope != null and user.params.dataScope != ''">
|
||||
AND ( ${user.params.dataScope} )
|
||||
</if>
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- <if test="user.params.dataScope != null and user.params.dataScope != ''">-->
|
||||
<!-- AND ( ${user.params.dataScope} )-->
|
||||
<!-- </if>-->
|
||||
</select>
|
||||
|
||||
<select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
@ -142,10 +142,10 @@
|
||||
AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(#{deptId},
|
||||
ancestors) ))
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
<if test="params.dataScope != null and params.dataScope != ''">
|
||||
AND ( ${params.dataScope} )
|
||||
</if>
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- <if test="params.dataScope != null and params.dataScope != ''">-->
|
||||
<!-- AND ( ${params.dataScope} )-->
|
||||
<!-- </if>-->
|
||||
</select>
|
||||
|
||||
<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
|
||||
|
Reference in New Issue
Block a user