Commit 75230ea3 authored by 赵杰's avatar 赵杰

修改数据库为with形式调用

parent 00eac2b5
......@@ -57,9 +57,9 @@ tamp_user_engine = create_engine(
),
echo=True
)
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))()
# 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'],
......
......@@ -12,7 +12,7 @@ from sqlalchemy import and_
import tushare as ts
import datetime
from decimal import Decimal
from app.api.engine import tamp_user_session, tamp_product_session
from app.api.engine import tamp_user_engine, tamp_product_engine, TAMP_SQL
# from app.model.tamp_user_models import CustomerOrder, CustomerInfo
# from app.model.tamp_product_models import FundInfo
......@@ -64,7 +64,9 @@ class UserCustomerDataAdaptor:
# # .filter(user_id = self.user_id).all()
# data2 = tamp_user_session.query(t_customer_info).all()
# data3 = tamp_product_session.query(t_fund_info).all()
with TAMP_SQL(tamp_user_engine) as tamp_user, TAMP_SQL(tamp_product_engine) as tamp_product:
tamp_user_session = tamp_user.session
tamp_product_session = tamp_product.session
sql_user = """select f2.realname,f3.customer_name,fund_id,f1.order_type,f1.pay_date,f1.subscription_fee,f1.confirm_share_date,f1.confirm_share,f1.confirm_amount,f1.nav,f1.folio_name from customer_order f1, user_info f2,customer_info f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.user_id='{}' and f1.customer_id='{}'""".format(self.user_id, self.customer_id)
cur = tamp_user_session.execute(sql_user)
data = cur.fetchall()
......@@ -83,6 +85,8 @@ class UserCustomerDataAdaptor:
# 获取客户持有的基金净值数据
def get_customer_fund_nav_data(self):
with TAMP_SQL(tamp_product_engine) as tamp_product:
tamp_product_session = tamp_product.session
now_date = datetime.datetime.now().strftime("%Y%m%d")
trade_date_df = self.get_trade_cal("20000101", now_date)
self.trade_cal_date = trade_date_df
......@@ -124,6 +128,8 @@ class UserCustomerDataAdaptor:
# 获取客户对比指数净值数据
def get_customer_index_nav_data(self, index_id="IN0000007M"):
with TAMP_SQL(tamp_product_engine) as tamp_product:
tamp_product_session = tamp_product.session
sql = "select distinct price_date,close from fund_market_indexes where index_id='{}' order by price_date ASC".format(index_id)
cur = tamp_product_session.execute(sql)
data = cur.fetchall()
......
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