Commit c2c9e6cb authored by pengxiong's avatar pengxiong

任务

parent 501b77af
......@@ -77,22 +77,12 @@ tamp_fund_engine = create_engine(
user=config[env]['MySQL']['user'],
password=config[env]['MySQL']['password'],
charset="utf8"
)
)
tamp_order_engine = create_engine(
'mysql+pymysql://{user}:{password}@{host}:{port}/{db}?charset={charset}'.format(
db=config[env]['MySQL']['tamp_order_db'],
host=config[env]['MySQL']['host'],
port=config[env]['MySQL']['port'],
user=config[env]['MySQL']['user'],
password=config[env]['MySQL']['password'],
charset="utf8"),
echo=True
),
max_overflow=0, # 超过连接池大小外最多创建的连接
pool_size=100, # 连接池大小
pool_timeout=5,
pool_recycle=600
)
# tamp_product_session = scoped_session(sessionmaker(bind=tamp_product_engine))()
# tamp_order_session = scoped_session(sessionmaker(bind=tamp_order_engine))()
# tamp_user_session = scoped_session(sessionmaker(bind=tamp_user_engine))()
# redis = redis.StrictRedis(
# host=config[env]['redis']['host'],
......
......@@ -245,7 +245,7 @@ class DataIntegrate:
'cover_back': template_folder + '/v2/img/cover-back.png',
'logo': template_folder + '/v2/img/logo.png',
'scene': template_folder + '/v2/img/scene.png',
'team': template_folder + '/v2/img/team.png',
'team': template_folder + '/v2/img/default-user.png',
# 全局数据
'customer_name': self.customer_name,
'year_month': self.user_customer.month_start_date.strftime("%Y-%m"),
......
......@@ -5,11 +5,13 @@
找出 ifa 所有的客户
进行月报生成
"""
import time
from app.api.engine import tamp_user_engine, tamp_order_engine, TAMP_SQL
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, and_
from app.utils.jinjia2html_v2 import DataIntegrate
from concurrent import futures
Base = declarative_base()
class IfaUser(Base):
......@@ -34,30 +36,40 @@ class Customer(Base):
customer_name = Column(String(128))
def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
# print('开始制作IFA: {}, 客户: {}的基金月报'.format(ifauser_name, customer_name))
# try:
DataIntegrate(ifauser_id, customer_id, '{}_{}_.pdf'.format(ifauser_name, customer_name))
# except IndexError:
# print("发生异常,下一个走起!")
# ifauser_id = args[0]
# ifauser_name = args[1]
# customer_id = args[2]
# customer_name = args[3]
print('开始制作IFA: {}, 客户: {}的基金月报'.format(ifauser_name, customer_name))
start = time.time()
try:
DataIntegrate(ifauser_id, customer_id, '{}_{}_.pdf'.format(ifauser_name, 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))
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).filter(IfaUser.id.in_(['USER_INFO15916072577875'])).all()
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(and_(Ifa_Customer.ifa_id == ifauser.id, Ifa_Customer.customer_id.in_(['6716613804182482944']))).all()
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)
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))
# with futures.ProcessPoolExecutor(8) as executor:
# executor.map(call_month_report, args)
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