Commit 377754e8 authored by pengxiong's avatar pengxiong

任务优化

parent 14de95aa
......@@ -91,8 +91,8 @@ tamp_fund_engine = create_engine(
# )
logging.basicConfig(level=logging.INFO,
# filename=work_dir + config[env]['log']['filename'],
# filemode=config[env]['log']['filemode'],
filename=work_dir + config[env]['log']['filename'],
filemode=config[env]['log']['filemode'],
format=config[env]['log']['format'],
datefmt=config[env]['log']['datefmt']
)
......
......@@ -327,5 +327,5 @@ class DataIntegrate:
if __name__ == '__main__':
start = time.time()
DataIntegrate(ifa_id='USER_INFO15916072577875', customer_id='6716613804182482944')
DataIntegrate(ifa_id='188843568193236992', customer_id='6734729261802467328')
print('耗时{}秒'.format(round(time.time()-start, 2)))
......@@ -6,6 +6,9 @@
进行月报生成
"""
import time
import traceback
from app.api.engine import logging, pdf_folder
import os
from app.api.engine import tamp_user_engine, tamp_order_engine, TAMP_SQL
from sqlalchemy.ext.declarative import declarative_base
......@@ -35,12 +38,26 @@ class Customer(Base):
id = Column(String(64), primary_key=True)
customer_name = Column(String(128))
# class CustomerOrder(Base):
# __tablename__ = 'customer_order'
#
# user_id = Column(String(128))
# customer_id = Column(String(128))
# class UserInfo(Base):
# __tablename__ = 'user_info'
#
# id = Column(String(64), primary_key=True)
# ui_username = Column(String(128))
def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
# ifauser_id = args[0]
# ifauser_name = args[1]
# customer_id = args[2]
# customer_name = args[3]
filename = '{}_{}_.pdf'.format(ifauser_name, customer_name)
if os.path.exists(pdf_folder + filename):
return None
print('开始制作IFA: {}, 客户: {}的基金月报'.format(ifauser_name, customer_name))
start = time.time()
try:
......@@ -48,28 +65,18 @@ def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
print('IFA: {}, 客户: {}的基金月报已经生成, 耗时{}秒'.format(ifauser_name, customer_name, time.time()-start))
except OSError:
print('IFA: {}, 客户: {}的基金月报已经生成,耗时{}秒'.format(ifauser_name, customer_name, time.time()-start))
except:
print("IFA: {}, 客户: {}的基金月报生成异常,开始制作下一个".format(ifauser_name, customer_name))
except Exception as e:
logging.error("IFA: {}, 客户: {}的基金月报生成异常,错误追踪:{}".format(ifauser_name, customer_name, traceback.format_exc()))
print("IFA: {}, 客户: {}的基金月报生成异常,错误追踪:{}".format(ifauser_name, customer_name, traceback.format_exc()))
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_order_engine) as tamp_order:
tamp_user_session = tamp_user.session
# 获取所有 ifauser
ifausers = tamp_user_session.query(IfaUser).all()
tamp_order_session = tamp_order.session
# for ifauser in ifausers:
for ifauser in ifausers:
# 获取某个 ifa 的所有 customer
customers = tamp_order_session.query(Ifa_Customer).\
filter(Ifa_Customer.ifa_id == ifauser.id).all()
# 循环这个 ifa 的所有 customer
# args = []
for customer in customers:
customer_full = tamp_order_session.query(Customer).get(customer.customer_id)
call_month_report(ifauser.id, ifauser.ui_username, customer_full.id, customer_full.customer_name)
# args.append((ifauser.id, ifauser.ui_username, customer_full.id, customer_full.customer_name))
res = tamp_user_session.execute('SELECT DISTINCT user_id, customer_id , realname, customer_name FROM (select f1.user_id, f1.customer_id, f2.realname,f3.customer_name from customer_order f1, user_info f2,customer_info f3 where f2.id=f1.user_id and f3.id=f1.customer_id) res;')
data = res.fetchall()
for d in data:
call_month_report(d[0], d[2], d[1], d[3])
# args.append((ifauser.id, ifauser.ui_username, customer_full.id, customer_full.customer_name))
# with futures.ProcessPoolExecutor(8) as executor:
# executor.map(call_month_report, args)
This source diff could not be displayed because it is too large. You can view the blob instead.
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