<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tuoheng.miniprogram.dao.DeptMapper">

    <resultMap id="DeptResult" type="com.tuoheng.miniprogram.entity.Dept" >
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="name"    column="name"    />
        <result property="code"    column="code"    />
        <result property="fullname"    column="fullname"    />
        <result property="type"    column="type"    />
        <result property="pid"    column="pid"    />
        <result property="sort"    column="sort"    />
        <result property="note"    column="note"    />
        <result property="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="mark"    column="mark"    />
    </resultMap>

    <sql id="Base_Column_List">
        id, tenant_id, name, code, fullname, type, pid, sort, note, create_user, create_time, update_user, update_time, mark
    </sql>

    <select id="selectAllChildListById" parameterType="String" resultType="java.lang.String">
	SELECT id
        FROM(
                SELECT @ids AS p_ids, (SELECT @ids := GROUP_CONCAT(id) FROM th_dept WHERE FIND_IN_SET(pid, CONVERT(@ids USING utf8) COLLATE utf8_unicode_ci)) AS c_ids, @l := @l+1 AS LEVEL
                FROM th_dept, (SELECT @ids := #{id}, @l := 0 ) b
                having @ids IS NOT NULL
            ) u1
        JOIN th_dept u2 ON FIND_IN_SET(u2.id, CONVERT(u1.p_ids USING utf8) COLLATE utf8_unicode_ci);
    </select>

    <select id="getSondeptId" parameterType="String" resultType="java.lang.String">
        <![CDATA[
             select eo.id from th_dept eo where eo.pid=#{parentId}
        ]]>
    </select>


</mapper>