<?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.recommend.mapper.AcRecomUpgradeRuleConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.activity.recommend.AcRecomUpgradeRuleConfig">
        <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_SETTLE_GRADE" property="pkSettleGrade"/>
        <result column="PK_RECOMMEND_GRADE" property="pkRecommendGrade"/>
        <result column="RECOMMEND_NUMBER" property="recommendNumber"/>
        <result column="PK_UPGRADE_GRADE" property="pkUpgradeGrade"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        CREATION_TIME,
        PK_CREATOR,
        MODIFIED_TIME,
        PK_MODIFIED,
        PK_COUNTRY,
        PK_ID, PK_BASE_ID, PK_SETTLE_GRADE, PK_RECOMMEND_GRADE, RECOMMEND_NUMBER, PK_UPGRADE_GRADE
    </sql>


    <select id="selectRuleConfig" resultMap="BaseResultMap">
        select *
          from AC_RECOM_UPGRADE_RULE_CONFIG u
         where u.del_flag = 0
           and u.pk_country = #{pkCountry}
           and u.pk_base_id = #{pkBaseId}
           and u.pk_settle_grade = #{pkSettleGrade}
           and u.pk_recommend_grade &lt;= #{pkRecommendGrade}
           and u.pk_settle_grade in (select m.pk_level
                                       from AC_GOAL_MEMBER_CONFIG m
                                      where m.del_flag = 0
                                        and m.pk_country = #{pkCountry}
                                        <if test="memberType != null">
                                            and m.member_type = #{memberType}
                                        </if>
                                        and m.pk_base_id = #{pkBaseId})
        order by u.creation_time desc

    </select>

</mapper>
