<?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.SysMusicCompareRecordDao">

	<resultMap type="com.yonge.cooleshow.biz.dal.entity.SysMusicCompareRecord" id="SysMusicCompareRecord">
		<result column="id_" property="id" />
		<result column="user_id_" property="userId" />
		<result column="music_sheet_id_" property="musicSheetId" />
		<result column="heard_level_" property="heardLevel" typeHandler="com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler" />
		<result column="sys_music_score_name_" property="sysMusicScoreName" />
		<result column="behavior_id_" property="behaviorId"/>
		<result column="score_data_" property="scoreData" />
		<result column="notes_data_index_" property="notesDataIndex"/>
		<result column="score_" property="score" />
		<result column="intonation_" property="intonation" />
		<result column="cadence_" property="cadence" />
		<result column="integrity_" property="integrity" />
		<result column="record_file_path_" property="recordFilePath" />
		<result column="video_file_path_" property="videoFilePath" />
		<result column="device_type_" property="deviceType" typeHandler="com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler" />
		<result column="client_id_" property="clientId" />
		<result column="source_time_" property="sourceTime"/>
		<result column="play_time_" property="playTime"/>
		<result column="speed_" property="speed"/>
		<result column="feature_" property="feature" typeHandler="com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler" />
		<result column="monday_" property="monday"/>
		<result column="create_time_" property="createTime" />
		<result column="part_index_" property="partIndex" />
		<result column="custom_configuration_" property="customConfiguration" />
		<result column="tenant_id_" property="tenantId" />
	</resultMap>

	<!-- 根据主键查询一条记录 -->
	<select id="get" resultMap="SysMusicCompareRecord" >
		SELECT * FROM sys_music_compare_record WHERE id_ = #{id}
	</select>

	<!-- 全查询 -->
	<select id="findAll" resultMap="SysMusicCompareRecord">
		SELECT * FROM sys_music_compare_record where tenant_id_ = #{tenantId} ORDER BY id_
	</select>

	<!-- 向数据库增加一条记录 -->
	<insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.SysMusicCompareRecord" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
		INSERT INTO sys_music_compare_record (id_,user_id_,music_sheet_id_,heard_level_,behavior_id_,score_data_,score_,intonation_,cadence_,integrity_,
		                                      record_file_path_,video_file_path_,device_type_,client_id_,play_time_,speed_,monday_,
												source_time_,feature_,create_time_,update_time_,part_index_,custom_configuration_,tenant_id_)
		VALUES(#{id},#{userId},#{musicSheetId},#{heardLevel,typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler},#{behaviorId},#{scoreData},
		       #{score},#{intonation},#{cadence},#{integrity},
		       #{recordFilePath},#{videoFilePath},#{deviceType,typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler},#{clientId},#{playTime},#{speed},#{monday},
		       #{sourceTime},#{feature,typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler}, NOW(), NOW(),#{partIndex},#{customConfiguration},#{tenantId})
	</insert>

	<!-- 根据主键查询一条记录 -->
	<update id="update" parameterType="com.yonge.cooleshow.biz.dal.entity.SysMusicCompareRecord">
		UPDATE sys_music_compare_record <set>
		<if test="userId != null">
			user_id_ = #{userId},
		</if>
		<if test="musicSheetId != null">
			music_sheet_id_ = #{musicSheetId},
		</if>
		<if test="behaviorId!=null">
			behavior_id_ = #{behaviorId},
		</if>
		<if test="scoreData != null">
			score_data_ = #{scoreData},
		</if>
		<if test="score != null">
			score_ = #{score},
		</if>
		<if test="intonation!=null">
			intonation_ = #{intonation},
		</if>
		<if test="integrity != null">
			integrity_ = #{integrity},
		</if>
		<if test="cadence != null">
			cadence_ = #{cadence},
		</if>
		<if test="recordFilePath != null">
			record_file_path_ = #{recordFilePath},
		</if>
		<if test="videoFilePath != null">
			video_file_path_ = #{videoFilePath},
		</if>
		<if test="clientId != null">
			client_id_ = #{clientId},
		</if>
		<if test="deviceType!=null">
			device_type_ = #{deviceType, typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler},
		</if>
		<if test="sourceTime != null">
			source_time_ = #{sourceTime},
		</if>
		<if test="playTime != null">
			play_time_ = #{playTime},
		</if>
		<if test="speed != null">
			speed_ = #{speed},
		</if>
		<if test="monday != null">
			monday_ = #{monday},
		</if>
		<if test="partIndex != null">
			part_index_ = #{partIndex},
		</if>
		<if test="customConfiguration != null">
			custom_configuration_ = #{customConfiguration},
		</if>
		<if test="feature!=null">
			feature_ = #{feature,typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler},
		</if>
		<if test="heardLevel!=null">
			heard_level_ = #{heardLevel,typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler},
		</if>
		update_time_ = NOW()
	</set> WHERE id_ = #{id} 
	</update>

	<!-- 根据主键删除一条记录 -->
	<delete id="delete" >
		DELETE FROM sys_music_compare_record WHERE id_ = #{id}
	</delete>

	<sql id="queryCondition">
		<where>
			smcr.score_data_ is not null and smcr.score_data_ != ''
			<if test="clientId != null and clientId != ''">
				and smcr.client_id_ = #{clientId}
			</if>
			<if test="userId!=null">
				AND smcr.user_id_=#{userId}
			</if>
			<if test="featureType != null">
				AND smcr.feature_ = #{featureType,typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler}
			</if>
			<if test="startTime != null and startTime != ''">
				AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') >= #{startTime}
			</if>
			<if test="endTime != null and endTime != ''">
				AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') &lt;= #{endTime}
			</if>
		</where>
	</sql>

	<!-- 分页查询 -->
	<select id="queryPage" resultMap="SysMusicCompareRecord" parameterType="map">
		SELECT
			smcr.id_, smcr.user_id_, smcr.music_sheet_id_, smcr.heard_level_,
			LOCATE('musicalNotesPlayStats', smcr.score_data_) notes_data_index_,
		       smcr.score_, smcr.intonation_, smcr.cadence_,
		       smcr.integrity_, smcr.record_file_path_, smcr.video_file_path_, smcr.client_id_, smcr.device_type_, smcr.play_time_,
		       smcr.monday_, smcr.create_time_,
			sms.music_sheet_name_ sys_music_score_name_,if(smcr.create_time_ is not null and date_add(smcr.create_time_,INTERVAL #{expireTime} DAY) &lt; now(),1,0) as expire,
			smcr.custom_configuration_ as customConfiguration
		FROM sys_music_compare_record smcr
		LEFT JOIN music_sheet sms on smcr.music_sheet_id_ = sms.id_
		<include refid="queryCondition"/>
		ORDER BY id_ DESC
		<include refid="global.limit"/>
	</select>

	<!-- 查询当前表的总记录数 -->
	<select id="queryCount" resultType="int">
		SELECT COUNT(*) FROM sys_music_compare_record smcr
		<include refid="queryCondition"/>
	</select>


	<select id="getUserTrainOverView" resultType="com.yonge.cooleshow.biz.dal.dto.StudentTrainOverviewDto">
		SELECT
			COUNT(DISTINCT smcr.behavior_id_) trainNum,
			COUNT(DISTINCT DATE(smcr.create_time_)) trainDays,
			SUM(smcr.play_time_) trainTime
		FROM sys_music_compare_record smcr
		WHERE smcr.user_id_=#{userId} and smcr.client_id_ = #{clientId}
	</select>

	<select id="getUserTrainChartData" resultType="com.yonge.cooleshow.biz.dal.dto.StudentTrainChartDto">
		SELECT
			DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') trainDate,
			COUNT(DISTINCT smcr.behavior_id_) trainNum,
			SUM(smcr.play_time_) trainTime
		FROM sys_music_compare_record smcr
		WHERE smcr.user_id_=#{userId}  and smcr.client_id_ = #{clientId}
		  AND DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') BETWEEN #{startTime} AND #{endTime}
		GROUP BY DATE_FORMAT(smcr.create_time_, '%Y-%m-%d')
		ORDER BY trainDate;
	</select>

	<sql id="queryMusicGroupStudentTrainDataConditon">
		<where>
			sr.music_group_status_='NORMAL' AND stu.user_id_ IS NOT NULL
			<if test="startTime!=null and endTime!=null">
				AND DATE_FORMAT( smcr.create_time_, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
			</if>
			<if test="musicGroupId!=null">
				AND sr.music_group_id_ = #{musicGroupId}
			</if>
			<if test="search!=null">
				AND (su.username_ LIKE CONCAT('%', #{search}, '%'))
			</if>
		</where>
	</sql>

	<select id="countMusicGroupStudentTrainData" resultType="int">
		SELECT
			COUNT(DISTINCT smcr.user_id_)
		FROM
			sys_music_compare_record smcr
		LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
		LEFT JOIN student stu ON stu.user_id_ = smcr.user_id_
		LEFT JOIN student_registration sr ON sr.user_id_=smcr.user_id_
		<include refid="queryMusicGroupStudentTrainDataConditon"/>
	</select>

	<select id="getOrganNewCloudStudyNum" resultType="int">
		SELECT
			COUNT( DISTINCT user_id_ )
		FROM
			(
				SELECT
					smcr.user_id_
				FROM
					sys_music_compare_record smcr
						LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
				WHERE
					su.del_flag_ = 0
					AND su.organ_id_ = #{organId}
				GROUP BY
					user_id_
				HAVING
						COUNT(
								DISTINCT DATE( smcr.create_time_ ))= 1
				   AND MAX(
							   DATE( smcr.create_time_ ))= CURDATE()) t
	</select>

	<select id="getOrgansTotalNewCloudStudyNum" resultType="int">
		SELECT
			COUNT( DISTINCT user_id_ )
		FROM
			(
				SELECT
					smcr.user_id_
				FROM
					sys_music_compare_record smcr
						LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
				WHERE
					su.del_flag_ = 0
					<if test="organIds!=null and organIds.size()>0">
						AND su.organ_id_ IN
						<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
							#{organId}
						</foreach>
					</if>
				GROUP BY
					user_id_
				HAVING
						COUNT(DISTINCT DATE( smcr.create_time_ ))= 1
				   AND MAX(DATE( smcr.create_time_ ))= CURDATE()) t
	</select>

	<select id="getOrgansNewCloudStudyNum" resultType="map">
		SELECT
			organ_id_ 'key',
			COUNT( DISTINCT user_id_ ) 'value'
		FROM
			(
				SELECT
					su.organ_id_,
					smcr.user_id_
				FROM
					sys_music_compare_record smcr
						LEFT JOIN sys_user su ON smcr.user_id_ = su.id_
				WHERE
					su.del_flag_ = 0
					<if test="organIds!=null and organIds.size()>0">
						AND su.organ_id_ IN
						<foreach collection="organIds" item="organId" open="(" close=")" separator=",">
							#{organId}
						</foreach>
					</if>
				GROUP BY
					user_id_
				HAVING
						COUNT(
								DISTINCT DATE( smcr.create_time_ ))= 1
				   AND MAX(
							   DATE( smcr.create_time_ ))= CURDATE()) t
		GROUP BY t.organ_id_
	</select>

    <select id="getUserLastEvaluationData" resultMap="SysMusicCompareRecord">
		SELECT * FROM sys_music_compare_record WHERE user_id_=#{userId} AND feature_ = 'CLOUD_STUDY_EVALUATION' and  client_id_ = 'student' ORDER BY create_time_ DESC LIMIT 1
	</select>

	<select id="getUserWeekMaxMusicScoreId" resultType="java.lang.Integer">
		SELECT music_sheet_id_ FROM sys_music_compare_record
		WHERE user_id_=#{userId} AND monday_ = #{monday} AND heard_level_ = #{heardLevel, typeHandler=com.yonge.toolset.mybatis.dal.CustomEnumTypeHandler}
		ORDER BY score_ DESC LIMIT 1
	</select>

	<!--曲目练习统计-->
	<select id="selectMusicCompareRecordStatInfo"
			resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
		SELECT
			<choose>
				<when test="record.musicSheetId != null">t1.music_sheet_id_ AS id,</when>
				<otherwise>t1.user_id_ AS id,</otherwise>
			</choose>
		    SUM(t1.play_time_) AS number
			<choose>
				<when test="record.feature.code == 'CLOUD_STUDY_TRAIN'">, COUNT(DISTINCT t1.behavior_id_) AS total</when>
				<otherwise>, COUNT(t1.id_) AS total</otherwise>
			</choose>
		FROM sys_music_compare_record t1
		<where>
			<if test="record.musicSheetId != null">
				AND t1.music_sheet_id_ = #{record.musicSheetId}
			</if>
			<if test="record.userId != null">
				AND t1.user_id_ = #{record.userId}
			</if>
			<if test="record.clientId != null">
				AND t1.client_id_ = #{record.clientId}
			</if>
			<if test="record.feature != null">
				AND t1.feature_ = #{record.feature}
			</if>
			<if test="record.scoreData != null">
				AND t1.score_data_ != ''
			</if>
		</where>
		<choose>
			<when test="record.musicSheetId != null"> GROUP BY t1.music_sheet_id_ <if test="record.userId != null">, t1.user_id_</if> </when>
			<otherwise>GROUP BY t1.user_id_</otherwise>
		</choose>

	</select>
    <select id="queryWeChatStudentTrainData"
            resultType="com.yonge.cooleshow.biz.dal.queryInfo.SysMusicCompareRecordQueryInfo$WechatCompareRecordPageDto">
		select st.user_id_                                                 userId,
		su.avatar_                                             avatar,
		su.username_                                           username,
		GROUP_CONCAT(DISTINCT sb.name_)                        subjectName,
		SUM(mprs.playTime) / 60                                trainTimes,
		COUNT(DISTINCT mprs.create_time_)                      trainDays,
		SUM(mprs.playTime) / 60 / COUNT(DISTINCT mprs.create_time_) avgTrainTimes
		from student st
		left join
		(select smcr.user_id_,
		DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') create_time_,
		SUM(smcr.play_time_)                       playTime
		from sys_music_compare_record smcr
		<where>
			<if test="startTime != null and startTime != ''">
				AND smcr.create_time_ BETWEEN #{startTime} AND #{endTime}
			</if>
			<if test="tenantId != null">
				AND smcr.tenant_id_ = #{tenantId}
			</if>
			<if test="clientId != null and clientId!= ''">
				AND smcr.client_id_ = #{clientId}
			</if>
		</where>
		group by smcr.user_id_, DATE_FORMAT(create_time_, '%Y-%m-%d')) mprs ON mprs.user_id_ = st.user_id_
		left join sys_user su ON st.user_id_ = su.id_
		left join subject sb ON sb.id_ = st.subject_id_
		where mprs.user_id_ = st.user_id_
		<if test="search != null and search != ''">
			AND su.username_ LIKE CONCAT('%',#{search},'%')
		</if>
		<if test="tenantId != null">
			AND st.tenant_id_ = #{tenantId}
		</if>
		group by st.user_id_
		<trim prefix="HAVING" suffixOverrides="AND" >
			<if test="minTrainTimes != null">
				trainTimes &gt;= #{minTrainTimes} AND
			</if>
			<if test="maxTrainTimes != null">
				trainTimes &lt;= #{maxTrainTimes} AND
			</if>
			<if test="minTrainDays != null">
				trainDays &gt;= #{minTrainDays} AND
			</if>
			<if test="maxTrainDays != null">
				trainDays &lt;= #{maxTrainDays} AND
			</if>
			<if test="minAvgTrainTimes != null">
				avgTrainTimes &gt;= #{minAvgTrainTimes} AND
			</if>
			<if test="maxAvgTrainTimes != null">
				avgTrainTimes &lt;= #{maxAvgTrainTimes} AND
			</if>
		</trim>
		ORDER BY ${sortField} ${sortType}
		<include refid="global.limit"/>
	</select>
	<select id="countWeChatStudentTrainData" resultType="java.lang.Integer">
		select COUNT(c.userId) from
		(
		select st.user_id_                                                 userId,
		su.avatar_                                             avatar,
		su.username_                                           username,
		GROUP_CONCAT(DISTINCT sb.name_)                        subjectName,
		SUM(mprs.playTime) / 60                                trainTimes,
		COUNT(DISTINCT mprs.create_time_)                      trainDays,
		SUM(mprs.playTime) / 60 / COUNT(DISTINCT mprs.create_time_) avgTrainTimes
		from student st
		left join
		(select smcr.user_id_,
		DATE_FORMAT(smcr.create_time_, '%Y-%m-%d') create_time_,
		SUM(smcr.play_time_)                       playTime
		from sys_music_compare_record smcr
		<where>
			<if test="startTime != null and startTime != ''">
				AND smcr.create_time_ BETWEEN #{startTime} AND #{endTime}
			</if>
			<if test="tenantId != null">
				AND smcr.tenant_id_ = #{tenantId}
			</if>
			<if test="clientId != null and clientId!= ''">
				AND smcr.client_id_ = #{clientId}
			</if>
		</where>
		group by smcr.user_id_, DATE_FORMAT(create_time_, '%Y-%m-%d')) mprs ON mprs.user_id_ = st.user_id_
		left join sys_user su ON st.user_id_ = su.id_
		left join subject sb ON sb.id_ = st.subject_id_
		where mprs.user_id_ = st.user_id_
		<if test="search != null and search != ''">
			AND su.username_ LIKE CONCAT('%',#{search},'%')
		</if>
		<if test="tenantId != null">
			AND st.tenant_id_ = #{tenantId}
		</if>
		group by st.user_id_
		<trim prefix="HAVING" suffixOverrides="AND" >
			<if test="minTrainTimes != null">
				trainTimes &gt;= #{minTrainTimes} AND
			</if>
			<if test="maxTrainTimes != null">
				trainTimes &lt;= #{maxTrainTimes} AND
			</if>
			<if test="minTrainDays != null">
				trainDays &gt;= #{minTrainDays} AND
			</if>
			<if test="maxTrainDays != null">
				trainDays &lt;= #{maxTrainDays} AND
			</if>
			<if test="minAvgTrainTimes != null">
				avgTrainTimes &gt;= #{minAvgTrainTimes} AND
			</if>
			<if test="maxAvgTrainTimes != null">
				avgTrainTimes &lt;= #{maxAvgTrainTimes} AND
			</if>
		</trim>
		)c
	</select>
	<select id="wechatCompareRecordSum"
			resultType="com.yonge.cooleshow.biz.dal.queryInfo.SysMusicCompareRecordQueryInfo$WechatCompareRecordSumDto">
		select COUNT(DISTINCT st.user_id_) studentNum,COUNT(DISTINCT DATE_FORMAT(smcr.create_time_,'%Y-%m-%d'),smcr.user_id_) trainDays,SUM(smcr.play_time_) / 60 trainTimes
		from student st
		LEFT JOIN sys_music_compare_record smcr ON smcr.user_id_ = st.user_id_
		<where>
			<if test="queryInfo.clientId != null and queryInfo.clientId!= ''">
				AND smcr.client_id_ = #{queryInfo.clientId}
			</if>
			<if test="queryInfo.startTime != null and queryInfo.startTime != ''">
				AND smcr.create_time_ BETWEEN #{queryInfo.startTime} AND #{queryInfo.endTime}
			</if>
			<if test="queryInfo.tenantId != null">
				AND smcr.tenant_id_ = #{queryInfo.tenantId}
			</if>
			<if test="queryInfo.tenantId != null">
				AND st.tenant_id_ = #{queryInfo.tenantId}
			</if>
		</where>
	</select>
    <select id="queryStudentTrain"
            resultType="com.yonge.cooleshow.biz.dal.queryInfo.SysMusicCompareRecordQueryInfo$StudentMusicCompareRecord">
		select
			ms.music_sheet_name_ as musicSheetName,
			smcr.id_ as id,
			smcr.user_id_ as userId,
			smcr.score_data_ as scoreData,
			smcr.score_ as score,
			smcr.intonation_ as intonation,
			smcr.cadence_ as cadence,
			smcr.integrity_ as integrity,
			smcr.record_file_path_ as recordFilePath,
			smcr.video_file_path_ as videoFilePath,
			smcr.heard_level_ as heardLevel,
			smcr.create_time_ as createTime
		from sys_music_compare_record smcr
		left join music_sheet ms ON ms.id_ = smcr.music_sheet_id_
		where smcr.user_id_ = #{userId} and DATE_FORMAT(smcr.create_time_,'%Y-%m') = #{month} AND smcr.score IS NOT NULL
		<if test="tenantId != null">
			AND smcr.tenant_id_ = #{tenantId}
		</if>
		order by smcr.id_ DESC
	</select>
	<select id="countStudentTrain" resultType="java.lang.Integer">
		select COUNT(smcr.id_)
		from sys_music_compare_record smcr
		where smcr.user_id_ = #{userId} and DATE_FORMAT(smcr.create_time_,'%Y-%m') = #{month}
		AND smcr.score IS NOT NULL
		<if test="tenantId != null">
			AND smcr.tenant_id_ = #{tenantId}
		</if>
	</select>
	<select id="studentMusicCompareRecordStat"
			resultType="com.yonge.cooleshow.biz.dal.queryInfo.SysMusicCompareRecordQueryInfo$StudentMusicCompareRecordStat">
		select smcr.user_id_ userId,su.avatar_ avatar,su.username_ username,SUM(smcr.play_time_) trainTime,
		       COUNT(DISTINCT DATE_FORMAT(smcr.create_time_,'%Y-%m-%d')) trainDays
		from sys_music_compare_record smcr
		left join sys_user su ON su.id_ = smcr.user_id_
		where smcr.user_id_ = #{query.userId} and DATE_FORMAT(smcr.create_time_,'%Y-%m') = #{query.month}
		<if test="query.tenantId != null">
			AND smcr.tenant_id_ = #{query.tenantId}
		</if>
		group by smcr.user_id_
	</select>
	<select id="studentTrainStat"
			resultType="com.yonge.cooleshow.biz.dal.queryInfo.SysMusicCompareRecordQueryInfo$StudentMusicCompareRecordDto">
		select SUM(smcr.play_time_) trainTime,COUNT(DISTINCT DATE_FORMAT(smcr.create_time_,'%Y-%m-%d')) trainDays,COUNT(smcr.id_) trainNum
		from sys_music_compare_record smcr
		where smcr.user_id_ = #{query.userId} and DATE_FORMAT(smcr.create_time_,'%Y-%m') = #{query.month}
		<if test="query.tenantId != null">
			AND smcr.tenant_id_ = #{query.tenantId}
		</if>
		group by smcr.user_id_
	</select>
    <select id="getUserWeekCompareData"
            resultType="com.yonge.cooleshow.biz.dal.entity.SysMusicCompareWeekData">
		SELECT
			COUNT(smcr.id_) trainNum,
			COUNT(DISTINCT DATE(smcr.create_time_)) trainDays,
			SUM(smcr.play_time_) trainTime,
			MAX(IF(heard_level_='BEGINNER' AND source_time_ &gt;= play_time_, smcr.score_, 0)) beginnerMaxScore,
			MAX(IF(heard_level_='ADVANCED' AND source_time_ &gt;= play_time_, smcr.score_, 0)) advancedMaxScore,
			MAX(IF(heard_level_='PERFORMER' AND source_time_ &gt;= play_time_, smcr.score_, 0)) performerMaxScore,smcr.tenant_id_ tenantId
		FROM sys_music_compare_record smcr
		WHERE user_id_=#{userId} AND monday_ = #{monday}
	</select>

	<select id="selectByIds" resultMap="SysMusicCompareRecord">
        select * from sys_music_compare_record where id_ in
        <foreach collection="musicPracticeRecordIds" item="musicPracticeRecordId" open="(" close=")" separator=",">
            #{musicPracticeRecordId}
        </foreach>
    </select>
    <!--曲目练习统计-->

</mapper>
