<?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.ym.mec.education.mapper.StudentAttendanceMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ym.mec.education.entity.StudentAttendance">
        <id column="id_" property="id"/>
        <result column="music_group_id_" property="musicGroupId"/>
        <result column="class_group_id_" property="classGroupId"/>
        <result column="course_schedule_id_" property="courseScheduleId"/>
        <result column="user_id_" property="userId"/>
        <result column="teacher_id_" property="teacherId"/>
        <result column="status_" property="status"/>
        <result column="create_time_" property="createTime"/>
        <result column="remark_" property="remark"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id_, music_group_id_, class_group_id_, course_schedule_id_, user_id_, teacher_id_, status_, create_time_, remark_
    </sql>
    <select id="selectPageByCondition" parameterType="com.ym.mec.education.req.AttendClassReq"
            resultType="com.ym.mec.education.resp.AttendClassResp">

     SELECT
	s.music_group_id_,s.class_group_id_,s.user_id_,s.teacher_id_,s.current_class_times_,s.status_,g.name_,g.total_class_times_,g.type_,c.teach_mode_,u.real_name_,c.name_ as courseName,c.class_date_,c.start_class_time_,c.end_class_time_
    FROM
	student_attendance s
    LEFT JOIN course_schedule c
    ON s.course_schedule_id_ = c.id_
    LEFT JOIN class_group g on g.id_ = s.class_group_id_
    LEFT JOIN sys_user u on u.id_ = c.teacher_id_
    LEFT JOIN class_group_student_mapper m ON m.class_group_id_ = g.id_
        WHERE
     m.user_id_ = #{query.userId}
       <if test="query.months != null">
          and DATE_FORMAT(s.create_time_, '%Y-%m') = #{query.months}
        </if>
        <if test="query.status != null">
            AND c.status_ = #{query.status}
        </if>

        <if test="query.classType != null">
            and g.type_ = #{query.classType}
        </if>

    </select>
</mapper>
