1. 程式人生 > 其它 >檢視許可權控制(部門及部門以下,看不到上級填的記錄)

檢視許可權控制(部門及部門以下,看不到上級填的記錄)

技術標籤:java

實現類

 SysUser sysUser = ShiroUtils.getSysUser();
        if (!sysUser.isAdmin()) {
            wgEnterpriceStyle.setCreateUserId(sysUser.getUserId());
        }

mapper.xml

oracle寫法

<select id="selectWgEnterpriceStyleList" resultMap="WgEnterpriceStyleResult">
        <include refid="selectWgEnterpriceStyleVo"/>
        LEFT join  SYS_USER u on f.create_user_id = u.user_id
        <if test="wgEnterpriceStyle.createUserId != null">
            INNER JOIN (
            select
            DEPT_ID
            from
            SYS_DEPT start with DEPT_ID = (select DEPT_ID from SYS_USER  where user_id = #{wgEnterpriceStyle.createUserId}) connect
            by prior DEPT_ID =  PARENT_ID
            )d  on  u.dept_id = d.DEPT_ID
        </if>
       
    </select>

mysql寫法

<select id="selectWgEnterpriceStyleList" resultMap="WgEnterpriceStyleResult">
        <include refid="selectWgEnterpriceStyleVo"/>
        LEFT join  SYS_USER u on f.create_user_id = u.user_id
        <if test="wgEnterpriceStyle.createUserId != null">
            INNER JOIN (
            select
            DEPT_ID
            from
            SYS_DEPT where (find_in_set(#{wgEnterpriceStyle.createUserId}, ancestors) or dept_id=#{wgEnterpriceStyle.createUserId}) and del_flag=0
            )d  on  u.dept_id = d.DEPT_ID
        </if>
       
    </select>

簡單來講

表A
INNER JOIN
sys_user c on A.create_user_id = c.user_id 
INNER JOIN 
d on c.dept_id = d.dept_id

d表就是查詢當前登入使用者所在的部門和該部門管轄下的所有小部門
整體意思:
查詢當前登入使用者所在的部門和該部門管轄下的所有小部門建立的A表記錄

在這裡插入圖片描述