Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
F
fund_report
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭熊
fund_report
Commits
cf6e6059
Commit
cf6e6059
authored
Jan 06, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
查询模版数据
parent
6a724123
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
149 additions
and
32 deletions
+149
-32
__main__.py
app/api/__main__.py
+1
-1
default_template_params.py
app/config/default_template_params.py
+53
-0
template_manage.py
app/controller/template_manage.py
+61
-0
version1.py
app/router/version1.py
+2
-0
format_transfer.py
app/utils/format_transfer.py
+19
-0
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+13
-31
No files found.
app/api/__main__.py
View file @
cf6e6059
...
@@ -9,5 +9,5 @@
...
@@ -9,5 +9,5 @@
from
app.api.app
import
app
from
app.api.app
import
app
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
app
.
run
(
'
127.0.0.1
'
,
port
=
8000
,
debug
=
True
)
app
.
run
(
'
0.0.0.0
'
,
port
=
8000
,
debug
=
True
)
app/config/default_template_params.py
0 → 100644
View file @
cf6e6059
# -*- 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'
,
}
app/controller/template_manage.py
0 → 100644
View file @
cf6e6059
# -*- 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
app/router/version1.py
View file @
cf6e6059
...
@@ -8,7 +8,9 @@
...
@@ -8,7 +8,9 @@
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
from
app.controller.report
import
*
from
app.controller.report
import
*
from
app.controller.template_manage
import
*
def
add_route
(
api
):
def
add_route
(
api
):
"""注册路由"""
"""注册路由"""
api
.
add_resource
(
ReportHandlers
,
'/fund_report/report'
)
api
.
add_resource
(
ReportHandlers
,
'/fund_report/report'
)
api
.
add_resource
(
TemplateManage
,
'/template_manage/get_data'
)
app/utils/format_transfer.py
0 → 100644
View file @
cf6e6059
# -*- 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
app/utils/jinjia2html_v2.py
View file @
cf6e6059
...
@@ -4,6 +4,7 @@ import uuid
...
@@ -4,6 +4,7 @@ import uuid
from
jinja2
import
PackageLoader
,
Environment
from
jinja2
import
PackageLoader
,
Environment
from
app.api.engine
import
work_dir
,
pdf_folder
,
template_folder
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.portfolio_diagnose
import
PortfolioDiagnose
from
app.service.result_service_v2
import
UserCustomerResultAdaptor
from
app.service.result_service_v2
import
UserCustomerResultAdaptor
import
numpy
as
np
import
numpy
as
np
...
@@ -40,6 +41,9 @@ class DataIntegrate:
...
@@ -40,6 +41,9 @@ class DataIntegrate:
# 月度回报表格
# 月度回报表格
self
.
get_month_table_return
()
self
.
get_month_table_return
()
# 合并数据
self
.
get_template_data
()
# # 渲染模版
# # 渲染模版
# self.render_data()
# self.render_data()
...
@@ -220,42 +224,15 @@ class DataIntegrate:
...
@@ -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"
]
=
group_result
[
"group_hoding_info"
]
cur_group_portfolio_result
[
"group_hoding_info_total"
]
=
group_result
[
"group_hoding_info_total"
]
cur_group_portfolio_result
[
"group_hoding_info_total"
]
=
group_result
[
"group_hoding_info_total"
]
def
get_template_data
(
self
):
def
render_data
(
self
):
""""""
# 全部数据
data
=
{
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
,
'customer_name'
:
self
.
customer_name
,
'year_month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
Y-
%
m"
),
'year_month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
Y-
%
m"
),
'month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
m"
),
'month'
:
self
.
user_customer
.
month_start_date
.
strftime
(
"
%
m"
),
'start_date'
:
self
.
user_customer
.
start_date
.
strftime
(
"
%
Y-
%
m-
%
d"
),
'start_date'
:
self
.
user_customer
.
start_date
.
strftime
(
"
%
Y-
%
m-
%
d"
),
'latest_worth_day'
:
self
.
user_customer
.
last_nav_date
,
'latest_worth_day'
:
self
.
user_customer
.
last_nav_date
,
'brand_name'
:
'资产管<br>理中心'
,
'customer_old'
:
42
,
'customer_level'
:
'平衡型'
,
'customer_level'
:
'平衡型'
,
# 综述数据
# 综述数据
'now_allocation_amount'
:
'{:,}'
.
format
(
self
.
total_cost
),
'now_yield'
:
self
.
now_yield
,
'index_yield'
:
self
.
index_yield
,
'now_allocation_amount'
:
'{:,}'
.
format
(
self
.
total_cost
),
'now_yield'
:
self
.
now_yield
,
'index_yield'
:
self
.
index_yield
,
...
@@ -312,11 +289,16 @@ class DataIntegrate:
...
@@ -312,11 +289,16 @@ class DataIntegrate:
# 'new_group_evaluation': []
# 'new_group_evaluation': []
}
}
self
.
data
=
{
**
default_template
,
**
data
}
return
self
.
data
def
render_data
(
self
):
# 全部数据
# 开始渲染html模板
# 开始渲染html模板
env
=
Environment
(
loader
=
PackageLoader
(
'app'
,
'templates'
))
# 创建一个包加载器对象
env
=
Environment
(
loader
=
PackageLoader
(
'app'
,
'templates'
))
# 创建一个包加载器对象
# template = env.get_template('monthReport.html') # 获取一个模板文件
# template = env.get_template('monthReport.html') # 获取一个模板文件
template
=
env
.
get_template
(
'/v2/monthReportV2.1.html'
)
# 获取一个模板文件
template
=
env
.
get_template
(
'/v2/monthReportV2.1.html'
)
# 获取一个模板文件
monthReport_html
=
template
.
render
(
data
)
# 渲染
monthReport_html
=
template
.
render
(
self
.
data
)
# 渲染
# 保存 monthReport_html
# 保存 monthReport_html
save_file
=
"app/html/monthReport.html"
save_file
=
"app/html/monthReport.html"
with
open
(
save_file
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
save_file
,
'w'
,
encoding
=
"utf-8"
)
as
f
:
...
@@ -331,5 +313,5 @@ class DataIntegrate:
...
@@ -331,5 +313,5 @@ class DataIntegrate:
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
start
=
time
.
time
()
start
=
time
.
time
()
dt
=
DataIntegrate
(
ifa_id
=
'USER_INFO15917853924996'
,
customer_id
=
'6741679287251775488'
)
dt
=
DataIntegrate
(
ifa_id
=
'USER_INFO15917853924996'
,
customer_id
=
'6741679287251775488'
)
d
t
.
render
_data
()
d
ata
=
dt
.
get_template
_data
()
print
(
'耗时{}秒'
.
format
(
round
(
time
.
time
()
-
start
,
2
)))
print
(
'耗时{}秒'
.
format
(
round
(
time
.
time
()
-
start
,
2
)))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment