<?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="org.springblade.modules.activities.mapper.PrizeRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="prizeRecordResultMap" type="org.springblade.modules.activities.entity.PrizeRecord">
        <result column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="create_user_id" property="createUserId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user_id" property="updateUserId"/>
        <result column="update_time" property="updateTime"/>
        <result column="prize_id" property="prizeId"/>
        <result column="user_id" property="userId"/>
        <result column="draw_time" property="drawTime"/>
        <result column="is_hit" property="isHit"/>
    </resultMap>


    <select id="selectPrizeRecordPage" resultMap="prizeRecordResultMap">
        select * from biz_prize_record where is_delete = 0
    </select>
    <select id="winningRecord" resultType="org.springblade.modules.activities.vo.PrizeRecordVO">
        SELECT
            pr.*,
            p.prize_image prizeImage,
            p.prize_type prizeType,
            p.prize_name,
            u.`name` userName
        FROM
            biz_prize_record pr
            JOIN biz_prize p ON pr.prize_id = p.id
            JOIN blade_user u on pr.user_id  = u.id
        WHERE 1 = 1
            and p.prize_type != 4
            <if test="userId != null">
                and pr.user_id = #{userId}
            </if>
        ORDER BY pr.draw_time desc
    </select>

</mapper>
