timed_task.py 2.14 KB
Newer Older
wang zhengwei's avatar
wang zhengwei committed
1 2 3 4 5 6 7 8 9 10
# coding: utf-8

"""
找出所有 ifa
        找出 ifa 所有的客户
                           进行月报生成
"""

from app.api.engine import tamp_user_engine, tamp_order_engine, TAMP_SQL
from sqlalchemy.ext.declarative import declarative_base
pengxiong's avatar
pengxiong committed
11
from sqlalchemy import Column, String, Integer, and_
12
from app.utils.jinjia2html import DataIntegrate
wang zhengwei's avatar
wang zhengwei committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

Base = declarative_base()
class IfaUser(Base):
    __tablename__ = "user_info"

    id = Column(String(64), primary_key=True)
    ui_username = Column(String(64))
    ui_sex = Column(String(64))
        
class Ifa_Customer(Base):
    __tablename__ = "ifa_customer"

    id = Column(String(64), primary_key=True)
    customer_id = Column(String(32))
    ifa_id = Column(String(64))
    
        
class Customer(Base):
    __tablename__ = "customer"

    id = Column(String(64), primary_key=True)
    customer_name = Column(String(128))



def call_month_report(ifauser_id, ifauser_name, customer_id, customer_name):
pengxiong's avatar
pengxiong committed
39 40 41 42 43
    # print('开始制作IFA: {}, 客户: {}的基金月报'.format(ifauser_name, customer_name))
    # try:
    DataIntegrate(ifauser_id, customer_id, '{}_{}_.pdf'.format(ifauser_name, customer_name))
    # except IndexError:
    #     print("发生异常,下一个走起!")
wang zhengwei's avatar
wang zhengwei committed
44 45 46 47 48 49



with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_order_engine) as tamp_order:
    tamp_user_session = tamp_user.session
    # 获取所有 ifauser
pengxiong's avatar
pengxiong committed
50
    ifausers = tamp_user_session.query(IfaUser).filter(IfaUser.id.in_(['USER_INFO15916072577875'])).all()
wang zhengwei's avatar
wang zhengwei committed
51 52 53
    
    tamp_order_session = tamp_order.session
    # for ifauser in ifausers:
pengxiong@wealthgrow.cn's avatar
pengxiong@wealthgrow.cn committed
54
    for ifauser in ifausers:
wang zhengwei's avatar
wang zhengwei committed
55 56
        # 获取某个 ifa 的所有 customer
        customers = tamp_order_session.query(Ifa_Customer).\
pengxiong's avatar
pengxiong committed
57
                        filter(and_(Ifa_Customer.ifa_id == ifauser.id, Ifa_Customer.customer_id.in_(['6716613804966817792']))).all()
pengxiong's avatar
pengxiong committed
58

wang zhengwei's avatar
wang zhengwei committed
59 60 61 62 63
        # 循环这个 ifa 的所有 customer
        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)