<?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.hzs.activity.draw.mapper.AcDrawRewardRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="AcDrawRewardRecord" type="com.hzs.common.domain.activity.draw.ext.AcDrawRewardRecordExt">
        <id column="PK_ID" property="pkId"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="PK_CREATOR" property="pkCreator"/>
        <result column="MODIFIED_TIME" property="modifiedTime"/>
        <result column="PK_MODIFIED" property="pkModified"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_BASE_ID" property="pkBaseId"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PK_DRAW_GIFT_ID" property="pkDrawGiftId"/>
        <result column="GIFT_COVER" property="giftCover"/>
        <result column="GIFT_NAME" property="giftName"/>
        <result column="PRODUCT_NAME" property="productName"/>
        <result column="QUANTITY" property="quantity"/>
        <result column="MEMBER_CODE" property="memberCode"/>
        <result column="MEMBER_NAME" property="memberName"/>
        <result column="PHONE" property="phone"/>
        <result column="GIFT_NUMBER" property="giftNumber"/>
        <result column="ACT_NAME" property="actName"/>
    </resultMap>

    <select id="queryCuMemberGiftRecordByCondition" resultMap="AcDrawRewardRecord">
        select af.gift_cover,af.gift_name,concat(bp.product_name, ag.specs_name) product_name,ag.quantity,cm.member_code,cm.member_name,
        cm.phone,af.gift_number,ac.act_name,ar.creation_time from ac_draw_reward_record ar
        inner join ac_base_config ac
        on ar.pk_base_id=ac.pk_id
        inner join ac_draw_gift_rule_config af
        on ar.pk_draw_gift_id=af.pk_id
        inner join cu_member cm
        on cm.pk_id=ar.pk_member
        left join ac_gift_config ag
        on ag.pk_rule_id =af.pk_id
        left join bd_product bp
        on ag.pk_product=bp.pk_id
        where ac.act_type=17 and ar.del_flag=0
        and ar.pk_country= #{pkCountry}
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="phone != null and phone != ''">
            and cm.phone = #{phone}
        </if>
        <if test="giftName != null and giftName != ''">
            and af.gift_name = #{giftName}
        </if>
        <if test="actName != null and actName != ''">
            and ac.act_name = #{actName}
        </if>
        <if test="startDate != null ">
            and ar.creation_time >= #{startDate}
        </if>
        <if test="endDate != null ">
            and ar.creation_time &lt; #{endDate}
        </if>
        order by ar.creation_time desc
    </select>

</mapper>
