<?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.MusicSheetDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.MusicSheet">
        <id column="id_" jdbcType="BIGINT" property="id"/>
        <result column="music_sheet_name_" jdbcType="VARCHAR" property="musicSheetName"/>
        <result column="user_id_" jdbcType="BIGINT" property="userId"/>
        <result column="composer_" jdbcType="VARCHAR" property="composer"/>
        <result column="music_subject_" jdbcType="VARCHAR" property="musicSubject"/>
        <result column="audio_type_" jdbcType="VARCHAR" property="audioType"/>
        <result column="music_tag_" jdbcType="VARCHAR" property="musicTag"/>
        <result column="play_speed_" jdbcType="INTEGER" property="playSpeed"/>
        <result column="favorite_count_" jdbcType="INTEGER" property="favoriteCount"/>
        <result column="virtual_number_" property="virtualNumber" />
        <result column="first_pass_audit_time_" jdbcType="TIMESTAMP" property="firstPassAuditTime"/>
        <result column="can_evaluate_" jdbcType="TINYINT" property="canEvaluate"/>
        <result column="show_fingering_" jdbcType="TINYINT" property="showFingering"/>
        <result column="charge_type_" jdbcType="TINYINT" property="chargeType"/>
        <result column="audit_status_" jdbcType="TINYINT" property="auditStatus"/>
        <result column="sort_number_" jdbcType="INTEGER" property="sortNumber"/>
        <result column="top_flag_" jdbcType="TINYINT" property="topFlag"/>
        <result column="hot_flag_" jdbcType="TINYINT" property="hotFlag"/>
        <result column="exquisite_flag_" jdbcType="TINYINT" property="exquisiteFlag"/>
        <result column="music_price_" jdbcType="DECIMAL" property="musicPrice"/>
        <result column="audio_file_url_" jdbcType="VARCHAR" property="audioFileUrl"/>
        <result column="xml_file_url_" jdbcType="VARCHAR" property="xmlFileUrl"/>
        <result column="has_beat_" jdbcType="TINYINT" property="hasBeat"/>
        <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_by_" jdbcType="BIGINT" property="createBy"/>
        <result column="update_time_" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_by_" jdbcType="BIGINT" property="updateBy"/>
        <result column="remark_" jdbcType="VARCHAR" property="remark"/>
        <result column="notation_" jdbcType="VARCHAR" property="notation"/>
        <result column="accompaniment_type_" jdbcType="VARCHAR" property="accompanimentType"/>
        <result column="title_img_" jdbcType="VARCHAR" property="titleImg"/>
        <result column="music_img_" jdbcType="VARCHAR" property="musicImg"/>
        <result column="first_tone_" jdbcType="VARCHAR" property="firstTone"/>
        <result column="fixed_tone_" jdbcType="VARCHAR" property="fixedTone"/>
        <result column="music_sheet_type_" jdbcType="VARCHAR" property="musicSheetType"/>
        <result column="provider_type_" jdbcType="VARCHAR" property="providerType"/>
        <result column="cbs_music_sheet_id_" property="cbsMusicSheetId"/>
        <result column="score_type_" property="scoreType"/>
        <result column="tenant_sort_number_" property="tenantSortNumber"/>
        <result column="tenant_state_" property="tenantState"/>
        <result column="tenant_notation_" property="tenantNotation"/>
        <result column="tenant_category_id_" property="tenantCategoryId"/>
        <result column="tenant_score_type_" property="tenantScoreType"/>
        <result column="tenant_del_flag_" property="tenantCategoryId"/>
    </resultMap>

    <sql id="Base_Column_List">
        t.id_ as id ,
        t.music_sheet_name_ as musicSheetName,
        t.user_id_ as userId,
        t.composer_ as composer,
        t.music_subject_ as musicSubject,
        t.audio_type_ as audioType,
        t.music_tag_ as musicTag,
        t.play_speed_ as playSpeed,
        t.favorite_count_ as favoriteCount,
        t.virtual_number_ as virtualNumber,
        t.first_pass_audit_time_ as firstPassAuditTime,
        t.can_evaluate_ as canEvaluate,
        t.show_fingering_ as showFingering,
        t.charge_type_ as chargeType,
        t.payment_type_ as paymentType,
        t.provider_type_ as providerType,
        t.state_ as state,
        t.client_state_ as clientState,
        t.platform_state_ as platformState,
        t.sort_number_ as sortNumber,
        t.top_flag_ as topFlag,
        t.exquisite_flag_ as exquisiteFlag,
        t.hot_flag_ as hotFlag,
        t.music_price_ as musicPrice,
        t.audio_file_url_ as audioFileUrl,
        t.xml_file_url_ as xmlFileUrl,
        t.has_beat_ as hasBeat,
        t.mp3_type_ as mp3Type,
        t.ext_config_json_ as extConfigJson,
        t.create_time_ as createTime,
        t.create_by_ as createBy,
        t.update_time_ as updateTime,
        t.update_by_ as updateBy,
        t.del_flag_ as delFlag,
        t.audit_version_ as auditVersion,
        t.source_type_ as sourceType,
        t.accompaniment_type_ as accompanimentType,
        t.remark_ as remark,
        t.first_tone_ as firstTone,
        t.fixed_tone_ as fixedTone,
        t.title_img_ as titleImg,
        t.reason_ as reason,
        t.music_img_ as musicImg,
        t.notation_ as notation,
        t.music_json_ as musicJSON,
        t.music_svg_ as musicSvg,
        t.music_jian_svg_ as musicJianSvg,
        t.music_first_svg_ as musicFirstSvg,
        t.music_sheet_type_ as musicSheetType,
        t.audit_status_ as auditStatus,
        t.submit_audit_time_ as submitAuditTime,
        t.cbs_music_sheet_id_ as cbsMusicSheetId,
        t.score_type_ as scoreType,
        t.tenant_sort_number_ as tenantSortNumber,
        t.tenant_state_ as tenantState,
        t.tenant_notation_ as tenantNotation,
        t.tenant_category_id_ as tenantCategoryId,
        t.tenant_score_type_ as tenantScoreType,
        t.tenant_del_flag_ as tenantDelFlag
    </sql>
    <insert id="batchInsert">
        insert into music_sheet
        (cbs_music_sheet_id_,music_tag_,payment_type_,charge_type_,top_flag_,exquisite_flag_,sort_number_,state_,audit_status_
            ,music_sheet_name_,music_subject_,music_svg_,composer_,accompaniment_type_,play_speed_,
         music_price_,notation_,music_sheet_type_,source_type_,provider_type_,audio_type_,show_fingering_,
         can_evaluate_,create_by_,user_id_,score_type_,is_all_subject_,first_pass_audit_time_
        )
        values
        <foreach collection="vos" item="item" separator=",">
            (#{item.musicSheetId},
             #{item.musicTagIds},#{item.paymentType},#{item.paymentType},
             #{item.topFlag},#{item.exquisiteFlag},#{item.sortNo},0
             ,'PASS'
            ,#{item.musicSheetUpdate.name},
            #{item.musicSheetUpdate.subjectIds},
            #{item.musicSheetUpdate.musicSvg},
            #{item.musicSheetUpdate.composer},
            #{item.musicSheetUpdate.audioType},
            #{item.musicSheetUpdate.playSpeed},
            #{item.musicSheetUpdate.musicPrice},
            #{item.isConvertibleScore},
            #{item.musicSheetUpdate.musicSheetType},
            CASE WHEN #{item.musicSheetUpdate.sourceType} = 'PLATFORM' THEN 'PLATFORM'
                WHEN #{item.musicSheetUpdate.sourceType} = 'PERSON' THEN 'TEACHER'
                ELSE 'TENANT' END,
            CASE WHEN #{item.availableType} = 'PLATFORM' THEN 'PLATFORM' ELSE 'TENANT' END,
            #{item.musicSheetUpdate.playMode},
            #{item.musicSheetUpdate.showFingering},
            #{item.musicSheetUpdate.canEvaluate},
            #{item.musicSheetUpdate.userId},#{item.musicSheetUpdate.userId},
            #{item.scoreType},#{item.musicSheetUpdate.isAllSubject},now()
             )
        </foreach>
    </insert>

    <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
        select <include refid="Base_Column_List"/>
        from music_sheet t
        left join sys_user su on t.create_by_ = su.id_
        <if test="param.sortByAlbumIdDesc != null">
            left join tenant_album_music tam on tam.music_sheet_id_ = t.id_ and tam.tenant_album_id_ = #{param.sortByAlbumIdDesc} and tam.del_flag_=0
        </if>
        <if test="param.auditStatus != null">
            left join music_sheet_auth_record msar ON msar.music_sheet_id_ = t.id_
        </if>
        <where>
            1=1
            <if test="param.clientState != null">
                and t.client_state_ = #{param.clientState}
            </if>
            <if test="param.platformState != null">
                and t.platform_state_ = #{param.platformState}
            </if>
            <if test="param.excludeMusicIds != null and param.excludeMusicIds.size() != 0">
                and t.id_ not in
                <foreach collection="param.excludeMusicIds" separator="," item="item" open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.mustMatchSubjectIds != null and param.mustMatchSubjectIds.size() != 0">
                and
                <foreach collection="param.mustMatchSubjectIds" separator="and" item="item" open="(" close=")">
                    find_in_set(#{item},t.music_subject_)
                </foreach>
            </if>
            <include refid="QueryInfo"/>
            <if test="param.auditStatus == null">
                AND t.cbs_music_sheet_id_ IS NOT NULL
            </if>
            <if test="param.tenantCategoryIds != null and param.tenantCategoryIds.size() != 0">
                and t.tenant_category_id_ in
                <foreach collection="param.tenantCategoryIds" separator="," item="item" open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.auditVersion != null ">
                and #{param.auditVersion} = t.audit_version_
            </if>
            <if test="param.notation">
                AND t.notation_ = #{param.notation}
            </if>
        </where>
        <if test="param.auditStatus != null">
            group by msar.music_sheet_id_
        </if>
        order by
        <if test="param.sortByAlbumIdDesc != null">
            if(isnull(tam.id_),0,1),
        </if>
        <if test="param.myself != null and param.myself == true ">
            t.cbs_music_sheet_id_ desc,
        </if>
        t.sort_group_, t.sort_num_, t.sort_num2_, t.alias_
    </select>

    <sql id="QueryInfo">
        <if test="param.musicSheetType != null">
            and t.music_sheet_type_ = #{param.musicSheetType}
        </if>
        <if test="param.idAndName != null and param.idAndName != ''">
            <if test="param.auditStatus != null">
                AND ((su.id_ like concat('%',#{param.idAndName} ,'%')
                or su.username_ like concat('%',#{param.idAndName},'%')
                or su.phone_ like concat('%',#{param.idAndName},'%')) OR
                (t.music_sheet_name_ like concat('%',#{param.idAndName},'%') AND msar.last_audit_state_ = 'PASS') OR
                (JSON_UNQUOTE(JSON_EXTRACT(music_sheet_json_, '$.name')) LIKE CONCAT('%',#{param.idAndName},'%') AND msar.last_audit_state_ != 'PASS'))
            </if>
            <if test="param.auditStatus == null">
                AND (su.id_ like concat('%',#{param.idAndName} ,'%')
                or su.username_ like concat('%',#{param.idAndName},'%')
                or su.phone_ like concat('%',#{param.idAndName},'%') OR
                t.music_sheet_name_ like concat('%',#{param.idAndName},'%'))
            </if>
        </if>
        <if test="param.search != null and param.search != ''">
            and (t.cbs_music_sheet_id_ like concat('%',#{param.search},'%') or
            t.music_sheet_name_ like concat('%',#{param.search},'%') or
            t.composer_ like concat ('%',#{param.search},'%'))
        </if>
        <if test="param.providerType != null">
            and find_in_set(#{param.providerType},t.provider_type_)
        </if>
        <if test="param.musicTagIds != null and param.musicTagIds != ''">
            and
            <foreach collection="param.musicTagIdList" open="(" close=")" separator="or" item="item">
                find_in_set(#{item},t.music_tag_)
            </foreach>
        </if>

        <if test="param.subjectIdList != null and param.subjectIdList.size() != 0">
            and(
            <foreach collection="param.subjectIdList" separator="or" item="item" open="(" close=")">
                find_in_set(#{item},t.music_subject_)
            </foreach>
            or t.music_subject_ is null or t.music_subject_ = '' OR t.is_all_subject_
            )
        </if>
        <if test="param.subjectIds != null and param.subjectIds != ''">
            and(find_in_set(#{param.subjectIds},t.music_subject_) or t.music_subject_ is null or t.music_subject_ = '' OR t.is_all_subject_)
        </if>
        <if test="param.musicSheetIdlist != null and param.musicSheetIdlist.size() != 0">
            and t.id_ in
            <foreach collection="param.musicSheetIdlist" separator="," item="item" open="(" close=")">
                 #{item}
            </foreach>
        </if>
        <if test="param.state != null">

            <if test="param.providerType != null">
                <if test="param.providerType.code == 'TENANT'">
                    and t.tenant_state_ = #{param.state}
                </if>

                <if test="param.providerType.code == 'PLATFORM'">
                    and t.state_ = #{param.state}
                </if>
            </if>

            <if test="param.providerType == null">
                and t.state_ = #{param.state}
            </if>

        </if>
        <if test="param.auditStatus != null">
            and msar.last_audit_state_ = #{param.auditStatus}
        </if>
        <if test="param.scoreType != null">
            and t.score_type_ = #{param.scoreType}
        </if>
        <if test="param.createBy != null">
            and t.create_by_ = #{param.createBy}
        </if>
        <if test="param.delFlag != null">
            <if test="param.providerType != null">
                <if test="param.providerType.code == 'TENANT'">
                    and t.tenant_del_flag_ = #{param.delFlag}
                </if>

                <if test="param.providerType.code == 'PLATFORM'">
                    and t.del_flag_ = #{param.delFlag}
                </if>
            </if>

            <if test="param.providerType == null">
                and t.del_flag_ = #{param.delFlag}
            </if>

        </if>
        <if test="param.sourceType != null">
            and t.source_type_ = #{param.sourceType}
        </if>
        <if test="param.chargeType != null">
            and (FIND_IN_SET(#{param.chargeType}, t.payment_type_))
        </if>
        <if test="param.topFlag != null">
            and t.top_flag_ = #{param.topFlag}
        </if>
        <if test="param.exquisiteFlag != null">
            and t.exquisite_flag_ = #{param.exquisiteFlag}
        </if>
        <if test="param.accompanimentType != null">
            and t.accompaniment_type_ = #{param.accompanimentType}
        </if>
        <if test="param.audioType != null">
            and t.audio_type_ = #{param.audioType}
        </if>
    </sql>

    <select id="selectAlbumDetailPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
        select distinct <include refid="Base_Column_List"/>
        ,su.username_ as addName
        ,su.avatar_ as addUserAvatar
        ,(select group_concat(mt.name_) from music_tag mt
            where find_in_set(mt.id_,t.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,(select group_concat(s.name_) from subject s
            where find_in_set(s.id_,t.music_subject_) and s.del_flag_ = 0 ) as subjectNames
        ,amr.sort_number_ as albumSortNumber
        from music_sheet t
        left join album_music_relate amr on t.id_ = amr.music_sheet_id_
        left join sys_user su on t.create_by_ = su.id_
        <where>
            t.cbs_music_sheet_id_ IS NOT NULL and find_in_set('PLATFORM',t.provider_type_)
            <if test="param.composer != null">
                AND t.composer_ LIKE '%${param.composer}%'
            </if>
            <if test="param.providerType != null">
                and find_in_set(#{param.providerType},t.provider_type_)
            </if>
            <if test="param.idAndName != null and param.idAndName != ''">
                and (t.id_ like concat('%',#{param.idAndName},'%') or
                t.music_sheet_name_ like concat('%',#{param.idAndName},'%'))
            </if>
            <if test="param.search != null and param.search != ''">
                and (t.cbs_music_sheet_id_ like concat('%',#{param.search},'%') or
                t.music_sheet_name_ like concat('%',#{param.search},'%'))
            </if>
            <if test="param.chargeType != null">
                and t.charge_type_ = #{param.chargeType}
            </if>
            <if test="param.excludeMusicIds != null and param.excludeMusicIds.size() != 0">
                and t.id_ not in
                <foreach collection="param.excludeMusicIds" separator="," item="item" open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.musicTagIds != null and param.musicTagIds != ''">
                and
                <foreach collection="param.musicTagIdList" separator="or" item="item"  open="(" close=")" >
                    find_in_set(#{item},t.music_tag_)
                </foreach>
            </if>
            <if test="param.subjectIdList != null and param.subjectIdList.size() != 0">
                and
                <foreach collection="param.subjectIdList" separator="or" item="item"  open="(" close=")" >
                    find_in_set(#{item},t.music_subject_)
                </foreach>
            </if>
            <if test="param.musicSheetType != null">
                and t.music_sheet_type_ = #{param.musicSheetType}
            </if>
            <if test="param.state != null">
                and t.state_ = #{param.state}
            </if>
            <if test="param.delFlag != null">
                and t.del_flag_ = #{param.delFlag}
            </if>
            <if test="param.sourceType != null">
                AND t.source_type_ = #{param.sourceType}
            </if>
            <if test="param.chargeType != null">
                AND (t.payment_type_ = 'FREE' OR FIND_IN_SET(#{param.chargeType}, t.payment_type_))
            </if>
            <if test="param.paymentTypes != null">
                AND t.payment_type_ IN (<foreach collection="param.paymentTypes" separator="," item="item">#{item}</foreach>)
            </if>
            <if test="param.id != null">
                <if test="param.type == 2">
                    and amr.album_id_ = #{param.id}
                    order by amr.sort_number_ desc,
                    t.sort_group_, t.sort_num_, t.sort_num2_, t.alias_
                </if>
                <if test="param.type == 1">
                    and t.id_ not in(select amr2.music_sheet_id_  from album_music_relate amr2
                        where amr2.album_id_ = #{param.id})
                    ORDER BY t.sort_group_, t.sort_num_, t.sort_num2_, t.alias_
                </if>
            </if>
            <if test="param.id == null">
                ORDER BY t.sort_group_, t.sort_num_, t.sort_num2_, t.alias_
            </if>
        </where>
    </select>

    <select id="detail" resultMap="DetailResultMap">
        SELECT
            <include refid="Base_Column_List"/>
            ,t.url_ as url
            ,t.midi_url_ as midiUrl
            ,t.metronome_url_ as metronomeUrl
            ,msa.id_ as accompanimentId
            ,msa.music_sheet_id_ as accompanimentMusicSheetId
            ,msa.audio_file_url_ as accompanimentAudioFileUrl
            ,msa.sort_number_ as accompanimentSortNumber
            ,msa.create_time_ as accompanimentCreateTime
            ,msa.track_ as track
            ,msa.musical_instrument_id_ as musicalInstrumentId
            ,su.username_ as userName
            ,su.avatar_ as userAvatar
            ,(
                select group_concat(mt.name_) from music_tag mt
                where find_in_set(mt.id_,t.music_tag_)
                and mt.del_flag_ = 0  and mt.state_ = 1
            ) as musicTagNames
            ,s2.name_ as subjectNames
            ,s2.code_ as code
        ,su.real_name_ as realName
            ,s2.ai_default_frequency_ as aiDefaultFrequency
        FROM music_sheet t
        left join music_sheet_accompaniment msa on msa.music_sheet_id_ = t.id_
        left join sys_user su on t.create_by_ = su.id_
        left join subject s2 on t.music_subject_ = s2.id_
        where t.id_ = #{id} AND t.cbs_music_sheet_id_ IS NOT NULL
         order by  msa.sort_number_
    </select>


    <resultMap id="DetailResultMap" type="com.yonge.cooleshow.biz.dal.vo.MusicSheetDetailVo">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="musicSheetName" jdbcType="VARCHAR" property="musicSheetName"/>
        <result column="userId" jdbcType="BIGINT" property="userId"/>
        <result column="cbsMusicSheetId" jdbcType="BIGINT" property="cbsMusicSheetId"/>
        <result column="composer" jdbcType="VARCHAR" property="composer"/>
        <result column="titleImg" jdbcType="VARCHAR" property="titleImg"/>
        <result column="musicSubject" jdbcType="VARCHAR" property="musicSubject"/>
        <result column="audioType" jdbcType="VARCHAR" property="audioType"/>
        <result column="providerType" jdbcType="VARCHAR" property="providerType"/>
        <result column="musicTag" jdbcType="VARCHAR" property="musicTag"/>
        <result column="playSpeed" jdbcType="INTEGER" property="playSpeed"/>
        <result column="canEvaluate" jdbcType="TINYINT" property="canEvaluate"/>
        <result column="showFingering" jdbcType="TINYINT" property="showFingering"/>
        <result column="chargeType" jdbcType="TINYINT" property="chargeType"/>
        <result column="auditStatus" property="auditStatus"/>
        <result column="state" jdbcType="TINYINT" property="state"/>
        <result column="sortNumber" jdbcType="INTEGER" property="sortNumber"/>
        <result column="topFlag" jdbcType="TINYINT" property="topFlag"/>
        <result column="hotFlag" jdbcType="TINYINT" property="hotFlag"/>
        <result column="musicPrice" jdbcType="DECIMAL" property="musicPrice"/>
        <result column="audioFileUrl" jdbcType="VARCHAR" property="audioFileUrl"/>
        <result column="musicTagNames" jdbcType="VARCHAR" property="musicTagNames"/>
        <result column="subjectNames" jdbcType="VARCHAR" property="subjectNames"/>
        <result column="xmlFileUrl" jdbcType="VARCHAR" property="xmlFileUrl"/>
        <result column="hasBeat" jdbcType="TINYINT" property="hasBeat"/>
        <result column="createTime" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="createBy" jdbcType="BIGINT" property="createBy"/>
        <result column="updateTime" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="updateBy" jdbcType="BIGINT" property="updateBy"/>
        <result column="delFlag" jdbcType="BOOLEAN" property="delFlag"/>
        <result column="url" jdbcType="BOOLEAN" property="url"/>
        <result column="metronomeUrl" jdbcType="BOOLEAN" property="metronomeUrl"/>
        <result column="midiUrl" jdbcType="BOOLEAN" property="midiUrl"/>
        <result column="mp3Type" jdbcType="VARCHAR" property="mp3Type"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="userName" jdbcType="VARCHAR" property="userName"/>
        <result column="auditVersion" jdbcType="VARCHAR" property="auditVersion"/>
        <result column="code" jdbcType="VARCHAR" property="code"/>
        <result column="reason" jdbcType="VARCHAR" property="reason"/>
        <result column="accompanimentType" jdbcType="VARCHAR" property="accompanimentType"/>
        <result column="notation" jdbcType="VARCHAR" property="notation"/>
	    <result column="musicImg" jdbcType="VARCHAR" property="musicImg"/>
	    <result column="favoriteCount" jdbcType="VARCHAR" property="favoriteCount"/>
	    <result column="firstPassAuditTime" jdbcType="VARCHAR" property="firstPassAuditTime"/>
        <result column="realName" jdbcType="VARCHAR" property="realName"/>
        <result column="auditTime" jdbcType="VARCHAR" property="auditTime"/>
        <result column="auditName" jdbcType="VARCHAR" property="auditName"/>
        <result column="auditReason" jdbcType="VARCHAR" property="auditReason"/>
        <result column="aiDefaultFrequency" jdbcType="VARCHAR" property="aiDefaultFrequency"/>
        <result column="musicJSON" jdbcType="VARCHAR" property="musicJSON"/>
        <result column="musicSvg" jdbcType="VARCHAR" property="musicSvg"/>
        <result column="musicJianSvg" jdbcType="VARCHAR" property="musicJianSvg"/>
        <result column="musicFirstSvg" jdbcType="VARCHAR" property="musicFirstSvg"/>
        <result column="musicSheetType" jdbcType="VARCHAR" property="musicSheetType"/>
        <result column="musicSheetJson" jdbcType="VARCHAR" property="musicSheetJson"/>
        <result column="tenantSortNumber" jdbcType="VARCHAR" property="tenantSortNumber"/>
        <result column="tenantState" jdbcType="VARCHAR" property="tenantState"/>
        <result column="tenantNotation" jdbcType="VARCHAR" property="tenantNotation"/>
        <result column="tenantCategoryId" jdbcType="VARCHAR" property="tenantCategoryId"/>
        <result column="tenantScoreType" jdbcType="VARCHAR" property="tenantScoreType"/>
        <result column="tenantDelFlag" jdbcType="VARCHAR" property="tenantDelFlag"/>
        <result column="scoreType" jdbcType="VARCHAR" property="scoreType"/>
        <collection property="background" ofType="com.yonge.cooleshow.biz.dal.entity.MusicSheetAccompaniment">
            <id column="accompanimentId" jdbcType="BIGINT" property="id"/>
            <result column="accompanimentMusicSheetId" jdbcType="BIGINT" property="musicSheetId"/>
            <result column="accompanimentMusicSubject" jdbcType="VARCHAR" property="musicSubjectId"/>
            <result column="accompanimentAudioFileUrl" jdbcType="VARCHAR" property="audioFileUrl"/>
            <result column="accompanimentSortNumber" jdbcType="TINYINT" property="sortNumber"/>
            <result column="accompanimentCreateTime" jdbcType="TIMESTAMP" property="createTime"/>
            <result column="accompanimentMetronomeUrl" jdbcType="VARCHAR" property="metronomeUrl"/>
            <result column="track" jdbcType="VARCHAR" property="track"/>
            <result column="musicalInstrumentId" jdbcType="VARCHAR" property="musicalInstrumentId"/>
        </collection>
    </resultMap>

    <select id="selectStudentMusicPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
        select <include refid="Base_Column_List"/>
        ,su.username_ as addName
        ,su.avatar_ as addUserAvatar
        from music_sheet t
        left join sys_user su on t.create_by_ = su.id_
        <if test="param.auditStatus != null">
            left join music_sheet_auth_record msar ON msar.music_sheet_id_ = t.id_
        </if>
        <where>
            1=1
            <include refid="QueryInfo"/>
            <if test="param.auditVersion != null ">
                and #{param.auditVersion} = t.audit_version_
            </if>
        </where>
        <if test="param.auditStatus != null">
            group by msar.music_sheet_id_
        </if>
        order by
        <choose>
            <when test="param.musicSortType != null and param.musicSortType.code == 'TOP'">
                t.top_flag_ desc, t.sort_number_ desc,
            </when>
            <when test="param.musicSortType != null and param.musicSortType.code == 'HOT'">
                t.favorite_count_ desc,
            </when>
            <when test="param.musicSortType != null and param.musicSortType.code == 'NEW'">
                t.first_pass_audit_time_ desc,
            </when>
            <otherwise>
                <if test="param.myself != null and param.myself == true ">
                    t.cbs_music_sheet_id_ desc,
                </if>
            </otherwise>
        </choose>
        t.sort_group_, t.sort_num_, t.sort_num2_, t.alias_
    </select>

    <select id="selectMyMusicPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
        select distinct <include refid="Base_Column_List"/>
        ,su.username_ as addName
        ,su.avatar_ as addUserAvatar
        ,(select group_concat(mt.name_) from music_tag mt
        where find_in_set(mt.id_,t.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,(select group_concat(s.name_) from subject s
        where find_in_set(s.id_,t.music_subject_) and s.del_flag_ = 0 ) as subjectNames
        ,if(mf.id_ is not null,1,0) as favorite
        from music_sheet t
        left join sys_user su on t.create_by_ = su.id_
        left join music_sheet_purchase_record mspr on mspr.music_sheet_id_ = t.id_
        left join music_favorite mf on t.id_ = mf.music_sheet_id_ and mspr.student_id_ = mf.user_id_
        <if test="param.auditStatus != null">
            left join music_sheet_auth_record msar ON msar.music_sheet_id_ = t.id_
        </if>
        <where>
            1=1
            <include refid="QueryInfo"/>
            <if test="param.studentId != null">
                and mspr.student_id_ = #{param.studentId}
                and mspr.order_status_ = 'PAID'
            </if>
            <if test="param.userType != null">
                and mspr.client_type_ = #{param.userType}
            </if>
            <if test="param.purchaseType != null">
                AND mspr.purchase_type_ = #{param.purchaseType}
            </if>
            <if test="param.courseGift != null">
                AND mspr.course_music_album_id_ <choose><when test="param.courseGift == 0"> = </when><otherwise> > </otherwise> </choose> 0
            </if>
        </where>
        <if test="param.auditStatus != null">
            group by msar.music_sheet_id_
        </if>
        order by  mspr.id_ desc
    </select>

    <select id="selectFavoriteMusicPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
        select <include refid="Base_Column_List"/>
        ,su.username_ as addName
        ,su.avatar_ as addUserAvatar
        ,(select group_concat(mt.name_) from music_tag mt
        where find_in_set(mt.id_,t.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,(select group_concat(s.name_) from subject s
        where find_in_set(s.id_,t.music_subject_) and s.del_flag_ = 0 ) as subjectNames
        ,if(mf.id_ is not null,1,0) as favorite
        from music_sheet t
        left join sys_user su on t.create_by_ = su.id_
        left join music_favorite mf on t.id_ = mf.music_sheet_id_
        <if test="param.auditStatus != null">
            left join music_sheet_auth_record msar ON msar.music_sheet_id_ = t.id_
        </if>
        <where>

            mf.client_type_ = #{clientType}
            <if test="clientType.code == 'STUDENT'">
                and t.del_flag_=0 and t.state_ =1 and find_in_set('PLATFORM',t.provider_type_)
            </if>
            <if test="clientType.code == 'TEACHER'">
                and ((t.del_flag_=0 and t.state_ =1 and find_in_set('PLATFORM',t.provider_type_))
                    <if test="param.tenantId !=null">
                        or (t.tenant_del_flag_=0 and t.tenant_state_ =1 and find_in_set('TENANT',t.provider_type_)
                            and t.id_ in (select s.music_sheet_id_ from tenant_album_music s
                                left join tenant_album s1 on s.tenant_album_id_ = s1.id_ where s.tenant_id_ = #{param.tenantId}
                                        and s.del_flag_ = 0 and s.subject_type_ in ('ENSEMBLE','MUSIC','SUBJECT') and s1.del_flag_= 0 and s1.status_ = 1

                            )
                        )
                    </if>
                )
            </if>

            <if test="param.studentId != null">
                and mf.user_id_ = #{param.studentId}
            </if>
        </where>
        <if test="param.auditStatus != null">
            group by msar.music_sheet_id_
        </if>
        order by mf.id_ desc
    </select>

    <select id="selectPracticeMusicPage" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">
        select <include refid="Base_Column_List"/>
        ,su.username_ as addName
        ,su.avatar_ as addUserAvatar
        ,(select group_concat(mt.name_) from music_tag mt
        where find_in_set(mt.id_,t.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,(select group_concat(s.name_) from subject s where find_in_set(s.id_,t.music_subject_) ) as subjectNames
        ,if(mf.id_ is not null,1,0) as favorite
        from sys_music_compare_record mspr
        left join music_sheet t on mspr.music_sheet_id_ = t.id_
        <if test="param.auditStatus != null">
            left join music_sheet_auth_record msar ON msar.music_sheet_id_ = t.id_
        </if>
        left join sys_user su on t.create_by_ = su.id_
        left join music_favorite mf on (t.id_ = mf.music_sheet_id_ and mspr.user_id_ = mf.user_id_ <if test="param.clientType != null"> AND mf.client_type_ = #{param.clientType}</if> )
        <where>
            1=1
            <include refid="QueryInfo"/>
            <if test="practiceMusicIdList != null and practiceMusicIdList.size() != 0">
                and mspr.id_ in
                <foreach collection="practiceMusicIdList" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
        </where>
        <if test="param.auditStatus != null">
            group by msar.music_sheet_id_
        </if>
        <if test="practiceMusicIdList != null and practiceMusicIdList.size() != 0">
            order by field(mspr.id_,
            <foreach collection="practiceMusicIdList" item="item" separator=",">
                #{item}
            </foreach>
        </if>
        )
    </select>

    <select id="selectStudentOrderPage" resultType="com.yonge.cooleshow.biz.dal.vo.StudentMusicSheetOrderVo">
        select distinct mspr.music_sheet_id_ as musicSheetId
        ,ms.music_sheet_name_ as musicSheetName
        ,ms.composer_ as composer
        ,ms.title_img_ as titleImg
        ,ms.music_tag_ as musicTag
        ,(select group_concat(mt.name_) from music_tag mt
        where find_in_set(mt.id_,ms.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,mspr.purchase_price_ as purchasePrice
        ,mspr.order_no_ as orderNo
        ,mspr.purchase_time_ as purchaseTime
        from music_sheet_purchase_record mspr
        left join music_sheet ms on mspr.music_sheet_id_ = ms.id_
        <where>
            mspr.order_status_ = 'PAID' and mspr.purchase_type_ = 'MUSIC'
            <if test="param.idAndName != null and param.idAndName != ''">
                and (ms.id_ like concat('%',#{param.idAndName} ,'%')
                    or ms.music_sheet_name_ like concat('%',#{param.idAndName},'%'))
            </if>
            <if test="param.studentId != null">
                and mspr.student_id_ = #{param.studentId}
            </if>
            <if test="param.orderNo != null and param.orderNo != ''">
                and mspr.order_no_ = #{param.orderNo}
            </if>
            <if test="param.musicTagList != null and param.musicTagList.size() != 0">
                and
                <foreach collection="param.musicTagList" separator="or" item="item"  open="(" close=")" >
                    find_in_set(#{item},ms.music_tag_)
                </foreach>
            </if>
            <if test="param.startTime != null">
                and mspr.purchase_time_ &gt; #{param.startTime}
            </if>
            <if test="param.endTime != null">
                and mspr.purchase_time_ &lt; #{param.endTime}
            </if>
        </where>
        order by mspr.id_ desc
    </select>

    <select id="selectTeacherPage" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherMusicSheetVo">
        select ms.id_ as musicSheetId
        ,ms.music_sheet_name_ as musicSheetName
        ,ms.composer_ as composer
        ,ms.title_img_ as titleImg
        ,ms.accompaniment_type_ as accompanimentType
        ,ms.music_tag_ as musicTag
        ,(select group_concat(mt.name_) from music_tag mt
        where find_in_set(mt.id_,ms.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,ms.play_speed_ as playSpeed
        ,ms.music_price_ as musicPrice
        ,ms.create_time_ as createTime
        ,ms.audit_status_ as auditStatus
        ,su.username_ as auditName
        from music_sheet ms
        left join music_sheet_auth_record msar on ms.id_ = msar.music_sheet_id_
        left join sys_user su on msar.verify_user_id_ = su.id_
        <where>
            <if test="param.idAndName != null and param.idAndName != ''">
                and (ms.id_ like concat('%',#{param.idAndName} ,'%')
                or ms.music_sheet_name_ like concat('%',#{param.idAndName},'%')
                or ms.composer_ like concat('%',#{param.idAndName},'%'))
            </if>
            <if test="param.teacherId != null">
                and ms.create_by_ = #{param.teacherId} and ms.source_type_ = 'TEACHER'
            </if>
            <if test="param.startTime != null">
                and ms.create_time_ &gt; #{param.startTime}
            </if>
            <if test="param.endTime != null">
                and ms.create_time_ &lt; #{param.endTime}
            </if>
            <if test="param.delFlag != null">
                and ms.del_flag_ = #{param.delFlag}
            </if>
        </where>
        order by  ms.id_ desc
    </select>

    <select id="selectAuditPage" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherMusicSheetVo">
        select
        msar.id_ as authMusicSheetId,
        ms.create_by_ as teacherId
        ,ms.exquisite_flag_ as exquisiteFlag
        ,ms.title_img_ as titleImg
        ,ms.accompaniment_type_ as accompanimentType
        ,su.username_ as username
        ,su.real_name_ as realName
        ,su.phone_ as phone
        ,ms.id_ as musicSheetId
        ,ms.music_sheet_name_ as musicSheetName
        ,ms.composer_ as composer
        ,ms.music_tag_ as musicTag
        ,(select group_concat(mt.name_) from music_tag mt
        where find_in_set(mt.id_,ms.music_tag_) and mt.del_flag_ = 0  and mt.state_ = 1) as musicTagNames
        ,ms.play_speed_ as playSpeed
        ,ms.music_price_ as musicPrice
        ,ms.update_time_ as createTime
        ,if(msar.audit_state_ is null,ms.audit_status_,msar.audit_state_) as auditStatus
        ,su2.username_ as auditName
        ,msar.first_auth_ as firstAuth
        from music_sheet_auth_record  msar
        left join  music_sheet ms on ms.id_ = msar.music_sheet_id_
        left join sys_user su on su.id_ = ms.create_by_
        left join sys_user su2 on msar.verify_user_id_ = su2.id_
        <where>ms.source_type_  = 'TEACHER'
            <if test="param.idAndName != null and param.idAndName != ''">
                and (su.id_ like concat('%',#{param.idAndName} ,'%')
                or su.username_ like concat('%',#{param.idAndName},'%')
                or ms.music_sheet_name_ like concat('%',#{param.idAndName},'%')
                or su.phone_ like concat('%',#{param.idAndName},'%'))
            </if>
            <if test="param.auditName != null and param.auditName != ''">
                and su2.username_ like concat('%',#{param.auditName},'%')
            </if>
            <if test="param.authStatus != null">
                and msar.audit_state_ = #{param.authStatus}  and msar.audit_state_ = msar.last_audit_state_
            </if>
            <if test="param.startTime != null">
                and ms.create_time_ &gt; #{param.startTime}
            </if>
            <if test="param.endTime != null">
                and ms.create_time_ &lt; #{param.endTime}
            </if>
            <if test="param.chargeType != null">
                and ms.charge_type_ = #{param.chargeType}
            </if>
            <if test="param.firstAuth != null">
                and msar.first_auth_ = #{param.firstAuth}
            </if>
	        <if test="param.exquisiteFlag != null">
	            and ms.exquisite_flag_ = #{param.exquisiteFlag}
	        </if>
        </where>
        order by field(ms.audit_status_,'DOING') desc,  ms.submit_audit_time_ desc
    </select>

    <select id="selectTeacherMusicSheetCount" resultType="java.lang.Integer">
        select count(1)
        from music_sheet
        where user_id_ = #{userId}
        and state_ = 1 and audit_status_ = 'PASS' and del_flag_ = 0 and source_type_ = 'TEACHER'
    </select>

    <select id="selectMusicNum" resultType="com.yonge.cooleshow.biz.dal.vo.HomeMusicSheetVo">
        select
            sum(if(ms.source_type_ = 'PLATFORM',1,0)) as musicSheetPlatformCount,
            sum(if(ms.source_type_ = 'TEACHER',1,0)) as musicSheetTeacherCount,
            count(1) as musicSheetCount
        from music_sheet ms
        where ms.state_ = 1 and ms.del_flag_ = 0 and ms.audit_status_ = 'PASS' and find_in_set('CHARGE',ms.payment_type_) and find_in_set('PLATFORM',ms.provider_type_)
    </select>

    <select id="selectPayMusicSheet" resultType="com.yonge.cooleshow.biz.dal.vo.HomeMusicSheetVo$MusicSheetSmall">

        SELECT
            ms.id_ as musicSheetId,
            ms.music_sheet_name_ as musicSheetName,
            count(DISTINCT pr.student_id_) as num
        FROM
            music_sheet ms
                LEFT JOIN music_sheet_purchase_record pr ON ms.id_ = pr.music_sheet_id_
        WHERE
            ms.del_flag_=0
          AND ms.charge_type_='CHARGE'
          AND ms.state_=1
          AND pr.order_status_='PAID'
        GROUP BY ms.id_
        ORDER BY count(DISTINCT pr.student_id_)  DESC,ms.id_ desc
        limit 5
    </select>

    <select id="selectTeacherCount" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherAuditMusicSheetVo">
        select
            sum(if(t.audit_status_ = 'DOING',1,0)) as doing,
            sum(if(t.audit_status_ = 'PASS'
                       and t.state_ = 1,1,0)) as pass,
            sum(if(t.audit_status_ = 'UNPASS',1,0)) as upPass
        from
            music_sheet t
        where t.user_id_ = #{userId}
    </select>

    <select id="queryStudentTotal" resultType="com.yonge.cooleshow.biz.dal.vo.StudentTotalVo">
        select
            t.user_id_ as userId,
            a.musicAlbumNum,
            b.musicSheetNum
        from student t
        left join (
            select
                user_id_, count(1) as musicAlbumNum
            from album_favorite
            <where>
                <if test="null != userId">
                    and user_id_ = #{userId}
                </if>
            </where>
            group by user_id_
        ) a on t.user_id_ = a.user_id_
        left join (
            select
                user_id_, count(1) as musicSheetNum
            from music_favorite
            <where>
                <if test="null != userId">
                    and user_id_ = #{userId}
                </if>
            </where>
            group by user_id_
        ) b on t.user_id_ = b.user_id_
        <where>
            <if test="null != userId">
                and t.user_id_ = #{userId}
            </if>
        </where>
    </select>

    <select id="queryTeacherTotal" resultType="com.yonge.cooleshow.biz.dal.vo.TeacherTotalVo">
        select
            t.user_id_ as userId,
            a.musicSheetNum as musicSheetNum
        from teacher t
        left join (
            select
                user_id_, count(1) as musicSheetNum
            from music_sheet
            where source_type_ = 'TEACHER' and state_ = 1 and audit_status_ = 'PASS' and del_flag_ = 0
            <if test="null != userId">
                and user_id_ = #{userId}
            </if>
            group by user_id_
        ) a on t.user_id_ = a.user_id_
        <where>
            <if test="null != userId">
                and t.user_id_ = #{userId}
            </if>
        </where>
    </select>
    <select id="auditDetail" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetDetailVo">
        SELECT
        su.username_ as userName
        ,su.avatar_ as userAvatar
        ,su.real_name_ as realName
        ,msar.update_time_ as auditTime
        ,msar.create_time_ as submitAuditTime
        ,msar.audit_state_ as auditStatus
        ,su2.username_ as auditName
        ,msar.reason_ as auditReason
        ,msar.music_sheet_json_ as musicSheetJson
        ,msar.batch_no_ as batchNo
        ,msar.id_ as id
        from music_sheet_auth_record  msar
        left join music_sheet t on t.id_ = msar.music_sheet_id_
        left join sys_user su on su.id_ = t.create_by_
        left join sys_user su2 on msar.verify_user_id_ = su2.id_
        WHERE msar.id_ = #{recordId}
    </select>

    <select id="auditDetailList" resultType="com.yonge.cooleshow.biz.dal.wrapper.MusicSheetWrapper$MusicSheetDetailVo">
        SELECT
        su.username_ as userName
        ,su.avatar_ as userAvatar
        ,su.real_name_ as realName
        ,msar.update_time_ as auditTime
        ,msar.create_time_ as submitAuditTime
        ,msar.audit_state_ as auditStatus
        ,su2.username_ as auditName
        ,msar.reason_ as auditReason
        ,msar.music_sheet_json_ as musicSheetJson
        ,msar.batch_no_ as batchNo
        ,msar.id_ as id
        from music_sheet_auth_record  msar
        left join music_sheet t on t.id_ = msar.music_sheet_id_
        left join sys_user su on su.id_ = t.create_by_
        left join sys_user su2 on msar.verify_user_id_ = su2.id_
        <where>
            <if test="batchNo != null and batchNo != ''">
                and #{batchNo} = msar.batch_no_
            </if>
        </where>
        order by msar.id_ desc
    </select>

    <!--单曲专辑数量统计-->
    <select id="selectMusicAlbumStatInfo" resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
        SELECT t1.music_sheet_id_ AS id, COUNT(DISTINCT t1.id_) AS total
        FROM album_music_relate t1 JOIN music_sheet t2 ON (t1.music_sheet_id_ = t2.id_)
        <where>
            <if test="musicIds != null">
                AND t1.music_sheet_id_ IN (<foreach collection="musicIds" separator="," item="item">#{item}</foreach>)
            </if>
        </where>
        GROUP BY t1.music_sheet_id_
    </select>

    <update id="updateFavoriteCount">
        update music_sheet set favorite_count_ =
        <choose>
            <when test="state.code == 0">
                favorite_count_ - 1
            </when>
            <when test="state.code == 1">
                favorite_count_ + 1
            </when>
            <otherwise>
                favorite_count_
            </otherwise>
        </choose>
        where id_ = #{musicSheetId}
    </update>
    <update id="updateBatchByCbsId">
        <foreach collection="vos" item="item" index="index" separator=";">
            update music_sheet ms set
            ms.music_tag_ = #{item.musicTagIds},ms.payment_type_ = #{item.paymentType},
            ms.charge_type_ = #{item.paymentType},
            ms.music_price_ = #{item.musicPrice},ms.top_flag_ = #{item.topFlag},
            ms.exquisite_flag_ = #{item.exquisiteFlag},ms.sort_number_ = #{item.sortNo},ms.del_flag_ = 0,
            ms.audit_status_ = 'PASS',
            ms.score_type_ = #{item.scoreType},
            ms.state_ = #{item.status},
            ms.notation_ = #{item.isConvertibleScore},
            ms.provider_type_ = CASE WHEN #{item.availableType} = 'PLATFORM' THEN 'PLATFORM' ELSE 'TENANT' END
            <if test="item.musicSheetUpdate != null">
                ,ms.music_sheet_name_ = #{item.musicSheetUpdate.name},
                ms.music_subject_ = #{item.musicSheetUpdate.subjectIds},
                ms.music_svg_ = #{item.musicSheetUpdate.musicSvg},
                ms.composer_ = #{item.musicSheetUpdate.composer},
                ms.accompaniment_type_ = #{item.musicSheetUpdate.audioType},
                ms.play_speed_ = #{item.musicSheetUpdate.playSpeed},
                ms.notation_ = #{item.musicSheetUpdate.notation},
                ms.music_sheet_type_ = #{item.musicSheetUpdate.musicSheetType},
                ms.create_by_ = #{item.musicSheetUpdate.userId},
                ms.audio_type_ = #{item.musicSheetUpdate.playMode},
                ms.show_fingering_ = #{item.musicSheetUpdate.showFingering},
                ms.can_evaluate_ = #{item.musicSheetUpdate.canEvaluate},
                ms.is_all_subject_ = #{item.musicSheetUpdate.isAllSubject},
                ms.source_type_ = CASE WHEN #{item.musicSheetUpdate.sourceType} = 'PLATFORM' THEN 'PLATFORM'
                WHEN #{item.musicSheetUpdate.sourceType} = 'PERSON' THEN 'TEACHER' ELSE 'TENANT' END,
                ms.first_pass_audit_time_ = IF(#{item.musicSheetUpdate.sourceType} = 'PERSON' and ms.first_pass_audit_time_ is null, now(), ms.first_pass_audit_time_)
            </if>
            where ms.cbs_music_sheet_id_ = #{item.musicSheetId}
        </foreach>
    </update>
    <update id="batchEnable">
        update music_sheet
        <set>
            <if test="tenantFlag == 1">
                tenant_state_ = #{status},
            </if>
            <if test="tenantFlag == 0">
                client_state_ = #{status}
            </if>
        </set>
        where FIND_IN_SET(cbs_music_sheet_id_,#{ids})
    </update>
    <update id="batchDel">
        update music_sheet
        <set>
            <if test="tenantFlag == 1">
                tenant_del_flag_ = 1,
            </if>
            <if test="tenantFlag == 0">
                del_flag_ = 1
            </if>
        </set>
         where FIND_IN_SET(cbs_music_sheet_id_,#{ids})
    </update>
    <update id="updateMusicSheet">
        update music_sheet
        set music_sheet_name_ = #{param.name},music_subject_ = #{param.subjectIds},music_svg_ = #{param.musicSvg},
            composer_ = #{param.composer},title_img_ = #{param.musicCover},music_img_ = #{param.musicCover},accompaniment_type_ = #{param.audioType},
            play_speed_ = #{param.playSpeed},is_all_subject_ = #{param.isAllSubject},platform_state_ = #{param.platformStatus},
            music_sheet_type_ = #{param.musicSheetType},source_type_ = CASE WHEN #{param.sourceType} = 'PLATFORM' THEN 'PLATFORM' ELSE 'TEACHER' END,
            create_by_ = #{param.userId},tenant_category_id_ = #{param.musicCategoryId}
        where cbs_music_sheet_id_ = #{param.id}
    </update>

    <select id="countByUser" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetUploadCountVo">
        select user_id_ userId, count(id_) count
        from music_sheet
        where del_flag_ = false and state_ =1 and source_type_ = 'TEACHER' and user_id_ in
        <foreach collection="userIds" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        group by user_id_
    </select>

    <select id="searchMusic" resultType="java.lang.Long">
        select t.id_ from music_sheet  t
        <if test="param.tenantAlbumIds != null and param.tenantAlbumIds.size() != 0">
            left join tenant_album_music tam on t.id_ = tam.music_sheet_id_
        </if>
            <where>
                <if test="param.subjectId != null">
                    and ( t.music_subject_ = #{param.subjectId} or t.music_subject_ is null or t.music_subject_ = '' OR t.is_all_subject_)
                </if>
                <if test="param.name != null and param.name != ''">
                    and t.music_sheet_name_ like concat('%',#{param.name},'%')
                </if>
                <if test="param.tenantAlbumIds != null and param.tenantAlbumIds.size() != 0">
                    and tam.tenant_album_id_ in
                    <foreach collection="param.tenantAlbumIds" item="item" open="(" close=")" separator=",">
                        #{item}
                    </foreach>
                    and tam.del_flag_=0
                    and tam.subject_type_ in ('ENSEMBLE', 'MUSIC', 'SUBJECT')
                </if>
                <if test="param.providerType != null">
                    and find_in_set(#{param.providerType},t.provider_type_)
                    <if test="param.providerType != null">
                        <if test="param.providerType.code == 'TENANT'">
                            and t.tenant_state_ = true and t.tenant_del_flag_ = 0
                        </if>

                        <if test="param.providerType.code == 'PLATFORM'">
                            and t.state_=1 and t.audit_version_ = 0 and t.del_flag_ = 0 and t.audit_status_ = 'PASS'
                        </if>
                    </if>
                </if>
            </where>
        order by t.top_flag_ desc, t.sort_number_ desc, t.favorite_count_ desc

    </select>

    <select id="searchAlbum" resultType="java.lang.Long">
        select id_ from music_album t
        <where>
            t.album_status_=1 and del_flag_=0 and audit_version_ = 0
            <if test="param.subjectId != null">
                and ( t.subject_id_ = #{param.subjectId} or t.subject_id_ is null or t.subject_id_ = '')
            </if>
            <if test="param.name != null and param.name != ''">
                and t.album_name_ like concat('%',#{param.name},'%')
            </if>
        </where>
        order by  t.sort_number_ desc
    </select>
    <select id="personOwnerList"
            resultType="com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetExtendWrapper$MusicSheetExtend">
        select su.id_ userId,su.username_ username
        ,'TEACHER' clientType,su.phone_ phone from teacher t
        left join sys_user su ON su.id_ = t.user_id_
        where su.user_type_ LIKE '%TEACHER%' AND su.del_flag_ = 0 AND su.lock_flag_ = 0 AND t.lock_flag_ = 0
        <if test="param.name != null and param.name != ''">
            AND (su.phone_ LIKE CONCAT('%',#{param.name},'%') OR su.username_ LIKE CONCAT('%',#{param.name},'%'))
        </if>
        <if test="param.userIdList != null and param.userIdList.size > 0">
            AND su.id_ IN
            <foreach collection="param.userIdList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="orgOwnerList"
            resultType="com.dayaedu.cbs.openfeign.wrapper.music.CbsMusicSheetExtendWrapper$MusicSheetExtend">
        select id_ organizationRoleId,name_ organizationRole,'ORG' clientType,phone_ phone from tenant_info where enable_flag_ = 1
        <if test="param.name != null and param.name != ''">
            AND (phone_ LIKE CONCAT('%',#{param.name},'%') OR name_ LIKE CONCAT('%',#{param.name},'%'))
        </if>
        <if test="param.userIdList != null and param.userIdList.size > 0">
            AND id_ IN
            <foreach collection="param.userIdList" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
    <select id="get" resultType="com.yonge.cooleshow.biz.dal.entity.MusicSheet">
        select <include refid="Base_Column_List"/>
        from music_sheet t
        where t.id_ = #{id}
    </select>


    <select id="selectSyncPage" resultType="com.yonge.cooleshow.biz.dal.entity.MusicSheet">
        select *
        from music_sheet
        where del_flag_ = 0 and audit_status_ = 'PASS' and cbs_music_sheet_id_ is null
    </select>

    <select id="queryTenantRelatedList" resultType="com.yonge.cooleshow.biz.dal.vo.MusicSheetVo">

        select
        <include refid="Base_Column_List"/>
        from music_sheet t
            left join tenant_album_music t1 on t1.music_sheet_id_ = t.id_
        <where>
            t.tenant_del_flag_ = 0 and t.tenant_state_ =1  and t.cbs_music_sheet_id_ is not null
            and t1.del_flag_=0 and t1.subject_type_ in ('ENSEMBLE', 'MUSIC', 'SUBJECT')
            <if test="queryInfo.albumId != null">
                and t1.tenant_album_id_ = #{queryInfo.albumId}
            </if>

            <if test="queryInfo.albumId == null">
                and 1=2
            </if>
            <if test="queryInfo.musicSheetId != null">
                and t.id_ != #{queryInfo.musicSheetId}
            </if>
            <if test="queryInfo.subjectId != null">
                and find_in_set(#{queryInfo.subjectId},t.music_subject_)
            </if>
            <if test="queryInfo.musicSheetType != null">
                and t.music_sheet_type_ = #{queryInfo.musicSheetType}
            </if>
        </where>

    </select>

    <select id="countTeacherEnable" resultType="int">
        select count(1)
        from music_sheet
        where state_ = 1 and del_flag_ = 0 and source_type_ = 'TEACHER' and create_by_ = #{userId}
    </select>

    <update id="updateTenantByCbsId">
        update music_sheet ms set
        ms.tenant_sort_number_ = #{item.sortNo},ms.tenant_del_flag_ = 0,
        ms.tenant_score_type_ = #{item.scoreType},
        ms.audit_status_ = 'PASS',
        ms.tenant_state_ = #{item.status},
        ms.tenant_notation_ = #{item.isConvertibleScore},
        ms.provider_type_ = CASE WHEN ms.provider_type_ is null or ms.provider_type_ = '' THEN 'TENANT'
        when find_in_set('TENANT',ms.provider_type_) then ms.provider_type_
        else concat(ms.provider_type_,',','TENANT') end
        <if test="item.musicSheetUpdate != null">
            ,ms.music_sheet_name_ = #{item.musicSheetUpdate.name},
            ms.music_subject_ = #{item.musicSheetUpdate.subjectIds},
            ms.music_svg_ = #{item.musicSheetUpdate.musicSvg},
            ms.composer_ = #{item.musicSheetUpdate.composer},
            ms.accompaniment_type_ = #{item.musicSheetUpdate.audioType},
            ms.play_speed_ = #{item.musicSheetUpdate.playSpeed},
            ms.music_sheet_type_ = #{item.musicSheetUpdate.musicSheetType},
            ms.create_by_ = #{item.musicSheetUpdate.userId},
            ms.audio_type_ = #{item.musicSheetUpdate.playMode},
            ms.tenant_category_id_ = #{item.musicSheetUpdate.musicCategoryId},
            ms.show_fingering_ = #{item.musicSheetUpdate.showFingering},
            ms.can_evaluate_ = #{item.musicSheetUpdate.canEvaluate},
            ms.alias_ = #{item.musicSheetUpdate.alias},
            ms.sort_num_ = #{item.musicSheetUpdate.sortNum},
            ms.sort_group_ = #{item.musicSheetUpdate.sortGroup},
            ms.sort_num2_ = #{item.musicSheetUpdate.sortNum2},
            ms.upload_time_ = #{item.musicSheetUpdate.createTime},
            ms.source_type_ = CASE WHEN #{item.musicSheetUpdate.sourceType} = 'PLATFORM' THEN 'PLATFORM'
            WHEN #{item.musicSheetUpdate.sourceType} = 'PERSON' THEN 'TEACHER' ELSE 'TENANT' END
        </if>
        where ms.cbs_music_sheet_id_ = #{item.musicSheetId}
    </update>

    <update id="updatePlatformByCbsId">
        update music_sheet ms set
        ms.music_tag_ = #{item.musicTagIds},ms.payment_type_ = #{item.paymentType},
        ms.first_pass_audit_time_ = IF((#{item.musicSheetUpdate.sourceType} = 'PERSON' and ms.first_pass_audit_time_ is null) or !find_in_set('PLATFORM',ms.provider_type_),
        now(), ms.first_pass_audit_time_),
        ms.charge_type_ = #{item.paymentType},
        ms.music_price_ = #{item.musicPrice},ms.top_flag_ = #{item.topFlag},
        ms.exquisite_flag_ = #{item.exquisiteFlag},ms.sort_number_ = #{item.sortNo},ms.del_flag_ = 0,
        ms.audit_status_ = 'PASS',
        ms.score_type_ = #{item.scoreType},
        ms.state_ = #{item.status},
        ms.client_state_ = #{item.clientStatus},
        ms.notation_ = #{item.isConvertibleScore},
        ms.provider_type_ = CASE WHEN ms.provider_type_ is null or ms.provider_type_ = '' THEN 'PLATFORM'
                            when find_in_set('PLATFORM',ms.provider_type_) then ms.provider_type_
                            else concat(ms.provider_type_,',','PLATFORM') end
        <if test="item.musicSheetUpdate != null">
            ,ms.music_sheet_name_ = #{item.musicSheetUpdate.name}
            ,ms.platform_state_ = #{item.musicSheetUpdate.platformStatus},
            ms.music_subject_ = #{item.musicSheetUpdate.subjectIds},
            ms.music_svg_ = #{item.musicSheetUpdate.musicSvg},
            ms.composer_ = #{item.musicSheetUpdate.composer},
            ms.accompaniment_type_ = #{item.musicSheetUpdate.audioType},
            ms.play_speed_ = #{item.musicSheetUpdate.playSpeed},
            ms.notation_ = #{item.musicSheetUpdate.notation},
            ms.music_sheet_type_ = #{item.musicSheetUpdate.musicSheetType},
            ms.create_by_ = #{item.musicSheetUpdate.userId},
            ms.audio_type_ = #{item.musicSheetUpdate.playMode},
            ms.show_fingering_ = #{item.musicSheetUpdate.showFingering},
            ms.can_evaluate_ = #{item.musicSheetUpdate.canEvaluate},
            ms.alias_ = #{item.musicSheetUpdate.alias},
            ms.sort_num_ = #{item.musicSheetUpdate.sortNum},
            ms.sort_group_ = #{item.musicSheetUpdate.sortGroup},
            ms.sort_num2_ = #{item.musicSheetUpdate.sortNum2},
            ms.source_type_ = CASE WHEN #{item.musicSheetUpdate.sourceType} = 'PLATFORM' THEN 'PLATFORM'
            WHEN #{item.musicSheetUpdate.sourceType} = 'PERSON' THEN 'TEACHER' ELSE 'TENANT' END
        </if>
        where ms.cbs_music_sheet_id_ = #{item.musicSheetId}
    </update>

    <insert id="tenantInsert">
        insert into music_sheet
        (cbs_music_sheet_id_,tenant_sort_number_,tenant_score_type_,tenant_state_,tenant_notation_,tenant_category_id_,tenant_del_flag_
        ,music_sheet_name_,music_subject_,music_svg_,composer_,accompaniment_type_,play_speed_,
        music_sheet_type_,provider_type_,audio_type_,show_fingering_,
        can_evaluate_,create_by_,user_id_,audit_status_,upload_time_,source_type_
        )
        values
            (#{item.musicSheetId},
        #{item.sortNo},#{item.scoreType},#{item.status},#{item.isConvertibleScore}
        ,#{item.musicSheetUpdate.musicCategoryId}
            ,#{item.delFlag}
            ,#{item.musicSheetUpdate.name},
            #{item.musicSheetUpdate.subjectIds},
            #{item.musicSheetUpdate.musicSvg},
            #{item.musicSheetUpdate.composer},
            #{item.musicSheetUpdate.audioType},
            #{item.musicSheetUpdate.playSpeed},
            #{item.musicSheetUpdate.musicSheetType},
            'TENANT',
            #{item.musicSheetUpdate.playMode},
            #{item.musicSheetUpdate.showFingering},
            #{item.musicSheetUpdate.canEvaluate},
            #{item.musicSheetUpdate.userId},
            #{item.musicSheetUpdate.userId},
            'PASS',

        #{item.musicSheetUpdate.createTime},
        CASE WHEN #{item.musicSheetUpdate.sourceType} = 'PLATFORM' THEN 'PLATFORM'
        WHEN #{item.musicSheetUpdate.sourceType} = 'PERSON' THEN 'TEACHER'
        ELSE 'TENANT' END
            )
    </insert>

    <insert id="platformInsert">
        insert into music_sheet
        (cbs_music_sheet_id_,music_tag_,payment_type_,charge_type_,top_flag_,exquisite_flag_,sort_number_,state_,audit_status_
        ,music_sheet_name_,music_subject_,music_svg_,composer_,accompaniment_type_,play_speed_,
        music_price_,notation_,music_sheet_type_,source_type_,provider_type_,audio_type_,show_fingering_,
        can_evaluate_,create_by_,user_id_,score_type_,platform_state_,client_state_,first_pass_audit_time_
        )
        values
        (#{item.musicSheetId},
        #{item.musicTagIds},#{item.paymentType},#{item.paymentType},
        #{item.topFlag},#{item.exquisiteFlag},#{item.sortNo},0
        ,'PASS'
        ,#{item.musicSheetUpdate.name},
        #{item.musicSheetUpdate.subjectIds},
        #{item.musicSheetUpdate.musicSvg},
        #{item.musicSheetUpdate.composer},
        #{item.musicSheetUpdate.audioType},
        #{item.musicSheetUpdate.playSpeed},
        #{item.musicSheetUpdate.musicPrice},
        #{item.isConvertibleScore},
        #{item.musicSheetUpdate.musicSheetType},
        CASE WHEN #{item.musicSheetUpdate.sourceType} = 'PLATFORM' THEN 'PLATFORM'
        WHEN #{item.musicSheetUpdate.sourceType} = 'PERSON' THEN 'TEACHER'
        ELSE 'TENANT' END,
        'PLATFORM',
        #{item.musicSheetUpdate.playMode},
        #{item.musicSheetUpdate.showFingering},
        #{item.musicSheetUpdate.canEvaluate},
        #{item.musicSheetUpdate.userId},#{item.musicSheetUpdate.userId},
        #{item.scoreType},
        #{item.musicSheetUpdate.platformStatus},
        #{item.clientStatus},
        now()
        )
    </insert>

    <update id="updateState">
        update music_sheet
        set state_ = client_state_ and platform_state_
        where FIND_IN_SET(cbs_music_sheet_id_,#{ids})
    </update>

    <update id="delPractice">
        update sys_music_compare_record
        set hidden_flag_ = 1
        where user_id_ = #{userId} and music_sheet_id_ = #{musicSheetId} and client_id_ = #{clientEnum}
    </update>
    <update id="updateExposureNum">
        update music_sheet
        set exposure_num_ = exposure_num_ + #{exposureNum}
        where id_ = #{musicSheetId}
    </update>

    <select id="musicSheetTotal"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherHomeWrapper$MusicSheetTotal">
        select
        if(t.audit_status_ = 'PASS' and t.state_ = 1,1,0) as musicSheetNum,
        if(t.audit_status_ = 'DOING' ,1,0) musicSheetAuditNum,
        t.exposure_num_ musicSheetExposureNum
        from music_sheet t
        where t.del_flag_=0 and t.user_id_ = #{teacherId}
    </select>

    <select id="musicSheetPage"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherHomeWrapper$MusicSheetTotal">
        select
        t.music_sheet_name_ musicSheetName,
        t.create_time_ createTime,
        t.exposure_num_ musicSheetExposureNum,
        count(distinct t1.buy_user_) musicSheetPayNum,
        sum(t1.trans_amount_) as musicSheetIncome
        from music_sheet t
         left join user_cash_account_record t1 on t.id_ = t1.biz_id_
        where t1.account_id_ =  #{param.teacherId}
        and t1.biz_type_ = 'MUSIC_SHARE'
        and t1.post_status_ = 'RECORDED'
        and t1.in_or_out_ = 'IN'
        and  t.del_flag_=0 and t.user_id_ = #{param.teacherId}
        group by t.id_
        order by t.create_time_ desc
        limit #{param.rows}

    </select>

    <select id="cloudPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.MusicSheetWrapper$MusicSheetCloud">
        select t.id_, t.music_sheet_name_,t.title_img_,t.composer_,t.cbs_music_sheet_id_ ,t.payment_type_,t.music_price_ as musicPrice
        from (
        select a.* from
        music_sheet a
        <if test="param.providerType != null and param.providerType.code == 'TENANT'">
            left join tenant_album_music tam on a.id_ = tam.music_sheet_id_ and tam.del_flag_ = 0 and tam.tenant_album_id_ in
            <foreach collection="param.tenantAlbumIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <where>
            a.cbs_music_sheet_id_ is not null
            <if test="param.providerType != null and param.providerType.code == 'TENANT'">
               and tam.id_ is not null
            </if>
            <if test="param.name != null and param.name != ''">
                and a.music_sheet_name_ like concat('%',#{param.name},'%')
            </if>
            <if test="param.status != null">

                <if test="param.providerType != null">
                    <if test="param.providerType.code == 'TENANT'">
                        and a.tenant_state_ = #{param.status}
                    </if>

                    <if test="param.providerType.code == 'PLATFORM'">
                        and a.state_ = #{param.status}
                    </if>
                </if>

                <if test="param.providerType == null">
                    and a.state_ = #{param.status}
                </if>
            </if>
            <if test="param.delFlag != null">
                <if test="param.providerType != null">
                    <if test="param.providerType.code == 'TENANT'">
                        and a.tenant_del_flag_ = #{param.delFlag}
                    </if>

                    <if test="param.providerType.code == 'PLATFORM'">
                        and a.del_flag_ = #{param.delFlag}
                    </if>
                </if>

                <if test="param.providerType == null">
                    and a.del_flag_ = #{param.delFlag}
                </if>

            </if>
            <if test="param.versionFlag != null">
                and a.audit_version_ = #{param.versionFlag}
            </if>

            <if test="param.mustMatchSubjectIds != null and param.mustMatchSubjectIds.size() != 0">
                and
                <foreach collection="param.mustMatchSubjectIds" separator="and" item="item" open="(" close=")">
                    find_in_set(#{item},a.music_subject_)
                </foreach>
            </if>
            <if test="param.excludeMusicId != null">
                and a.id_ != #{param.excludeMusicId}
            </if>
            <if test="param.ids != null and param.ids.size() != 0">
                and a.id_ in
                <foreach collection="param.ids" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>


            <if test="param.providerType != null and param.providerType.code == 'TENANT'">
                <if test="param.albumId != null">
                    and tam.tenant_album_id_ = #{param.albumId}
                    and tam.subject_type_ in ('ENSEMBLE', 'MUSIC', 'SUBJECT')
                </if>
                <if test="param.albumId == null and param.recentFlag == null and param.favoriteFlag == null">
                    and 1=2
                </if>
            </if>
            <if test="param.providerType != null">
                and find_in_set(#{param.providerType},a.provider_type_)
            </if>
            <if test="param.musicSheetType != null">
                and a.music_sheet_type_ = #{param.musicSheetType}
            </if>
            <if test="param.subjectId != null">
                and (find_in_set(#{param.subjectId},a.music_subject_)or a.music_subject_ is null or a.music_subject_ = '' OR a.is_all_subject_)
            </if>
            <if test="param.musicTagIdList != null and param.musicTagIdList.size() >0">
                and
                <foreach collection="param.musicTagIdList" open="(" close=")" separator="or" item="item">
                    find_in_set(#{item},a.music_tag_)
                </foreach>
            </if>
        </where>
        ) t
        <if test="param.recentFlag != null and param.recentFlag == 1">
            left join sys_music_compare_record msar on t.id_ = msar.music_sheet_id_ and msar.provider_type_ = #{param.providerType}
        </if>
        <if test="param.albumId != null and param.providerType.code == 'TENANT'">
            left join tenant_album_music tam on t.id_ = tam.music_sheet_id_ and tam.del_flag_ = 0  and tam.tenant_album_id_ = #{param.albumId}
        </if>

        <if test="param.albumId != null and param.providerType.code == 'PLATFORM'">
            left join album_music_relate amr on t.id_ = amr.music_sheet_id_ and amr.album_id_ = #{param.albumId}
        </if>
        <if test="param.favoriteFlag != null and param.favoriteFlag == 1">
            left join music_favorite mf on t.id_ = mf.music_sheet_id_ and mf.user_id_ = #{param.userId} and mf.client_type_ = #{param.clientType} and mf.provider_type_ = #{param.providerType}
        </if>
        <where>

            <if test="param.favoriteFlag != null and param.favoriteFlag == 1">
                and mf.id_ is not null
            </if>

            <if test="param.recentFlag != null and param.recentFlag == 1">
                <if test="param.userId != null">
                    and msar.user_id_ = #{param.userId}
                </if>
                <if test="param.clientType != null and param.clientType != ''">
                    and msar.client_id_ = #{param.clientType}
                </if>
            </if>

            <if test="param.providerType != null and param.providerType.code == 'PLATFORM'">
                <if test="param.albumId != null">
                    and amr.id_ is not null
                </if>

            </if>

        </where>

        GROUP BY t.id_
        order by
        <if test="param.recentFlag !=null and param.recentFlag == true">
            max(msar.create_time_) desc,
        </if>
        <if test="param.favoriteFlag != null and param.favoriteFlag == 1">
            mf.id_ desc,
        </if>

        t.sort_group_, t.sort_num_, t.sort_num2_, t.alias_
    </select>

    <select id="musicSheetTotal"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherHomeWrapper$MusicSheetTotal">
        select
        if(t.audit_status_ = 'PASS' and t.state_ = 1,1,0) as musicSheetNum,
        if(t.audit_status_ = 'DOING' ,1,0) musicSheetAuditNum,
        t.exposure_num_ musicSheetExposureNum
        from music_sheet t
        where t.del_flag_=0 and t.user_id_ = #{teacherId}
    </select>

    <select id="musicSheetPage"
            resultType="com.yonge.cooleshow.biz.dal.wrapper.teacher.TeacherHomeWrapper$MusicSheetTotal">
        select
        t.music_sheet_name_ musicSheetName,
        t.create_time_ createTime,
        t.exposure_num_ musicSheetExposureNum,
        count(distinct t1.buy_user_) musicSheetPayNum,
        sum(t1.trans_amount_) as musicSheetIncome
        from music_sheet t
         left join user_cash_account_record t1 on t.id_ = t1.biz_id_
        where t1.account_id_ =  #{param.teacherId}
        and t1.biz_type_ = 'MUSIC_SHARE'
        and t1.post_status_ = 'RECORDED'
        and t1.in_or_out_ = 'IN'
        and  t.del_flag_=0 and t.user_id_ = #{param.teacherId}
        group by t.id_
        order by t.create_time_ desc
        limit #{param.rows}

    </select>
    <select id="selectMusicAlbumNum" resultType="java.lang.Long">
        SELECT COUNT(DISTINCT t1.id_) AS total
        FROM album_music_relate t1 JOIN music_sheet t2 ON (t1.music_sheet_id_ = t2.id_)
        WHERE t1.music_sheet_id_ = #{musicId}
    </select>
    <!--单曲专辑数量统计-->
</mapper>