根据省市区查询对应权限下的数据
場景:如果是省級賬號,可以查詢其它省和本省內的所有數據;即可以查看無論哪個權限的所有數據;如果是市級權限,可以查看自己、兄弟以及下屬內的所有數據,但不可以查看省級的數據;如果是區級權限,可以查看自己、兄弟以及下屬內的所有數據,但是不可以查看市級和省級的數據;如果是油站級,只能查看自己和兄弟,不能查看其它權限的數據。
目標:用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>
總結
以上是生活随笔為你收集整理的根据省市区查询对应权限下的数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java读取excel中的数据存到数据库
- 下一篇: ifelse语句是否必须以else结尾?