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
08710f04
Commit
08710f04
authored
Jan 13, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
编辑报告
parent
57cd1e89
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
143 additions
and
17 deletions
+143
-17
report.py
app/controller/report.py
+51
-7
version1.py
app/router/version1.py
+1
-0
report_service.py
app/service/report_service.py
+72
-0
template_manage_service.py
app/service/template_manage_service.py
+19
-10
No files found.
app/controller/report.py
View file @
08710f04
...
...
@@ -16,7 +16,7 @@ from flask import request, render_template
from
flask
import
make_response
from
app.api.engine
import
config
from
app.service.report_service
import
get_report_list
,
delete_report
from
app.service.report_service
import
get_report_list
,
delete_report
,
get_one_report
,
edit_report
from
app.service.template_manage_service
import
make_report
,
get_make_report_data
from
app.utils.html_to_pdf
import
html_to_pdf
from
app.api.engine
import
pdf_folder
,
redis
,
env
,
TAMP_SQL
,
tamp_diagnose_app_engine
...
...
@@ -37,7 +37,7 @@ class ReportHandlers(Resource):
self
.
parser
=
reqparse
.
RequestParser
()
def
get
(
self
):
"""获取
制作模版
数据."""
"""获取
新建报告
数据."""
self
.
parser
.
add_argument
(
'id'
,
type
=
str
,
required
=
True
,
help
=
'模版id不能为空'
)
self
.
parser
.
add_argument
(
'customer_id'
,
type
=
str
,
required
=
True
,
help
=
'customer_id不能为空'
)
args
=
self
.
parser
.
parse_args
()
...
...
@@ -51,9 +51,13 @@ class ReportHandlers(Resource):
return
resp
def
post
(
self
):
"""制作报告."""
"""保存报告."""
self
.
parser
.
add_argument
(
'type'
,
type
=
int
,
required
=
True
,
help
=
'1为持仓报告2为诊断报告3周期报告'
)
self
.
parser
.
add_argument
(
'name'
,
type
=
str
,
required
=
False
,
help
=
'报告名称或者客户姓名'
)
self
.
parser
.
add_argument
(
'customer_id'
,
type
=
str
,
required
=
True
,
help
=
'customer_id不能为空'
)
self
.
parser
.
add_argument
(
'template_data'
,
type
=
str
,
required
=
True
,
help
=
'template_data不能为空'
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
make_report
(
args
)
...
...
@@ -98,15 +102,27 @@ class ReportList(Resource):
return
resp
def
post
(
self
):
"""
制作
报告."""
"""
保存
报告."""
self
.
parser
.
add_argument
(
'customer_id'
,
type
=
str
,
required
=
True
,
help
=
'customer_id不能为空'
)
args
=
self
.
parser
.
parse_args
()
make_report
(
args
)
def
put
(
self
,
id
):
"""."""
pass
def
put
(
self
):
"""编辑报告."""
self
.
parser
.
add_argument
(
'type'
,
type
=
int
,
required
=
True
,
help
=
'1为持仓报告2为诊断报告3周期报告'
)
self
.
parser
.
add_argument
(
'id'
,
type
=
int
,
required
=
True
,
help
=
'报告id不能为空'
)
self
.
parser
.
add_argument
(
'report_data'
,
type
=
str
,
required
=
True
,
help
=
'报告数据不能为空'
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
data
=
edit_report
(
args
)
resp
=
{
"statusCode"
:
"0000"
,
"message"
:
"成功"
,
"attributes"
:
data
}
return
resp
def
delete
(
self
):
"""."""
...
...
@@ -120,4 +136,32 @@ class ReportList(Resource):
"message"
:
"成功"
,
"attributes"
:
[]
}
return
resp
class
FindReport
(
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
(
'type'
,
type
=
int
,
required
=
True
,
help
=
'1为持仓报告2为诊断报告3周期报告'
)
self
.
parser
.
add_argument
(
'id'
,
type
=
str
,
required
=
False
,
help
=
''
)
args
=
self
.
parser
.
parse_args
()
args
[
'ifa_id'
]
=
self
.
ifa_id
data
=
get_one_report
(
args
)
resp
=
{
"statusCode"
:
"0000"
,
"message"
:
"成功"
,
"attributes"
:
data
}
return
resp
\ No newline at end of file
app/router/version1.py
View file @
08710f04
...
...
@@ -14,6 +14,7 @@ def add_route(api):
"""注册路由"""
api
.
add_resource
(
ReportHandlers
,
'/api/fund_report/report'
)
api
.
add_resource
(
ReportList
,
'/api/fund_report/reportlist'
)
api
.
add_resource
(
FindReport
,
'/api/fund_report/get_one_report'
)
api
.
add_resource
(
TemplateManage
,
'/api/template_manage'
)
api
.
add_resource
(
TemplateList
,
'/api/template_list'
)
api
.
add_resource
(
CustomerList
,
'/api/customer_list'
)
...
...
app/service/report_service.py
View file @
08710f04
...
...
@@ -6,6 +6,8 @@
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import
datetime
from
sqlalchemy
import
and_
# from sqlalchemy import union_all
...
...
@@ -81,3 +83,73 @@ def delete_report(args):
PeriodicReport
.
ifa_id
==
ifa_id
,
PeriodicReport
.
id
==
id
))
.
delete
()
def
get_one_report
(
args
):
"""."""
id
=
args
.
get
(
'id'
)
type
=
args
.
get
(
'type'
)
ifa_id
=
args
.
get
(
'ifa_id'
)
res
=
[]
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
hold_report
=
tamp_diagnose_session
.
query
(
HoldReport
)
.
filter
(
and_
(
HoldReport
.
id
==
id
,
HoldReport
.
ifa_id
==
ifa_id
,
))
hold_diagnose_report
=
tamp_diagnose_session
.
query
(
HoldDiagnoseReport
)
.
filter
(
and_
(
HoldDiagnoseReport
.
id
==
id
,
HoldDiagnoseReport
.
ifa_id
==
ifa_id
,
))
periodic_report
=
tamp_diagnose_session
.
query
(
PeriodicReport
)
.
filter
(
and_
(
PeriodicReport
.
id
==
id
,
PeriodicReport
.
ifa_id
==
ifa_id
,
))
if
type
==
0
:
res
=
hold_report
.
union_all
(
hold_diagnose_report
)
.
union_all
(
periodic_report
)
elif
type
==
1
:
res
=
hold_report
elif
type
==
2
:
res
=
hold_diagnose_report
elif
type
==
3
:
res
=
periodic_report
data
=
[
r
.
to_dict
()
for
r
in
res
]
return
data
def
edit_report
(
args
):
"""编辑报告"""
id
=
args
.
get
(
'id'
)
type
=
args
.
get
(
'type'
)
ifa_id
=
args
.
get
(
'ifa_id'
)
report_data
=
args
.
get
(
'report_data'
)
res
=
[]
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
hold_report
=
tamp_diagnose_session
.
query
(
HoldReport
)
.
filter
(
and_
(
HoldReport
.
id
==
id
,
HoldReport
.
ifa_id
==
ifa_id
,
))
hold_diagnose_report
=
tamp_diagnose_session
.
query
(
HoldDiagnoseReport
)
.
filter
(
and_
(
HoldDiagnoseReport
.
id
==
id
,
HoldDiagnoseReport
.
ifa_id
==
ifa_id
,
))
periodic_report
=
tamp_diagnose_session
.
query
(
PeriodicReport
)
.
filter
(
and_
(
PeriodicReport
.
id
==
id
,
PeriodicReport
.
ifa_id
==
ifa_id
,
))
if
type
==
1
:
res
=
hold_report
elif
type
==
2
:
res
=
hold_diagnose_report
elif
type
==
3
:
res
=
periodic_report
if
not
res
:
return
False
r
=
res
.
update
({
'report_data'
:
report_data
,
'update_time'
:
datetime
.
datetime
.
now
()
})
if
r
>
0
:
return
True
return
False
app/service/template_manage_service.py
View file @
08710f04
...
...
@@ -8,12 +8,15 @@
# -----------------------------------------------------------------------------
import
datetime
import
json
import
time
import
uuid
import
oss2
from
ftfy
import
fix_text
from
sqlalchemy
import
and_
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
,
config
,
env
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
*
...
...
@@ -177,7 +180,7 @@ def get_make_report_data(args):
id
=
args
.
get
(
'id'
)
ifa_id
=
args
.
get
(
'ifa_id'
)
customer_id
=
args
.
get
(
'customer_id'
)
default_
template
=
''
template
=
''
type
=
1
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
...
...
@@ -188,12 +191,13 @@ def get_make_report_data(args):
if
not
res
:
return
False
type
=
res
.
type
default_template
=
res
.
default_template
if
not
default_template
:
default_template
=
res
.
custom_template
default_template
=
json
.
loads
(
default_template
)
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
customer_id
,
type
=
type
)
data
=
dt
.
get_template_data
(
default_template
)
template
=
res
.
default_template
if
not
template
:
template
=
res
.
custom_template
template
=
json
.
loads
(
template
)
# dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id, type=type)
# data = dt.get_template_data(template)
data
=
template
return
data
...
...
@@ -221,6 +225,10 @@ def set_default_template(args):
def
make_report
(
args
):
"""制作报告."""
ifa_id
=
args
.
get
(
'ifa_id'
)
customer_id
=
args
.
get
(
'customer_id'
)
type
=
args
.
get
(
'type'
)
name
=
args
.
get
(
'name'
)
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_app_session
=
tamp_diagnose_app
.
session
...
...
@@ -233,7 +241,8 @@ def make_report(args):
tamp_diagnose_app_session
.
execute
(
sql
)
start
=
time
.
time
()
try
:
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
customer_id
,
pdf_name
=
pdf_name
)
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
customer_id
,
pdf_name
=
pdf_name
,
type
=
type
)
dt
.
render_data
()
except
:
pass
...
...
@@ -254,4 +263,4 @@ def make_report(args):
ifa_id
,
customer_id
)
tamp_diagnose_app_session
.
execute
(
sql
)
\ No newline at end of file
tamp_diagnose_app_session
.
execute
(
sql
)
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