src/main/resources/mapper/DepartmentMapper.xml
@@ -129,4 +129,18 @@ SELECT id as value, name as label, parent_id FROM t_department WHERE deleted = 0 </select> <select id="getChilds" resultType="integer"> WITH RECURSIVE temp_table AS ( SELECT id, name, parent_id FROM t_department WHERE id in <foreach collection="deptIds" open="(" item="deptId" close=")" separator=",">#{deptId}</foreach> UNION ALL SELECT so.id, so.name, so.parent_id FROM t_department so INNER JOIN temp_table tb ON so.parent_id = tb.id ) SELECT DISTINCT id FROM temp_table </select> </mapper>