Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
financial-system
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
xianyang
financial-system
Commits
110d8850
Commit
110d8850
authored
Sep 21, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化业务类型汇总查询,线程版
parent
153461ec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
3 deletions
+21
-3
crud.py
app/api/account/crud.py
+21
-3
No files found.
app/api/account/crud.py
View file @
110d8850
import
math
import
threading
import
time
from
concurrent.futures.thread
import
ThreadPoolExecutor
...
...
@@ -737,18 +738,28 @@ class HomePageDisplay(object):
self
.
unique_tag
=
unique_tag
self
.
account
=
[]
self
.
guild
=
[]
self
.
bus_data
=
[]
self
.
income
=
0
self
.
outcome
=
0
def
th_task
(
self
,
sql
):
res_ads
=
LinkMysql
(
env
.
DB_HISTORY
)
.
query_mysql
(
sql
)
if
res_ads
:
self
.
bus_data
+=
res_ads
def
get_month_data
(
self
):
acc_sql
=
"select unique_tag,uuid from fi_account"
guild_sql
=
"select uuid from guild"
count_sql
=
f
"select count(id) as num from {self.date}"
with
ThreadPoolExecutor
(
max_workers
=
2
)
as
pool
:
future1
=
pool
.
submit
(
LinkMysql
(
env
.
DB_3YV2
)
.
query_mysql
,
acc_sql
)
future2
=
pool
.
submit
(
LinkMysql
(
env
.
DB_3YV2
)
.
query_mysql
,
guild_sql
)
future3
=
pool
.
submit
(
LinkMysql
(
env
.
DB_HISTORY
)
.
query_mysql
,
count_sql
)
acc_data
=
future1
.
result
()
guild_data
=
future2
.
result
()
count
=
future3
.
result
()
account
=
[
i
[
'uuid'
]
for
i
in
acc_data
]
guild
=
[
i
[
'uuid'
]
for
i
in
guild_data
]
assets_cond
=
[
'type in(0,1)'
]
...
...
@@ -766,12 +777,19 @@ class HomePageDisplay(object):
Logger
(
20
)
.
logger
.
info
(
'没找到系统账户'
)
return
[],
0
,
0
assets_cond
.
append
(
f
" uuid='{acc_uuid[0]}'"
)
assets_sql
=
f
"select reference_type,type,sum(amount) as amount from {self.date} where {' and '.join(assets_cond)} GROUP BY reference_type,type"
total_data
=
LinkMysql
(
env
.
DB_HISTORY
)
.
query_mysql
(
assets_sql
)
ths_count
=
math
.
ceil
(
count
[
0
][
'num'
]
/
10000000
)
ths
=
[]
for
x
in
range
(
ths_count
):
assets_sql
=
f
"select reference_type,type,sum(amount) as amount from {self.date} where {' and '.join(assets_cond)} GROUP BY reference_type,type LIMIT {x * 10000000},{(x+1) * 10000000}"
ths
.
append
(
threading
.
Thread
(
target
=
self
.
th_task
,
args
=
[
assets_sql
]))
for
y
in
range
(
ths_count
):
ths
[
y
]
.
start
()
for
z
in
range
(
ths_count
):
ths
[
z
]
.
join
()
# 数据分类
income
=
[]
outcome
=
[]
for
i
in
total
_data
:
for
i
in
self
.
bus
_data
:
op
=
{}
if
TYPE_NAME
.
get
(
i
[
'reference_type'
]):
op
[
'name'
]
=
TYPE_NAME
.
get
(
i
[
'reference_type'
])
...
...
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