package com.hai.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * mapper扩展类
 */
public interface HighActivityAwardUserMapperExt {

    @Select(" select insert(b.phone, 4, 4, '****') phone,a.name awardName,a.create_time receiveTime from " +
            " (select a.create_time, b.name,a.user_id " +
            " from high_activity_award_user a,high_activity_award b " +
            " where a.activity_award_id = b.id and a.activity_info_id = #{activityId} " +
            " ORDER BY a.create_time desc LIMIT 50) a" +
            " LEFT JOIN high_user b on b.id = a.user_id")
    List<Map<String, Object>> selectWinLotteryList(@Param("activityId") Long activityId);



    /**
     * 查询活动中奖的用户
     * @param activityId
     * @param param
     * @return
     */
    @Select("<script>" +
            " select " +
            " b.phone userPhone," +
            " b.`name` userName," +
            " a.`name` awardName," +
            " a.create_time winLotteryTime " +
            " from " +
            " (select a.user_id,b.name,a.create_time from high_activity_award_user a,high_activity_award b" +
            " where " +
            " a.activity_award_id = b.id " +
            " and b.activity_info_id = #{activityId}" +
            " <if test='param.awardName != null'> and b.`name` LIKE concat('%',#{param.awardName},'%') </if>" +
            " GROUP BY a.id" +
            " ORDER BY a.create_time desc) a" +
            " LEFT JOIN high_user b on a.user_id  = b.id" +
            " where 1 = 1" +
            " <if test='param.userPhone != null'> and b.phone = #{param.userPhone} </if>" +
            "</script>")
    List<Map<String, Object>> selectWinLotteryUserList(@Param("activityId") Long activityId, @Param("param") Map<String, Object> param);

}
