period NUMBER(6) default 0 not null, 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, account_status number(1) default 0 not null, pay_status NUMBER(2) default 0 not null, register_authority number(2) default 0 not null, category number(2) default 0 not null, purchase_type number(2) default 0 not null, purchase_status number(2) default 0 not null, share_status number(2) default 0 not null, income_status number(2) default 0 not null, pk_team_code number(20), pk_center_code number(20), pk_vertex number(20), pk_settle_country number(4) not null, is_real_name NUMBER(1) default 1 not null, is_bus_license NUMBER(1) default 1 not null, is_maker_space NUMBER(1) default 1 not null, pk_country number(4) default 1 not null, store_level NUMBER(2) default 0, is_maker_gift NUMBER(1) default 1, expire_status number(1) default 1 , , pk_rate NUMBER(6) , 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, min_achieve number(17,6) default 0 not null, round NUMBER(6) default 0 not null, second NUMBER(4) default 1 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 select pk_member, pk_parent, member_code, member_name, a.pk_awards, account_status, a.register_authority, customer_type, income_status, pk_settle_country, purchase_status, share_status, is_maker_space, a_balance, b_balance, r_a_balance, r_b_balance, rep_a_balance, rep_b_balance, r_rep_a_balance, r_rep_b_balance, register_amount, register_pv, upgrade_amount, upgrade_pv, repurchase_amount, repurchase_pv, hi_fun_amount, hi_fun_pv, mall_amount, mall_pv, category, pk_grade, pk_center_code, min_achieve, round, second, bg.grade_value, store_level, expire_status from ( ) a inner join bd_grade bg on a.pk_grade = bg.pk_id net_first_achieve NUMBER(17,6) default 0 not null, net_repurchase_achieve 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 CREATE OR REPLACE TRIGGER ${tableName}_TRIG BEFORE INSERT OR UPDATE ON ${tableName} FOR EACH ROW DECLARE v_newVal NUMBER(12) := 0; v_incval NUMBER(12) := 0; BEGIN IF INSERTING AND :new.pk_id IS NULL THEN SELECT ${tableNameSeq}.NEXTVAL INTO v_newVal FROM DUAL; IF v_newVal = 1 THEN SELECT NVL(max(pk_id), 0) INTO v_newVal FROM ${tableName}; v_newVal := v_newVal + 1; LOOP EXIT WHEN v_incval >= v_newVal; SELECT ${tableNameSeq}.nextval INTO v_incval FROM dual; END LOOP; END IF; :new .pk_id := v_newVal; END IF; END; select pk_member, pk_parent, member_code, member_name, pk_awards, register_authority, customer_type, account_status, income_status, pk_settle_country, purchase_status, share_status, is_maker_space, a_balance, b_balance, r_a_balance, r_b_balance, rep_a_balance, rep_b_balance, r_rep_a_balance, r_rep_b_balance, register_amount, register_pv, upgrade_amount, upgrade_pv, repurchase_amount, repurchase_pv, hi_fun_amount,hi_fun_pv,mall_amount,mall_pv, pk_center_code, category,pk_grade, min_achieve, round, second, store_level, expire_status from ${settleTableName} where pay_status = 1 start with pk_member = #{item} connect by pk_member = prior pk_parent insert into ${settleTableName}(pk_member, pk_parent, pk_place_parent, place_dept, member_code, member_name, customer_type, phone, pk_grade, pk_awards, account_status, pay_status, register_authority, category, purchase_type, purchase_status, share_status, income_status, pk_team_code, is_maker_space, pk_center_code, pk_vertex, pk_settle_country, is_real_name, pk_country, pk_rate, store_level, is_maker_gift, expire_status) select cm.pk_id, pk_parent, pk_place_parent, place_dept, member_code, member_name, customer_type, phone, pk_settle_grade, pk_awards, account_status, pay_status, register_authority, category, (case when purchase_status = 0 then 1 else 0 end) purchase_type, purchase_status, share_status, income_status, pk_team_code, is_maker_space, pk_center_code, pk_vertex, pk_settle_country, is_real_name, cm.pk_country, nvl(bc.pk_id, -1) pk_rate, nvl(b.store_level, 0) store_level, cm.is_maker_gift, cm.expire_status from cu_member cm left join ( select pk_country, max(pk_id) pk_id from bd_currency where del_flag = 0 and pk_country = 1 and enable_state = 0 and effective_date <= sysdate group by pk_country) bc on cm.pk_settle_country = bc.pk_country left join( select pk_member, store_level from cu_maker_space where del_flag = 0 and approve_status = 5 and apply_status = 5 and store_type = 1 ) b on cm.pk_id = b.pk_member where cm.del_flag = 0 and cm.system_type = 0 insert into ${targetTableName}(period, pk_member, pk_parent, pk_place_parent, place_dept, member_code, member_name, customer_type, phone, pk_grade, pk_awards, account_status, pay_status, register_authority, category, purchase_type, purchase_status, share_status, income_status, pk_team_code, pk_center_code, pk_vertex, pk_settle_country, is_real_name, is_bus_license, is_maker_space, pk_country) select #{period} period, pk_member, pk_parent, pk_place_parent, place_dept, member_code, member_name, customer_type, phone, pk_grade, pk_awards, account_status, pay_status, register_authority, category, purchase_type, purchase_status, share_status, income_status, pk_team_code, pk_center_code, pk_vertex, pk_settle_country, is_real_name, is_bus_license, is_maker_space, pk_country from ${sourceTableName} create table ${tableName} ( pk_id NUMBER(20) primary key, ) create table ${tableName} ( ) create table ${tableName} ( pk_member NUMBER(20) not null, pk_country number(4) default 1 not null, expire_status number(1) default 1, ) create index ${tableName}_parent on ${tableName} ( pk_parent ) create index ${tableName}_place on ${tableName} ( pk_place_parent, place_dept ) create unique index ${tableName}_PK_M on ${tableName} ( PK_MEMBER, period ) create unique index ${tableName}_PK_M on ${tableName} ( PK_MEMBER ) update ${settleTableName} set customer_type = 2, category = 1 where pk_member in #{item.pkMember} merge into ${updateTableName} a using ( select pk_member, max(new_level) pk_awards from cu_member_awards where period = #{period} and del_flag = 0 group by pk_member) b on (a.pk_member = b.pk_member) when matched then update set a.pk_awards = b.pk_awards insert into ${settleTableName}(pk_member, PK_PARENT, PK_PLACE_PARENT, PLACE_DEPT, MEMBER_CODE, member_name, CUSTOMER_TYPE, PHONE, PK_GRADE, PK_AWARDS, ACCOUNT_STATUS, PAY_STATUS, REGISTER_AUTHORITY, CATEGORY, PURCHASE_TYPE, PURCHASE_STATUS, SHARE_STATUS, INCOME_STATUS, PK_TEAM_CODE, PK_CENTER_CODE, PK_VERTEX, PK_SETTLE_COUNTRY, IS_REAL_NAME, IS_BUS_LICENSE, IS_MAKER_SPACE, PK_COUNTRY, 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, MIN_ACHIEVE, ROUND, SECOND) select ca.pk_member, ca.PK_PARENT, ca.PK_PLACE_PARENT, ca.PLACE_DEPT, ca.MEMBER_CODE, ca.member_name, ca.CUSTOMER_TYPE, ca.PHONE, PK_GRADE, PK_AWARDS, ACCOUNT_STATUS, PAY_STATUS, REGISTER_AUTHORITY, CATEGORY, PURCHASE_TYPE, PURCHASE_STATUS, SHARE_STATUS, INCOME_STATUS, PK_TEAM_CODE, PK_CENTER_CODE, PK_VERTEX, ca.PK_SETTLE_COUNTRY, IS_REAL_NAME, IS_BUS_LICENSE, IS_MAKER_SPACE, ca.PK_COUNTRY, 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, 0 MIN_ACHIEVE, 0 ROUND, 1 SECOND from ${achieveTableName} ct inner join ${treeTableName} ca on ca.pk_member = ct.pk_member and ca.period = ct.period where ca.period = #{period} insert into ${settleTableName}(pk_member, pk_parent, member_code, member_name, customer_type, phone, pk_grade, pk_awards, pk_range_awards, pk_benefit_awards, account_status, pay_status, register_authority, category, purchase_status, income_status, pk_team_code, pk_center_code, pk_vertex, pk_settle_country, is_real_name, pk_country, pk_rate, assess_status, month_member, range_store_status, pay_time) select cm.pk_id, pk_parent, member_code, member_name, customer_type, phone, pk_settle_grade, cm.pk_awards, pk_range_awards, pk_benefit_awards, account_status, pay_status, register_authority, category, purchase_status, income_status, pk_team_code, pk_center_code, pk_vertex, pk_settle_country, is_real_name, cm.pk_country, nvl(bc.pk_id, -1) pk_rate, (case when nvl(ca.assess_status, 2) = 1 then 0 else nvl(ca.assess_status, 2) end) assess_status, (case when pay_time > #{firstDate,jdbcType=DATE} then 0 else 1 end) month_member, nvl(cs.status, 0) range_store_status, cm.pay_time from cu_member cm left join ( select pk_country, max(pk_id) pk_id from bd_currency where del_flag = 0 and pk_country = 1 and enable_state = 0 and effective_date <= sysdate group by pk_country) bc on cm.pk_settle_country = bc.pk_country left join cu_range_store cs on cs.pk_member = cm.pk_id and cs.del_flag = 0 left join cu_member_assess${year} ca on ca.pk_member = cm.pk_id and ca.period = #{period} and ca.assess_type = 0 where cm.del_flag = 0 and cm.system_type = 1 merge into ${updateTableName} a using (select pk_member, pk_awards from tmp_cu_member_awards) b on (a.pk_member = b.pk_member) when matched then update set a.pk_awards = b.pk_awards where period >= #{period} merge into ${settleTableName} a using ( select pk_member, max(purchase_type) purchase_type from ( select pk_id pk_member, 2 purchase_type from cu_member where del_flag = 0 and category = 0 and pay_status = 1 and pay_time >= #{startDate, jdbcType=DATE} and pay_time < #{endDate, jdbcType=DATE} union select pk_member, 3 purchase_type from cu_member_awards where del_flag = 0 and purchase_status = 0 and creation_time >= #{startDate, jdbcType=DATE} and creation_time < #{endDate, jdbcType=DATE}) group by pk_member ) b on (a.pk_member = b.pk_member) when matched then update set a.purchase_status = 0,a.purchase_type = b.purchase_type merge into ${settleTableName} a using( select * from ( select #{item.pkMember} pk_member, #{item.aBalance} a_balance, #{item.bBalance} b_balance, #{item.aNewAmount} a_new_amount, #{item.bNewAmount} b_new_amount, #{item.aNewPv} a_new_pv, #{item.bNewPv} b_new_pv, #{item.repABalance} rep_a_balance, #{item.repBBalance} rep_b_balance, #{item.repANewAmount} rep_a_new_amount, #{item.repBNewAmount} rep_b_new_amount, #{item.repANewPv} rep_a_new_pv, #{item.repBNewPv} rep_b_new_pv, #{item.registerAmount} register_amount, #{item.registerPv} register_pv, #{item.registerNewAmount} register_new_amount, #{item.registerNewPv} register_new_pv, #{item.upgradeAmount} upgrade_amount, #{item.upgradePv} upgrade_pv, #{item.upgradeNewAmount} upgrade_new_amount ,#{item.upgradeNewPv} upgrade_new_pv, #{item.repurchaseAmount} repurchase_amount, #{item.repurchasePv} repurchase_pv, #{item.repurchaseNewAmount} repurchase_new_amount, #{item.repurchaseNewPv} repurchase_new_pV, #{item.hiFunAmount} hi_fun_amount, #{item.hiFunPv} hi_fun_pv, #{item.hiFunNewAmount} hi_fun_new_amount, #{item.hiFunNewPv} hi_fun_new_pv, #{item.mallAmount} mall_amount, #{item.mallPv} mall_pv, #{item.mallNewAmount} mall_new_amount, #{item.mallNewPv} mall_new_pv, #{item.registerBloNewPv} register_blo_new_pv, #{item.upgradeBloNewPv} upgrade_blo_new_pv, #{item.repurchaseBloNewPv} repurchase_blo_new_pv, #{item.hiFunBloNewPv} hi_fun_blo_new_pv, #{item.mallBloNewPv} mall_blo_new_pv, #{item.rABalance} r_a_balance, #{item.rBBalance} r_b_balance, #{item.rRepABalance} r_rep_a_balance, #{item.rRepBBalance} r_rep_b_balance, #{item.minAchieve} min_achieve, #{item.round} round, #{item.second} second from dual ) ) 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_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.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.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_rep_a_balance = b.r_rep_a_balance, a.r_rep_b_balance = b.r_rep_b_balance, a.min_achieve = b.min_achieve, a.round = b.round, a.second = b.second, 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 merge into ${settleTableName} a using( select #{item.pkMember} pk_member, #{item.aBalance} a_balance, #{item.bBalance} b_balance, #{item.aNewAmount} a_new_amount,#{item.bNewAmount} b_new_amount, #{item.aNewPv} a_new_pv, #{item.bNewPv} b_new_pv, #{item.repABalance} rep_a_balance, #{item.repBBalance} rep_b_balance, #{item.repANewAmount} rep_a_new_amount, #{item.repBNewAmount} rep_b_new_amount, #{item.repANewPv} rep_a_new_pv, #{item.repBNewPv} rep_b_new_pv, #{item.registerAmount} register_amount, #{item.registerPv} register_pv, #{item.registerNewPv} register_new_pv, #{item.upgradeAmount} upgrade_amount ,#{item.upgradePv} upgrade_pv, #{item.upgradeNewPv} upgrade_new_pv, #{item.repurchaseAmount} repurchase_amount, #{item.repurchasePv} repurchase_pv, #{item.repurchaseNewPv} repurchase_new_pv, #{item.hiFunAmount} hi_fun_amount, #{item.hiFunPv} hi_fun_pv, #{item.hiFunNewPv} hi_fun_new_pv, #{item.mallAmount} mall_amount, #{item.mallPv} mall_pv, #{item.mallNewPv} mall_new_pv, #{item.minAchieve} min_achieve, #{item.round} round, #{item.second} second , #{item.aNewBox} a_new_box, #{item.bNewBox} b_new_box, from dual ) 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_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.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.register_amount = b.register_amount, a.register_pv = b.register_pv, a.register_new_pv = b.register_new_pv, a.upgrade_amount = b.upgrade_amount, a.upgrade_pv = b.upgrade_pv, a.upgrade_new_pv = b.upgrade_new_pv, a.repurchase_amount = b.repurchase_amount, a.repurchase_pv = b.repurchase_pv, 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_pv = b.hi_fun_new_pv, a.mall_amount = b.mall_amount, a.mall_pv = b.mall_pv, a.mall_new_pv = b.mall_new_pv, a.min_achieve = b.min_achieve, a.round = b.round, a.second = b.second, 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.a_new_box = b.a_new_box, a.b_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 merge into ${secondTableName} a using ( select B.pk_id,b.pk_settle_country pk_country,nvl(st.A_BALANCE,0) A_BALANCE,nvl(st.B_BALANCE,0) B_BALANCE, nvl(yt.A_SUM_AMOUNT,0) A_SUM_AMOUNT,nvl(yt.B_SUM_AMOUNT,0) B_SUM_AMOUNT, nvl(yt.A_SUM_PV,0) A_SUM_PV,nvl(yt.b_SUM_PV,0) b_SUM_PV,nvl(st.A_NEW_AMOUNT,0) A_NEW_AMOUNT, nvl(st.B_NEW_AMOUNT,0) B_NEW_AMOUNT,nvl(st.A_NEW_PV,0) A_NEW_PV, nvl(ST.B_NEW_PV,0) B_NEW_PV,nvl(yt.A_SUM_REAL_AMOUNT,0) A_SUM_REAL_AMOUNT, nvl(yt.B_SUM_REAL_AMOUNT,0) B_SUM_REAL_AMOUNT, nvl(yt.A_SUM_REAL_PV,0) A_SUM_REAL_PV, nvl(yt.B_SUM_REAL_PV,0) B_SUM_REAL_PV, nvl(ST.REP_A_BALANCE,0) REP_A_BALANCE,nvl(ST.REP_B_BALANCE,0) REP_B_BALANCE, nvl(ST.REP_A_NEW_AMOUNT,0) REP_A_NEW_AMOUNT, nvl(ST.REP_B_NEW_AMOUNT,0) REP_B_NEW_AMOUNT,nvl(ST.REP_A_NEW_PV,0) REP_A_NEW_PV, nvl(ST.REP_B_NEW_PV,0) REP_B_NEW_PV,nvl(yt.REP_A_SUM_AMOUNT,0) REP_A_SUM_AMOUNT, nvl(yt.REP_B_SUM_AMOUNT,0) REP_B_SUM_AMOUNT,nvl(yt.REP_A_SUM_PV,0) REP_A_SUM_PV, nvl(yt.REP_B_SUM_PV,0) REP_B_SUM_PV, nvl(ST.ROUND,0) ROUND,nvl(nvl(ST.SECOND,yt.second),1) SECOND,nvl(ST.MIN_ACHIEVE,0) MIN_ACHIEVE,b.expire_status from (select t.pk_id,t.pk_settle_country,t.expire_status from cu_member t where t.del_flag = 0 start with t.pk_id = #{pkMember} connect by t.pk_id = prior t.pk_place_parent t.pk_parent union select pk_id,t.pk_settle_country,t.expire_status from cu_member t where t.del_flag= 0 and pk_id in #{item} ) b left join ${secondTableName} st on b.pk_id = st.pk_member left join ${settleTableName} yt on b.pk_id=yt.pk_member ) b on (a.pk_member = b.pk_id) when matched then update set 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_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 when not matched then insert (pk_member,pk_country,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,round,second,min_achieve,expire_status) values(b.pk_id,b.pk_country,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.round,b.second,b.min_achieve,b.expire_status) drop table ${tableName} merge into ${settleTableName} a using (select cl.pk_id,cl.pk_member, cl.new_level from cu_member_level cl inner join ( select pk_member, max(pk_id) pk_id from cu_member_level where del_flag = 0 and upgrade_time < #{currentDate, jdbcType=DATE} and pk_member in #{item.pkMember} group by pk_member) ce on cl.pk_id = ce.pk_id ) b on (a.pk_member = b.pk_member) when matched then update set a.pk_grade = b.new_level merge into ${targetTableName} a using ( select #{period} period, pk_member, pk_parent, pk_place_parent, place_dept, member_code, member_name, customer_type, phone, pk_grade, pk_awards, account_status, pay_status, register_authority, category, purchase_type, purchase_status, share_status, income_status, pk_team_code, pk_center_code, pk_vertex, pk_settle_country, is_real_name, is_bus_license, is_maker_space, pk_country from ${sourceTableName} ) b on (a.pk_member = b.pk_member and a.period = b.period) 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.account_status = b.account_status,a.pay_status = b.pay_status, a.register_authority = b.register_authority,a.category = b.category,a.purchase_type = b.purchase_type, a.purchase_status = b.purchase_status,a.share_status = b.share_status,a.income_status = b.income_status, 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.is_real_name = b.is_real_name, a.is_bus_license = b.is_bus_license,a.is_maker_space = b.is_maker_space,a.pk_country = b.pk_country WHEN NOT MATCHED THEN insert (period, pk_member, pk_parent, pk_place_parent, place_dept, member_code, member_name, customer_type, phone, pk_grade, pk_awards, account_status, pay_status, register_authority, category, purchase_type, purchase_status, share_status, income_status, pk_team_code, pk_center_code, pk_vertex, pk_settle_country, is_real_name, is_bus_license, is_maker_space, pk_country) values (b.period, 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.account_status, b.pay_status, b.register_authority, b.category, b.purchase_type, b.purchase_status, b.share_status, b.income_status, b.pk_team_code, b.pk_center_code, b.pk_vertex, b.pk_settle_country, b.is_real_name, b.is_bus_license, b.is_maker_space, b.pk_country) merge into ${settleTableName} a using (select pk_member, max(old_level) old_level from cu_member_awards where period = #{period} and del_flag = 0 group by pk_member) b on (a.pk_member = b.pk_member) when matched then update set a.pk_awards = b.old_level merge into ${rangeTableName} a using ( select pk_member, old_level, ba.pk_awards from ( select pk_member, max(old_level) old_level from cu_member_awards where period = #{period} and up_type = 1 group by pk_member) ca inner join bd_range_awards ba on ca.old_level = ba.pk_id where ba.del_flag = 0 ) b on (a.pk_member = b.pk_member) when matched then update set a.pk_awards = b.pk_awards,a.pk_range_awards = b.old_level merge into ${settleTableName} a using( select * from ( select #{item.pkMember} pk_member,#{item.aBalance} a_balance, #{item.bBalance} b_balance, #{item.minAchieve} min_achieve,#{item.round} round,#{item.second} second from dual ) ) 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 merge into cu_member a using ( select ca.pk_member, max(ca.pk_awards) pk_awards from cu_member_settle_awards ca inner join cu_member cm on cm.pk_id = ca.pk_member where cm.system_type = 0 and period between #{startPeriod} and #{period} group by ca.pk_member ) b on (a.pk_id = b.pk_member) when matched then update set a.pk_awards = b.pk_awards merge into ${settleTableName} a using ( select pk_member, max(pk_awards) pk_awards from cu_member_settle_awards where period between #{startPeriod} and #{period} group by pk_member ) b on (a.pk_member = b.pk_member) when matched then update set a.pk_awards = b.pk_awards merge into cu_member a using ( select pk_member, max(pk_awards) pk_awards from cu_member_settle_awards group by pk_member ) b on (a.pk_id = b.pk_member) when matched then update set a.pk_max_awards = b.pk_awards merge into cu_member a using ( select ct.pk_id, ba.pk_id pk_awards from cu_member ct inner join bd_awards ba on ct.pk_settle_country = ba.pk_country where ba.awards_value = 0 and ba.del_flag = 0 and ct.system_type = 0) b on (a.pk_id = b.pk_id) when matched then update set a.pk_awards = b.pk_awards,a.pk_max_awards = b.pk_awards merge into ${settleTableName} a using ( select ct.pk_member, ba.pk_id pk_awards from ${settleTableName} ct inner join bd_awards ba on ct.pk_settle_country = ba.pk_country where ba.awards_value = 0 and ba.del_flag = 0) b on (a.pk_member = b.pk_member) when matched then update set a.pk_awards = b.pk_awards create table ${tableName} ( pk_member NUMBER(20) not null, pk_parent NUMBER(20) not null, 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_range_awards number(4) default 1 not null, pk_benefit_awards number(6) default 1 not null, account_status number(1) default 0 not null, pay_status NUMBER(2) default 0 not null, pay_time DATE, register_authority number(2) default 0 not null, category number(2) default 0 not null, purchase_status number(2) default 0 not null, income_status number(2) default 0 not null, pk_team_code number(20), pk_center_code number(20), pk_vertex number(20), pk_settle_country number(4) not null, is_real_name NUMBER(1) default 1 not null, pk_country number(4) default 1 not null, pk_rate NUMBER(6), consume_status number(2) default 1 not null, consume_pv number(17,6) default 0 not null, month_pv number(17,6) default 0 not null, new_pv number(17,6) default 0 not null, new_team_pv number(17,6) default 0 not null, dept_new_team_pv number(17,6) default 0 not null, effective_num number(8) default 0 not null, ev_effective_num number(8) default 0 not null, provide_state number(1) default 1 not null, buy_effective_num number(8) default 0 not null, first_agent number(4) default 0 not null, second_agent number(4) default 0 not null, recommend_num number(8) default 0 not null, team_num number(8) default 0 not null, team_consume_amount number(17,6) default 0 not null, team_consume_pv number(17,6) default 0 not null, team_month_amount number(17,6) default 0 not null, team_month_pv number(17,6) default 0 not null, dept_team_consume_amount number(17,6) default 0 not null, dept_team_consume_pv number(17,6) default 0 not null, dept_team_month_amount number(17,6) default 0 not null, dept_team_month_pv number(17,6) default 0 not null, small_area_pv number(17,6) default 0 not null, assess_status number(2) default 3 not null, month_member number(1) default 1 not null, range_store_status number(1) default 0 not null ) create table ${tableName} ( pk_member NUMBER(20) not null, pk_parent NUMBER(20) not null, pk_range_awards number(4) default 1 not null, buy_effective_num number(8) default 0 not null, first_agent number(4) default 0 not null, second_agent number(4) default 0 not null, new_pv number(17,6) default 0 not null, new_effective_num number(8) default 0 not null, new_team_pv number(17,6) default 0 not null, dept_new_team_pv number(17,6) default 0 not null, assess_status number(2) default 3 not null, consume_status number(2) default 1 not null, month_member number(1) default 1 not null ) merge into ${rangeTableName} a using ( select ct.pk_member, ba.pk_id pk_awards from ${rangeTableName} ct inner join bd_awards ba on ct.pk_settle_country = ba.pk_country where ba.awards_value = 0 and ba.del_flag = 0) b on (a.pk_member = b.pk_member) when matched then update set a.pk_benefit_awards = b.pk_awards merge into ${rangeTableName} a using ( select pk_member, max(pk_awards) pk_awards from cu_member_settle_awards where period between #{startPeriod} and #{period} group by pk_member ) b on (a.pk_member = b.pk_member) when matched then update set a.pk_benefit_awards = b.pk_awards merge into cu_member a using ( select ct.pk_id, ba.pk_id pk_awards from cu_member ct inner join bd_awards ba on ct.pk_settle_country = ba.pk_country where ba.awards_value = 0 and ba.del_flag = 0 and ct.system_type = 1) b on (a.pk_id = b.pk_id) when matched then update set a.pk_benefit_awards = b.pk_awards,a.pk_max_awards = b.pk_awards merge into cu_member a using ( select ca.pk_member, max(ca.pk_awards) pk_awards from cu_member_settle_awards ca inner join cu_member cm on cm.pk_id = ca.pk_member where cm.system_type = 1 and period between #{startPeriod} and #{period} group by ca.pk_member ) b on (a.pk_id = b.pk_member) when matched then update set a.pk_benefit_awards = b.pk_awards delete from ${targetTableName} where period = #{period} truncate table ${tableName} merge into ${settleTableName} a using (select pk_member, max(old_level) old_level from cu_member_level where period = #{period} and del_flag = 0 group by pk_member) b on (a.pk_member = b.pk_member) when matched then update set a.pk_grade = b.old_level merge into ${updateTableName} a using ( select pk_member, max(new_level) pk_grade from cu_member_level where period = #{period} and del_flag = 0 group by pk_member) b on (a.pk_member = b.pk_member) when matched then update set a.pk_grade = b.pk_grade