<?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.yonge.cooleshow.biz.dal.dao.CourseScheduleStudentMusicSheetDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.CourseScheduleStudentMusicSheet">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="course_schedule_id_" jdbcType="INTEGER" property="courseScheduleId"/>
        <result column="user_id_" jdbcType="INTEGER" property="userId"/>
        <result column="down_status_" jdbcType="INTEGER" property="downStatus"/>
        <result column="music_sheet_accompaniment_id_" jdbcType="INTEGER" property="musicScoreAccompanimentId"/>
        <result column="play_status_" jdbcType="INTEGER" property="playStatus"/>
        <result column="accompaniment_play_status_" jdbcType="INTEGER" property="accompanimentPlayStatus"/>
        <result column="user_type_" jdbcType="INTEGER" property="userType"/>
        <result column="speed_" jdbcType="INTEGER" property="speed"/>
        <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , course_schedule_id_, user_id_, down_status_, music_sheet_accompaniment_id_, play_status_,
    accompaniment_play_status_, user_type_, speed_, create_time_, update_time_
    </sql>
    <insert id="batchInsert">
        INSERT INTO course_schedule_student_music_sheet (course_schedule_id_,user_id_,user_type_,down_status_,
        music_sheet_accompaniment_id_,play_status_,accompaniment_play_status_,
                                                         speed_,create_time_,update_time_)
        VALUE
        <foreach collection="musicSheet" item="item" separator=",">
            (#{item.courseScheduleId},#{item.userId},#{item.userType},#{item.downStatus},#{item.musicScoreAccompanimentId},
            #{item.playStatus},#{item.accompanimentPlayStatus},#{item.speed},now(),now())
        </foreach>
    </insert>
    <update id="closePlayStatus">
        UPDATE course_schedule_student_music_sheet SET play_status_ = 0,accompaniment_play_status_ = 0,update_time_ = NOW()
        WHERE course_schedule_id_ = #{courseId}
        <if test="userId != null">
            AND user_id_ = #{userId}
        </if>
    </update>
    <update id="openPlayStatus">
        UPDATE course_schedule_student_music_sheet SET play_status_ = 1,update_time_ = NOW()
        WHERE course_schedule_id_ = #{scheduleId}
        AND music_sheet_accompaniment_id_ = #{musicSheetAccompanimentId}
        <if test="userId != null">
            AND user_id_ = #{userId}
        </if>
    </update>
    <update id="openAccompanimentPlayStatus">
        UPDATE course_schedule_student_music_sheet SET accompaniment_play_status_ = 1,update_time_ = NOW()
        WHERE course_schedule_id_ = #{scheduleId} AND music_sheet_accompaniment_id_ = #{musicSheetAccompanimentId}
        <if test="userId != null">
            AND user_id_ = #{userId}
        </if>
    </update>

    <resultMap id="queryBySheetIdAndCourseIdMap" type="com.yonge.cooleshow.biz.dal.dto.CourseScheduleStudentMusicSheetResult" extends="BaseResultMap">
    </resultMap>
    <select id="queryBySheetIdAndCourseId" resultMap="queryBySheetIdAndCourseIdMap">
        SELECT cssm.*
        FROM course_schedule_student_music_sheet cssm
        <where>
            <if test="courseId != null">
                AND cssm.course_schedule_id_ = #{courseId}
            </if>
            <if test="musicSheetAccompanimentId != null">
                AND cssm.music_sheet_accompaniment_id_ = #{musicSheetAccompanimentId}
            </if>
            <if test="userType != null">
                AND cssm.user_type_ = #{userType}
            </if>
            <if test="userId != null">
                AND cssm.user_id_ = #{userId}
            </if>
            <if test="downStatus != null">
                AND cssm.down_status_ = #{downStatus}
            </if>
        </where>
    </select>

</mapper>
