<?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.school.smart.mapper.EduSmartWelcomeGuideRosterRelationMapper">

    <resultMap id="resultMap" type="com.yida.data.common.core.entity.smart.EduSmartWelcomeGuideRosterRelation">
        <id column="relation_id" property="id"/>
        <result column="relation_avatar" property="avatar"/>
        <result column="sex" property="sex"/>
        <association property="guideRoster" javaType="com.yida.data.common.core.entity.smart.EduSmartWelcomeGuideRoster">
            <id column="id" property="id"/>
            <result column="full_name" property="fullName"/>
            <result column="id_number" property="idNumber"/>
            <result column="avatar" property="avatar"/>
            <result column="qr_code_url" property="qrCodeUrl"/>
            <result column="admitted_department" property="admittedDepartment"/>
            <result column="admitted_department" property="admittedDepartment"/>
            <result column="pay_status" property="payStatus"/>
        </association>
    </resultMap>

    <!-- 根据名称查询花名册列表信息 -->
    <select id="listRoster" resultMap="resultMap">
        SELECT
            r.*,
            relation.id as relation_id,
            relation.avatar as relation_avatar,
            relation.sex
        FROM
            edu_smart_welcome_guide_roster_relation relation
        LEFT JOIN edu_smart_welcome_guide_roster r ON relation.roster_id = r.id
        WHERE
            relation.del_flag = 0
            AND r.del_flag = 0
        <if test='dto.rosterName != null and dto.rosterName != ""'>
            AND r.full_name LIKE CONCAT( '%', #{dto.rosterName}, '%' )
        </if>
          AND r.dept_id = #{dto.deptId}
        ORDER BY
            relation.create_date DESC
    </select>

</mapper>
