<?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.bonus.achieve.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="R_REP_B_SUM_PV" property="rRepBSumPv"/>
        <result column="ALGEBRA" property="algebra"/>
        <result column="VERTEX_NAME" property="vertexName"/>
        <result column="TEAM_NAME" property="teamName"/>
        <result column="ASSESS_STATUS" property="assessStatus"/>
        <result column="A_NEW_BOX" property="aNewBox"/>
        <result column="B_NEW_BOX" property="bNewBox"/>
        <result column="A_SUM_BOX" property="aSumBox"/>
        <result column="B_SUM_BOX" property="bSumBox"/>
        <result column="TOTAL_NEW_BOX" property="totalNewBox"/>
        <result column="TOTAL_SUM_BOX" property="totalSumBox"/>
    </resultMap>

    <sql id="CuMemberAchieveColumn">
        pk_id
        NUMBER(20) primary key,
            period            number(6) not null,
            pk_member         NUMBER(20) not null,
            pk_rate           NUMBER(6) not null,
            a_balance         NUMBER(17,6) default 0 not null,
            b_balance         NUMBER(17,6) default 0 not null,
            a_sum_amount      NUMBER(17,6) default 0 not null,
            b_sum_amount      NUMBER(17,6) default 0 not null,
            a_sum_pv          NUMBER(17,6) default 0 not null,
            b_sum_pv          NUMBER(17,6) default 0 not null,
            a_new_amount      NUMBER(17,6) default 0 not null,
            b_new_amount      NUMBER(17,6) default 0 not null,
            a_new_pv          NUMBER(17,6) default 0 not null,
            b_new_pv          NUMBER(17,6) default 0 not null,
            a_sum_real_amount NUMBER(17,6) default 0 not null,
            b_sum_real_amount NUMBER(17,6) default 0 not null,
            a_sum_real_pv     NUMBER(17,6) default 0 not null,
            b_sum_real_pv     NUMBER(17,6) default 0 not null,
            rep_a_balance     NUMBER(17,6) default 0 not null,
            rep_b_balance     NUMBER(17,6) default 0 not null,
            rep_a_new_amount  NUMBER(17,6) default 0 not null,
            rep_b_new_amount  NUMBER(17,6) default 0 not null,
            rep_a_new_pv      NUMBER(17,6) default 0 not null,
            rep_b_new_pv      NUMBER(17,6) default 0 not null,
            rep_a_sum_amount  NUMBER(17,6) default 0 not null,
            rep_b_sum_amount  NUMBER(17,6) default 0 not null,
            rep_a_sum_pv      NUMBER(17,6) default 0 not null,
            rep_b_sum_pv      NUMBER(17,6) default 0 not null,
            register_amount  NUMBER(17,6) default 0 not null,
            register_pv     NUMBER(17,6) default 0 not null,
            register_new_amount     NUMBER(17,6) default 0 not null,
            register_new_pv NUMBER(17,6) default 0 not null,
            upgrade_amount  NUMBER(17,6) default 0 not null,
            upgrade_pv      NUMBER(17,6) default 0 not null,
            upgrade_new_amount       NUMBER(17,6) default 0 not null,
            upgrade_new_pv NUMBER(17,6) default 0 not null,
            repurchase_amount NUMBER(17,6) default 0 not null,
            repurchase_pv   NUMBER(17,6) default 0 not null,
            repurchase_new_amount    NUMBER(17,6) default 0 not null,
            repurchase_new_pv NUMBER(17,6) default 0 not null,
            hi_fun_amount NUMBER(17,6) default 0 not null,
            hi_fun_pv   NUMBER(17,6) default 0 not null,
            hi_fun_new_amount        NUMBER(17,6) default 0 not null,
            hi_fun_new_pv NUMBER(17,6) default 0 not null,
            mall_amount NUMBER(17,6) default 0 not null,
            mall_pv     NUMBER(17,6) default 0 not null,
            mall_new_amount          NUMBER(17,6) default 0 not null,
            mall_new_pv NUMBER(17,6) default 0 not null,
            REGISTER_Blo_NEW_PV  NUMBER(17,6) default 0 not null,
            UPGRADE_Blo_NEW_PV    NUMBER(17,6) default 0 not null,
            REPURCHASE_Blo_NEW_PV    NUMBER(17,6) default 0 not null,
            HI_FUN_Blo_NEW_PV    NUMBER(17,6) default 0 not null,
            MALL_Blo_NEW_PV    NUMBER(17,6) default 0 not null,
            r_a_balance         NUMBER(17,6) default 0 not null,
            r_b_balance         NUMBER(17,6) default 0 not null,
            r_a_sum_amount      NUMBER(17,6) default 0 not null,
            r_b_sum_amount      NUMBER(17,6) default 0 not null,
            r_a_sum_pv          NUMBER(17,6) default 0 not null,
            r_b_sum_pv          NUMBER(17,6) default 0 not null,
            r_a_sum_real_amount NUMBER(17,6) default 0 not null,
            r_b_sum_real_amount NUMBER(17,6) default 0 not null,
            r_a_sum_real_pv     NUMBER(17,6) default 0 not null,
            r_b_sum_real_pv     NUMBER(17,6) default 0 not null,
            r_rep_a_balance     NUMBER(17,6) default 0 not null,
            r_rep_b_balance     NUMBER(17,6) default 0 not null,
            r_rep_a_sum_amount  NUMBER(17,6) default 0 not null,
            r_rep_b_sum_amount  NUMBER(17,6) default 0 not null,
            r_rep_a_sum_pv      NUMBER(17,6) default 0 not null,
            r_rep_b_sum_pv      NUMBER(17,6) default 0 not null,
            pk_country        NUMBER(6) not null,
            A_NEW_BOX         NUMBER(8) default 0 not null,
            B_NEW_BOX         NUMBER(8) default 0 not null,
            A_SUM_BOX         NUMBER(12) default 0 not null,
            B_SUM_BOX         NUMBER(12) default 0 not null,
            TOTAL_NEW_BOX     NUMBER(8) default 0 not null,
            TOTAL_SUM_BOX     NUMBER(12) default 0 not null
    </sql>

    <update id="createCuMemberAchieveTable">
        create table ${tableName}
        (
        <include refid="CuMemberAchieveColumn"></include>
        )
    </update>

    <!--每日更新累计金额-->
    <update id="updateCuMemberBackOldAchieveEveryDay">
        merge into ${tableName} a
        using (
        select pk_member, max(a.pk_rate) pk_rate,
        sum(a_new_amount / bc.out_exchange_rate) a_new_amount,
        sum(a_new_pv) a_new_pv,
        sum(b_new_amount / bc.out_exchange_rate) b_new_amount,
        sum(b_new_pv) b_new_pv,
        sum(rep_a_new_amount / bc.out_exchange_rate) rep_a_new_amount,
        sum(rep_a_new_pv) rep_a_new_pv,
        sum(rep_b_new_amount / bc.out_exchange_rate) rep_b_new_amount,
        sum(rep_b_new_pv) rep_b_new_pv,
        sum(a_new_real_amount / bc.out_exchange_rate) a_new_real_amount,
        sum(a_new_real_pv) a_new_real_pv,
        sum(b_new_real_amount / bc.out_exchange_rate) b_new_real_amount,
        sum(b_new_real_pv) b_new_real_pv
        from (
        <foreach collection="memberAchieveParamList" item="achieve" open=" " separator=" union all " close=" ">
            select pk_place_parent pk_member, #{achieve.pkRate} pk_rate,
            (case when place_dept = 1 then #{achieve.newAmount} else 0 end) a_new_amount,
            (case when place_dept = 1 then #{achieve.newPv} else 0 end) a_new_pv,
            (case when place_dept = 1 then #{achieve.repNewAmount} else 0 end) rep_a_new_amount,
            (case when place_dept = 1 then #{achieve.repNewPv} else 0 end) rep_a_new_pv,
            (case when place_dept = 1 then #{achieve.newRealAmount} else 0 end) a_new_real_amount,
            (case when place_dept = 1 then #{achieve.newRealPv} else 0 end) a_new_real_pv,
            (case when place_dept = 2 then #{achieve.newAmount} else 0 end) b_new_amount,
            (case when place_dept = 2 then #{achieve.newPv} else 0 end) b_new_pv,
            (case when place_dept = 2 then #{achieve.repNewAmount} else 0 end) rep_b_new_amount,
            (case when place_dept = 2 then #{achieve.repNewPv} else 0 end) rep_b_new_pv,
            (case when place_dept = 2 then #{achieve.newRealAmount} else 0 end) b_new_real_amount,
            (case when place_dept = 2 then #{achieve.newRealPv} else 0 end) b_new_real_pv
            from(
            select pk_place_parent, place_dept from (
            select * from ${tableName}
            start with pk_member = #{achieve.pkMember}
            connect by pk_member = prior pk_place_parent
            )
            where nvl(pk_place_parent, 0) != 0
            )
        </foreach>
        ) a
        inner join bd_currency bc
        on a.pk_rate = bc.pk_id
        group by pk_member
        ) b
        on (a.pk_member = b.pk_member)
        when matched then
        update
        set a.period = a.period + 1,
        a.a_sum_pv = a.a_sum_pv - b.a_new_pv,
        a.b_sum_pv = a.b_sum_pv - b.b_new_pv,
        a.rep_a_sum_pv = a.rep_a_sum_pv - b.rep_a_new_pv,
        a.rep_b_sum_pv = a.rep_b_sum_pv - b.rep_b_new_pv,
        a.a_sum_real_pv = a.a_sum_real_pv - b.a_new_real_pv,
        a.b_sum_real_pv = a.b_sum_real_pv - b.b_new_real_pv
    </update>

    <!-- 每日更新累计业绩、金额 -->
    <update id="updateCuMemberBackAchieveEveryDay">
        merge into ${tableName} a
        using (
        select pk_member, max(a.pk_rate) pk_rate,
        sum(a_new_amount / bc.out_exchange_rate) a_new_amount,
        sum(a_new_pv) a_new_pv,
        sum(b_new_amount / bc.out_exchange_rate) b_new_amount,
        sum(b_new_pv) b_new_pv,
        sum(rep_a_new_amount / bc.out_exchange_rate) rep_a_new_amount,
        sum(rep_b_new_amount / bc.out_exchange_rate) rep_b_new_amount,
        sum(rep_a_new_pv) rep_a_new_pv,
        sum(rep_b_new_pv) rep_b_new_pv,
        sum(a_new_real_amount / bc.out_exchange_rate) a_new_real_amount,
        sum(a_new_real_pv) a_new_real_pv,
        sum(b_new_real_amount / bc.out_exchange_rate) b_new_real_amount,
        sum(b_new_real_pv) b_new_real_pv,
        sum(a_new_box) a_new_box,
        sum(b_new_box) b_new_box
        from (
        <foreach collection="memberAchieveParamList" item="achieve" open=" " separator=" union all " close=" ">
            select pk_place_parent pk_member, #{achieve.pkRate} pk_rate,
            (case when place_dept = 1 then #{achieve.newAmount} else 0 end) a_new_amount,
            (case when place_dept = 1 then #{achieve.newPv} else 0 end) a_new_pv,
            (case when place_dept = 1 then #{achieve.repNewAmount} else 0 end) rep_a_new_amount,
            (case when place_dept = 1 then #{achieve.repNewPv} else 0 end) rep_a_new_pv,
            (case when place_dept = 1 then #{achieve.newRealAmount} else 0 end) a_new_real_amount,
            (case when place_dept = 1 then #{achieve.newRealPv} else 0 end) a_new_real_pv,
            (case when place_dept = 1 then #{achieve.newBox} else 0 end) a_new_box,
            (case when place_dept = 2 then #{achieve.newAmount} else 0 end) b_new_amount,
            (case when place_dept = 2 then #{achieve.newPv} else 0 end) b_new_pv,
            (case when place_dept = 2 then #{achieve.repNewAmount} else 0 end) rep_b_new_amount,
            (case when place_dept = 2 then #{achieve.repNewPv} else 0 end) rep_b_new_pv,
            (case when place_dept = 2 then #{achieve.newRealAmount} else 0 end) b_new_real_amount,
            (case when place_dept = 2 then #{achieve.newRealPv} else 0 end) b_new_real_pv,
            (case when place_dept = 2 then #{achieve.newBox} else 0 end) b_new_box
            from(
            select pk_place_parent, place_dept from (
            select * from ${tableName}
            start with pk_member = #{achieve.pkMember}
            connect by pk_member = prior pk_place_parent
            )
            where nvl(pk_place_parent, 0) != 0
            )
        </foreach>
        ) a
        inner join bd_currency bc
        on a.pk_rate = bc.pk_id
        group by pk_member
        ) b
        on (a.pk_member = b.pk_member)
        when matched then
        update set a.period = a.period + 1, a.pk_rate = b.pk_rate,
        a.a_sum_pv = a.a_sum_pv + b.a_new_pv,
        a.b_sum_pv = a.b_sum_pv + b.b_new_pv,
        a.rep_a_sum_pv = a.rep_a_sum_pv + b.rep_a_new_pv,
        a.rep_b_sum_pv = a.rep_b_sum_pv + b.rep_b_new_pv,
        a.a_sum_real_pv = a.a_sum_real_pv + b.a_new_real_pv,
        a.b_sum_real_pv = a.b_sum_real_pv + b.b_new_real_pv,
        a.r_a_sum_amount = a.r_a_sum_amount + b.a_new_amount,
        a.r_b_sum_amount = a.r_b_sum_amount + b.b_new_amount,
        a.r_a_sum_pv = a.r_a_sum_pv + b.a_new_pv,
        a.r_b_sum_pv = a.r_b_sum_pv + b.b_new_pv,
        a.r_rep_a_sum_amount = a.r_rep_a_sum_amount +b.rep_a_new_amount,
        a.r_rep_b_sum_amount = a.r_rep_b_sum_amount + b.rep_b_new_amount,
        a.r_rep_a_sum_pv = a.r_rep_a_sum_pv + b.rep_a_new_pv,
        a.r_rep_b_sum_pv = a.r_rep_b_sum_pv + b.rep_b_new_pv,
        a.r_a_sum_real_amount = a.r_a_sum_real_amount + b.a_new_real_amount,
        a.r_b_sum_real_amount = a.r_b_sum_real_amount + b.b_new_real_amount,
        a.r_a_sum_real_pv = a.r_a_sum_real_pv + b.a_new_real_pv,
        a.r_b_sum_real_pv = a.r_b_sum_real_pv + b.b_new_real_pv,
        a.a_new_box = b.a_new_box, a.b_new_box = b.b_new_box, a.total_new_box = b.a_new_box + b.b_new_box,
        a.a_sum_box = a.a_sum_box + b.a_new_box, a.b_sum_box = a.b_sum_box + b.b_new_box, a.total_sum_box = a.total_sum_box + b.a_new_box + b.b_new_box
    </update>

    <!-- 将昨天的各种金额作为今天的期初 -->
    <update id="updateCuMemberSettleAchieveByBeforeDay">
        merge into ${targetTable} a
            using (select pk_member,
                          a_balance,
                          b_balance,
                          a_sum_amount,
                          b_sum_amount,
                          a_sum_pv,
                          b_sum_pv,
                          a_new_amount,
                          b_new_amount,
                          a_new_pv,
                          b_new_pv,
                          a_sum_real_amount,
                          b_sum_real_amount,
                          a_sum_real_pv,
                          b_sum_real_pv,
                          rep_a_balance,
                          rep_b_balance,
                          rep_a_sum_amount,
                          rep_b_sum_amount,
                          rep_a_sum_pv,
                          rep_b_sum_pv,
                          register_amount,
                          register_pv,
                          upgrade_amount,
                          upgrade_pv,
                          repurchase_amount,
                          repurchase_pv,
                          hi_fun_amount,
                          hi_fun_pv,
                          mall_amount,
                          mall_pv,
                          pk_country,
                          min_achieve,
                          round, second,
                       net_first_achieve, net_repurchase_achieve,
                       r_a_balance, r_b_balance,
                       r_a_sum_amount, r_b_sum_amount,
                       r_a_sum_pv, r_b_sum_pv,
                       r_rep_a_sum_amount, r_rep_b_sum_amount,
                       r_rep_a_sum_pv, r_rep_b_sum_pv,
                       r_a_sum_real_amount, r_b_sum_real_amount,
                       r_a_sum_real_pv, r_b_sum_real_pv,
                       r_rep_a_balance, r_rep_b_balance,
                       A_SUM_BOX, B_SUM_BOX, TOTAL_SUM_BOX
                   from ${sourceTable}) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.a_balance = b.a_balance, a.b_balance = b.b_balance,
                    a.a_sum_amount = b.a_sum_amount, a.b_sum_amount = b.b_sum_amount,
                    a.a_sum_pv = b.a_sum_pv, a.b_sum_pv = b.b_sum_pv,
                    a.a_sum_real_amount = b.a_sum_real_amount, a.b_sum_real_amount = b.b_sum_real_amount,
                    a.a_sum_real_pv = b.a_sum_real_pv, a.b_sum_real_pv = b.b_sum_real_pv,
                    a.rep_a_balance = b.rep_a_balance, a.rep_b_balance = b.rep_b_balance,
                    a.rep_a_sum_pv = b.rep_a_sum_pv, a.rep_b_sum_pv = b.rep_b_sum_pv,
                    a.register_amount = b.register_amount, a.register_pv = b.register_pv,
                    a.upgrade_amount = b.upgrade_amount, a.upgrade_pv = b.upgrade_pv,
                    a.repurchase_amount = b.repurchase_amount, a.repurchase_pv = b.repurchase_pv,
                    a.hi_fun_amount = b.hi_fun_amount, a.hi_fun_pv = b.hi_fun_pv,
                    a.mall_amount = b.mall_amount, a.mall_pv = b.mall_pv,
                    a.min_achieve = b.min_achieve, a.round = b.round, a.second = b.second,
                    a.net_first_achieve = b.net_first_achieve, a.net_repurchase_achieve = b.net_repurchase_achieve,
                    a.r_a_balance = b.r_a_balance, a.r_b_balance = b.r_b_balance,
                    a.r_a_sum_amount = b.r_a_sum_amount, a.r_b_sum_amount = b.r_b_sum_amount,
                    a.r_a_sum_pv = b.r_a_sum_pv, a.r_b_sum_pv = b.r_b_sum_pv,
                    a.r_rep_a_sum_amount = b.r_rep_a_sum_amount, a.r_rep_b_sum_amount = b.r_rep_b_sum_amount,
                    a.r_rep_a_sum_pv = b.r_rep_a_sum_pv, a.r_rep_b_sum_pv = b.r_rep_b_sum_pv,
                    a.r_a_sum_real_amount = b.r_a_sum_real_amount, a.r_b_sum_real_amount = b.r_b_sum_real_amount,
                    a.r_a_sum_real_pv = b.r_a_sum_real_pv, a.r_b_sum_real_pv = b.r_b_sum_real_pv,
                    a.r_rep_a_balance = b.r_rep_a_balance, a.r_rep_b_balance = b.r_rep_b_balance,
                    a.A_SUM_BOX = b.A_SUM_BOX, a.B_SUM_BOX = b.B_SUM_BOX, a.TOTAL_SUM_BOX = b.TOTAL_SUM_BOX
    </update>

    <update id="updateCuMemberSettleAchieveBySpecialBus">
        merge into ${targetTable} a
            using (select cl.pk_member,
                          (case infusing_water_type
                               when 1 then ca.a_sum_real_pv + a_sum_real_modify_pv
                               when 2 then ca.a_sum_real_pv - a_sum_real_modify_pv
                               else a_sum_real_modify_pv end)       a_sum_real_pv,
                          (case infusing_water_type
                               when 1 then ca.b_sum_real_pv + b_sum_real_modify_pv
                               when 2 then ca.b_sum_real_pv - b_sum_real_modify_pv
                               else b_sum_real_modify_pv end)       b_sum_real_pv,
                          (case infusing_water_type
                               when 1 then ca.a_sum_pv + a_first_modify_pv
                               when 2 then ca.a_sum_pv - a_first_modify_pv
                               else a_first_modify_pv end)          a_sum_pv,
                          (case infusing_water_type
                               when 1 then ca.b_sum_pv + b_first_modify_pv
                               when 2 then ca.b_sum_pv - b_first_modify_pv
                               else b_first_modify_pv end)          b_sum_pv,
                          (case infusing_water_type
                               when 1 then ca.a_balance + rep_a_first_modify_balance
                               when 2 then ca.a_balance - rep_a_first_modify_balance
                               else rep_a_first_modify_balance end) a_balance,
                          (case infusing_water_type
                               when 1 then ca.b_balance + rep_b_first_modify_balance
                               when 2 then ca.b_balance - rep_b_first_modify_balance
                               else rep_b_first_modify_balance end) b_balance,
                          (case infusing_water_type
                               when 1 then ca.rep_a_sum_pv + rep_a_modify_sum_pv
                               when 2 then ca.rep_a_sum_pv - rep_a_modify_sum_pv
                               else rep_a_modify_sum_pv end)        rep_a_sum_pv,
                          (case infusing_water_type
                               when 1 then ca.rep_b_sum_pv + rep_b_modify_sum_pv
                               when 2 then ca.rep_b_sum_pv - rep_b_modify_sum_pv
                               else rep_b_modify_sum_pv end)        rep_b_sum_pv,
                          (case infusing_water_type
                               when 1 then ca.rep_a_balance + rep_a_modify_balance
                               when 2 then ca.rep_a_balance - rep_a_modify_balance
                               else rep_a_modify_balance end)       rep_a_balance,
                          (case infusing_water_type
                               when 1 then ca.rep_b_balance + rep_b_modify_balance
                               when 2 then ca.rep_b_balance - rep_b_modify_balance
                               else rep_b_modify_balance end)       rep_b_balance
                   from cu_member_achieve_log cl
                            left join ${targetTable} ca
                                      on cl.pk_member = ca.pk_member
                   where cl.period = #{period}
                     and approve_status = 5
                     and cl.pk_id = #{pkId}
                   order by cl.pk_member, cl.creation_time) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.a_sum_real_pv = b.a_sum_real_pv, a.b_sum_real_pv = b.b_sum_real_pv,
                    a.a_sum_pv = b.a_sum_pv, a.b_sum_pv = b.b_sum_pv,
                    a.a_balance = b.a_balance, a.b_balance = b.b_balance,
                    a.rep_a_sum_pv = b.rep_a_sum_pv, a.rep_b_sum_pv = b.rep_b_sum_pv,
                    a.rep_a_balance = b.rep_a_balance,a.rep_b_balance = b.rep_b_balance
    </update>

    <update id="updateCuMemberSettleAchieveByDueDate">
        merge into ${currentTableName} a
            using (
                select ct.pk_member,
                       r_a_balance,
                       r_b_balance,
                       r_a_sum_pv,
                       r_b_sum_pv,
                       r_a_sum_real_pv,
                       r_b_sum_real_pv,
                       r_rep_a_sum_pv,
                       r_rep_b_sum_pv,
                       r_rep_a_balance,
                       r_rep_b_balance
                from ${yesTableName} ct
                         inner join cu_member_achieve_log cl
                                    on ct.pk_member = cl.pk_member
                where cl.due_date = #{currentDate, jdbcType=DATE}
            ) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.r_a_balance = b.r_a_balance, a.r_b_balance = b.r_b_balance,
                    a.r_a_sum_pv = b.r_a_sum_pv, a.r_b_sum_pv = b.r_b_sum_pv,
                    a.r_a_sum_real_pv = b.r_a_sum_real_pv, a.r_b_sum_real_pv = b.r_b_sum_real_pv,
                    a.r_rep_a_sum_pv = b.r_rep_a_sum_pv, a.r_rep_b_sum_pv = b.r_rep_b_sum_pv,
                    a.r_rep_a_balance = b.r_rep_a_balance, a.r_rep_b_balance = b.r_rep_b_balance
    </update>

    <update id="mergeCuMemberAchieveBySettleDate">
        merge into ${targetTableName} a
            using (
                select #{period}       period,
                       pk_member,
                       nvl(pk_rate, 0) pk_rate,
                       a_balance,
                       b_balance,
                       a_sum_amount,
                       b_sum_amount,
                       a_sum_pv,
                       b_sum_pv,
                       a_new_amount,
                       b_new_amount,
                       a_new_pv,
                       b_new_pv,
                       a_sum_real_amount,
                       b_sum_real_amount,
                       a_sum_real_pv,
                       b_sum_real_pv,
                       rep_a_balance,
                       rep_b_balance,
                       rep_a_new_amount,
                       rep_b_new_amount,
                       rep_a_new_pv,
                       rep_b_new_pv,
                       rep_a_sum_amount,
                       rep_b_sum_amount,
                       rep_a_sum_pv,
                       rep_b_sum_pv,
                       register_amount,
                       register_pv,
                       register_new_amount,
                       register_new_pv,
                       upgrade_amount,
                       upgrade_pv,
                       upgrade_new_amount,
                       upgrade_new_pv,
                       repurchase_amount,
                       repurchase_pv,
                       repurchase_new_amount,
                       repurchase_new_pv,
                       hi_fun_amount,
                       hi_fun_pv,
                       hi_fun_new_amount,
                       hi_fun_new_pv,
                       mall_amount,
                       mall_pv,
                       mall_new_amount,
                       mall_new_pv,
                       register_blo_new_pv,
                       upgrade_blo_new_pv,
                       repurchase_blo_new_pv,
                       hi_fun_blo_new_pv,
                       mall_blo_new_pv,
                       r_a_balance,
                       r_b_balance,
                       r_a_sum_amount,
                       r_b_sum_amount,
                       r_a_sum_pv,
                       r_b_sum_pv,
                       r_a_sum_real_amount,
                       r_b_sum_real_amount,
                       r_a_sum_real_pv,
                       r_b_sum_real_pv,
                       r_rep_a_balance,
                       r_rep_b_balance,
                       r_rep_a_sum_amount,
                       r_rep_b_sum_amount,
                       r_rep_a_sum_pv,
                       r_rep_b_sum_pv,
                       pk_country
                from ${sourceTableName}
            ) b
            on (a.pk_member = b.pk_member and a.period = b.period)
            WHEN MATCHED THEN
                update set a.pk_rate = b.pk_rate,a.a_balance = b.a_balance,a.b_balance = b.b_balance,
                    a.a_sum_amount = b.a_sum_amount,a.b_sum_amount = b.b_sum_amount,
                    a.a_sum_pv = b.a_sum_pv,a.b_sum_pv = b.b_sum_pv,a.a_new_amount = b.a_new_amount,
                    a.b_new_amount = b.b_new_amount,a.a_new_pv = b.a_new_pv,a.b_new_pv = b.b_new_pv,
                    a.a_sum_real_amount = b.a_sum_real_amount,a.b_sum_real_amount = b.b_sum_real_amount,
                    a.a_sum_real_pv = b.a_sum_real_pv,a.b_sum_real_pv = b.b_sum_real_pv,
                    a.rep_a_balance = b.rep_a_balance,a.rep_b_balance = b.rep_b_balance,
                    a.rep_a_new_amount = b.rep_a_new_amount,a.rep_b_new_amount = b.rep_b_new_amount,
                    a.rep_a_new_pv = b.rep_a_new_pv,a.rep_b_new_pv = b.rep_b_new_pv,
                    a.rep_a_sum_amount = b.rep_a_sum_amount,a.rep_b_sum_amount = b.rep_b_sum_amount,
                    a.rep_a_sum_pv = b.rep_a_sum_pv,a.rep_b_sum_pv = b.rep_b_sum_pv,
                    a.register_amount = b.register_amount,a.register_pv = b.register_pv,a.register_new_amount = b.register_new_amount,
                    a.register_new_pv = b.register_new_pv,a.upgrade_amount = b.upgrade_amount,a.upgrade_pv = b.upgrade_pv,
                    a.upgrade_new_amount = b.upgrade_new_amount,a.upgrade_new_pv = b.upgrade_new_pv,
                    a.repurchase_amount = b.repurchase_amount,a.repurchase_pv = b.repurchase_pv,
                    a.repurchase_new_amount = b.repurchase_new_amount,a.repurchase_new_pv = b.repurchase_new_pv,
                    a.hi_fun_amount = b.hi_fun_amount,a.hi_fun_pv = b.hi_fun_pv,a.hi_fun_new_amount = b.hi_fun_new_amount,
                    a.hi_fun_new_pv = b.hi_fun_new_pv,a.mall_amount = b.mall_amount,a.mall_pv = b.mall_pv,
                    a.mall_new_amount = b.mall_new_amount,a.mall_new_pv = b.mall_new_pv,
                    a.register_blo_new_pv = b.register_blo_new_pv,a.upgrade_blo_new_pv = b.upgrade_blo_new_pv,
                    a.repurchase_blo_new_pv = b.repurchase_blo_new_pv,
                    a.hi_fun_blo_new_pv = b.hi_fun_blo_new_pv,a.mall_blo_new_pv = b.mall_blo_new_pv,
                    a.r_a_balance = b.r_a_balance,a.r_b_balance = b.r_b_balance,a.r_a_sum_amount = b.r_a_sum_amount,
                    a.r_b_sum_amount = b.r_b_sum_amount,a.r_a_sum_pv = b.r_a_sum_pv,a.r_b_sum_pv = b.r_b_sum_pv,
                    a.r_a_sum_real_amount = b.r_a_sum_real_amount,a.r_b_sum_real_amount = b.r_b_sum_real_amount,
                    a.r_a_sum_real_pv = b.r_a_sum_real_pv,a.r_b_sum_real_pv = b.r_b_sum_real_pv,
                    a.r_rep_a_balance = b.r_rep_a_balance,a.r_rep_b_balance = b.r_rep_b_balance,
                    a.r_rep_a_sum_amount = b.r_rep_a_sum_amount,a.r_rep_b_sum_amount = b.r_rep_b_sum_amount,
                    a.r_rep_a_sum_pv = b.r_rep_a_sum_pv,a.r_rep_b_sum_pv = b.r_rep_b_sum_pv,a.pk_country = b.pk_country
            WHEN NOT MATCHED THEN
                insert (period, pk_member, pk_rate, a_balance, b_balance, a_sum_amount,
                        b_sum_amount, a_sum_pv, b_sum_pv, a_new_amount, b_new_amount, a_new_pv,
                        b_new_pv, a_sum_real_amount, b_sum_real_amount, a_sum_real_pv, b_sum_real_pv,
                        rep_a_balance, rep_b_balance, rep_a_new_amount, rep_b_new_amount, rep_a_new_pv,
                        rep_b_new_pv, rep_a_sum_amount, rep_b_sum_amount, rep_a_sum_pv, rep_b_sum_pv,
                        register_amount, register_pv, register_new_amount, register_new_pv,
                        upgrade_amount, upgrade_pv, upgrade_new_amount, upgrade_new_pv,
                        repurchase_amount, repurchase_pv, repurchase_new_amount, repurchase_new_pv,
                        hi_fun_amount, hi_fun_pv, hi_fun_new_amount, hi_fun_new_pv,
                        mall_amount, mall_pv, mall_new_amount, mall_new_pv,
                        register_blo_new_pv, upgrade_blo_new_pv, repurchase_blo_new_pv, hi_fun_blo_new_pv,
                        mall_blo_new_pv,
                        r_a_balance, r_b_balance, r_a_sum_amount, r_b_sum_amount, r_a_sum_pv, r_b_sum_pv,
                        r_a_sum_real_amount, r_b_sum_real_amount, r_a_sum_real_pv, r_b_sum_real_pv,
                        r_rep_a_balance, r_rep_b_balance, r_rep_a_sum_amount, r_rep_b_sum_amount,
                        r_rep_a_sum_pv, r_rep_b_sum_pv, pk_country)
                    values (b.period, b.pk_member, b.pk_rate, b.a_balance, b.b_balance, b.a_sum_amount,
                            b.b_sum_amount, b.a_sum_pv, b.b_sum_pv, b.a_new_amount, b.b_new_amount, b.a_new_pv,
                            b.b_new_pv, b.a_sum_real_amount, b.b_sum_real_amount, b.a_sum_real_pv, b.b_sum_real_pv,
                            b.rep_a_balance, b.rep_b_balance, b.rep_a_new_amount, b.rep_b_new_amount, b.rep_a_new_pv,
                            b.rep_b_new_pv, b.rep_a_sum_amount, b.rep_b_sum_amount, b.rep_a_sum_pv, b.rep_b_sum_pv,
                            b.register_amount, b.register_pv, b.register_new_amount, b.register_new_pv,
                            b.upgrade_amount, b.upgrade_pv, b.upgrade_new_amount, b.upgrade_new_pv,
                            b.repurchase_amount, b.repurchase_pv, b.repurchase_new_amount, b.repurchase_new_pv,
                            b.hi_fun_amount, b.hi_fun_pv, b.hi_fun_new_amount, b.hi_fun_new_pv,
                            b.mall_amount, b.mall_pv, b.mall_new_amount, b.mall_new_pv,
                            b.register_blo_new_pv, b.upgrade_blo_new_pv, b.repurchase_blo_new_pv, b.hi_fun_blo_new_pv,
                            b.mall_blo_new_pv,
                            b.r_a_balance, b.r_b_balance, b.r_a_sum_amount, b.r_b_sum_amount, b.r_a_sum_pv,
                            b.r_b_sum_pv,
                            b.r_a_sum_real_amount, b.r_b_sum_real_amount, b.r_a_sum_real_pv, b.r_b_sum_real_pv,
                            b.r_rep_a_balance, b.r_rep_b_balance, b.r_rep_a_sum_amount, b.r_rep_b_sum_amount,
                            b.r_rep_a_sum_pv, b.r_rep_b_sum_pv, b.pk_country)
    </update>

    <update id="updateCuMemberSettleInitAchieve">
        update ${targetTableName} a
        set a.a_balance              = 0,
            a.b_balance              = 0,
            a.a_sum_amount           = 0,
            a.b_sum_amount           = 0,
            a.a_sum_pv               = 0,
            a.b_sum_pv               = 0,
            a.a_new_amount           = 0,
            a.b_new_amount           = 0,
            a.a_new_pv               = 0,
            a.b_new_pv               = 0,
            a.a_sum_real_amount      = 0,
            a.b_sum_real_amount      = 0,
            a.a_sum_real_pv          = 0,
            a.b_sum_real_pv          = 0,
            a.rep_a_balance          = 0,
            a.rep_b_balance          = 0,
            a.rep_a_new_amount       = 0,
            a.rep_b_new_amount       = 0,
            a.rep_a_new_pv           = 0,
            a.rep_b_new_pv           = 0,
            a.rep_a_sum_amount       = 0,
            a.rep_b_sum_amount       = 0,
            a.rep_a_sum_pv           = 0,
            a.rep_b_sum_pv           = 0,
            a.register_amount        = 0,
            a.register_pv            = 0,
            a.register_new_amount    = 0,
            a.register_new_pv        = 0,
            a.upgrade_amount         = 0,
            a.upgrade_pv             = 0,
            a.upgrade_new_amount     = 0,
            a.upgrade_new_pv         = 0,
            a.repurchase_amount      = 0,
            a.repurchase_pv          = 0,
            a.repurchase_new_amount  = 0,
            a.repurchase_new_pv      = 0,
            a.hi_fun_amount          = 0,
            a.hi_fun_pv              = 0,
            a.hi_fun_new_amount      = 0,
            a.hi_fun_new_pv          = 0,
            a.mall_amount            = 0,
            a.mall_pv                = 0,
            a.mall_new_amount        = 0,
            a.mall_new_pv            = 0,
            a.register_blo_new_pv    = 0,
            a.upgrade_blo_new_pv     = 0,
            a.repurchase_blo_new_pv  = 0,
            a.hi_fun_blo_new_pv      = 0,
            a.mall_blo_new_pv        = 0,
            a.net_first_achieve      = 0,
            a.net_repurchase_achieve = 0,
            a.min_achieve            = 0,
            a.round                  = 0,
            a.second                 = 1,
            a.r_a_balance            = 0,
            a.r_b_balance            = 0,
            a.r_a_sum_amount         = 0,
            a.r_b_sum_amount         = 0,
            a.r_a_sum_pv             = 0,
            a.r_b_sum_pv             = 0,
            a.r_rep_a_sum_amount     = 0,
            a.r_rep_b_sum_amount     = 0,
            a.r_rep_a_sum_pv         = 0,
            a.r_rep_b_sum_pv         = 0,
            a.r_a_sum_real_amount    = 0,
            a.r_b_sum_real_amount    = 0,
            a.r_a_sum_real_pv        = 0,
            a.r_b_sum_real_pv        = 0,
            a.r_rep_a_balance        = 0,
            a.r_rep_b_balance        = 0,
            a.A_NEW_BOX              = 0,
            a.B_NEW_BOX              = 0,
            a.A_SUM_BOX              = 0,
            a.B_SUM_BOX              = 0,
            a.TOTAL_NEW_BOX          = 0,
            a.TOTAL_SUM_BOX          = 0
    </update>

    <update id="updateCuMemberAchieve">
        merge into ${tableName} a
            using (select #{period} period, a.*
                   from (select user_id                              pk_member,
                                sum(CURR_DAY_MAIN_REG_AMOUNT) / 1    REGISTER_AMOUNT,
                                sum(CURR_DAY_MAIN_REG_PV) / 1        REGISTER_PV,
                                sum(CURR_DAY_MAIN_UP_AMOUNT) / 1     UPGRADE_AMOUNT,
                                sum(CURR_DAY_MAIN_UP_PV) / 1         UPGRADE_PV,
                                sum(CURR_DAY_MAIN_REPUR_AMOUNT) / 1  REPURCHASE_AMOUNT,
                                sum(CURR_DAY_MAIN_REPURCHASE_PV) / 1 REPURCHASE_PV,
                                sum(CURR_DAY_SEA2_REG_AMOUNT) / 1    HI_FUN_AMOUNT,
                                sum(CURR_DAY_SEA2_REG_PV) / 1        HI_FUN_PV,
                                sum(CURR_DAY_MALL_AMOUNT) / 1        MALL_AMOUNT,
                                sum(CURR_DAY_MALL_PV) / 1            MALL_PV
                         from G_MEMBER_ACHIV@link_test
                         where period between - 729 and #{period}
                         group by user_id) a) b on
                (a.pk_member = b.pk_member and a.period = b.period)
            when matched then update set a.REGISTER_AMOUNT = b.REGISTER_AMOUNT,
                a.REGISTER_PV = b.REGISTER_PV, a.UPGRADE_AMOUNT = b.UPGRADE_AMOUNT,
                a.UPGRADE_PV = b.UPGRADE_PV, a.REPURCHASE_AMOUNT = b.REPURCHASE_AMOUNT,
                a.REPURCHASE_PV = b.REPURCHASE_PV, a.HI_FUN_AMOUNT = b.HI_FUN_AMOUNT,
                a.HI_FUN_PV = b.HI_FUN_PV, a.MALL_AMOUNT = b.MALL_AMOUNT, a.MALL_PV = b.MALL_PV
    </update>

    <update id="createCuMemberMonthTable">
        create table ${tableName}
        (
            pk_member         NUMBER(20) not null,
            pk_parent         NUMBER(20) not null,
            pk_place_parent   NUMBER(20),
            place_dept        NUMBER(3),
            member_code       VARCHAR2(30) not null,
            member_name       VARCHAR2(100) not null,
            customer_type     NUMBER(2) not null,
            phone             VARCHAR2(40) not null,
            pk_grade          NUMBER(4) not null,
            pk_awards         NUMBER(4) not null,
            pk_team_code      NUMBER(20),
            pk_center_code    NUMBER(20),
            pk_vertex         NUMBER(20) default 1,
            pk_settle_country NUMBER(4) not null,
            a_sum_pv          NUMBER(17,6) default 0 not null,
            b_sum_pv          NUMBER(17,6) default 0 not null,
            rep_a_sum_pv      NUMBER(17,6) default 0 not null,
            rep_b_sum_pv      NUMBER(17,6) default 0 not null,
            register_pv       NUMBER(17,6) default 0 not null,
            upgrade_pv        NUMBER(17,6) default 0 not null,
            repurchase_pv     NUMBER(17,6) default 0 not null,
            hi_fun_pv         NUMBER(17,6) default 0 not null,
            mall_pv           NUMBER(17,6) default 0 not null
        )
    </update>
    <update id="mergeCuMemberMonth">
        merge into cu_member_month${date} a
            using (
                select a.*,
                       b.A_SUM_PV,
                       b.b_SUM_PV,
                       b.REGISTER_PV,
                       b.UPGRADE_PV,
                       b.REPURCHASE_PV,
                       b.HI_FUN_PV,
                       b.MALL_PV
                from (
                         select ct.pk_member,
                                ct.pk_parent,
                                ct.pk_place_parent,
                                ct.place_dept,
                                ct.member_code,
                                ct.member_name,
                                ct.customer_type,
                                ct.phone,
                                ct.pk_grade,
                                ct.pk_awards,
                                ct.pk_team_code,
                                ct.pk_center_code,
                                ct.pk_vertex,
                                ct.pk_settle_country
                         from cu_member_tree${date} ct
                         where period = #{period}) a
                         inner join(
                    select pk_member,
                           sum(A_NEW_PV + REP_A_NEW_PV) A_SUM_PV,
                           sum(b_NEW_PV + REP_B_NEW_PV) b_SUM_PV,
                           sum(register_new_pv)         REGISTER_PV,
                           sum(upgrade_new_pv)          UPGRADE_PV,
                           sum(repurchase_new_pv)       REPURCHASE_PV,
                           sum(hi_fun_new_pv)           HI_FUN_PV,
                           sum(mall_new_pv)             MALL_PV
                    from cu_member_achieve${date}
                    group by pk_member) b
                                   on a.pk_member = b.pk_member
            ) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.pk_parent = b.pk_parent,a.pk_place_parent = b.pk_place_parent,a.place_dept = b.place_dept,
                    a.member_code = b.member_code,a.member_name = b.member_name,a.customer_type = b.customer_type,
                    a.phone = b.phone,a.pk_grade = b.pk_grade,a.pk_awards = b.pk_awards,a.pk_team_code = b.pk_team_code,
                    a.pk_center_code = b.pk_center_code,a.pk_vertex = b.pk_vertex,a.pk_settle_country = b.pk_settle_country,
                    a.A_SUM_PV = b.A_SUM_PV,a.b_SUM_PV = b.b_SUM_PV,
                    a.REGISTER_PV = b.REGISTER_PV,a.UPGRADE_PV = b.UPGRADE_PV,
                    a.REPURCHASE_PV = b.REPURCHASE_PV,a.HI_FUN_PV = b.HI_FUN_PV,a.MALL_PV = b.MALL_PV
            WHEN NOT MATCHED THEN
                insert (pk_member, pk_parent, pk_place_parent, place_dept, member_code,
                        member_name, customer_type, phone, pk_grade, pk_awards, pk_team_code,
                        pk_center_code, pk_vertex, pk_settle_country, a_sum_pv, b_sum_pv,
                        register_pv, upgrade_pv, repurchase_pv,
                        hi_fun_pv, mall_pv)
                    values (b.pk_member, b.pk_parent, b.pk_place_parent, b.place_dept, b.member_code,
                            b.member_name, b.customer_type, b.phone, b.pk_grade, b.pk_awards, b.pk_team_code,
                            b.pk_center_code, b.pk_vertex, b.pk_settle_country, b.a_sum_pv, b.b_sum_pv,
                            b.register_pv, b.upgrade_pv, b.repurchase_pv,
                            b.hi_fun_pv, b.mall_pv)
    </update>
    <update id="chargeBackSaOrder">
        merge into ${targetTable} a
            using (
                select pk_member,
                       max(a.pk_rate)                               pk_rate,
                       sum(a_new_amount / bc.out_exchange_rate)     a_new_amount,
                       sum(a_new_pv)
                                                                    a_new_pv,
                       sum(b_new_amount / bc.out_exchange_rate)     b_new_amount,
                       sum(b_new_pv)                                b_new_pv,
                       sum(rep_a_new_amount / bc.out_exchange_rate) rep_a_new_amount,
                       sum(rep_b_new_amount / bc.out_exchange_rate)
                                                                    rep_b_new_amount,
                       sum(rep_a_new_pv)                            rep_a_new_pv,
                       sum(rep_b_new_pv)                            rep_b_new_pv,
                       sum(a_new_real_amount / bc.out_exchange_rate)
                                                                    a_new_real_amount,
                       sum(a_new_real_pv)                           a_new_real_pv,
                       sum(b_new_real_amount / bc.out_exchange_rate)
                                                                    b_new_real_amount,
                       sum(b_new_real_pv)                           b_new_real_pv
                from (
                         select pk_place_parent                                                     pk_member,
                                #{achieve.pkRate}                                                   pk_rate,
                                (case when place_dept = 1 then #{achieve.newAmount} else 0 end)     a_new_amount,
                                (case when place_dept = 1 then #{achieve.newPv} else 0 end)         a_new_pv,
                                (case when place_dept = 1 then #{achieve.repNewAmount} else 0 end)  rep_a_new_amount,
                                (case when place_dept = 1 then #{achieve.repNewPv} else 0 end)      rep_a_new_pv,
                                (case when place_dept = 1 then #{achieve.newRealAmount} else 0 end) a_new_real_amount,
                                (case when place_dept = 1 then #{achieve.newRealPv} else 0 end)     a_new_real_pv,
                                (case when place_dept = 2 then #{achieve.newAmount} else 0 end)     b_new_amount,
                                (case when place_dept = 2 then #{achieve.newPv} else 0 end)         b_new_pv,
                                (case when place_dept = 2 then #{achieve.repNewAmount} else 0 end)  rep_b_new_amount,
                                (case when place_dept = 2 then #{achieve.repNewPv} else 0 end)      rep_b_new_pv,
                                (case when place_dept = 2 then #{achieve.newRealAmount} else 0 end) b_new_real_amount,
                                (case when place_dept = 2 then #{achieve.newRealPv} else 0 end)     b_new_real_pv
                         from (
                                  select pk_place_parent, place_dept
                                  from (
                                           select *
                                           from (select *
                                                 from ${sourceTable}
                                                 where period = #{period}) start with pk_member = #{achieve.pkMember}
                                           connect by pk_member = prior pk_place_parent
                                       )
                                  where nvl(pk_place_parent, 0) ! = 0
                              )
                     ) a
                         inner join bd_currency bc
                                    on a.pk_rate = bc.pk_id
                group by pk_member
            ) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.a_sum_amount = a.a_sum_amount - b.a_new_amount,
                    a.b_sum_amount = a.b_sum_amount - b.b_new_amount,
                    a.a_sum_pv = a.a_sum_pv - b.a_new_pv,
                    a.b_sum_pv = a.b_sum_pv - b.b_new_pv,
                    a.rep_a_sum_amount = a.rep_a_sum_amount - b.rep_a_new_amount,
                    a.rep_b_sum_amount = a.rep_b_sum_amount - b.rep_b_new_amount,
                    a.rep_a_sum_pv = a.rep_a_sum_pv - b.rep_a_new_pv,
                    a.rep_b_sum_pv = a.rep_b_sum_pv - b.rep_b_new_pv,
                    a.a_sum_real_amount = a.a_sum_real_amount - b.a_new_amount - b.rep_a_new_amount,
                    a.b_sum_real_amount = a.b_sum_real_amount - b.b_new_amount - b.rep_b_new_amount,
                    a.a_sum_real_pv = a.a_sum_real_pv - b.a_new_pv - b.rep_a_new_pv,
                    a.b_sum_real_pv = a.b_sum_real_pv - b.b_new_pv - b.rep_b_new_pv,
                    a.r_a_sum_amount = a.r_a_sum_amount - b.a_new_amount,
                    a.r_b_sum_amount = a.r_b_sum_amount - b.b_new_amount,
                    a.r_a_sum_pv = a.r_a_sum_pv - b.a_new_pv,
                    a.r_b_sum_pv = a.r_b_sum_pv - b.b_new_pv,
                    a.r_rep_a_sum_amount = a.r_rep_a_sum_amount - b.rep_a_new_amount,
                    a.r_rep_b_sum_amount = a.r_rep_b_sum_amount - b.rep_b_new_amount,
                    a.r_rep_a_sum_pv = a.r_rep_a_sum_pv - b.rep_a_new_pv,
                    a.r_rep_b_sum_pv = a.r_rep_b_sum_pv - b.rep_b_new_pv,
                    a.r_a_sum_real_amount = a.r_a_sum_real_amount - b.a_new_amount - b.rep_a_new_amount,
                    a.r_b_sum_real_amount = a.r_b_sum_real_amount - b.b_new_amount - b.rep_b_new_amount,
                    a.r_a_sum_real_pv = a.r_a_sum_real_pv - b.a_new_pv - b.rep_a_new_pv,
                    a.r_b_sum_real_pv = a.r_b_sum_real_pv - b.b_new_pv - b.rep_b_new_pv
    </update>

    <update id="updateCuMemberNetAchieve">
        merge into ${tableName} a
        using (
        <foreach collection="updMemberAchieveExtList" item="achieve" open=" " separator=" union " close=" ">
            select #{achieve.pkMember} pk_member,
            #{achieve.aSumRealPv} a_sum_real_pv,#{achieve.bSumRealPv} b_sum_real_pv,
            #{achieve.repANewPv} rep_a_sum_pv,#{achieve.repBNewPv} rep_b_sum_pv,
            #{achieve.netFirstAchieve} net_first_achieve,#{achieve.netRepurchaseAchieve} net_repurchase_achieve
            from dual
        </foreach>
        ) b
        on (a.pk_member = b.pk_member)
        when matched then
        update set
        a.a_sum_real_pv=a.a_sum_real_pv+b.a_sum_real_pv,
        a.b_sum_real_pv=a.b_sum_real_pv+b.b_sum_real_pv,
        a.rep_a_new_pv=b.rep_a_sum_pv,a.rep_b_new_pv=b.rep_b_sum_pv,
        a.net_first_achieve=a.net_first_achieve+b.net_first_achieve,
        a.net_repurchase_achieve=a.net_repurchase_achieve+b.net_repurchase_achieve
    </update>

    <update id="mergeCuMemberSettleByAchieveLogByDate">
        merge into ${targetTable} a
            using (select a.pk_member,
                          (a.a_sum_real_pv - b.a_sum_real_pv)              a_sum_real_pv,
                          (a.b_sum_real_pv - b.b_sum_real_pv)              b_sum_real_pv,
                          (a.a_sum_pv - b.a_sum_pv)                        a_sum_pv,
                          (a.b_sum_pv - b.b_sum_pv)                        b_sum_pv,
                          (case
                               when a.a_balance - b.a_balance &lt; 0 then 0
                               else a.a_balance - b.a_balance end)         a_balance,
                          (case
                               when a.b_balance - b.b_balance &lt; 0 then 0
                               else a.b_balance - b.b_balance end)         b_balance,
                          (a.rep_a_sum_pv - b.rep_a_sum_pv)                rep_a_sum_pv,
                          (a.rep_b_sum_pv - b.rep_b_sum_pv)                rep_b_sum_pv,
                          (case
                               when a.rep_a_balance - b.rep_a_balance &lt; 0 then 0
                               else a.rep_a_balance - b.rep_a_balance end) rep_a_balance,
                          (case
                               when a.rep_b_balance - b.rep_b_balance &lt; 0 then 0
                               else a.rep_b_balance - b.rep_b_balance end) rep_b_balance
                   from ${targetTable} a
                            inner join(
                       select pk_member,
                              sum(a_sum_real_pv) a_sum_real_pv,
                              sum(B_SUM_REAL_PV) B_SUM_REAL_PV,
                              sum(A_SUM_PV)      A_SUM_PV,
                              sum(B_SUM_PV)      B_SUM_PV,
                              sum(A_BALANCE)     A_BALANCE,
                              sum(B_BALANCE)     B_BALANCE,
                              sum(REP_A_SUM_PV)  REP_A_SUM_PV,
                              sum(REP_B_SUM_PV)  REP_B_SUM_PV,
                              sum(REP_A_BALANCE) REP_A_BALANCE,
                              sum(REP_B_BALANCE) REP_B_BALANCE
                       from (
                                select pk_id,
                                       pk_member,
                                       pk_country,
                                       (case infusing_water_type
                                            when 1 then a_sum_real_modify_pv
                                            when 2 then -a_sum_real_modify_pv
                                            else a_sum_real_modify_pv - a_sum_real_pv end)   a_sum_real_pv,
                                       (case infusing_water_type
                                            when 1 then B_SUM_REAL_MODIFY_PV
                                            when 2 then -B_SUM_REAL_MODIFY_PV
                                            else B_SUM_REAL_MODIFY_PV - B_SUM_REAL_PV end)   B_SUM_REAL_PV,
                                       (case infusing_water_type
                                            when 1 then A_FIRST_MODIFY_PV
                                            when 2 then -A_FIRST_MODIFY_PV
                                            else A_FIRST_MODIFY_PV - A_SUM_PV end)           A_SUM_PV,
                                       (case infusing_water_type
                                            when 1 then B_FIRST_MODIFY_PV
                                            when 2 then -B_FIRST_MODIFY_PV
                                            else B_FIRST_MODIFY_PV - B_SUM_PV end)           B_SUM_PV,
                                       (case infusing_water_type
                                            when 1 then REP_A_FIRST_MODIFY_BALANCE
                                            when 2 then -REP_A_FIRST_MODIFY_BALANCE
                                            else REP_A_FIRST_MODIFY_BALANCE - A_BALANCE end) A_BALANCE,
                                       (case infusing_water_type
                                            when 1 then REP_B_FIRST_MODIFY_BALANCE
                                            when 2 then -REP_B_FIRST_MODIFY_BALANCE
                                            else REP_B_FIRST_MODIFY_BALANCE - B_BALANCE end) B_BALANCE,
                                       (case infusing_water_type
                                            when 1 then REP_A_MODIFY_SUM_PV
                                            when 2 then -REP_A_MODIFY_SUM_PV
                                            else REP_A_MODIFY_SUM_PV - REP_A_SUM_PV end)     REP_A_SUM_PV,
                                       (case infusing_water_type
                                            when 1 then REP_B_MODIFY_SUM_PV
                                            when 2 then -REP_B_MODIFY_SUM_PV
                                            else REP_B_MODIFY_SUM_PV - REP_B_SUM_PV end)     REP_B_SUM_PV,
                                       (case infusing_water_type
                                            when 1 then REP_A_MODIFY_BALANCE
                                            when 2 then -REP_A_MODIFY_BALANCE
                                            else REP_A_MODIFY_BALANCE - REP_A_BALANCE end)   REP_A_BALANCE,
                                       (case infusing_water_type
                                            when 1 then REP_B_MODIFY_BALANCE
                                            when 2 then -REP_B_MODIFY_BALANCE
                                            else REP_B_MODIFY_BALANCE - REP_B_BALANCE end)   REP_B_BALANCE
                                from cu_member_achieve_log
                                where creation_time >= to_date('2025-02-01', 'yyyy-mm-dd')
                                  and APPROVE_STATUS = 5
                                  and del_flag = 0
                                  and due_date = #{settleDate,jdbcType=DATE}
                            )
                       group by pk_member
                   ) b
                                      on b.pk_member = a.pk_member) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.a_sum_real_pv = b.a_sum_real_pv, a.b_sum_real_pv = b.b_sum_real_pv,
                    a.a_sum_pv = b.a_sum_pv, a.b_sum_pv = b.b_sum_pv,
                    a.a_balance = b.a_balance, a.b_balance = b.b_balance,
                    a.rep_a_sum_pv = b.rep_a_sum_pv, a.rep_b_sum_pv = b.rep_b_sum_pv,
                    a.rep_a_balance = b.rep_a_balance, a.rep_b_balance = b.rep_b_balance
    </update>

    <update id="updateCuMemberExpandSettleAchieveByBeforeDay">
        merge into ${targetTable} a
            using (select pk_member, a_balance, b_balance, min_achieve, round, second
                   from ${sourceTable}) b
            on (a.pk_member = b.pk_member)
            when matched then
                update set
                    a.a_balance = b.a_balance,a.b_balance = b.b_balance,
                    a.min_achieve = b.min_achieve,a.round = b.round,a.second = b.second
    </update>

    <select id="queryCuMemberAchieveByPkMember" resultMap="CuMemberAchieve">
        SELECT PK_MEMBER,
               PK_RATE,
               A_BALANCE,
               B_BALANCE,
               A_SUM_PV,
               B_SUM_PV,
               A_SUM_REAL_PV,
               B_SUM_REAL_PV,
               REP_A_BALANCE,
               REP_B_BALANCE,
               REP_A_NEW_PV,
               REP_B_NEW_PV,
               REP_A_SUM_PV,
               REP_B_SUM_PV,
               PK_COUNTRY
        FROM ${tableName}
        WHERE (pk_member = #{pkMember} AND pk_country = #{pkCountry})
    </select>
    <select id="queryCuMemberUnderBloodAchieveByPkMember" resultType="java.math.BigDecimal">
        select sum(REGISTER_PV + UPGRADE_PV + REPURCHASE_PV + HI_FUN_PV + MALL_PV) pv
        from ${achieveTable}
        where pk_member in (
            select pk_member
            from ${treeTable}
            where pk_member != #{pkMember}
        start with pk_member = #{pkMember}
        connect by pk_parent = prior pk_member) and period >= #{period}
    </select>


    <select id="selectNewAddAchieve" resultType="com.hzs.bonus.achieve.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}
        <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>


    <select id="selectAwardsByPkMember" resultType="com.hzs.bonus.achieve.vo.CuMemberAwardsUnderVO">
        select s.pk_member,
               s.a_sum_real_pv aSumRealPv,
               s.b_sum_real_pv bSumRealPv,
               s.member_name   memberName,
               s.pk_awards     pkAwards
        from ${settleTable} s
        where s.pay_status = 1
          and s.category = 0
          and s.pk_country = #{pkCountry}
          and s.pk_member = #{pkMember}
    </select>


    <select id="selectUnderMemberAwards" resultType="com.hzs.bonus.achieve.vo.CuMemberAwardsUnderVO">
        select pk_member,
               a_sum_real_pv aSumRealPv,
               b_sum_real_pv bSumRealPv,
               head_path     memberPath,
               member_name   memberName,
               pk_awards     pkAwards
        from (select a.pk_member,
                     b.pk_awards,
                     a.a_sum_real_pv,
                     a.b_sum_real_pv,
                     b.head_path,
                     a.member_name
              from ${settleTable} a
                       inner join (select mt.pk_id,
                                          mt.pk_place_parent,
                                          mt.pk_awards,
                                          mt.head_path
                                   from (select m.pk_id,
                                                m.pk_place_parent,
                                                m.place_dept,
                                                m.pk_awards,
                                                m.head_path
                                         from cu_member m
                                         where m.del_flag = 0
                                           and m.pk_settle_country = #{pkCountry}) mt
                                       start
                                   with mt.pk_id =
                                       (select t.pk_id
                                       from cu_member t
                                       where t.category = 0
                                       and t.del_flag = 0
                                       and t.pk_settle_country = #{pkCountry}
                                       and t.pk_place_parent = #{pkMember}
                                       and t.place_dept = #{placeDept})
                                   connect by prior mt.pk_id = mt.pk_place_parent) b
                                  on a.pk_member = b.pk_id
              where a.pk_country = #{pkCountry}
                and a.pay_status = 1
                and a.category = 0
              order by b.pk_awards desc, a.a_sum_real_pv desc) tt
        where rownum &lt;= 5
    </select>


    <select id="selectNewAddAchieveContrast" resultType="com.hzs.bonus.achieve.vo.CuMemberMonthAchieveContrastVO">
        select sum(a.a_new_pv + a.rep_a_new_pv) / 10000 aNewPv, sum(a.b_new_pv + a.rep_b_new_pv) / 10000 bNewPv
        from ${achieveTable} a
        where a.pk_member = #{pkMember}
          and a.pk_country = #{pkCountry}
    </select>

    <select id="selectExistTable" resultType="Integer">
        select count(1)
        from user_tables t
        where t.table_name = upper('${achieveTable}')
    </select>


    <select id="selectByParent" resultType="decimal">
        select sum(a.REGISTER_PV) registerPv
        from ${achieveTable} a
        where
        a.pk_country = #{pkCountry}
        <if test="memberIds != null">
            and a.PK_MEMBER in
            <foreach item="pkMember" collection="memberIds" open="(" separator="," close=")">
                #{pkMember}
            </foreach>
        </if>
        group by a.PK_MEMBER
        order by registerPv desc
    </select>

    <select id="queryMemberMonthAchieve" resultType="com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt">
        select * from(
        <foreach collection="monthList" item="item" separator=" union ">
            select ${item} month,bc.out_exchange_rate,cm.pk_settle_country,member_name,bg.pk_transaction
            pk_grade,ba.pk_transaction pk_awards,
            cm.A_SUM_PV,cm.B_SUM_PV,cm.REP_A_SUM_PV,cm.REP_B_SUM_PV,nvl((a.REGISTER_PV+a.UPGRADE_PV), 0) firstAchieve,
            nvl((a.REPURCHASE_PV+a.HI_FUN_PV+a.MALL_PV), 0) repurchaseAchieve from cu_member_month${item} cm
            inner join(
            select #{pkMember} pk_member,sum(REGISTER_PV) REGISTER_PV,
            sum(UPGRADE_PV) UPGRADE_PV,
            sum(REPURCHASE_PV) REPURCHASE_PV,
            sum(HI_FUN_PV) HI_FUN_PV,
            sum(MALL_PV) MALL_PV from cu_member_month${item}
            start with pk_parent = #{pkMember}
            connect by pk_parent = prior pk_member)a
            on cm.pk_member = a.pk_member
            left join bd_grade bg
            on bg.pk_id=cm.pk_grade
            left join bd_awards ba
            on ba.pk_id=cm.pk_awards
            left join bd_currency bc
            on bc.pk_country = cm.pk_settle_country
        </foreach>)
        order by month desc
    </select>
    <select id="queryMemberMonthAchieveDetail" resultType="com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt">
        select * from(
        <foreach collection="memberList" item="item" separator=" union ">
            select bc.out_exchange_rate,cm.pk_settle_country,cm.member_code,member_name,bg.pk_transaction pk_grade,
            cm.pk_grade grade,ba.pk_transaction pk_awards,cm.pk_awards awards,
            cm.A_SUM_PV,cm.B_SUM_PV,cm.REP_A_SUM_PV,cm.REP_B_SUM_PV,(a.REGISTER_PV+a.UPGRADE_PV) firstAchieve,
            (a.REPURCHASE_PV+a.HI_FUN_PV+a.MALL_PV) repurchaseAchieve from cu_member_month${monthAchieveParam.month} cm
            inner join(
            select #{item} pk_member,sum(REGISTER_PV) REGISTER_PV,
            sum(UPGRADE_PV) UPGRADE_PV,
            sum(REPURCHASE_PV) REPURCHASE_PV,
            sum(HI_FUN_PV) HI_FUN_PV,
            sum(MALL_PV) MALL_PV from cu_member_month${monthAchieveParam.month}
            start with pk_member = #{item}
            connect by pk_parent = prior pk_member)a
            on cm.pk_member = a.pk_member
            left join bd_grade bg
            on bg.pk_id=cm.pk_grade
            left join bd_awards ba
            on ba.pk_id=cm.pk_awards
            left join bd_currency bc
            on bc.pk_country = cm.pk_settle_country
        </foreach>
        ) a
        where 1=1
        <if test="monthAchieveParam.memberCode != null and monthAchieveParam.memberCode != ''">
            and a.member_code = #{monthAchieveParam.memberCode}
        </if>
        <if test="monthAchieveParam.memberName != null and monthAchieveParam.memberName != ''">
            and a.member_name = #{monthAchieveParam.memberName}
        </if>
        <if test="monthAchieveParam.pkGrade != null">
            and a.grade = #{monthAchieveParam.pkGrade}
        </if>
        <if test="monthAchieveParam.pkAwards != null">
            and a.awards = #{monthAchieveParam.pkAwards}
        </if>
    </select>
    <select id="queryPkMemberMonthAchieve" resultType="java.lang.Long">
        select pk_member
        from cu_member_month${month}
        where pk_parent = #{pkMember}
    </select>

    <select id="queryPlaceParentMemberMonthAchieve"
            resultType="com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt">
        select so.pk_member,so.order_type,cm.member_code,cm.member_name,
        so.order_achieve,bc.out_exchange_rate,bg.pk_transaction pk_grade,
        cm.pk_grade grade,ba.pk_transaction pk_awards,cm.pk_awards awards,cm.pk_settle_country from sa_order so
        inner join(
        select pk_member,member_code,member_name,PK_GRADE,PK_AWARDS,pk_settle_country from cu_member_month${month}
        start with pk_place_parent = #{pkMember} and place_dept=#{placeDept}
        connect by pk_place_parent = prior pk_member) cm
        on so.pk_member=cm.pk_member
        left join bd_grade bg
        on bg.pk_id=cm.pk_grade
        left join bd_awards ba
        on ba.pk_id=cm.pk_awards
        left join bd_currency bc
        on bc.pk_country = cm.pk_settle_country
        where so.del_flag = 0 and so.order_status=1 and so.pay_time >= #{startDate, jdbcType=DATE}
        and so.pay_time &lt; #{endDate, jdbcType=DATE}
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="pk_grade != null">
            and cm.PK_GRADE = #{pk_grade}
        </if>
        <if test="pk_awards != null">
            and cm.PK_AWARDS = #{pk_awards}
        </if>
        order by so.creation_time desc
    </select>

    <select id="queryParentMemberMonthAchieve" resultType="com.hzs.common.domain.member.achieve.ext.CuMemberAchieveExt">
        select so.pk_member,so.order_type,cm.member_code,cm.member_name,
        so.order_achieve,bc.out_exchange_rate,bg.pk_transaction pk_grade,
        cm.pk_grade grade,ba.pk_transaction pk_awards,cm.pk_awards awards,cm.pk_settle_country from sa_order so
        inner join(
        select pk_member,member_code,member_name,PK_GRADE,PK_AWARDS,pk_settle_country from cu_member_month${month}
        start with pk_parent = #{pkMember}
        connect by pk_parent = prior pk_member) cm
        on so.pk_member=cm.pk_member
        left join bd_grade bg
        on bg.pk_id=cm.pk_grade
        left join bd_awards ba
        on ba.pk_id=cm.pk_awards
        left join bd_currency bc
        on bc.pk_country = cm.pk_settle_country
        where so.del_flag = 0 and so.order_status=1 and so.pay_time >= #{startDate, jdbcType=DATE}
        and so.pay_time &lt; #{endDate, jdbcType=DATE}
        <if test="memberCode != null and memberCode != ''">
            and cm.member_code = #{memberCode}
        </if>
        <if test="memberName != null and memberName != ''">
            and cm.member_name = #{memberName}
        </if>
        <if test="pk_grade != null">
            and cm.PK_GRADE = #{pk_grade}
        </if>
        <if test="pk_awards != null">
            and cm.PK_AWARDS = #{pk_awards}
        </if>
        order by so.creation_time desc
    </select>

    <select id="queryCuMemberMonthAchieveByMemberIdList" resultMap="CuMemberAchieve">
        select pk_member,pk_country,register_blo_new_pv,upgrade_blo_new_pv,repurchase_blo_new_pv from ${settleTableName}
        where pk_member in
        <foreach collection="memberSwingNetExtList" item="item" open="(" close=")" separator=",">
            #{item.pkSourceMember}
        </foreach>
    </select>

</mapper>
