场景:如果是省级账号,可以查询其它省和本省内的所有数据;即可以查看无论哪个权限的所有数据;如果是市级权限,可以查看自己、兄弟以及下属内的所有数据,但不可以查看省级的数据;如果是区级权限,可以查看自己、兄弟以及下属内的所有数据,但是不可以查看市级和省级的数据;如果是油站级,只能查看自己和兄弟,不能查看其它权限的数据。
目标:用mybatis实现
MySQL:
<select id="selectByLimit" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from tb_admin
<if test="province == null || province == ''">
where role_id IN(SELECT role_id FROM tb_role)
</if>
<if test="province != null">
where role_id IN(
SELECT role_id FROM tb_role where
province = #{province,jdbcType=VARCHAR}
<if test="city == null || city == ''">
AND city is not null
</if>
<if test="city != null and city != ''">
AND city = #{city,jdbcType=VARCHAR}
<if test="partition == null || partition == ''">
AND `PARTITION` is not null
</if>
<if test="partition != null">
AND `PARTITION` = #{partition,jdbcType=VARCHAR}
</if>
</if>
)
</if>
<if test="start != null and end != null">
limit #{start,jdbcType=INTEGER},#{end,jdbcType=INTEGER}
</if>
order by create_time desc
</select>