| | |
| | | SELECT id, name, father_id |
| | | FROM DepartmentHierarchy; |
| | | </select> |
| | | <select id="showUserById" resultType="com.yuanchu.mom.dto.UserDto"> |
| | | select * from (select id, name, age, email, phone,depart_id |
| | | from user where state=1 and SUBSTRING_INDEX(depart_id, ',', -1) in |
| | | <foreach collection="ids" item="id" separator="," open="(" close=")"> |
| | | #{id} |
| | | </foreach> ) a |
| | | <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''"> |
| | | ${ew.customSqlSegment} |
| | | </if> |
| | | </select> |
| | | <select id="selectSonById" resultType="java.lang.Integer"> |
| | | WITH RECURSIVE DepartmentHierarchy AS ( |
| | | SELECT id, name, father_id |
| | | FROM department |
| | | WHERE id = #{id} |
| | | UNION ALL |
| | | SELECT d.id, d.name, d.father_id |
| | | FROM department d |
| | | JOIN DepartmentHierarchy dh ON d.father_id = dh.id |
| | | ) |
| | | SELECT id |
| | | FROM DepartmentHierarchy |
| | | order by id desc; |
| | | </select> |
| | | </mapper> |