<?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.report.report.mapper.CuMemberAchieveMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="CuMemberAchieve" type="com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt">
        <id column="PK_ID" property="pkId"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_MEMBER" property="pkMember"/>
        <result column="PK_RATE" property="pkRate"/>
        <result column="A_BALANCE" property="aBalance"/>
        <result column="B_BALANCE" property="bBalance"/>
        <result column="A_SUM_AMOUNT" property="aSumAmount"/>
        <result column="B_SUM_AMOUNT" property="bSumAmount"/>
        <result column="A_SUM_PV" property="aSumPv"/>
        <result column="B_SUM_PV" property="bSumPv"/>
        <result column="A_NEW_AMOUNT" property="aNewAmount"/>
        <result column="B_NEW_AMOUNT" property="bNewAmount"/>
        <result column="A_NEW_PV" property="aNewPv"/>
        <result column="B_NEW_PV" property="bNewPv"/>
        <result column="A_SUM_REAL_AMOUNT" property="aSumRealAmount"/>
        <result column="B_SUM_REAL_AMOUNT" property="bSumRealAmount"/>
        <result column="A_SUM_REAL_PV" property="aSumRealPv"/>
        <result column="B_SUM_REAL_PV" property="bSumRealPv"/>
        <result column="REP_A_BALANCE" property="repABalance"/>
        <result column="REP_B_BALANCE" property="repBBalance"/>
        <result column="REP_A_NEW_AMOUNT" property="repANewAmount"/>
        <result column="REP_B_NEW_AMOUNT" property="repBNewAmount"/>
        <result column="REP_A_NEW_PV" property="repANewPv"/>
        <result column="REP_B_NEW_PV" property="repBNewPv"/>
        <result column="REP_A_SUM_AMOUNT" property="repASumAmount"/>
        <result column="REP_B_SUM_AMOUNT" property="repBSumAmount"/>
        <result column="REP_A_SUM_PV" property="repASumPv"/>
        <result column="REP_B_SUM_PV" property="repBSumPv"/>
        <result column="REGISTER_AMOUNT" property="registerAmount"/>
        <result column="REGISTER_PV" property="registerPv"/>
        <result column="REGISTER_NEW_PV" property="registerNewPv"/>
        <result column="UPGRADE_AMOUNT" property="upgradeAmount"/>
        <result column="UPGRADE_PV" property="upgradePv"/>
        <result column="UPGRADE_NEW_PV" property="upgradeNewPv"/>
        <result column="REPURCHASE_AMOUNT" property="repurchaseAmount"/>
        <result column="REPURCHASE_PV" property="repurchasePv"/>
        <result column="REPURCHASE_NEW_PV" property="repurchaseNewPv"/>
        <result column="HI_FUN_AMOUNT" property="hiFunAmount"/>
        <result column="HI_FUN_PV" property="hiFunPv"/>
        <result column="HI_FUN_NEW_PV" property="hiFunNewPv"/>
        <result column="MALL_AMOUNT" property="mallAmount"/>
        <result column="MALL_PV" property="mallPv"/>
        <result column="MALL_NEW_PV" property="mallNewPv"/>
        <result column="REGISTER_Blo_NEW_PV" property="registerBloNewPv"/>
        <result column="UPGRADE_Blo_NEW_PV" property="upgradeBloNewPv"/>
        <result column="REPURCHASE_Blo_NEW_PV" property="repurchaseBloNewPv"/>
        <result column="HI_FUN_Blo_NEW_PV" property="hiFunBloNewPv"/>
        <result column="MALL_Blo_NEW_PV" property="mallBloNewPv"/>
        <result column="R_A_BALANCE" property="rABalance"/>
        <result column="R_B_BALANCE" property="rBBalance"/>
        <result column="R_A_SUM_AMOUNT" property="rASumAmount"/>
        <result column="R_B_SUM_AMOUNT" property="rBSumAmount"/>
        <result column="R_A_SUM_PV" property="rASumPv"/>
        <result column="R_B_SUM_PV" property="rBSumPv"/>
        <result column="R_A_SUM_REAL_AMOUNT" property="rASumRealAmount"/>
        <result column="R_B_SUM_REAL_AMOUNT" property="rBSumRealAmount"/>
        <result column="R_A_SUM_REAL_PV" property="rASumRealPv"/>
        <result column="R_B_SUM_REAL_PV" property="rBSumRealPv"/>
        <result column="R_REP_A_BALANCE" property="rRepABalance"/>
        <result column="R_REP_B_BALANCE" property="rRepBBalance"/>
        <result column="R_REP_A_SUM_AMOUNT" property="rRepASumAmount"/>
        <result column="R_REP_B_SUM_AMOUNT" property="rRepBSumAmount"/>
        <result column="R_REP_A_SUM_PV" property="rRepASumPv"/>
        <result column="ALGEBRA" property="algebra"/>
        <result column="VERTEX_NAME" property="vertexName"/>
        <result column="TEAM_NAME" property="teamName"/>
        <result column="ASSESS_STATUS" property="assessStatus"/>
    </resultMap>

    <select id="selectNewAddAchieve" resultType="com.hzs.report.report.vo.CuMemberNewAddAchieveVO">
        select t.*, s.settle_date
        from (select a.period,
        a.a_new_pv aNewPv,
        a.b_new_pv bNewPv,
        a.rep_a_new_pv repANewPv,
        a.rep_b_new_pv repBNewPv
        from ${achieveTableName} a
        where a.pk_member = #{pkMember}
        and a.pk_country = #{pkCountry}
        union all
        SELECT #{period}               period,
        cms.a_new_pv     aNewPv,
        cms.b_new_pv     bNewPv,
        cms.rep_a_new_pv repANewPv,
        cms.rep_b_new_pv repBNewPv
        FROM ${secondTableName} cms
        WHERE cms.pk_member = #{pkMember}
        AND cms.pk_country = #{pkCountry}
        <if test="upAchieveTableName != null and upAchieveTableName != ''">
            union all
            select up.period,
            up.a_new_pv aNewPv,
            up.b_new_pv bNewPv,
            up.rep_a_new_pv repANewPv,
            up.rep_b_new_pv repBNewPv
            from ${upAchieveTableName} up
            where up.pk_member = #{pkMember}
            and up.pk_country = #{pkCountry}
        </if>
        ) t,
        cu_member_settle_period s
        where t.period = s.pk_id
        and s.del_flag = 0
        and s.settle_date >= to_date(#{startDate}, 'yyyy-mm-dd')
        and s.settle_date &lt;= to_date(#{endDate}, 'yyyy-mm-dd')
        order by s.settle_date
    </select>

</mapper>
