<?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.AcDrawGiftRuleConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="AcDrawGiftConfig" type="com.hzs.common.domain.activity.draw.ext.AcDrawGiftRuleConfigExt">
        <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="GIFT_COVER" property="giftCover" />
        <result column="GIFT_NAME" property="giftName" />
        <result column="GIFT_NUMBER" property="giftNumber" />
        <result column="MIN_NUMBER" property="minNumber" />
        <result column="GRANT_WAY" property="grantWay" />
        <result column="ACT_NAME" property="actName" />
        <result column="ACT_START_DATE" property="actStartDate" />
        <result column="ACT_END_DATE" property="actEndDate" />
        <result column="ACT_COVER" property="actCover" />
        <collection property="acGiftConfigList" ofType="com.hzs.common.domain.activity.base.ext.AcGiftConfigExt">
            <result column="PRODUCT_NAME" property="productName" />
            <result column="PRODUCT_ATTR" property="productAttr" />
            <result column="RETAIL_PRICE" property="retailPrice" />
            <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"/>
        </collection>
    </resultMap>

    <select id="queryList" parameterType="com.hzs.activity.draw.param.DrawGiftConfigParam" resultMap="AcDrawGiftConfig" >
          select dgc.*,bc.ACT_NAME,bc.ACT_START_DATE,bc.ACT_END_DATE,bc.CREATION_TIME,bc.ACT_COVER  from AC_DRAW_GIFT_RULE_CONFIG dgc
          left join  AC_BASE_CONFIG bc on bc.PK_ID = dgc.PK_BASE_ID
           where 1 = 1 and bc.del_flag = 0 and dgc.DEL_FLAG = 0
        <if test="startActStartDate!=null">
            and bc.ACT_START_DATE &gt;= #{startActStartDate}
        </if>
        <if test="endActStartDate!=null">
            and bc.ACT_START_DATE &lt;= #{endActStartDate}
        </if>
        <if test="startActEndDate!=null">
            and bc.ACT_END_DATE &gt;= #{startActEndDate}
        </if>
        <if test="endActEndDate!=null">
            and bc.ACT_END_DATE &lt;= #{endActEndDate}
        </if>
        <if test="startCreationTime!=null">
            and bc.CREATION_TIME &gt;= #{startCreationTime}
        </if>
        <if test="endCreationTime!=null">
            and bc.CREATION_TIME &lt;= #{endCreationTime}
        </if>
        <if test="pkCountry!=null">
            and dgc.PK_COUNTRY = #{pkCountry}
        </if>
        <if test="actType!=null">
            and bc.act_type = #{actType}
        </if>
        <if test="actName!=null">
            and bc.act_name= #{actName}
        </if>
        <if test="activityStatus!=null">
            <if test="activityStatus == 0">
             and  (  (SELECT SYSDATE FROM DUAL) &gt;= bc.ACT_START_DATE  and (SELECT SYSDATE FROM DUAL) &lt;= bc.ACT_END_DATE   )
            </if>
            <if test="activityStatus == 1">
                and  (   (SELECT SYSDATE FROM DUAL) &lt; bc.ACT_START_DATE   )
            </if>
            <if test="activityStatus == 2">
                and  (   (SELECT SYSDATE FROM DUAL) &gt; bc.ACT_START_DATE   )
            </if>
        </if>
    </select>
    <select id="queryAcDrawGiftConfig" resultMap="AcDrawGiftConfig">
        select dr.pk_id,dr.pk_base_id,dr.gift_cover,dr.gift_name,dr.gift_number,dr.min_number,dr.grant_way,
               bp.product_name,ac.specs_name,ac.quantity,bp.product_attr,bp.retail_price from ac_base_config ba
        inner join ac_draw_gift_rule_config dr
        on dr.pk_base_id = ba.pk_id
        inner join ac_gift_config ac
        on dr.pk_id = ac.pk_rule_id
        left join bd_product bp
        on ac.pk_product = bp.pk_id
        where ba.del_flag = 0 and dr.del_flag=0 and ac.del_flag=0
        and ba.pk_country = #{pkCountry}
        and ba.act_start_date &lt;= sysdate and ba.act_end_date >= sysdate
        <if test="pkBaseId != null">
            and ba.pk_id = #{pkBaseId}
        </if>
        <if test="pkId != null">
            and dr.pk_id = #{pkId}
        </if>
    </select>
</mapper>
