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
0a880f7e
Commit
0a880f7e
authored
Jan 11, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新建模版,更新模版,删除模版,获取默认列表分页数据
parent
1c6b5c23
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
1278 additions
and
42 deletions
+1278
-42
__main__.py
app/api/__main__.py
+1
-1
default_template_params.py
app/config/default_template_params.py
+795
-14
template_manage.py
app/controller/template_manage.py
+78
-22
tamp_diagnose_app.py
app/model/tamp_diagnose_app.py
+253
-0
version1.py
app/router/version1.py
+4
-2
template_manage_service.py
app/service/template_manage_service.py
+141
-0
jinjia2html_v2.py
app/utils/jinjia2html_v2.py
+6
-3
No files found.
app/api/__main__.py
View file @
0a880f7e
...
...
@@ -9,5 +9,5 @@
from
app.api.app
import
app
if
__name__
==
'__main__'
:
app
.
run
(
'0.0.0.0'
,
port
=
8000
,
debug
=
Tru
e
)
app
.
run
(
'0.0.0.0'
,
port
=
8000
,
debug
=
Fals
e
)
app/config/default_template_params.py
View file @
0a880f7e
This diff is collapsed.
Click to expand it.
app/controller/template_manage.py
View file @
0a880f7e
...
...
@@ -12,7 +12,12 @@ from flask_restful import Resource, reqparse
from
flask
import
request
from
app.api.engine
import
redis
from
app.config.default_template_params
import
hold_default_template
,
hold_default_data
,
diagnose_default_data
,
\
diagnose_default_template
from
app.service.template_manage_service
import
add_template
,
update_template
,
delete_template
,
get_template_list
,
\
get_default_template
from
app.utils.format_transfer
import
npEncoder
from
flask
import
jsonify
from
app.utils.jinjia2html_v2
import
DataIntegrate
import
numpy
as
np
...
...
@@ -22,25 +27,19 @@ class TemplateManage(Resource):
def
__init__
(
self
):
"""."""
token
=
request
.
headers
.
get
(
'Authorization'
,
''
)
token
=
's:sid:'
+
token
.
split
(
' '
)[
1
]
ifa_id
=
redis
.
get
(
token
)
if
not
ifa_id
:
return
{
"code"
:
'9005'
,
"message"
:
"请登录"
,
"attributes"
:
[]}
self
.
ifa_id
=
ifa_id
.
decode
()
.
replace
(
'
\'
'
,
''
)
self
.
parser
=
reqparse
.
RequestParser
()
def
get
(
self
):
"""."""
self
.
parser
.
add_argument
(
'
customer_id'
,
type
=
str
,
required
=
True
,
help
=
'customer_id
不能为空'
)
"""
获取默认模版数据
."""
self
.
parser
.
add_argument
(
'
type'
,
type
=
int
,
required
=
True
,
help
=
'type
不能为空'
)
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
data
=
get_default_template
(
args
)
resp
=
{
"statusCode"
:
"0000"
,
"message"
:
"成功"
,
...
...
@@ -48,14 +47,71 @@ class TemplateManage(Resource):
}
return
json
.
dumps
(
resp
,
cls
=
npEncoder
,
ensure_ascii
=
False
)
def
post
(
self
):
"""."""
pass
"""新建定义模版."""
self
.
parser
.
add_argument
(
'name'
,
type
=
str
,
required
=
True
,
help
=
'模版名称不能为空'
)
self
.
parser
.
add_argument
(
'custom_template'
,
type
=
str
,
required
=
True
,
help
=
'模版数据不能为空'
)
self
.
parser
.
add_argument
(
'type'
,
type
=
int
,
required
=
True
,
help
=
'模版类型不能为空'
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
add_template
(
args
)
def
put
(
self
):
"""更新模版."""
self
.
parser
.
add_argument
(
'update_type'
,
type
=
int
,
required
=
True
,
help
=
'1默认模版2自定义模版'
)
self
.
parser
.
add_argument
(
'type'
,
type
=
int
,
required
=
True
,
help
=
'1持仓报告2诊断报告'
)
self
.
parser
.
add_argument
(
'name'
,
type
=
int
,
required
=
False
,
help
=
'自定义模版名称'
)
self
.
parser
.
add_argument
(
'default_template'
,
type
=
str
,
required
=
False
,
help
=
'模版数据不能为空'
)
self
.
parser
.
add_argument
(
'custom_template'
,
type
=
str
,
required
=
False
,
help
=
'模版数据不能为空'
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
update_template
(
args
)
resp
=
{
"statusCode"
:
"0000"
,
"message"
:
"成功"
,
"attributes"
:
[]
}
return
resp
def
delete
(
self
):
"""删除模版."""
self
.
parser
.
add_argument
(
'id'
,
type
=
str
,
required
=
True
,
help
=
'模版id'
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
delete_template
(
args
)
resp
=
{
"statusCode"
:
"0000"
,
"message"
:
"成功"
,
"attributes"
:
[]
}
return
resp
def
put
(
self
,
id
):
class
TemplateList
(
Resource
):
"""."""
pass
def
delete
(
self
,
id
):
def
__init__
(
self
):
"""."""
pass
\ No newline at end of file
token
=
request
.
headers
.
get
(
'Authorization'
,
''
)
token
=
's:sid:'
+
token
.
split
(
' '
)[
1
]
ifa_id
=
redis
.
get
(
token
)
if
not
ifa_id
:
return
{
"code"
:
'9005'
,
"message"
:
"请登录"
,
"attributes"
:
[]}
self
.
ifa_id
=
ifa_id
.
decode
()
.
replace
(
'
\'
'
,
''
)
self
.
parser
=
reqparse
.
RequestParser
()
def
get
(
self
):
"""获取模版列表,分页."""
self
.
parser
.
add_argument
(
'type'
,
type
=
int
,
required
=
True
,
help
=
'0为全部1为持仓报告2为诊断报告'
)
self
.
parser
.
add_argument
(
'pageNumber'
,
type
=
int
,
required
=
False
)
self
.
parser
.
add_argument
(
'pageSize'
,
type
=
int
,
required
=
False
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
data
=
get_template_list
(
args
)
resp
=
{
"statusCode"
:
"0000"
,
"message"
:
"成功"
,
"attributes"
:
data
}
return
resp
app/model/tamp_diagnose_app.py
0 → 100644
View file @
0a880f7e
This diff is collapsed.
Click to expand it.
app/router/version1.py
View file @
0a880f7e
...
...
@@ -12,5 +12,7 @@ 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'
)
api
.
add_resource
(
ReportHandlers
,
'/api/fund_report/report'
)
api
.
add_resource
(
TemplateManage
,
'/api/template_manage'
)
api
.
add_resource
(
TemplateList
,
'/api/template_list'
)
app/service/template_manage_service.py
0 → 100644
View file @
0a880f7e
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : template_manage_service.py
# @Time : 2021/1/8 下午5:26
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import
datetime
import
json
import
uuid
from
sqlalchemy
import
and_
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
from
app.config.default_template_params
import
hold_default_template
,
hold_default_data
,
diagnose_default_data
,
\
diagnose_default_template
from
app.model.tamp_diagnose_app
import
*
def
get_default_template
(
args
):
""""""
type
=
args
.
get
(
'type'
)
data
=
[]
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
res
=
tamp_diagnose_session
.
query
(
FundReportManange
)
.
filter
(
and_
(
FundReportManange
.
ifa_id
==
args
.
get
(
'ifa_id'
),
FundReportManange
.
type
==
type
,
FundReportManange
.
delete_tag
==
0
,
FundReportManange
.
default_template
is
not
None
))
.
first
()
default_template
,
default_data
=
None
,
None
if
type
==
1
:
default_template
=
hold_default_template
default_data
=
hold_default_data
elif
type
==
2
:
default_template
=
diagnose_default_template
default_data
=
diagnose_default_data
if
res
:
data
=
{
**
json
.
loads
(
res
.
get
(
'default_template'
)),
**
default_data
}
else
:
data
=
{
**
default_template
,
**
default_data
}
return
data
def
add_template
(
args
):
"""新建模版"""
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
args
[
'id'
]
=
str
(
uuid
.
uuid4
())
args
[
'default_template'
]
=
json
.
dumps
(
hold_default_template
)
args
[
'create_by'
]
=
args
.
get
(
'ifa_id'
)
args
[
'create_time'
]
=
datetime
.
datetime
.
now
()
fund_report_manange
=
FundReportManange
(
args
)
tamp_diagnose_session
.
add
(
fund_report_manange
)
def
update_template
(
args
):
"""更新默认模版"""
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
update_type
=
args
.
get
(
'update_type'
)
type
=
args
.
get
(
'type'
)
res
=
tamp_diagnose_session
.
query
(
FundReportManange
)
.
filter
(
and_
(
FundReportManange
.
ifa_id
==
args
.
get
(
'ifa_id'
),
FundReportManange
.
type
==
type
,
FundReportManange
.
delete_tag
==
0
,
))
if
update_type
==
1
:
# 更新默认模版
if
type
==
1
:
args
[
'name'
]
=
'持仓报告默认模版'
elif
type
==
2
:
args
[
'name'
]
=
'诊断报告默认模版'
if
res
:
res
.
update
({
'default_template'
:
args
.
get
(
'default_template'
),
'update_by'
:
args
.
get
(
'ifa_id'
),
'update_time'
:
datetime
.
datetime
.
now
()
})
else
:
args
[
'create_by'
]
=
args
.
get
(
'ifa_id'
)
args
[
'create_time'
]
=
datetime
.
datetime
.
now
()
new_template
=
FundReportManange
(
**
args
)
tamp_diagnose_session
.
add
(
new_template
)
elif
update_type
==
2
:
# 更新自定义模版
args
[
'update_by'
]
=
args
.
get
(
'ifa_id'
)
args
[
'update_time'
]
=
datetime
.
datetime
.
now
()
res
.
update
({
'name'
:
args
.
get
(
'name'
),
'custom_template'
:
args
.
get
(
'custom_template'
),
'update_by'
:
args
.
get
(
'ifa_id'
),
'update_time'
:
datetime
.
datetime
.
now
()
})
return
True
def
delete_template
(
args
):
"""."""
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
tamp_diagnose_session
.
query
(
FundReportManange
)
.
filter
(
FundReportManange
.
id
==
args
.
get
(
id
)
)
.
update
({
'delete_tag'
:
1
,
'update_by'
:
args
.
get
(
'ifa_id'
),
'update_time'
:
datetime
.
datetime
.
now
()
})
def
get_template_list
(
args
):
"""."""
pageNumber
=
args
[
'pageNumber'
]
pageSize
=
args
[
'pageSize'
]
offset
=
(
pageNumber
-
1
)
*
pageSize
dtype
=
args
.
get
(
'type'
)
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
res
=
[]
if
dtype
==
0
:
res
=
tamp_diagnose_session
.
query
(
FundReportManange
)
.
filter
(
and_
(
FundReportManange
.
delete_tag
==
0
,
FundReportManange
.
ifa_id
==
args
.
get
(
'ifa_id'
)
))
else
:
res
=
tamp_diagnose_session
.
query
(
FundReportManange
)
.
filter
(
and_
(
FundReportManange
.
delete_tag
==
0
,
FundReportManange
.
ifa_id
==
args
.
get
(
'ifa_id'
),
FundReportManange
.
type
==
args
.
get
(
'type'
)
))
if
not
res
:
return
False
totalSize
=
res
.
count
()
data
=
res
.
offset
(
offset
)
.
limit
(
pageSize
)
data
=
[
r
.
to_dict
()
for
r
in
data
]
return
{
'content'
:
data
,
'pageNum'
:
pageNumber
,
'pageSize'
:
pageSize
,
'totalSize'
:
totalSize
}
app/utils/jinjia2html_v2.py
View file @
0a880f7e
...
...
@@ -19,7 +19,7 @@ from app.utils.radar_chart import gen_radar_chart
class
DataIntegrate
:
def
__init__
(
self
,
ifa_id
=
'USER_INFO1591
4346866762'
,
customer_id
=
'202009281545001
'
,
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
,
type
=
1
):
def
__init__
(
self
,
ifa_id
=
'USER_INFO1591
7850824287'
,
customer_id
=
'6716613802534121472
'
,
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
,
type
=
1
):
self
.
user_customer
=
UserCustomerResultAdaptor
(
ifa_id
,
customer_id
)
self
.
customer_name
=
self
.
user_customer
.
customer_real_name
self
.
ifa_name
=
self
.
user_customer
.
ifa_real_name
...
...
@@ -254,7 +254,8 @@ class DataIntegrate:
'all_folio_result'
:
self
.
all_folio_result
,
}
self
.
data
=
{
**
hold_default_template
,
**
data
}
# self.data = {**hold_default_template, **data}
self
.
data
=
data
elif
self
.
type
==
2
:
# 诊断报告数据
data
=
{
...
...
@@ -284,7 +285,9 @@ class DataIntegrate:
# 组合数据
'all_folio_result'
:
self
.
all_folio_result
,
}
self
.
data
=
{
**
diagnose_default_template
,
**
data
}
# self.data = {**diagnose_default_template, **data}
self
.
data
=
data
print
(
data
)
return
self
.
data
def
render_data
(
self
):
...
...
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