<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.dept.dao.ibatis.DeptDaoImpl">

    <select id="queryDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
        select * from mortals_xhx_dept where deptCode = #{deptCode}
    </select>
    <select id="queryDeptParient" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
        select * from mortals_xhx_dept where deptCode = #{parentCode}
    </select>
    <select id="queryDeptParentId" resultType="integer">
        select parentId from mortals_xhx_dept where deptId = #{deptId}
    </select>
    <!--查询所有子部门-->
    <select id="getAllChildrenDept" resultType="com.mortals.xhx.module.dept.model.DeptEntity">
        SELECT T3.id,T3.parentId, T3.deptName,T3.deptCode,T3.deptStatus
        FROM(
        SELECT
        @codes as _ids,
        ( SELECT @codes := GROUP_CONCAT(id)
        FROM mortals_xhx_dept
        WHERE FIND_IN_SET(parentId, @codes)
        ) as T1,
        @l := @l+1 as level_
        FROM mortals_xhx_dept, (SELECT @codes := #{deptId}, @l := 0 ) T4
        WHERE @codes IS NOT NULL
        ) T2, mortals_xhx_dept T3
        WHERE FIND_IN_SET(T3.parentId, T2._ids)
    </select>
</mapper>