<?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.ActivityPlanEvaluationDao">
	<resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ActivityPlanEvaluation">
            <result column="id_" property="id" />
	        <result column="evaluation_difficulty_" property="evaluationDifficulty" />
	        <result column="create_time_" property="createTime" />
	        <result column="create_by_" property="createBy" />
	        <result column="update_time_" property="updateTime" />
	        <result column="update_by_" property="updateBy" />
		</resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
         t.id_ as id
        , t.evaluation_difficulty_ as evaluationDifficulty
        , t.create_time_ as createTime
        , t.create_by_ as createBy
        , t.update_time_ as updateTime
        , t.update_by_ as updateBy
        </sql>

    <select id="getUserReward" resultType="com.yonge.cooleshow.biz.dal.entity.ActivityUserReward">
            select
                a.activity_id_ as activityId,
                a.evaluation_id_ as bizId,
                a.user_id_ as userId,
                c.reward_id_ as rewardId
            from (
                
                select * from 
		    	(
				select aer.id_,aer.evaluation_id_,aer.score_ ,aer.user_id_ ,aer.activity_id_,aer.times_
				from activity_evaluation_record aer 
				where aer.activity_id_ = #{activityPlanId}  and aer.score_ > 0
				order by aer.score_ desc,aer.times_ asc, aer.id_ asc limit 1000000
				) a group by evaluation_id_ order by score_ desc,times_ asc,id_ asc
            ) a
            left join activity_plan_reward c on a.activity_id_ = c.activity_id_
            
    </select>
</mapper>