Commit cf6e6059 authored by pengxiong's avatar pengxiong

查询模版数据

parent 6a724123
......@@ -9,5 +9,5 @@
from app.api.app import app
if __name__ == '__main__':
app.run('127.0.0.1', port=8000, debug=True)
app.run('0.0.0.0', port=8000, debug=True)
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : default_template_params.py
# @Time : 2021/1/6 下午3:30
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
from app.api.engine import template_folder
default_template = {
# 封面 值为None不不显示,为block显示
'box0': 'block',
# 目录
'box1': 'block',
# 投资总览
'box2': 'block',
'box2-section1': 'block',
'box2-section2': 'block',
'box2-section3': 'block',
'box2-section4': 'block',
# 目标与业绩
'box3': 'block',
'box3-section1': 'block',
'box3-section2': 'block',
'box3-section3': 'block',
'box3-section4': 'block',
# 业绩的明细
'box4': 'block',
'box4-section1': 'block',
'box4-section2': 'block',
'box4-section3': 'block',
# 个基点评
'box5': None,
# 优化组合建议
'box6': None,
'box6-section1': 'block',
'box6-section2': 'block',
'box6-section3': 'block',
'box6-section4': 'block',
# 新增基金
'box7': None,
# 结尾
'box8': 'block',
'logo': template_folder + '/v2/img/logo.png',
'brand_name': '资产管<br>理中心',
'cover_back': template_folder + '/v2/img/cover-back.png',
'scene': template_folder + '/v2/img/scene.png',
'team': template_folder + '/v2/img/default-user.png',
'red_rect': template_folder + '/v2/img/red-rect.png',
'sh': template_folder + '/v2/img/sh.png',
}
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : template_manage.py
# @Time : 2021/1/6 下午6:25
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import json
from flask_restful import Resource, reqparse
from flask import request
from app.api.engine import redis
from app.utils.format_transfer import npEncoder
from app.utils.jinjia2html_v2 import DataIntegrate
import numpy as np
class TemplateManage(Resource):
"""."""
def __init__(self):
"""."""
self.parser = reqparse.RequestParser()
def get(self):
"""."""
self.parser.add_argument('customer_id', type=str, required=True, help='customer_id不能为空')
args = self.parser.parse_args()
token = request.headers.get('Authorization', '')
token = 's:sid:' + token.split(' ')[1]
ifa_id = redis.get(token).decode()
if not ifa_id:
return {"code":40005,"data":None,"lang":"zh_CN","msg":"请登陆"}
ifa_id = ifa_id.replace('\'', '')
customer_id = args.get('customer_id')
data = []
try:
dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id)
data = dt.get_template_data()
except:
pass
resp = {
"statusCode": "0000",
"message": "成功",
"attributes": data
}
return json.dumps(resp, cls=npEncoder, ensure_ascii=False)
def post(self):
"""."""
pass
def put(self, id):
"""."""
pass
def delete(self, id):
"""."""
pass
\ No newline at end of file
......@@ -8,7 +8,9 @@
# -----------------------------------------------------------------------------
from app.controller.report import *
from app.controller.template_manage import *
def add_route(api):
"""注册路由"""
api.add_resource(ReportHandlers, '/fund_report/report')
api.add_resource(TemplateManage, '/template_manage/get_data')
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : format_transfer.py
# @Time : 2021/1/6 下午7:58
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import decimal
import json
import numpy as np
class npEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
elif isinstance(obj, decimal.Decimal):
return obj.__str__()
return json.JSONEncoder.default(self, obj)
\ No newline at end of file
......@@ -4,6 +4,7 @@ import uuid
from jinja2 import PackageLoader, Environment
from app.api.engine import work_dir, pdf_folder, template_folder
from app.config.default_template_params import default_template
from app.service.portfolio_diagnose import PortfolioDiagnose
from app.service.result_service_v2 import UserCustomerResultAdaptor
import numpy as np
......@@ -40,6 +41,9 @@ class DataIntegrate:
# 月度回报表格
self.get_month_table_return()
# 合并数据
self.get_template_data()
# # 渲染模版
# self.render_data()
......@@ -220,42 +224,15 @@ class DataIntegrate:
cur_group_portfolio_result["group_hoding_info"] = group_result["group_hoding_info"]
cur_group_portfolio_result["group_hoding_info_total"] = group_result["group_hoding_info_total"]
def render_data(self):
# 全部数据
def get_template_data(self):
""""""
data = {
# 封面 值为None不不显示,为block显示
'box0': 'block',
# 目录
'box1': 'block',
# 投资总览
'box2': 'block',
# 目标与业绩
'box3': 'block',
# 业绩的明细
'box4': 'block',
# 个基点评
'box5': None,
# 优化组合建议
'box6': None,
# 新增基金
'box7': None,
# 结尾
'box8': 'block',
'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/default-user.png',
'red_rect': template_folder + '/v2/img/red-rect.png',
'sh': template_folder + '/v2/img/sh.png',
# 全局数据
'customer_name': self.customer_name,
'year_month': self.user_customer.month_start_date.strftime("%Y-%m"),
'month': self.user_customer.month_start_date.strftime("%m"),
'start_date': self.user_customer.start_date.strftime("%Y-%m-%d"),
'latest_worth_day': self.user_customer.last_nav_date,
'brand_name': '资产管<br>理中心',
'customer_old': 42,
'customer_level': '平衡型',
# 综述数据
'now_allocation_amount': '{:,}'.format(self.total_cost), 'now_yield': self.now_yield, 'index_yield': self.index_yield,
......@@ -312,11 +289,16 @@ class DataIntegrate:
# 'new_group_evaluation': []
}
self.data = {**default_template, **data}
return self.data
def render_data(self):
# 全部数据
# 开始渲染html模板
env = Environment(loader=PackageLoader('app', 'templates')) # 创建一个包加载器对象
# template = env.get_template('monthReport.html') # 获取一个模板文件
template = env.get_template('/v2/monthReportV2.1.html') # 获取一个模板文件
monthReport_html = template.render(data) # 渲染
monthReport_html = template.render(self.data) # 渲染
# 保存 monthReport_html
save_file = "app/html/monthReport.html"
with open(save_file, 'w', encoding="utf-8") as f:
......@@ -331,5 +313,5 @@ class DataIntegrate:
if __name__ == '__main__':
start = time.time()
dt = DataIntegrate(ifa_id='USER_INFO15917853924996', customer_id='6741679287251775488')
dt.render_data()
data = dt.get_template_data()
print('耗时{}秒'.format(round(time.time()-start, 2)))
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