<?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.yida.data.user.mapper.EduStaffDeptMapper">
    <resultMap id="BaseResultMap" type="com.yida.data.common.core.entity.user.EduStaffDept">
        <!--@mbg.generated-->
        <!--@Table edu_staff_dept-->
        <id column="id" property="id"/>
        <result column="create_date" property="createDate"/>
        <result column="create_id" property="createId"/>
        <result column="update_date" property="updateDate"/>
        <result column="update_id" property="updateId"/>
        <result column="staff_id" property="staffId"/>
        <result column="staff_name" property="staffName"/>
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="is_leader" property="isLeader"/>
        <result column="is_main" property="isMain"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id, create_date, create_id, update_date, update_id, staff_id, staff_name, dept_id,
        dept_name, is_leader, is_main
    </sql>

    <select id="listStaffWithDept" resultType="com.yida.data.user.vo.StaffWithDeptVO">
        select distinct a.dept_id,b.id staff_id,b.name staff_name
        from edu_staff_dept a right join edu_staff b on a.staff_id=b.id
        where b.del_flag=0 and b.school_id=#{schoolId}
    </select>

    <select id="getStaffDeptByStaffIds" resultType="com.yida.data.common.core.entity.user.EduStaffDept">
        SELECT
        GROUP_CONCAT(a.dept_name) as dept_name,
        a.staff_id,
        a.staff_name,
        b.mobile
        FROM
        edu_staff_dept a
        LEFT JOIN edu_staff b on a.staff_id = b.id
        where 1=1
        <if test="staffIds != null and staffIds.size > 0">
            and a.staff_id in
            <foreach collection="staffIds" item="item" close=")" open="(" separator=",">
                #{item}
            </foreach>
        </if>

        GROUP BY a.staff_id,a.staff_name
    </select>
</mapper>