<?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.zsc.edu.gateway.modules.system.repo.DeptRepository">

    <resultMap id="deptMap" type="com.zsc.edu.gateway.modules.system.entity.Dept">
        <id column="id" property="id"/>
        <result column="sub_count" property="subCount"/>
        <result column="pid" property="pid"/>
        <result column="name" property="name"/>
        <result column="dept_sort" property="deptSort"/>
        <collection
                property="members"
                ofType="com.zsc.edu.gateway.modules.system.vo.UserVo"
                autoMapping="true"
                columnPrefix="members_"
        >
            <id column="id" jdbcType="BIGINT" property="userId"/>
            <result column="username" jdbcType="VARCHAR" property="username"/>
            <result column="email" jdbcType="VARCHAR" property="email"/>
            <result column="phone" jdbcType="VARCHAR" property="phone"/>
        </collection>
    </resultMap>

    <select id="selectDeptTree" resultMap="deptMap">
        SELECT sd.*,
               su.id       as members_id,
               su.username as members_username,
               su.email    as members_email,
               su.phone    as members_phone
        FROM sys_dept sd
                 left join sys_user su on sd.id = su.dept_id
    </select>
</mapper>
