# -*- coding: utf-8 -*-
import datetime
import sys
import multiprocessing as mtp
from itertools import product

import pandas as pd
from sqlalchemy import create_engine
from dateutil.relativedelta import relativedelta

reload(sys)
sys.setdefaultencoding('utf8')


'''
16年12月31日前放款，17年1月到7月还款
'''
# path = 'E:/hk/bt/'
# 注意修改数据源
engine_new_transaction = create_engine(
    'mysql+mysqldb://internal_r:ArbNgtvlJzZHXsEu@172.16.3.201:3306/qunaer_new?charset=utf8',
    echo=True)

read_quna_sql='''
SELECT r.product_no,SUM(r.repay_principle)
FROM `repay_detail_201706` r
JOIN `pay_detail` pay ON r.product_no = pay.`product_no` and pay.trans_time <'2017-01-01'
WHERE
r.`repay_time` <'2017-08-01'  and r.repay_time>= '2017-01-01'
group by 1

'''
df_quna=pd.read_sql(read_quna_sql,con=engine_new_transaction)
print df_quna.head()

ff_quna=pd.read_excel(u"C:\\Users\\dinghiguo\\Desktop\\16年底在贷白条在贷截止2017.7.31收回\\2.1去哪儿白条在贷校验版 - 副本.xlsx")
print ff_quna.head()
# ff_quna['cp'] = ff_quna['cp'].astype(str)
df_all=pd.merge(ff_quna,df_quna,how='left',left_on='cp',right_on='product_no')
df_all.head()
df_all.to_excel(u"C:\\Users\\dinghiguo\\Desktop\\201707去哪未还本金收回.xlsx", index=None)


