<?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.add.mapper.AcAddUpgradeRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.activity.add.AcAddUpgradeRecord">
        <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_RULE_ID" property="pkRuleId" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="PK_ORIGIN_GRADE" property="pkOriginGrade" />
        <result column="PK_UPGRADE_GRADE" property="pkUpgradeGrade" />
        <result column="PK_ORDER_ID" property="pkOrderId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        CREATION_TIME,
        PK_CREATOR,
        MODIFIED_TIME,
        PK_MODIFIED,
        PK_COUNTRY,
        PK_ID, PK_BASE_ID, PK_RULE_ID, PK_MEMBER, PK_ORIGIN_GRADE, PK_UPGRADE_GRADE, PK_ORDER_ID
    </sql>
    <select id="queryList" resultType="com.hzs.activity.add.vo.AcAddUpgradeListVO">
        SELECT
        abc.ACT_NAME,
        cm.member_code,
        cm.member_name,
        BG.GRADE_NAME AS originalLevelVal,
        BGG.GRADE_NAME AS upgradeLevelVal,
        abc.ACT_START_DATE,
        abc.ACT_END_DATE,
        aaur.*
        FROM
        AC_ADD_UPGRADE_RECORD aaur
        LEFT JOIN AC_BASE_CONFIG abc ON aaur.PK_BASE_ID = abc.PK_ID
        LEFT JOIN CU_MEMBER cm ON aaur.PK_MEMBER = cm.PK_ID
        LEFT JOIN BD_GRADE BG ON aaur.PK_ORIGIN_GRADE = BG.PK_ID
        LEFT JOIN BD_GRADE BGG ON aaur.PK_UPGRADE_GRADE = BGG.PK_ID
        WHERE
        aaur.DEL_FLAG = 0 AND cm.DEL_FLAG = 0 AND cm.CUSTOMER_TYPE = 0
        <if test="actName != null and actName != ''">
            AND abc.ACT_NAME = #{actName}
        </if>
        <if test="memberCode != null and memberCode != ''">
            AND cm.member_code = #{memberCode}
        </if>
        <if test="startActStartDate != null and startActStartDate != ''">
            AND abc.ACT_START_DATE >= TO_DATE(SUBSTR(#{startActStartDate},1,10), 'YYYY-MM-DD')
        </if>
        <if test="startActEndDate != null and startActEndDate != ''">
            AND abc.ACT_START_DATE &lt;= TO_DATE(SUBSTR(#{startActEndDate},1,10), 'YYYY-MM-DD')
        </if>
        <if test="endActStartDate != null and endActStartDate != ''">
            AND abc.ACT_END_DATE >= TO_DATE(SUBSTR(#{endActStartDate},1,10), 'YYYY-MM-DD')
        </if>
        <if test="endActEndDate != null and endActEndDate != ''">
            AND abc.ACT_END_DATE &lt;= TO_DATE(SUBSTR(#{endActEndDate},1,10), 'YYYY-MM-DD')
        </if>
    </select>

</mapper>
