<?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.qs.mp.user.mapper.UserHitPrizeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.user.domain.UserHitPrize">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="order_id" property="orderId" />
        <result column="order_item_id" property="orderItemId" />
        <result column="ticket_id" property="ticketId" />
        <result column="awards_id" property="awardsId" />
        <result column="prize_id" property="prizeId" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, order_id, order_item_id, ticket_id, awards_id, prize_id, created_time, updated_time
    </sql>

    <select id="selectTicketHitPrizeBarrageNotByUserId"
            resultType="com.qs.mp.user.domain.vo.TicketHitPrizeBarrageVO">
        SELECT su.nick_name nickName,
                su.avatar avatar,
                mtap.title prizeInfo,
                mtap.value value,
                mtap.prize_type prizeType,
                muhp.created_time

        FROM mp_user_hit_prize muhp
         LEFT JOIN mp_ticket_awards_prize mtap ON muhp.prize_id = mtap.prize_id
         LEFT JOIN sys_user su ON muhp.user_id = su.user_id
        WHERE muhp.prize_id != ''
        AND muhp.user_id != #{userId}
        AND ((mtap.prize_type = 'coin' AND mtap.value >= 100) OR mtap.prize_type='goods')
        ORDER BY muhp.created_time DESC
        LIMIT 40
    </select>

    <select id="selectTicketHitPrizeBarrageByUserId" resultType="com.qs.mp.user.domain.vo.TicketHitPrizeBarrageVO">
        SELECT su.nick_name nickName,
                su.avatar avatar,
                mtap.title prizeInfo,
                mtap.value value,
                mtap.prize_type prizeType,
                muhp.created_time

        FROM mp_user_hit_prize muhp
                 LEFT JOIN mp_ticket_awards_prize mtap ON muhp.prize_id = mtap.prize_id
                 LEFT JOIN sys_user su ON muhp.user_id = su.user_id
        WHERE muhp.prize_id != ''
          AND muhp.user_id = #{userId}
          AND muhp.created_time BETWEEN	#{startTime} AND #{endTime}
        ORDER BY muhp.created_time DESC
        LIMIT 2
    </select>

    <select id="selectTicketExpensiveHitPrizeBarrageNotByUserId"
            resultType="com.qs.mp.user.domain.vo.TicketHitPrizeBarrageVO">
        SELECT su.nick_name nickName,
                su.avatar avatar,
                mtap.title prizeInfo,
                mtap.value value,
                mtap.prize_type prizeType,
                muhp.created_time
        FROM mp_user_hit_prize muhp
                 LEFT JOIN mp_ticket_awards_prize mtap ON muhp.prize_id = mtap.prize_id
                 LEFT JOIN sys_user su ON muhp.user_id = su.user_id
        WHERE muhp.prize_id != ''
          AND muhp.user_id != #{userId}
          AND mtap.prize_type='goods'
          AND muhp.created_time BETWEEN #{startTime} AND #{endTime}
        ORDER BY mtap.`value` DESC
        LIMIT 8
    </select>
</mapper>