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
5ebe5b3e
Commit
5ebe5b3e
authored
Apr 21, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化公会质押金,新增首页查询
parent
13d3d23f
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
118 additions
and
7 deletions
+118
-7
api_v1.py
app/api/api_v1.py
+2
-0
__init__.py
app/api/home/__init__.py
+0
-0
crud.py
app/api/home/crud.py
+63
-0
views.py
app/api/home/views.py
+25
-0
env.py
core/config/env.py
+10
-1
db_link.py
libs/db_link.py
+15
-0
main.py
main.py
+3
-6
No files found.
app/api/api_v1.py
View file @
5ebe5b3e
...
...
@@ -5,6 +5,7 @@ from app.api.role import views as r_view
from
app.api.account
import
views
as
a_view
from
app.api.margin
import
views
as
m_view
from
app.api.export
import
views
as
e_view
from
app.api.home
import
views
as
h_view
api_router
=
APIRouter
()
api_router
.
include_router
(
u_view
.
router
,
prefix
=
"/users"
,
tags
=
[
"users"
])
...
...
@@ -13,3 +14,4 @@ api_router.include_router(r_view.router, prefix="/role", tags=["role"])
api_router
.
include_router
(
a_view
.
router
,
prefix
=
"/account"
,
tags
=
[
"account"
])
api_router
.
include_router
(
m_view
.
router
,
prefix
=
"/margin"
,
tags
=
[
"margin"
])
api_router
.
include_router
(
e_view
.
router
,
prefix
=
"/export"
,
tags
=
[
"export"
])
api_router
.
include_router
(
h_view
.
router
,
prefix
=
"/home"
,
tags
=
[
"home"
])
app/api/home/__init__.py
0 → 100644
View file @
5ebe5b3e
app/api/home/crud.py
0 → 100644
View file @
5ebe5b3e
import
json
import
threading
from
concurrent.futures.thread
import
ThreadPoolExecutor
import
pandas
as
pd
from
core.config.env
import
env
,
red
from
libs.db_link
import
LinkMysql
class
HomePageDisplay
(
object
):
def
__init__
(
self
,
date
,
unique_tag
,
amount_type
,
reference_type
,
type
):
self
.
date
=
'assets_log_'
+
date
self
.
unique_tag
=
unique_tag
self
.
amount_type
=
amount_type
self
.
reference_type
=
reference_type
self
.
type
=
type
self
.
account
=
[]
self
.
guild
=
[]
self
.
total_money
=
0
def
mysql_query_data
(
self
,
assets_cond
,
page
,
size
):
assets_sql
=
f
"select amount from {self.date} where {' and '.join(assets_cond)} limit {page},{size}"
total_data
=
LinkMysql
(
env
.
DB_HISTORY
)
.
perform_mysql
(
assets_sql
)
df
=
pd
.
DataFrame
(
total_data
)
total
=
df
[
'amount'
]
.
sum
()
self
.
total_money
=
self
.
total_money
+
total
def
get_month_data
(
self
):
acc_sql
=
"select unique_tag,uuid from fi_account"
guild_sql
=
"select uuid from guild"
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
)
acc_data
=
future1
.
result
()
guild_data
=
future2
.
result
()
account
=
[
i
[
'uuid'
]
for
i
in
acc_data
]
guild
=
[
i
[
'uuid'
]
for
i
in
guild_data
]
assets_cond
=
[]
assets_cond
.
append
(
f
" reference_type='{self.reference_type}'"
)
if
self
.
unique_tag
==
'guild_account'
:
assets_cond
.
append
(
f
" uuid in{tuple(guild)}"
)
elif
self
.
unique_tag
==
'user_account'
:
if
self
.
amount_type
==
0
:
amount_type
=
'consumablel'
else
:
amount_type
=
'withdrawable'
assets_cond
.
append
(
f
" uuid not in{tuple(guild + account)} and amount_type='{amount_type}'"
)
elif
self
.
unique_tag
==
'knapsack_account'
:
assets_cond
.
append
(
f
" amount_type='backpack'"
)
else
:
acc_uuid
=
[
i
[
'uuid'
]
for
i
in
acc_data
if
i
[
'unique_tag'
]
==
self
.
unique_tag
]
if
not
acc_uuid
:
print
(
'没找到系统账户'
)
return
[]
assets_cond
.
append
(
f
" uuid='{acc_uuid[0]}'"
)
assets_sql
=
f
"select amount from {self.date} where {' and '.join(assets_cond)}"
total_data
=
LinkMysql
(
env
.
DB_HISTORY
)
.
query_mysql
(
assets_sql
)
df
=
pd
.
DataFrame
(
total_data
)
df_total
=
df
.
sum
()
total_dict
=
df_total
.
to_dict
()
if
total_data
:
return
total_dict
.
get
(
'amount'
)
/
1000
return
0
app/api/home/views.py
0 → 100644
View file @
5ebe5b3e
from
typing
import
Optional
from
fastapi
import
APIRouter
,
Depends
from
app.api.home.crud
import
HomePageDisplay
from
libs.result_format
import
HttpResultResponse
,
HttpMessage
from
libs.token_verify
import
login_required
router
=
APIRouter
()
@
router
.
get
(
"/multidimensional/total"
)
def
read_account
(
date
:
Optional
[
str
]
=
""
,
unique_tag
:
Optional
[
str
]
=
""
,
account_type
:
Optional
[
str
]
=
""
,
amount_type
:
Optional
[
str
]
=
""
,
reference_type
:
Optional
[
str
]
=
""
,
type
:
Optional
[
int
]
=
None
,
token
=
Depends
(
login_required
)):
"""月,业务类型,消费类型,出入账目统计"""
if
not
all
([
date
,
reference_type
])
or
type
is
None
or
(
not
unique_tag
and
not
account_type
):
return
HttpResultResponse
(
code
=
500
,
msg
=
HttpMessage
.
MISSING_PARAMETER
)
if
account_type
and
not
unique_tag
:
unique_tag
=
account_type
total
=
HomePageDisplay
(
date
,
unique_tag
,
amount_type
,
reference_type
,
type
)
.
get_month_data
()
return
HttpResultResponse
(
data
=
total
)
core/config/env.py
View file @
5ebe5b3e
...
...
@@ -61,8 +61,17 @@ class Env(BaseSettings):
PASSWORD
:
str
=
"fj123456"
# DB_HISTORY = "3yakj_v2"
# guild_url=""
oss_url
=
'http://oss.3yakj.com/application_static_data'
oss_url
=
'http://oss.3yakj.com/application_static_data'
CLEARING_CENTER_URL
:
str
=
'http://106.55.103.148:6464/'
RABBITMQ
:
dict
=
{
"url"
:
"http://106.55.103.148:16672/"
,
"host"
:
"106.55.103.148"
,
"vhost"
:
"/"
,
"port"
:
6672
,
"username"
:
"admin"
,
"password"
:
"nimda"
,
"queue"
:
"financial_consistency"
}
class
TestingEnv
(
Env
):
...
...
libs/db_link.py
View file @
5ebe5b3e
import
json
import
pymysql
import
pika
from
DBUtils.PooledDB
import
PooledDB
# 连接mysql
from
core.config.env
import
env
,
red
class
LinkMysql
(
object
):
def
__init__
(
self
,
db_info
):
self
.
POOLMYSQL
=
PooledDB
(
...
...
@@ -46,3 +52,12 @@ class LinkMysql(object):
conn
=
self
.
POOLMYSQL
.
connection
()
cursor
=
conn
.
cursor
(
cursor
=
pymysql
.
cursors
.
DictCursor
)
cursor
.
execute
(
sql
)
# class RabbitMqConn(object):
# """rabbitmq 连接"""
# def __init__(self):
# rb = env.RABBITMQ
# rb_info = pika.PlainCredentials(rb.get('username'), rb.get('password'))
# self.connection = pika.BlockingConnection(parameters=pika.ConnectionParameters(rb.get('host'), rb.get('port'), rb.get('vhost'), rb_info))
# self.channel = self.connection.channel()
main.py
View file @
5ebe5b3e
import
time
from
datetime
import
timedelta
,
datetime
from
datetime
import
timedelta
import
uvicorn
from
fastapi
import
FastAPI
,
Depends
from
fastapi
import
FastAPI
from
jose
import
jwt
from
app.api.api_v1
import
api_router
from
starlette.middleware.cors
import
CORSMiddleware
from
fastapi
import
Request
from
core.config.env
import
env
from
core.dependencies.auth_dependen
import
create_access_token
from
libs.functions
import
time_format
from
libs.token_verify
import
oauth2_scheme
app
=
FastAPI
()
...
...
@@ -25,6 +21,7 @@ app.add_middleware(
allow_methods
=
[
'*'
],
# 设置允许跨域的http方法,比如 get、post、put等。
allow_headers
=
[
'*'
])
# 允许跨域的headers,可以用来鉴别来源等作用。
@
app
.
middleware
(
"http"
)
async
def
add_process_time_header
(
request
:
Request
,
call_next
):
hs
=
request
.
headers
...
...
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