Commit 988c0a4f authored by 李宗熹's avatar 李宗熹

解决找不到基金名称

parent 955237c7
...@@ -28,15 +28,15 @@ class StatementController(Resource): ...@@ -28,15 +28,15 @@ class StatementController(Resource):
""".""" """."""
self.parser = reqparse.RequestParser() self.parser = reqparse.RequestParser()
# @login_require @login_require
def get(self): def get(self):
"""""" """"""
self.parser.add_argument('user_id', type=str, required=True, help='用户id不能为空') # self.parser.add_argument('user_id', type=str, required=True, help='用户id不能为空')
self.parser.add_argument('statement_time', required=False, help='对账单时间戳') self.parser.add_argument('statement_time', required=False, help='对账单时间戳')
args = self.parser.parse_args() args = self.parser.parse_args()
print(args.get('statement_time')) print(args.get('statement_time'))
user_id = args.get('user_id') # user_id = args.get('user_id')
# user_id = g.ifa_id user_id = g.ifa_id
print(user_id) print(user_id)
if args.get('statement_time') != '': if args.get('statement_time') != '':
year = datetime.fromtimestamp(int(args.get('statement_time')) / 1000).year year = datetime.fromtimestamp(int(args.get('statement_time')) / 1000).year
......
...@@ -10,10 +10,8 @@ import numpy as np ...@@ -10,10 +10,8 @@ import numpy as np
from datetime import datetime, date from datetime import datetime, date
from decimal import Decimal from decimal import Decimal
from app.api.engine import tamp_order_engine, tamp_user_engine, tamp_diagnose_app_engine, TAMP_SQL from app.api.engine import tamp_order_engine, tamp_user_engine, \
# from app.service.data_service_v2_1 import * tamp_fund_engine, tamp_product_engine, tamp_diagnose_app_engine, TAMP_SQL
# from app.service.customer import get_customer_list
from app.service.portfolio_diagnose import get_fund_name
class DateEncoder(json.JSONEncoder): class DateEncoder(json.JSONEncoder):
...@@ -25,16 +23,58 @@ class DateEncoder(json.JSONEncoder): ...@@ -25,16 +23,58 @@ class DateEncoder(json.JSONEncoder):
return json.JSONEncoder.default(self, obj) return json.JSONEncoder.default(self, obj)
def get_fund_name(fund, fund_type=1):
if fund_type == 0:
with TAMP_SQL(tamp_fund_engine) as tamp_fund:
tamp_fund_session = tamp_fund.session
sql = "SELECT fund_short_name FROM tx_fund_info WHERE `id`='{}'".format(fund)
# df = pd.read_sql(sql, con)
cur = tamp_fund_session.execute(sql)
data = cur.fetchall()
df = pd.DataFrame(list(data), columns=['fund_short_name'])
elif fund_type == 1 or fund_type == 2:
with TAMP_SQL(tamp_fund_engine) as tamp_fund:
tamp_fund_session = tamp_fund.session
sql = "SELECT fund_short_name FROM fund_info WHERE id='{}'".format(fund)
# df = pd.read_sql(sql, con)
cur = tamp_fund_session.execute(sql)
data = cur.fetchall()
df = pd.DataFrame(list(data), columns=['fund_short_name'])
if len(df) == 0:
with TAMP_SQL(tamp_product_engine) as tamp_product:
tamp_product_session = tamp_product.session
sql = "SELECT fund_short_name FROM fund_info WHERE id='{}'".format(fund)
# df = pd.read_sql(sql, con)
cur = tamp_product_session.execute(sql)
data = cur.fetchall()
df = pd.DataFrame(list(data), columns=['fund_short_name'])
else:
with TAMP_SQL(tamp_fund_engine) as tamp_fund:
tamp_fund_session = tamp_fund.session
sql = "SELECT fund_name FROM ifa_imported_fund_info WHERE id='{}'".format(fund)
# df = pd.read_sql(sql, con)
cur = tamp_fund_session.execute(sql)
data = cur.fetchall()
df = pd.DataFrame(list(data), columns=['fund_short_name'])
if df.fund_short_name.count() > 0:
return df.fund_short_name.values[0]
else:
return fund
def get_order_info(user_id): def get_order_info(user_id):
with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app: with TAMP_SQL(tamp_diagnose_app_engine) as tamp_diagnose_app:
tamp_diagnose_app_session = tamp_diagnose_app.session tamp_diagnose_app_session = tamp_diagnose_app.session
sql_user = """select f1.fund_id, f2.realname, f3.customer_name, f1.customer_id, f3.valueSex,f1.type,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 tamp_diagnose_app.customer_order_view f1, tamp_user.user_info f2,tamp_diagnose_app.customer_view f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.delete_tag=0 and user_id='{}'""".format( sql_user = """select f1.id, f1.fund_id, f2.realname, f3.customer_name, f1.customer_id, f3.valueSex,f1.type,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 tamp_diagnose_app.customer_order_view f1, tamp_user.user_info f2,tamp_diagnose_app.customer_view f3 where f2.id=f1.user_id and f3.id=f1.customer_id and f1.delete_tag=0 and user_id='{}'""".format(
user_id) user_id)
cur = tamp_diagnose_app_session.execute(sql_user) cur = tamp_diagnose_app_session.execute(sql_user)
data = cur.fetchall() data = cur.fetchall()
order_df = pd.DataFrame(list(data), order_df = pd.DataFrame(list(data),
columns=['fund_id', 'user_name', 'customer_name', 'customer_id', 'value_sex', 'type', columns=['order_id', 'fund_id', 'user_name', 'customer_name', 'customer_id', 'value_sex',
'order_type', 'pay_date', 'type', 'order_type', 'pay_date',
'subscription_fee', 'confirm_share_date', 'confirm_share', 'subscription_fee', 'confirm_share_date', 'confirm_share',
'confirm_amount', 'nav', 'folio_name']) 'confirm_amount', 'nav', 'folio_name'])
return order_df return order_df
...@@ -79,7 +119,7 @@ def get_month_list(quarter, year): ...@@ -79,7 +119,7 @@ def get_month_list(quarter, year):
def type2note(type): def type2note(type):
type2note_dict = {1: "入", type2note_dict = {1: "入",
2: "赎回", 2: "赎回",
4: "分红"} 4: "分红"}
return type2note_dict.get(type) return type2note_dict.get(type)
...@@ -184,7 +224,7 @@ class Statement(object): ...@@ -184,7 +224,7 @@ class Statement(object):
detail = [] detail = []
for i in range(df_length): for i in range(df_length):
detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]).values[0][0], detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]),
'pay_date': np.datetime_as_string(customer_df['pay_date'].values[i], unit='D'), 'pay_date': np.datetime_as_string(customer_df['pay_date'].values[i], unit='D'),
'confirm_share_date': np.datetime_as_string(customer_df['confirm_share_date'].values[i], 'confirm_share_date': np.datetime_as_string(customer_df['confirm_share_date'].values[i],
unit='D'), unit='D'),
...@@ -265,7 +305,7 @@ class Statement(object): ...@@ -265,7 +305,7 @@ class Statement(object):
for i in range(df_length): for i in range(df_length):
tax_rate = get_tax_rate() tax_rate = get_tax_rate()
detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]).values[0][0], detail.append({'fund': get_fund_name(customer_df['fund_id'].values[i]),
'confirm_amount': customer_df['confirm_amount'].values[i], 'confirm_amount': customer_df['confirm_amount'].values[i],
'pay_date': np.datetime_as_string(customer_df['pay_date'].values[i], unit='D'), 'pay_date': np.datetime_as_string(customer_df['pay_date'].values[i], unit='D'),
'subscription_fee': customer_df['subscription_fee'].values[i], 'subscription_fee': customer_df['subscription_fee'].values[i],
...@@ -305,7 +345,7 @@ class Statement(object): ...@@ -305,7 +345,7 @@ class Statement(object):
customer_fund_df = customer_fund[1] customer_fund_df = customer_fund[1]
fund_id = customer_fund_df['fund_id'].values[0] fund_id = customer_fund_df['fund_id'].values[0]
fund_name = get_fund_name(fund_id).values[0][0] fund_name = get_fund_name(fund_id)
df_length = customer_fund_df['predict_date'].count() df_length = customer_fund_df['predict_date'].count()
before_tax = 0 before_tax = 0
...@@ -361,7 +401,7 @@ class Statement(object): ...@@ -361,7 +401,7 @@ class Statement(object):
if carry_sum == 0: if carry_sum == 0:
continue continue
try: try:
fund_name = get_fund_name(fund_id).values[0][0] fund_name = get_fund_name(fund_id)
except: except:
fund_name = fund_id fund_name = fund_id
...@@ -382,14 +422,14 @@ class Statement(object): ...@@ -382,14 +422,14 @@ class Statement(object):
confirm_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0] confirm_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0]
nav = self.ifa_order[self.ifa_order['order_id'] == order_id]['nav'].values[0] nav = self.ifa_order[self.ifa_order['order_id'] == order_id]['nav'].values[0]
native_amount = nav native_amount = nav
provision_date = '2020-12-31' provision_date = self.ifa_order[self.ifa_order['order_id'] == order_id]['confirm_date'].values[0]
detail.append({'customer': customer_name, detail.append({'customer': customer_name,
'order_type': order_type, 'order_type': order_type,
'confirm_date': confirm_date, 'confirm_date': confirm_date,
'native_amount': native_amount, 'native_amount': native_amount,
'nav': nav, 'nav': nav,
'provision_date': provision_date, 'provision_date': provision_date,
'provision_carry':provision_carry} 'provision_carry': provision_carry}
) )
before_tax += provision_carry before_tax += provision_carry
...@@ -423,7 +463,7 @@ class Statement(object): ...@@ -423,7 +463,7 @@ class Statement(object):
customer_id = customer_fund[0][0] customer_id = customer_fund[0][0]
customer_name = self.ifa_order[self.ifa_order['customer_id'] == customer_id]['customer_name'].values[0] customer_name = self.ifa_order[self.ifa_order['customer_id'] == customer_id]['customer_name'].values[0]
fund_id = customer_fund[0][1] fund_id = customer_fund[0][1]
fund_name = get_fund_name(fund_id).values[0][0] fund_name = get_fund_name(fund_id)
customer_fund_df = customer_fund[1] customer_fund_df = customer_fund[1]
incentive_rate_sum = customer_fund_df['incentive_fee_ratio'].sum() incentive_rate_sum = customer_fund_df['incentive_fee_ratio'].sum()
......
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