insert ALL into CU_MEMBER_TRADE_DETAIL(period,pk_member_trade,consume_money,pk_country,creation_time,pk_creator) values ( #{item.period},#{item.pkMemberTrade},#{item.consumeMoney,jdbcType=NUMERIC},#{item.pkCountry}, #{item.creationTime, jdbcType=TIMESTAMP},#{item.pkCreator} ) SELECT 1 FROM dual merge into cu_member_trade_detail a using ( select cd.pk_id,cd.consume_money from cu_member_trade ct inner join cu_member_trade_detail cd on cd.pk_member_trade = ct.pk_id where cd.del_flag=0 and ct.del_flag=0 and cd.trade_statue=1 and cd.period between #{startPeriod} and #{endPeriod} and ct.pk_country = #{pkCountry} )b on (a.pk_id = b.pk_id) when matched then update set a.consume_money = 0,modified_time=sysdate merge into cu_member_trade_detail a using ( select #{item.pkId} pk_id,#{item.grantMoney,jdbcType=NUMERIC} grant_money,#{item.consumeMoney,jdbcType=NUMERIC} consume_money from dual ) b on (a.pk_id = b.pk_id) when matched then update set a.grant_money = b.grant_money, a.consume_money = b.consume_money merge into cu_member_trade_detail a using ( select #{item.pkId} pk_id,#{item.grantMoney,jdbcType=NUMERIC} grant_money,#{item.consumeMoney,jdbcType=NUMERIC} consume_money from dual ) b on (a.pk_id = b.pk_id) when matched then update set a.grant_money = a.grant_money + b.grant_money, a.consume_money = a.consume_money + b.consume_money merge into cu_member_trade_detail d using (select t.pk_id, t.trade_amount, t.pk_country, t.pk_creator from cu_member_trade t left join bd_account a on t.pk_account = a.pk_id and a.del_flag = 0 where t.del_flag = 0 and a.field_value = 4 and t.trade_amount > 0 and t.source_code = #{sourceCode}) tt on (1 = 0) when not matched then insert (d.period, d.pk_member_trade, d.consume_money, d.pk_country, d.pk_creator) values (#{period},tt.pk_id, tt.trade_amount, tt.pk_country, tt.pk_creator)