@@ -233,4 +233,8 @@ public interface SysDeptMapper {
*/
Integer thisDeptIdIsParentIdChild(@Param("deptId") Long deptId, @Param("parentId") Long parentId);
+ /**
+ * 根据用户名查询dept_id, parent_id, ancestors, dept_name
+ */
+ SysDept findDeptIdByUserName(@Param("userName") String userName);
}
@@ -621,4 +621,21 @@
#{item}
</foreach>
</select>
+ <select id="findDeptIdByUserName" parameterType="SysDept" resultMap="SysDeptResult">
+ SELECT
+ dept.dept_id,
+ dept.parent_id,
+ dept.ancestors,
+ dept.dept_name,
+ su.user_name
+ FROM
+ sys_user su
+ LEFT JOIN sys_user_dept ud ON ud.user_id = su.user_id
+ LEFT JOIN sys_dept dept ON ud.dept_id = dept.dept_id
+ WHERE
+ su.del_flag = 0
+ AND dept.del_flag = 0
+ AND su.user_name = #{userName}
+ LIMIT 1
+ </select>
</mapper>