sql_in_list='''select case when a.is_frozen=0 then left(a.effective_time::text,7) end as 积分生效月份,
d.company,
case when a.is_frozen=0 then a.effective_time end as 生效时间,
b.id as "推荐人ID",
b.username as "推荐人姓名",
b.mobile as "推荐人号码",
bb.pom_order_sn as "推荐人合同号",
bb.pom_sign_time as "推荐人签单时间",
b2.id as "被推荐人ID",
b2.username as 被推荐人姓名,
bbb.pom_sign_time 被推荐人签约时间,
bbb.pom_order_sn 被推荐人合同号,
bbb.fpp_name 被推荐人签约项目,
bbb.fpp_type 被推荐人项目类型,
a.change as 积分发放金额,
a.point_event_name as 积分类型,
case when a.point_event_name = '推荐签约' and bbb.fpp_type in (1,2,3,14) then '身份类推荐'
when a.point_event_name = '活动赠送' then '活动赠送' end
as 积分发放类型,
a.change ,
case when a.change <0 and a.is_frozen=0 then '已支出'
when a.change >0 and a.is_frozen=1 then '锁定中'
when a.change >0 and a.is_frozen=0 then '已发放' end as 积分状态,
a.remarks
from ods.ods_mbm_micros_point_event_log a
left join ods.ods_pre_micros_customer b on a.mobile = b.mobile and b.deleted_at is null and b.mobile <>''
left join ods.ods_pre_micros_customer b2 on a.crm_source_mobile = b2.mobile and b.deleted_at is null and b2.mobile <>''
left join
(
select * from
(select pom_customer_id ,pom_order_sn ,pom_sign_time ,row_number()over(partition by pom_customer_id order by pom_sign_time ) as row_num from dws.dws_pre_sign_order_main_v)aa where row_num = 1
)bb on b.id = bb.pom_customer_id
left join
(
select * from
(select pom_customer_id ,pom_order_sn ,pom_sign_time,fpp_name,fpp_type,row_number()over(partition by pom_customer_id order by pom_sign_time ) as row_num from dws.dws_pre_sign_order_main_v)aa where row_num = 1
)bbb on b2.id = bbb.pom_customer_id
left join
(select phone ,min(nick_name)nick_name from ods.ods_gal_galaxy_wechat_client where is_deleted='0' and phone is not null group by phone)c on a.mobile = c.phone
left join
(select point_event_log_id ,array_agg(company)company from ods.ods_mbm_micros_point_company where deleted_at is null
group by point_event_log_id )d on a."id" = d.point_event_log_id
where a.is_frozen in (0) and a.deleted_at is null
-- and left(a.created_at,10) between '${start_date}' and '${end_date}'
and a.point_event_name in ('积分同步','系统调整-增加','推荐签约','线下推荐签约','活动赠送')
order by b.mobile,a.created_at'''
# 积分兑换的sql
sql_out_list='''select mobile ,amount::int * 10 as amount,updated_at from ods.ods_mbm_micros_cash_out_log where deleted_at is null and "status" in (1,3)
union all
select mobile , change*(-1) as change ,effective_time from ods.ods_mbm_micros_point_event_log where point_event_name = '系统调整-减少' and effective_time is not null