Commit 36a7dd16 authored by Perry_Zhu's avatar Perry_Zhu

Merge remote-tracking branch 'origin/master'

parents 73326ce5 efccf9d9
......@@ -13,7 +13,7 @@ pd.options.mode.chained_assignment = None
max_limit = 800000
import os
path = u'd:/Users/Desktop/test/'
path = u'E:/审计出表/11月份开始使用表数据/11月份现金贷出表/'
engine_xjd = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/?charset=utf8',
echo=False).connect()
......@@ -45,8 +45,8 @@ sql_repay_frr_2 = '''
sum(urp.principle) 'principle',
sum(urp.interest) 'interest'
FROM all_back_0930.user_repayment_plan urp
JOIN all_back_0930.loan_manifest lm ON lm.ref_id = urp.ref_id
FROM new_transaction.user_repayment_plan urp
JOIN audit.loan_manifest lm ON lm.ref_id = urp.ref_id
WHERE lm.loan_paid_at>='%s' AND loan_paid_at<'%s'
AND urp.fund_code IN (210,270,310,320,410,430)
GROUP BY 1,2
......@@ -63,7 +63,7 @@ sql_repay_frr_3 = '''
sum(frp.interest) 'interest'
FROM audit.funding_repayment_plan frp
JOIN all_back_0930.loan_manifest lm ON lm.ref_id = frp.ref_id
JOIN audit.loan_manifest lm ON lm.ref_id = frp.ref_id
WHERE lm.loan_paid_at>='%s' AND loan_paid_at<'%s'
AND lm.funding_code NOT IN (210,270,310,320,410,430)
GROUP BY 1,2
......@@ -75,10 +75,10 @@ SELECT t1.real_loan_id loan_id,date(lm.loan_paid_at) 'loan_paid_at',t1.ref_id,t1
t2.principle-t2.mitigate_principle 'repay_prin',t2.interest-t2.mitigate_interest 'repay_intes',
ifnull(t2.`service_fee`-t2.mitigate_service_fee,0) 'repay_fee',IFNULL(t2.`punish`-t2.mitigate_collection_relief, 0) 'repay_due',
t2.remain_income 'remain',t2.repay_channel,t6.order_id AS 'flow_no',t6.amount 'bank_amount',t1.service_fee 'service_fee',t1.required_repayment 'required_repayment'
FROM audit_temp.xjd_repay_plan_repay_record_ref t2
JOIN all_back_0930.user_repayment_plan t1 ON t1.id=t2.plan_id
JOIN all_back_0930.repay_record_online t6 ON t2.record_id=t6.id AND t2.repay_channel = t6.pay_approach
JOIN all_back_0930.loan_manifest lm ON lm.ref_id = t1.ref_id
FROM new_transaction.xjd_repay_plan_repay_record_ref t2
JOIN new_transaction.user_repayment_plan t1 ON t1.id=t2.plan_id
JOIN new_transaction.repay_record_online t6 ON t2.record_id=t6.id AND t2.repay_channel = t6.pay_approach
JOIN audit.loan_manifest lm ON lm.ref_id = t1.ref_id
WHERE lm.loan_paid_at >= '%s' AND lm.loan_paid_at < '%s'
'''
......@@ -88,10 +88,10 @@ SELECT t1.real_loan_id loan_id,date(lm.loan_paid_at) 'loan_paid_at',t1.ref_id,t1
t2.principle-t2.mitigate_principle 'repay_prin',t2.interest-t2.mitigate_interest 'repay_intes',
ifnull(t2.`service_fee`-t2.mitigate_service_fee,0) 'repay_fee',IFNULL(t2.`punish`-t2.mitigate_collection_relief, 0) 'repay_due',
t2.remain_income 'remain',t2.repay_channel,t6.business_flow 'flow_no',t6.income 'bank_amount',t1.service_fee 'service_fee',t1.required_repayment 'required_repayment'
FROM audit_temp.xjd_repay_plan_repay_record_ref t2
JOIN all_back_0930.`user_repayment_plan` t1 ON t1.id=t2.plan_id
JOIN all_back_0930.`offline_alipay_record` t6 ON t2.record_id=t6.id AND t2.repay_channel = 13
JOIN all_back_0930.loan_manifest lm ON lm.ref_id = t1.ref_id
FROM new_transaction.xjd_repay_plan_repay_record_ref t2
JOIN new_transaction.`user_repayment_plan` t1 ON t1.id=t2.plan_id
JOIN new_transaction.`offline_alipay_record` t6 ON t2.record_id=t6.id AND t2.repay_channel = 13
JOIN audit.loan_manifest lm ON lm.ref_id = t1.ref_id
WHERE lm.loan_paid_at >= '%s' AND lm.loan_paid_at < '%s'
'''
......@@ -101,10 +101,10 @@ SELECT t1.real_loan_id loan_id,date(lm.loan_paid_at) 'loan_paid_at',t1.ref_id,t1
t2.principle-t2.mitigate_principle 'repay_prin',t2.interest-t2.mitigate_interest 'repay_intes',
ifnull(t2.`service_fee`-t2.mitigate_service_fee,0) 'repay_fee',IFNULL(t2.`punish`-t2.mitigate_collection_relief, 0) 'repay_due',
t2.remain_income 'remain',t2.repay_channel,t6.transfer_amount 'bank_amount',t1.service_fee 'service_fee',t1.required_repayment 'required_repayment'
FROM audit_temp.xjd_repay_plan_repay_record_ref t2
JOIN all_back_0930.`user_repayment_plan` t1 ON t1.id=t2.plan_id
JOIN all_back_0930.loan_manifest lm ON lm.ref_id = t1.ref_id
JOIN all_back_0930.`offline_bank_repay_record` t6 ON t2.record_id=t6.id AND t2.repay_channel IN (14,15,16)
FROM new_transaction.xjd_repay_plan_repay_record_ref t2
JOIN new_transaction.`user_repayment_plan` t1 ON t1.id=t2.plan_id
JOIN audit.loan_manifest lm ON lm.ref_id = t1.ref_id
JOIN new_transaction.`offline_bank_repay_record` t6 ON t2.record_id=t6.id AND t2.repay_channel IN (14,15,16)
WHERE lm.loan_paid_at >= '%s' AND lm.loan_paid_at < '%s'
'''
......@@ -194,12 +194,12 @@ def handle_hk(year, month):
temp_list = temp.values.tolist()
temp_list.insert(0, temp.columns.tolist())
all_wb.new_sheet(str(int(i / max_limit + 1)), data=temp_list)
all_wb.save(path + u'人工控制-现金贷-客户实还表-测试(%d-%02d).xlsx' % (start_time.year, start_time.month))
all_wb.save(path + u'人工控制-现金贷-客户实还表(%d-%02d).xlsx' % (start_time.year, start_time.month))
if __name__ == '__main__':
year = [2017]
month = range(9, 10, 1)
month = range(10, 11, 1)
for year, month in product(year, month):
print '____%d__%d' % (year, month)
......
......@@ -25,9 +25,10 @@ import os
# loan_manifest.is_active in (1,-2)
# 需要先进行数据的获取,需要时间较长,sql_repay_all中xrd.repaid_at同样需要修改
# sql_contract_no需要每月进行修改
path = u'1020_files/'
path = u'E:/审计出表/非去哪儿白条-客户实还表-1023版/'
path = u'E:/审计出表/11月份开始使用表数据/11月份现金贷出表/'
engine_xjd = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/audit?charset=utf8',
echo=False).connect()
......@@ -48,7 +49,7 @@ def faster_sql_reader(sql):
sql_fund = '''
select frp.ref_id,frp.term_no 'term_no',date(frp.deadline) 'deadline',frp.principle+ifnull(frp.interest,0) 'prin_interes'
from audit.funding_repayment_plan frp
where frp.deadline >= '2017-01-01'
where frp.deadline >= '2017-10-01'
'''
df_fund = faster_sql_reader(sql_fund)
df_fund.rename(columns={'term_no':u'应还期数','deadline':u'应还资金方时间','prin_interes':u'应还资金方本息'},inplace=True)
......@@ -58,13 +59,13 @@ df_fund.rename(columns={'term_no':u'应还期数','deadline':u'应还资金方
#此部分不需要进行修改
sql_contract_no = '''
select ref_id,contract_no
from basic.loan_class_contract_1002 lco
from basic.loan_class_contract_201711 lco
'''
#10月05日修改为basic.loan_class_contract_1002
df_contract_no = faster_sql_reader(sql_contract_no)
sql_fund_name = '''
sql_fund_name = '''
select funding_code,name '资金方'
from basic.funding_corp
'''
......@@ -81,9 +82,9 @@ def mc_pay(year, month):
urp.term_no 'term_no',
sum(xrprrr.principle-IFNULL(xrprrr.mitigate_principle,0)+xrprrr.interest-IFNULL(xrprrr.mitigate_interest,0)) 'principle_interes',
sum(xrprrr.service_fee-IFNULL(xrprrr.mitigate_service_fee,0)) 'service_fee'
from audit_temp.xjd_repay_plan_repay_record_ref_0831 xrprrr
join all_back_0831.user_repayment_plan urp on xrprrr.plan_id = urp.id
join all_back_0831.loan_manifest lm on lm.ref_id = urp.ref_id
from new_transaction.xjd_repay_plan_repay_record_ref xrprrr
join new_transaction.user_repayment_plan urp on xrprrr.plan_id = urp.id
join audit.loan_manifest lm on lm.ref_id = urp.ref_id
where lm.loan_paid_at>='%s' and lm.loan_paid_at<'%s'
group by 1,2
''' %(start_time,end_time)
......@@ -168,7 +169,7 @@ def mc_pay(year, month):
temp_list = temp.values.tolist()
temp_list.insert(0,temp.columns.tolist())
all_wb.new_sheet(str(int(i/max_limit + 1)),data=temp_list)
all_wb.save(path+u'人工控制-现金贷-放款表_测试(%d-%02d).xlsx' %(start_time.year,start_time.month))
all_wb.save(path+u'人工控制-现金贷-放款表(%d-%02d).xlsx' %(start_time.year,start_time.month))
# if len(df_pay) > max_limit:
......@@ -180,7 +181,7 @@ def mc_pay(year, month):
if __name__ == '__main__':
year = [2017]
month = range(1, 2, 1)
month = range(10, 11, 1)
for year, month in product(year, month):
mc_pay(year, month)
......@@ -13,7 +13,7 @@ sys.setdefaultencoding("utf-8")
pd.options.mode.chained_assignment = None
#此路径为服务器路径专用
path = u'E:/审计出表/人工控制/现金贷-还资金方表-1010版本/'
path = u'E:/审计出表/11月份开始使用表数据/11月份现金贷出表/'
# path = u'E:/审计出表/人工控制/现金贷-还资金方表-1010版本/'
engine_xjd = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/?charset=utf8',
echo=False).connect()
......@@ -37,7 +37,7 @@ def faster_sql_reader(sql):
sql_lm = '''
select ref_id,loan_id,funding_code,date(loan_paid_at) 'loan_paid_at',contract_term 'contract_term'
from all_back_0831.loan_manifest lm
from audit.loan_manifest lm
where loan_paid_at>='%s' and loan_paid_at <'%s'
and is_active in (1, -2)
'''
......@@ -56,8 +56,8 @@ sql_repay_frr_2 = '''
urp.term_no 'term_no',
date(urp.deadline) 'deadline',
urp.principle+urp.interest 'prin_intere'
from all_back_0831.user_repayment_plan urp
join all_back_0831.loan_manifest lm on lm.ref_id = urp.ref_id
from new_transaction.user_repayment_plan urp
join audit.loan_manifest lm on lm.ref_id = urp.ref_id
where lm.loan_paid_at>='%s' and loan_paid_at<'%s'
and urp.fund_code in (210,270,310,320,410,430)
GROUP BY 1,2
......@@ -72,7 +72,7 @@ sql_repay_frr_3 = '''
frp.interest+frp.principle 'prin_intere'
from audit.funding_repayment_plan frp
join all_back_0831.loan_manifest lm on lm.ref_id = frp.ref_id
join audit.loan_manifest lm on lm.ref_id = frp.ref_id
WHERE lm.loan_paid_at>='%s' and loan_paid_at<'%s'
and lm.funding_code not in (210,270,310,320,410,430)
GROUP BY 1,2
......@@ -89,8 +89,8 @@ sql_refund = '''
frr.flow_id 'flow_id',
frr.term_no 'term_no'
FROM
all_back_0831.funding_repayment_record frr
join all_back_0831.loan_manifest lm on lm.ref_id = frr.ref_id
audit.funding_repayment_record frr
join audit.loan_manifest lm on lm.ref_id = frr.ref_id
JOIN basic.funding_corp fc ON fc.funding_code = frr.funding_code
WHERE lm.loan_paid_at>='%s'
and lm.loan_paid_at <'%s'
......@@ -185,7 +185,7 @@ def refund(year,month):
temp_list = temp.values.tolist()
temp_list.insert(0, temp.columns.tolist())
all_wb.new_sheet(str(int(i / max_limit + 1)), data=temp_list)
all_wb.save(path + u'人工控制-现金贷—还资金方表-V4(%d-%02d).xlsx' % (start_time.year, start_time.month))
all_wb.save(path + u'人工控制-现金贷—还资金方表(%d-%02d).xlsx' % (start_time.year, start_time.month))
# if len(df) > max_limit:
# for i in xrange(0, len(df), max_limit):
......@@ -196,7 +196,7 @@ def refund(year,month):
if __name__ == '__main__':
year = [2017]
month = range(4, 5, 1)
month = range(10, 11, 1)
for year, month in product(year, month):
print('-----------%s-%s begins') %(year,month)
......
......@@ -19,7 +19,7 @@ max_limit = 900000
注意 is_active = 1 的订单
使用之前需要先修改时间点,sql_query_flowid中的 t1.repaid_at,比如出9月份的表,t1.repaid_at<'2017-10-01'
'''
path = u'E:/审计出表/人工控制/现金贷-银行流水相关/'
path = u'E:/审计出表/11月份开始使用表数据/11月份现金贷出表/'
engine_new_transaction = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/?charset=utf8',
echo=False).connect()
......@@ -27,19 +27,19 @@ engine_new_transaction = create_engine('mysql+mysqldb://internal_r:ArbNgtvlJzZHX
# 还资金方流水明细--1
sql_query_flowid = """
SELECT DISTINCT t1.flow_id flow_id
FROM all_back_0930.funding_repayment_record t1
JOIN all_back_0930.loan_manifest t2 ON t1.ref_id = t2.ref_id AND t2.is_active = 1
FROM audit.funding_repayment_record t1
JOIN audit.loan_manifest t2 ON t1.ref_id = t2.ref_id AND t2.is_active = 1
AND t2.loan_paid_at >= '%s' AND t2.loan_paid_at < '%s'
AND t1.repaid_at < '2017-10-01' AND t1.lkb_to_fund_type = 2 AND t1.lkb2fund_id IS NOT NULL
AND t1.repaid_at < '2017-11-01' AND t1.lkb_to_fund_type = 2 AND t1.lkb2fund_id IS NOT NULL
"""
# 流水明细对应的实还资金方表
sql_query_detail = """
SELECT t1.loan_id,t2.`name` '资金方',date(t3.loan_paid_at) '放款时间',t1.term_no '期数',date(t1.repaid_at) '实还时间',t1.current_repayment '实还总额',
t1.principle '实还本金',t1.interest '实还利息',t1.flow_id '流水号'
FROM all_back_0930.funding_repayment_record t1
FROM audit.funding_repayment_record t1
JOIN new_transaction.funding_corp t2 ON t1.funding_code = t2.id
JOIN all_back_0930.loan_manifest t3 ON t1.ref_id = t3.ref_id AND t3.is_active =1 AND t1.lkb_to_fund_type = 2 AND t1.flow_id IN %s
JOIN audit.loan_manifest t3 ON t1.ref_id = t3.ref_id AND t3.is_active =1 AND t1.lkb_to_fund_type = 2 AND t1.flow_id IN %s
"""
'''
......@@ -110,7 +110,7 @@ if __name__ == '__main__':
# handle(2016, 12)
# pool = mtp.Pool(processes=6)
for year in [2017]:
for month in range(9,10,1):
for month in range(10,11,1):
handle(year,month)
# handle(year, month)
# pool.apply_async(handle, (year, month))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment