<?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.wares.mapper.AcGiftConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="AcGiftConfigExt" type="com.hzs.common.domain.activity.base.ext.AcGiftConfigExt">
        <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_RULE_ID" property="pkRuleId"/>
        <result column="ACT_TYPE" property="actType"/>
        <result column="PK_PRODUCT" property="pkProduct"/>
        <result column="SPECS_NAME" property="specsName"/>
        <result column="SPECS_NAME_ID" property="specsNameId"/>
        <result column="QUANTITY" property="quantity"/>
        <result column="PRICE" property="price"/>
    </resultMap>

    <!-- 根据活动规则列表查询赠品列表 -->
    <select id="queryListByRuleIdList" resultType="com.hzs.common.domain.activity.base.ext.AcGiftConfigExt">
        select agc.*,
        bp.product_name,
        bp.cover
        from AC_GIFT_CONFIG agc
        inner join bd_product bp
        on bp.pk_id = agc.pk_product
        where agc.del_flag = 0
        and
        (agc.pk_rule_id in
        <foreach collection="ruleIdList" item="item" index="index" open="(" close=")">
            <if test="index != 0">
                <choose>
                    <when test="index % 500 == 0">) or agc.pk_rule_id IN (</when>
                    <otherwise>,</otherwise>
                </choose>
            </if>
            #{item}
        </foreach>
        )
        and agc.pk_country = #{pkCountry}
        order by agc.PK_RULE_ID, agc.pk_id
    </select>

</mapper>
