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

    <!-- 通用查询映射结果 -->
    <resultMap id="AcDrawRuleConfig" type="com.hzs.common.domain.activity.draw.AcDrawRuleConfig">
        <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="ORDER_TYPE" property="orderType"/>
        <result column="ORDER_AMOUNT" property="orderAmount"/>
        <result column="ORDER_ACHIEVE" property="orderAchieve"/>
        <result column="GIVE_NUMBER" property="giveNumber"/>
    </resultMap>

    <select id="queryDrawRuleConfigByCondition" resultMap="AcDrawRuleConfig">
        select dr.pk_base_id, max(dr.GIVE_NUMBER) GIVE_NUMBER
        from ac_base_config ba
                 inner join ac_draw_rule_config dr
                            on dr.pk_base_id = ba.pk_id
        where ba.del_flag = 0
          and dr.del_flag = 0
          and ba.pk_country = #{pkCountry}
          and dr.order_type = #{orderType}
          and ba.act_start_date &lt;= sysdate
          and ba.act_end_date >= sysdate
          and dr.order_amount &lt;= #{orderAmount}
          and dr.order_achieve &lt;= #{orderAchieve}
        group by dr.pk_base_id
    </select>

</mapper>
