<?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.MusicSheetAuthRecordDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.MusicSheetAuthRecord">
            <result column="id_" property="id" />
	        <result column="music_sheet_id_" property="musicSheetId" />
	        <result column="audit_state_" property="auditState" />
	        <result column="verify_user_id_" property="verifyUserId" />
	        <result column="reason_" property="reason" />
	        <result column="music_sheet_json_" property="musicSheetJson" />
	        <result column="batch_no_" property="batchNo" />
	        <result column="create_time_" property="createTime" />
	        <result column="update_time_" property="updateTime" />
		</resultMap>  
    
    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_
        , t.music_sheet_id_
        , t.audit_state_
        , t.verify_user_id_
        , t.reason_
        , t.create_time_
        , t.update_time_
        , t.music_sheet_json_
        </sql>
    <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
        ,msar.batch_no_ as batchNo
        ,msar.id_ as id
        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>
            su.del_flag_ = 0 AND
            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}
            </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>


</mapper>