<?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.njcn.product.cnuser.user.mapper.DeptMapper">


    <select id="getDeptDescendantIndexes" resultType="DeptDTO">
        SELECT
        *
        FROM
        (
        SELECT
        T3.id,
        T3.pid,
        T3.pids,
        T3.NAME,
        T3.CODE,
        T3.type,
        T5.Short_Name area,
        T3.Remark,
        T3.sort
        FROM
        sys_dept T3,
        sys_area T5
        WHERE
        FIND_IN_SET( #{id}, T3.pids )
        and T3.type in
        <foreach collection="type" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        AND T3.area = T5.id
        AND T3.State = 1
        UNION
        SELECT
        T3.id,
        T3.pid,
        T3.pids,
        T3.NAME,
        T3.CODE,
        T3.type,
        T5.Short_Name area,
        T3.Remark,
        T3.sort
        FROM
        sys_dept T3,
        sys_area T5
        WHERE
        T3.area = T5.id
        AND T3.id = #{id}
        AND T3.State = 1
        ) T3
        ORDER BY
        T3.sort ASC;
    </select>

    <select id="getAllDeptTree" resultType="DeptAllTreeVO">
        SELECT
        T3.*
        FROM
        sys_dept T3,
        sys_area T5
        WHERE
        FIND_IN_SET( #{id}, T3.pids )
        and T3.type in
        <foreach collection="type" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        AND T3.area = T5.id
        AND T3.State = 1
        UNION
        SELECT
        T3.*
        FROM
        sys_dept T3,
        sys_area T5
        WHERE
        T3.area = T5.id
        and T3.id = #{id}
        AND T3.State = 1
    </select>


</mapper>
