目录
1、用户管理界面新增用户:FangXinYi ,分配角色为普通用户
2、在相应的xml文件DeviceMapper.xml内修改sql语句
一、前端数据权限设置
一个车间[部门]的负责人[角色]只能查看自己车间的设备数据
1、用户管理界面新增用户:FangXinYi ,分配角色为普通用户
2、在角色管理界面设置分配数据权限

3、 新建数据表
4、生成代码,导入ruoyi后rebuild一下程序,
二、后端设置
1、设置注解@DataScope
通过注解会触发数据权限判断
@Override
@DataScope(deptAlias ="d",userAlias = "u")
public List<Device> selectDeviceList(Device device)
{
return deviceMapper.selectDeviceList(device);
}
2、在相应的xml文件DeviceMapper.xml内修改sql语句
向左绑定sys_dept表单,${params.dataScope}对数据范围进行过滤
<sql id="selectDeviceVo">
select d.id, d.num, d.tem, d.dept_id from device d left join sys_dept s on d.dept_id=s.dept_id
</sql>
<select id="selectDeviceList" parameterType="Device" resultMap="DeviceResult">
<include refid="selectDeviceVo"/>
<where>
<if test="num != null and num != ''"> and num = #{num}</if>
<if test="tem != null and tem != ''"> and tem = #{tem}</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
${params.dataScope}
</where>
</select>
三、测试结果
超级管理员显示界面
ry普通用户显示界面
FangXinYi普通用户显示界面