<?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.consume.mapper.AcMemberConsumeRuleMapper">

    <!-- 查询结果导出映射 -->
    <resultMap id="resultMapExt" type="com.hzs.common.domain.activity.consume.ext.AcMemberConsumeRuleExt">
        <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_GRADE" property="pkGrade"/>
        <collection property="giftConfigExtList" ofType="com.hzs.common.domain.activity.base.ext.AcGiftConfigExt">
            <result column="PK_PRODUCT" property="pkProduct"/>
            <result column="QUANTITY" property="quantity"/>
            <result column="PRODUCT_CODE" property="productCode"/>
            <result column="SPECS_NAME" property="specsName"/>
            <result column="SPECS_NAME_ID" property="specsNameId"/>
        </collection>
    </resultMap>

    <!-- 规则列表以及商品信息 -->
    <select id="listRuleAndProduct" resultMap="resultMapExt">
        select amcr.pk_id,
        amcr.pk_base_id,
        amcr.pk_grade,
        amcr.member_point,
        agc.pk_product,
        agc.quantity,
        agc.specs_name,
        agc.specs_name_id,
        bp.product_code
        from ac_base_config abc
        left join AC_MEMBER_CONSUME_RULE amcr
        on amcr.pk_base_id = abc.pk_id
        left join AC_GIFT_CONFIG agc
        on agc.pk_rule_id = amcr.pk_id
        left join bd_product bp
        on bp.pk_id = agc.pk_product
        where abc.del_flag = 0
        and abc.pk_country = #{pkCountry}
        and abc.act_type = 25
        <if test="startDate != null">
            and abc.act_start_date &lt;= #{startDate}
        </if>
        <if test="endDate != null">
            and abc.act_end_date >= #{endDate}
        </if>
        and amcr.pk_grade = #{pkGrade}
        and #{memberPoint} = amcr.member_point
        order by abc.act_start_date desc
    </select>

</mapper>
