通过ruoyi代码生成工具生成代码并插入测试数据
添加注解,填入部门表别名
@Override
@DataScope(deptAlias = "w")
public List<TbWorkshop> selectTbWorkshopList(TbWorkshop tbWorkshop)
{
return tbWorkshopMapper.selectTbWorkshopList(tbWorkshop);
}
sql语句
<sql id="selectTbWorkshopVo">
select w.id, w.temperature, w.dept_id, w.device_num from tb_workshop w
</sql>
<select id="selectTbWorkshopList" parameterType="TbWorkshop" resultMap="TbWorkshopResult">
<include refid="selectTbWorkshopVo"/>
<where>
<if test="temperature != null "> and temperature = #{temperature}</if>
<if test="deviceNum != null and deviceNum != ''"> and device_num = # {deviceNum}</if>
${params.dataScope}
</where>
</select>
测试
超级管理员权限用户可以查看所有部门的数据
部门权限的用户只能查看到自己所属部门的数据