<?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.xxfc.platform.activity.mapper.ActivityWinningRecordMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.activity.entity.ActivityWinningRecord" id="activityWinningRecordMap">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="activityId" column="activity_id"/>
        <result property="prizeType" column="prize_type"/>
        <result property="prizeName" column="prize_name"/>
        <result property="iconPath" column="icon_path"/>
        <result property="hasWinning" column="has_winning"/>
        <result property="expiryDateCode" column="expiry_date_code"/>
        <result property="crtTime" column="crt_time"/>
        <result property="lotteryTime" column="lottery_time"/>
        <result property="goodsId" column="goods_id"/>
    </resultMap>

    <select id="selectActivityWinningRecord" resultType="com.xxfc.platform.activity.dto.ActivityWinningRecordPageDTO">
        select aar.user_id as `userId`,aar.user_name as `userName`, aar.phone as `phone`,aar.position_name as `positionName`,awr.* from `activity_winning_record` as `awr`
        left join `activity_attendance_record` as `aar` ON aar.user_id=awr.user_id and aar.activity_id=awr.activity_id
        where 1=1
        <if test="activityId!=null">
            and awr.`activity_id`=#{activityId}
        </if>
        <if test="hasWinning!=null">
            and awr.`has_winning`=#{hasWinning}
        </if>
        <if test="phone!=null and phone!=''">
            and aar.`phone`=#{phone}
        </if>
        <if test="prizeType!=null">
            and awr.`prize_type`=#{prizeType}
        </if>
        <if test="startTime!=null and endTime!=null">
            and awr.`lottery_time` between #{startTime} and #{endTime}
        </if>
        <if test="startTime!=null and endTime==null">
            and <![CDATA[
           awr.`lottery_time` >=#{startTime}
          ]]>
        </if>
        <if test="startTime==null and endTime!=null">
            and <![CDATA[
           awr.`lottery_time` <=#{endTime}
          ]]>
        </if>
        order by awr.`lottery_time` desc
    </select>

</mapper>