<?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.mapper.UserMusicMapper">



    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.UserMusicWrapper$UserMusic">
        SELECT t.id_,
        t.user_id_,
        t.client_type_,
        t.music_practice_record_id_,
        t.music_sheet_id_,
        t.accompany_url_,
        t.type_,
        t.img_,
        t.video_img_,
        t.desc_,
        t.video_url_,
        t.json_config_,
        t.like_num_,
        t.submit_time_,
        t.update_time_ as createTime
		FROM user_music t
        left join music_sheet t1 on t1.id_ = t.music_sheet_id_
        <where>
            t.del_flag_ = 0 and t.expire_flag_ = 0
            <if test="param.keyword != null and param.keyword != ''">
                and t1.music_sheet_name_ like concat('%', #{param.keyword}, '%')
            </if>
            <if test="param.userId != null">
                and t.user_id_ = #{param.userId}
            </if>
            <if test="param.clientType != null">
                and t.client_type_ = #{param.clientType}
            </if>
            <if test="param.type != null">
                and t.type_ = #{param.type}
            </if>
            <if test="param.id != null">
                and t.id_ = #{param.id}
            </if>
            <if test="param.exclusionId != null">
                and t.id_ != #{param.exclusionId}
            </if>
        </where>
        <if test="param.sort != null">
            order by
            <if test="param.sort == 1">
                t.like_num_ desc,
            </if>
            t.submit_time_ desc ,t.create_time_ desc ,t.id_ desc
        </if>

	</select>

    <update id="updateStar">
        update user_music set like_num_ =(select count(1) from  user_music_star where  user_music_id_ = #{userMusicId}) where id_ = #{userMusicId}
    </update>


    <update id="workOverdue">
        update user_music set expire_flag_ = 1 where date_add(update_time_,interval #{time} day ) &lt;= now() and type_ = 'DRAFT' and expire_flag_ = 0
    </update>
</mapper>
