pk_id NUMBER(20) primary key,
pk_member NUMBER(20) not null,
period NUMBER(6) not null,
settle_month VARCHAR2(12) not null,
assess_type NUMBER(2) not null,
pk_awards NUMBER(6) not null,
assess_target NUMBER(17,6) default 0 not null,
is_examine NUMBER(1) default 1 not null,
assess_status NUMBER(2) not null,
month_balance NUMBER(17,6) default 0 not null,
month_add NUMBER(17,6) default 0 not null,
cur_month_add number(17,6) default 0 not null,
month_used NUMBER(17,6) default 0 not null,
month_surplus NUMBER(17,6) default 0 not null,
del_flag NUMBER(1) default 0 not null,
pk_country NUMBER(4) not null,
pk_creator NUMBER(20) not null,
creation_time DATE default sysdate not null,
modified_time DATE,
pk_modified NUMBER(20)
merge into ${tableName} a
using(
select pk_member,#{period} period,#{month} settle_month,0 assess_type,pk_awards,nvl(b.purchase_check,0) ASSESS_TARGET,
1 IS_EXAMINE,2 assess_status,ct.pk_settle_country PK_COUNTRY,1 pk_creator
from ${sourceTableName} ct
left join bd_awards b
on ct.pk_awards=b.pk_id
where category=0
) b
on (a.pk_member=b.pk_member and a.period=b.period and a.assess_type=b.assess_type)
WHEN MATCHED THEN
update set a.SETTLE_MONTH=b.SETTLE_MONTH,a.PK_AWARDS=b.PK_AWARDS,a.ASSESS_TARGET=b.ASSESS_TARGET,
a.IS_EXAMINE=b.IS_EXAMINE,a.ASSESS_STATUS=b.ASSESS_STATUS
when not matched then
insert (PK_MEMBER,period,SETTLE_MONTH,ASSESS_TYPE,PK_AWARDS,ASSESS_TARGET,
IS_EXAMINE,ASSESS_STATUS,PK_COUNTRY,PK_CREATOR)
values(b.PK_MEMBER,b.period,b.SETTLE_MONTH,b.ASSESS_TYPE,b.PK_AWARDS,b.ASSESS_TARGET,
b.IS_EXAMINE,b.ASSESS_STATUS,b.PK_COUNTRY,b.PK_CREATOR)
merge into ${tableName} a
using(
select pk_member,#{period} period,#{month} settle_month,0 assess_type,pk_range_awards pk_awards,nvl(b.purchase_check,0) ASSESS_TARGET,
1 IS_EXAMINE,2 assess_status,ct.pk_settle_country PK_COUNTRY,1 pk_creator
from ${sourceTableName} ct
left join bd_range_awards b
on ct.pk_range_awards=b.pk_id
where category=0
) b
on (a.pk_member=b.pk_member and a.period=b.period and a.assess_type=b.assess_type)
WHEN MATCHED THEN
update set a.SETTLE_MONTH=b.SETTLE_MONTH,a.PK_AWARDS=b.PK_AWARDS,a.ASSESS_TARGET=b.ASSESS_TARGET,
a.IS_EXAMINE=b.IS_EXAMINE,a.ASSESS_STATUS=b.ASSESS_STATUS
when not matched then
insert (PK_MEMBER,period,SETTLE_MONTH,ASSESS_TYPE,PK_AWARDS,ASSESS_TARGET,
IS_EXAMINE,ASSESS_STATUS,PK_COUNTRY,PK_CREATOR)
values(b.PK_MEMBER,b.period,b.SETTLE_MONTH,b.ASSESS_TYPE,b.PK_AWARDS,b.ASSESS_TARGET,
b.IS_EXAMINE,b.ASSESS_STATUS,b.PK_COUNTRY,b.PK_CREATOR)
merge into ${tableName} a
using(
select pk_member,#{period} period,#{month} settle_month,1 assess_type,pk_awards,nvl(b.SHARE_CHECK,0) ASSESS_TARGET,
1 IS_EXAMINE,2 assess_status,ct.pk_settle_country PK_COUNTRY,1 pk_creator
from ${sourceTableName} ct
left join bd_awards b
on ct.pk_awards=b.pk_id
where category=0 and awards_value >0
) b
on (a.pk_member=b.pk_member and a.period=b.period and a.assess_type=b.assess_type)
WHEN MATCHED THEN
update set a.SETTLE_MONTH=b.SETTLE_MONTH,a.PK_AWARDS=b.PK_AWARDS,a.ASSESS_TARGET=b.ASSESS_TARGET,
a.IS_EXAMINE=b.IS_EXAMINE,a.ASSESS_STATUS=b.ASSESS_STATUS
when not matched then
insert (PK_MEMBER,period,SETTLE_MONTH,ASSESS_TYPE,PK_AWARDS,ASSESS_TARGET,
IS_EXAMINE,ASSESS_STATUS,PK_COUNTRY,PK_CREATOR)
values(b.PK_MEMBER,b.period,b.SETTLE_MONTH,b.ASSESS_TYPE,b.PK_AWARDS,b.ASSESS_TARGET,
b.IS_EXAMINE,b.ASSESS_STATUS,b.PK_COUNTRY,b.PK_CREATOR)
insert ALL
into tmp_cu_member_assess(pk_id,pk_awards,assess_target,assess_status,month_add,month_used,month_surplus,
is_examine) values
(
#{item.pkId},#{item.pkAwards},#{item.assessTarget},#{item.assessStatus},#{item.monthAdd},#{item.monthUsed},#{item.monthSurplus},
#{item.isExamine})
SELECT 1 FROM dual
create table ${tableName}
(
)
create unique index ${tableName}_PK_M on ${tableName}(PK_MEMBER,period, assess_type)
merge into ${tableName} a
using (select pk_member,assess_type,month_surplus from ${beforeTableName} cs
inner join cu_member cm
on cs.pk_member=cm.pk_id and cm.del_flag=0
where period = #{sourcePeriod} and assess_type = #{assessType} and cm.system_type=0) b
on (a.pk_member = b.pk_member and a.assess_type = b.assess_type)
when matched then
update set a.month_balance = b.month_surplus where a.del_flag= 0 and a.period= #{period}
merge into ${tableName} a
using (select pk_member,#{period} period,#{assessType} assess_type,sum(order_achieve) order_achieve from(
select pk_member,(case when #{assessType} = 0 then order_achieve else order_ass_achieve end) order_achieve from sa_order
where del_flag = 0 and order_status = 1 and order_type in
#{item}
and pay_time >= #{startDate, jdbcType=DATE} and pay_time < #{endDate, jdbcType=DATE}
)
group by pk_member
) b
on (a.pk_member = b.pk_member and a.period= b.period and a.assess_type= b.assess_type)
when matched then
update set a.MONTH_ADD=b.order_achieve
update ${tableName} set month_surplus = month_balance+month_add
where del_flag= 0 and period = #{period}
update ${tableName} set assess_status = 0, month_used = assess_target, month_surplus = month_balance+month_add-assess_target
where del_flag= 0 and assess_status=2 and period = #{period} and assess_target <= month_balance+month_add
merge into ${tableName} a
using (select pk_id,pk_awards,assess_target,assess_status,month_add,month_used,month_surplus,is_examine
from TMP_CU_MEMBER_ASSESS) b
on (a.pk_id = b.pk_id)
when matched then
update set a.pk_awards = b.pk_awards,a.assess_target=b.assess_target,a.assess_status=b.assess_status,
a.month_add=b.month_add,a.month_used=b.month_used,
a.month_surplus=b.month_surplus,a.is_examine=b.is_examine
update ${tableName} a set a.assess_status = 0, a.month_used = a.assess_target, a.month_surplus = a.month_balance+a.month_add-a.assess_target
where a.del_flag= 0 and a.assess_status=2 and a.period = #{period} and a.assess_target <= a.month_balance+a.month_add
and a.pk_member in
#{item.pkMember}
comment on column CU_MEMBER_ASSESS2022.pk_id is '主键';
comment on column CU_MEMBER_ASSESS2022.pk_member is '会员主键';
comment on column CU_MEMBER_ASSESS2022.period is '期间';
comment on column CU_MEMBER_ASSESS2022.settle_month is '结算月';
comment on column CU_MEMBER_ASSESS2022.assess_type is '考核类型 0=复购考核 1=分红考核';
comment on column CU_MEMBER_ASSESS2022.pk_awards is '奖衔';
comment on column CU_MEMBER_ASSESS2022.assess_target is '考核目标';
comment on column CU_MEMBER_ASSESS2022.is_examine is '是否免考';
comment on column CU_MEMBER_ASSESS2022.assess_status is '考核状态 0=考核通过 1=免考通过 2=考核不通过 3=不考核';
comment on column CU_MEMBER_ASSESS2022.month_balance is '上月结余';
comment on column CU_MEMBER_ASSESS2022.month_add is '考核月新增';
comment on column CU_MEMBER_ASSESS2022.cur_month_add is '本月新增';
comment on column CU_MEMBER_ASSESS2022.month_used is '考核月使用';
comment on column CU_MEMBER_ASSESS2022.month_surplus is '考核月剩余';
comment on column CU_MEMBER_ASSESS2022.del_flag is '逻辑删除 (0=未删除,1已删除)';
comment on column CU_MEMBER_ASSESS2022.creation_time is '创建时间';
comment on column CU_MEMBER_ASSESS2022.modified_time is '修改时间';
comment on column CU_MEMBER_ASSESS2022.pk_country is '国家';
comment on column CU_MEMBER_ASSESS2022.pk_creator is '创建者';
comment on column CU_MEMBER_ASSESS2022.pk_modified is '更新者';
merge into ${tableName} a
using (
select distinct pk_member,#{period} period,0 assess_type from(
select pk_id pk_member 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 from cu_member_awards
where del_flag=0 and purchase_status= 0 and
period >= #{startPeriod} and period < #{endPeriod}
union
select pk_member from ${settleTableName} ct
inner join bd_awards ba
on ct.pk_awards = ba.pk_id
where ct.purchase_status=0 and ba.purchase_check >0)
) b
on (a.pk_member = b.pk_member and a.period=b.period and a.assess_type=b.assess_type)
when matched then
update set a.is_examine=0
merge into ${settleTableName} a
using ( select distinct pk_id pk_member 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}
) b
on (a.pk_member = b.pk_member)
when matched then
update set a.purchase_status=0
update ${settleTableName} set purchase_status=0
merge into ${tableName} a
using (
select distinct pk_member from ${settleTableName} ct
inner join bd_awards ba
on ct.pk_awards = ba.pk_id
where ct.share_status=0 and ba.share_check >0
) b
on (a.pk_member = b.pk_member)
when matched then
update set a.is_examine=0 where a.del_flag= 0 and a.period= #{period} and a.assess_type= 1
delete from ${tableName} where period = #{period} and del_flag=0