Commit a92cddbd authored by 白条—徐加哲 's avatar 白条—徐加哲

格式化王博的代码

parent ba2f3811
...@@ -20,21 +20,37 @@ fundcodes = ( ...@@ -20,21 +20,37 @@ fundcodes = (
240, 240,
250, 251, 260, 300, 290, 270, 330, 310, 320, 350, 340) 250, 251, 260, 300, 290, 270, 330, 310, 320, 350, 340)
file_path = u'/vpants/svn_loan_xjd_txt/' file_path = u'/vpants/svn_loan_xjd_txt/'
sql_funding_corp = """select funding_code 'funding_code', name '资金方' from audit.funding_corp;""" sql_funding_corp = """select funding_code 'funding_code', name '资金方' from audit.funding_corp;"""
sql_loan_account = """select id loan_account_id, accountName '放款渠道' from audit.loan_account;""" sql_loan_account = """select id loan_account_id, accountName '放款渠道' from audit.loan_account;"""
sql_loan = """SELECT lm.funding_code 'funding_code',lm.loan_id 'loan_id',loan_paid_at '放款日期',lm.real_loan_amount '放款金额',lm.loan_account_id 'loan_account_id',lm.contract_loan_amount '本金(债权)',lm.qg_one_time_service_fee '一次性手续费(QG)',lm.funding_one_time_service_fee '一次性手续费(点滴)',lm.contract_term '贷款总期数',lm.per_term_service_fee '每期手续费',lm.monthly_interest_rate '月利率',luc.uuid '借款人id' sql_loan = """
FROM loan_manifest lm JOIN temp.loan_uuid_class luc ON lm.ref_id = luc.ref_id WHERE lm.loan_paid_at>="%d-%d-01" AND lm.loan_paid_at<"%d-%d-01" AND lm.funding_code=%d AND lm.is_active in (1,-2) ;""" SELECT
lm.funding_code 'funding_code',
lm.loan_id 'loan_id',
loan_paid_at '放款日期',
lm.real_loan_amount '放款金额',
lm.loan_account_id 'loan_account_id',
lm.contract_loan_amount '本金(债权)',
lm.qg_one_time_service_fee '一次性手续费(QG)',
lm.funding_one_time_service_fee '一次性手续费(点滴)',
lm.contract_term '贷款总期数',
lm.per_term_service_fee '每期手续费',
lm.monthly_interest_rate '月利率',
luc.uuid '借款人id'
FROM loan_manifest lm
JOIN temp.loan_uuid_class luc
ON lm.ref_id = luc.ref_id
WHERE
lm.loan_paid_at >= "%d-%d-01" AND lm.loan_paid_at < "%d-%d-01"
AND lm.funding_code = %d AND lm.is_active in (1, -2);"""
sql_plan = """SELECT ref_id ,term_no ,deadline ,required_repayment FROM user_repayment_plan WHERE ref_id in %s """ sql_plan = """SELECT ref_id ,term_no ,deadline ,required_repayment FROM user_repayment_plan WHERE ref_id in %s """
chunksize = 10000 chunksize = 10000
step = 3000 step = 3000
columns = [u'资金方', u'loan_id', u'放款日期', u'放款金额', u'放款渠道', u'本金(债权)', u'一次性手续费(QG)', u'一次性手续费(点滴)', columns = [u'资金方', u'loan_id', u'放款日期', u'放款金额', u'放款渠道', u'本金(债权)',
u'贷款总期数', u'每期手续费', u'月利率',u'借款人id'] u'一次性手续费(QG)', u'一次性手续费(点滴)', u'贷款总期数', u'每期手续费', u'月利率', u'借款人id']
con_audit_audit = create_engine( con_audit_audit = create_engine(
'mysql+mysqldb://yulong_rw:TouBStYwN8wkdxVt@172.16.3.201:3306/all_back_0430?charset=utf8', echo=True) 'mysql+mysqldb://yulong_rw:TouBStYwN8wkdxVt@172.16.3.201:3306/all_back_0430?charset=utf8', echo=True)
...@@ -69,4 +85,4 @@ for fund_code in fundcodes: ...@@ -69,4 +85,4 @@ for fund_code in fundcodes:
# loan_id,放款日期,放款金额,本金(债权),一次性手续费(QG),一次性手续费(点滴),贷款总期数,每期手续费,月利率,资金方,放款渠道 # loan_id,放款日期,放款金额,本金(债权),一次性手续费(QG),一次性手续费(点滴),贷款总期数,每期手续费,月利率,资金方,放款渠道
# np.savetxt(file_path + 'xjd_loan_2015-2016_' +str(fund_code)+ '.txt', X=df_loan.values, # np.savetxt(file_path + 'xjd_loan_2015-2016_' +str(fund_code)+ '.txt', X=df_loan.values,
# fmt='%s|%s|%f|%f|%.2f|%.2f|%d|%.2f|%f|%s|%s|%s|', header=header_line, delimiter='|') # fmt='%s|%s|%f|%f|%.2f|%.2f|%d|%.2f|%f|%s|%s|%s|', header=header_line, delimiter='|')
df_loan.to_csv(file_path + 'xjd_loan_2015-2016_' +str(fund_code)+ '.csv') df_loan.to_csv(file_path + 'xjd_loan_2015-2016_' + str(fund_code) + '.csv')
...@@ -15,37 +15,39 @@ import multiprocessing as mtp ...@@ -15,37 +15,39 @@ import multiprocessing as mtp
reload(sys) reload(sys)
sys.setdefaultencoding('utf8') sys.setdefaultencoding('utf8')
path = './' path = './'
start_time = "2017-04-01 00:00:00" start_time = "2017-04-01 00:00:00"
end_time = "2017-07-01 00:00:00" end_time = "2017-07-01 00:00:00"
read_fund_sql = ''' read_fund_sql = '''
select id fund_corp_id,name fund_name from new_transaction.funding_corp where id not in (40,60) select id fund_corp_id,name fund_name
from new_transaction.funding_corp
where id not in (40,60)
''' '''
read_repay_sql = ''' read_repay_sql = '''
SELECT id,`approach_name` FROM new_transaction.`repay_channel` SELECT id,`approach_name`
FROM new_transaction.`repay_channel`
''' '''
sql_query_dunjiao = """ sql_query_dunjiao = """
SELECT SELECT
t1.funding_code, lm.funding_code,
t1.loan_paid_at, lm.loan_paid_at,
t1.loan_id, lm.loan_id,
t1.contract_term, lm.contract_term,
t4.bill_time repaid_at, rro.bill_time repaid_at,
t3.ref_amount, xjd_dpr.ref_amount,
t4.order_id, rro.order_id,
t3.repay_channel xjd_dpr.repay_channel
FROM FROM
loan_manifest t1 loan_manifest lm
JOIN xjd_dunjiao_plan t2 ON t1.ref_id = t2.ref_id JOIN xjd_dunjiao_plan xjd_dp
JOIN xjd_dunjiao_plan_ref t3 ON t2.id = t3.plan_id ON lm.ref_id = xjd_dp.ref_id
JOIN repay_record_online t4 ON t3.record_id = t4.id JOIN xjd_dunjiao_plan_ref xjd_dpr
WHERE ON xjd_dp.id = xjd_dpr.plan_id
bill_time >= "%s" JOIN repay_record_online rro
AND bill_time < "%s" ON xjd_dpr.record_id = rro.id
WHERE bill_time >= "%s" AND bill_time < "%s"
""" """
engine_new_transaction = engine_new_transaction = create_engine( engine_new_transaction = engine_new_transaction = create_engine(
...@@ -54,22 +56,29 @@ engine_new_transaction = engine_new_transaction = create_engine( ...@@ -54,22 +56,29 @@ engine_new_transaction = engine_new_transaction = create_engine(
df_fund = pd.read_sql(read_fund_sql, con=engine_new_transaction) df_fund = pd.read_sql(read_fund_sql, con=engine_new_transaction)
df_approach = pd.read_sql(read_repay_sql, con=engine_new_transaction) df_approach = pd.read_sql(read_repay_sql, con=engine_new_transaction)
df_approach['id'] = df_approach['id'].astype(int) df_approach['id'] = df_approach['id'].astype(int)
df_dunjiao = pd.read_sql(sql_query_dunjiao % (start_time, end_time), con=engine_new_transaction)
df_dunjiao = pd.merge(df_dunjiao, df_fund, how='left', left_on=['funding_code'], right_on=['fund_corp_id'])
df_dunjiao = pd.merge(df_dunjiao, df_approach, how='left', left_on=['repay_channel'], right_on=['id'])
df_dunjiao = df_dunjiao[['fund_name', 'loan_paid_at', 'loan_id',
'contract_term', 'repaid_at', 'ref_amount',
'order_id', 'approach_name']]
df_dunjiao = pd.read_sql(sql_query_dunjiao % (start_time,end_time),con=engine_new_transaction)
df_dunjiao = pd.merge(df_dunjiao,df_fund,how='left',left_on=['funding_code'],right_on=['fund_corp_id'])
df_dunjiao = pd.merge(df_dunjiao,df_approach,how='left',left_on=['repay_channel'],right_on=['id'])
df_dunjiao = df_dunjiao[['fund_name','loan_paid_at','loan_id','contract_term','repaid_at','ref_amount','order_id','approach_name']]
df_dunjiao.sort_values(by=['repaid_at'], inplace=True) df_dunjiao.sort_values(by=['repaid_at'], inplace=True)
df_dunjiao.rename( df_dunjiao.rename(
columns={'fund_name': '资金方', columns={'fund_name': '资金方',
'loan_paid_at':'放款时间', 'loan_paid_at': '放款时间',
'loan_id': '放款id', 'loan_id': '放款id',
'contract_term': '放款期数', 'contract_term': '放款期数',
'repaid_at': '实还款日', 'repaid_at': '实还款日',
'ref_amount': '实还金额', 'ref_amount': '实还金额',
'order_id': '渠道流水号', 'order_id': '渠道流水号',
'approach_name': '收款账户' 'approach_name': '收款账户'
}, inplace=True) }, inplace=True)
df_dunjiao.to_excel(path + 'dunjiao_'+str(2017) +'.xlsx', columns=df_dunjiao.columns,index=None, encoding='utf8')
\ No newline at end of file df_dunjiao.to_excel(path + 'dunjiao_' + str(2017) + '.xlsx', columns=df_dunjiao.columns, index=None, encoding='utf8')
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