<?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.MusicSheetPracticeRecordDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.MusicSheetPracticeRecord">
            <result column="id_" property="id" />
	        <result column="user_id_" property="userId" />
	        <result column="music_sheet_id_" property="musicSheetId" />
	        <result column="create_time_" property="createTime" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_
        , t.user_id_
        , t.music_sheet_id_
        , t.create_time_
        </sql>

	<select id="selectPracticeMusicIdPage" resultType="java.lang.Long">
        select t.id_ from  (select
        max(mspr.id_) as id_
        from sys_music_compare_record mspr
        left join music_sheet ms on mspr.music_sheet_id_ = ms.id_
        <if test="param.auditStatus != null">
            left join music_sheet_auth_record msar ON msar.music_sheet_id_ = ms.id_
        </if>
        <where>
            mspr.hidden_flag_ = 0
            <if test="param.auditStatus != null">
                and msar.last_audit_state_ = #{param.auditStatus}
            </if>
            <if test="param.clientType != null">
                and mspr.client_id_ = #{param.clientType}
            </if>
<!--            <if test="param.providerType.code == 'TENANT'">-->
<!--                and find_in_set('TENANT',ms.provider_type_)-->

<!--                <if test="param.state != null">-->
<!--                    and ms.tenant_state_ = #{param.state}-->
<!--                </if>-->
<!--            </if>-->

<!--            <if test="param.providerType.code == 'PLATFORM'">-->
<!--                and find_in_set('PLATFORM',ms.provider_type_)-->

<!--                <if test="param.state != null">-->
<!--                    and ms.state_ = #{param.state}-->
<!--                </if>-->
<!--            </if>-->
            <if test="param.studentId != null">
                and mspr.user_id_ = #{param.studentId}
            </if>
        </where>
        group by mspr.music_sheet_id_
        ) t  order by t.id_ desc
    </select>
</mapper>