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
65c1fe78
Commit
65c1fe78
authored
Jan 21, 2021
by
pengxiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
controller
parent
9e9909c6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
257 additions
and
6 deletions
+257
-6
report.py
app/controller/report.py
+5
-4
report_service.py
app/service/report_service.py
+245
-0
celery.py
app/utils/celery.py
+7
-2
No files found.
app/controller/report.py
View file @
65c1fe78
...
@@ -14,6 +14,7 @@ from flask import request, render_template, g
...
@@ -14,6 +14,7 @@ from flask import request, render_template, g
from
flask
import
make_response
from
flask
import
make_response
from
app.api.engine
import
config
from
app.api.engine
import
config
from
app.service.report_service
import
make_report
from
app.utils.auth
import
login_require
from
app.utils.auth
import
login_require
from
app.utils.html_to_pdf
import
html_to_pdf
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
from
app.api.engine
import
pdf_folder
,
redis
,
env
,
TAMP_SQL
,
tamp_diagnose_app_engine
...
@@ -32,13 +33,13 @@ class ReportHandlers(Resource):
...
@@ -32,13 +33,13 @@ class ReportHandlers(Resource):
"""."""
"""."""
self
.
parser
.
add_argument
(
'customer_id'
,
type
=
str
,
required
=
True
,
help
=
'customer_id不能为空'
)
self
.
parser
.
add_argument
(
'customer_id'
,
type
=
str
,
required
=
True
,
help
=
'customer_id不能为空'
)
args
=
self
.
parser
.
parse_args
()
args
=
self
.
parser
.
parse_args
()
customer_id
=
args
[
'customer_id'
]
args
[
'ifa_id'
]
=
g
.
ifa_id
ifa_id
=
g
.
ifa_id
# 默认模版制作持仓报告
# 默认模版制作持仓报告
data
=
make_report
(
args
)
resp
=
{
resp
=
{
"code"
:
0
,
"code"
:
0
,
"data"
:
[]
,
"data"
:
data
,
"lang"
:
"zh_CN"
,
"lang"
:
"zh_CN"
,
"msg"
:
"成功"
"msg"
:
"成功"
}
}
...
...
app/service/report_service.py
0 → 100644
View file @
65c1fe78
# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name : report_service.py
# @Time : 2021/1/13 下午3:14
# @Author : X. Peng
# @Email : acepengxiong@163.com
# @Software : PyCharm
# -----------------------------------------------------------------------------
import
datetime
import
json
import
os
import
uuid
from
sqlalchemy
import
and_
,
or_
# from sqlalchemy import union_all
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
,
template_folder
,
temp_img_save_folder
from
app.model.tamp_diagnose_app
import
HoldReport
,
HoldDiagnoseReport
,
PeriodicReport
,
Customer
,
ReportView
from
app.utils.jinjia2html_v2
import
DataIntegrate
from
app.utils.celery
import
save_pdf
def
get_report_list
(
args
):
"""."""
type
=
args
.
get
(
'type'
)
ifa_id
=
args
.
get
(
'ifa_id'
)
name
=
args
.
get
(
'name'
)
pageNumber
=
args
[
'pageNumber'
]
pageSize
=
args
[
'pageSize'
]
start_time
=
args
.
get
(
'start_time'
)
end_time
=
args
.
get
(
'end_time'
)
offset
=
(
pageNumber
-
1
)
*
pageSize
res
=
[]
totalSize
=
0
conditions
=
()
if
type
==
0
:
conditions
=
[
ReportView
.
ifa_id
==
ifa_id
,
or_
(
ReportView
.
name
.
like
(
'
%
'
+
name
+
'
%
'
),
ReportView
.
customer_name
.
like
(
'
%
'
+
name
+
'
%
'
)),
ReportView
.
create_time
>=
start_time
,
ReportView
.
create_time
<=
end_time
]
else
:
conditions
=
[
ReportView
.
ifa_id
==
ifa_id
,
ReportView
.
type
==
type
,
or_
(
ReportView
.
name
.
like
(
'
%
'
+
name
+
'
%
'
),
ReportView
.
customer_name
.
like
(
'
%
'
+
name
+
'
%
'
)),
ReportView
.
create_time
>=
start_time
,
ReportView
.
create_time
<=
end_time
]
allow_field
=
[
'id'
,
'customer_id'
,
'ifa_id'
,
'update_time'
,
'create_time'
,
'update_status'
,
'file'
,
'be_viewed'
,
'name'
,
'customer_name'
,
'author_name'
,
'type'
]
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
report_res
=
tamp_diagnose_session
.
query
(
ReportView
)
.
filter
(
and_
(
*
conditions
))
totalSize
=
report_res
.
count
()
report_res
=
report_res
.
order_by
(
ReportView
.
create_time
.
desc
())
.
offset
(
offset
)
.
limit
(
pageSize
)
res
=
[
r
.
to_dict
(
allow_field
=
allow_field
)
for
r
in
report_res
]
return
{
'content'
:
res
,
'pageNum'
:
pageNumber
,
'pageSize'
:
pageSize
,
'totalSize'
:
totalSize
}
def
delete_report
(
args
):
"""."""
type
=
args
.
get
(
'type'
)
id
=
args
.
get
(
'id'
)
ifa_id
=
args
.
get
(
'ifa_id'
)
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
if
type
==
1
:
tamp_diagnose_session
.
query
(
HoldReport
)
.
filter
(
and_
(
HoldReport
.
ifa_id
==
ifa_id
,
HoldReport
.
id
==
id
))
.
delete
()
elif
type
==
2
:
tamp_diagnose_session
.
query
(
HoldDiagnoseReport
)
.
filter
(
and_
(
HoldDiagnoseReport
.
ifa_id
==
ifa_id
,
HoldDiagnoseReport
.
id
==
id
))
.
delete
()
elif
type
==
3
:
tamp_diagnose_session
.
query
(
PeriodicReport
)
.
filter
(
and_
(
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'
)
data
=
[]
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
res
=
tamp_diagnose_session
.
query
(
ReportView
)
.
filter
(
and_
(
ReportView
.
id
==
id
,
ReportView
.
type
==
type
,
ReportView
.
ifa_id
==
ifa_id
,
))
data
=
[
r
.
to_dict
()
for
r
in
res
]
if
data
:
return
data
[
0
]
return
False
def
edit_report
(
args
):
"""编辑报告"""
id
=
args
.
get
(
'id'
)
type
=
args
.
get
(
'type'
)
ifa_id
=
args
.
get
(
'ifa_id'
)
report_data
=
args
.
get
(
'report_data'
)
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
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_status'
:
1
,
'update_time'
:
datetime
.
datetime
.
now
()
})
save_pdf
.
delay
(
id
,
ifa_id
,
res
[
0
]
.
customer_id
,
pdf_name
,
type
,
report_data
)
# try:
# dt = DataIntegrate(ifa_id=ifa_id, customer_id=res[0].customer_id, pdf_name=pdf_name, type=type)
# dt.render_data(data=json.loads(report_data.replace(template_folder, temp_img_save_folder)))
# except:
# pass
# 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
# res.update({
# 'file': pdf_name,
# 'update_status': 2,
# 'update_time': datetime.datetime.now()
# })
return
True
def
make_report
(
args
):
"""制作报告."""
ifa_id
=
args
.
get
(
'ifa_id'
)
customer_id
=
args
.
get
(
'customer_id'
)
type
=
1
pdf_name
=
str
(
uuid
.
uuid4
())
+
'.pdf'
args
[
'create_time'
]
=
datetime
.
datetime
.
now
()
args
[
'update_status'
]
=
1
args
.
pop
(
'type'
)
record_id
=
0
with
TAMP_SQL
(
tamp_diagnose_app_engine
)
as
tamp_diagnose_app
:
tamp_diagnose_session
=
tamp_diagnose_app
.
session
report_record
=
None
if
type
==
1
:
report_record
=
HoldReport
(
**
args
)
elif
type
==
2
:
report_record
=
HoldDiagnoseReport
(
**
args
)
elif
type
==
3
:
report_record
=
PeriodicReport
(
**
args
)
if
not
report_record
:
return
False
tamp_diagnose_session
.
add
(
report_record
)
tamp_diagnose_session
.
flush
()
record_id
=
report_record
.
id
save_pdf
.
delay
(
record_id
,
ifa_id
,
customer_id
,
pdf_name
,
type
)
return
{
'record_id'
:
record_id
}
# pid = os.fork()
# if pid == 0:
# try:
# dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id, pdf_name=pdf_name, type=type)
# dt.render_data(data=report_data)
# except:
# pass
# 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 == record_id,
# HoldReport.ifa_id == ifa_id,
# ))
# hold_diagnose_report = tamp_diagnose_session.query(HoldDiagnoseReport).filter(and_(
# HoldDiagnoseReport.id == record_id,
# HoldDiagnoseReport.ifa_id == ifa_id,
# ))
# periodic_report = tamp_diagnose_session.query(PeriodicReport).filter(and_(
# PeriodicReport.id == record_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
# res.update({
# 'file': pdf_name,
# 'update_status': 2,
# 'update_time': datetime.datetime.now()
# })
# else:
# return {'record_id': record_id}
app/utils/celery.py
View file @
65c1fe78
import
datetime
import
datetime
import
json
from
celery
import
Celery
from
celery
import
Celery
from
sqlalchemy
import
and_
,
or_
from
sqlalchemy
import
and_
,
or_
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
,
template_folder
,
redis_host
,
redis_port
,
redis_db
,
redis_password
from
app.api.engine
import
TAMP_SQL
,
tamp_diagnose_app_engine
,
template_folder
,
redis_host
,
redis_port
,
redis_db
,
\
redis_password
,
temp_img_save_folder
from
app.model.tamp_diagnose_app
import
HoldReport
,
HoldDiagnoseReport
,
PeriodicReport
,
Customer
,
ReportView
from
app.model.tamp_diagnose_app
import
HoldReport
,
HoldDiagnoseReport
,
PeriodicReport
,
Customer
,
ReportView
from
app.utils.jinjia2html_v2
import
DataIntegrate
from
app.utils.jinjia2html_v2
import
DataIntegrate
...
@@ -14,7 +16,7 @@ celery_app.conf.update({"broker_url": celery_conf, "result_backend": celery_conf
...
@@ -14,7 +16,7 @@ celery_app.conf.update({"broker_url": celery_conf, "result_backend": celery_conf
@
celery_app
.
task
@
celery_app
.
task
def
save_pdf
(
id
,
ifa_id
,
customer_id
,
pdf_name
,
type
,
report_data
):
def
save_pdf
(
id
,
ifa_id
,
customer_id
,
pdf_name
,
type
):
"""
"""
加法
加法
:param x:
:param x:
...
@@ -23,6 +25,9 @@ def save_pdf(id, ifa_id, customer_id, pdf_name, type, report_data):
...
@@ -23,6 +25,9 @@ def save_pdf(id, ifa_id, customer_id, pdf_name, type, report_data):
"""
"""
try
:
try
:
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
customer_id
,
pdf_name
=
pdf_name
,
type
=
type
)
dt
=
DataIntegrate
(
ifa_id
=
ifa_id
,
customer_id
=
customer_id
,
pdf_name
=
pdf_name
,
type
=
type
)
report_data
=
dt
.
get_template_data
()
report_data
=
json
.
dumps
(
report_data
)
.
replace
(
template_folder
,
temp_img_save_folder
)
report_data
=
json
.
loads
(
report_data
)
dt
.
render_data
(
data
=
report_data
)
dt
.
render_data
(
data
=
report_data
)
except
:
except
:
pass
pass
...
...
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