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
ac4b41d1
Commit
ac4b41d1
authored
Apr 23, 2023
by
xianyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志添加
parent
0aaca536
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
14 deletions
+96
-14
crud.py
app/api/account/crud.py
+7
-5
views.py
app/api/account/views.py
+1
-0
crud.py
app/api/export/crud.py
+8
-7
crud.py
app/api/margin/crud.py
+4
-2
env.py
core/config/env.py
+3
-0
log_utils.py
libs/log_utils.py
+73
-0
No files found.
app/api/account/crud.py
View file @
ac4b41d1
...
...
@@ -11,6 +11,7 @@ from libs.business import TYPE_NAME, query_fi_account_type
from
libs.db_link
import
LinkMysql
from
libs.functions
import
wrapper_out
,
get_now_timestamp
,
uuid
,
get_before_timestamp
,
time_str_to_timestamp
,
\
get_yesterday_timestamp
,
search
,
get_last_month
,
get_date_list
from
libs.log_utils
import
Logger
from
libs.orm
import
QueryAllData
from
models
import
account
as
models
from
models.account
import
AccountFinance
,
AccountFinanceDetails
,
AccountType
...
...
@@ -165,13 +166,14 @@ def create_account(param):
}
try
:
result
=
search
(
clearing_dict
,
'Server.UserExecute.CreateBalanceUser'
)
Logger
()
.
logger
.
info
(
f
"创建账户清算结果:{str(result)}"
)
if
result
[
'data'
][
'result'
][
'status'
]:
account_uuid
=
result
[
'data'
][
'result'
][
'data'
][
'uuid'
]
sql
=
f
"insert into fi_account(name, unique_tag, config_key, description, uuid, income, output, create_time) "
\
f
"values('{param.name}', '{param.unique_tag}', '{param.config_key}', '{param.remark}', '{account_uuid}', '{income}', '{output}', {get_now_timestamp()});"
account
=
LinkMysql
(
env
.
DB_3YV2
)
.
perform_mysql
(
sql
)
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"创建新账户失败,原因:{str(e)}"
)
if
'config_key'
in
str
(
e
):
return
'config_key重复'
return
e
...
...
@@ -187,7 +189,7 @@ def update_account_info(old_data):
f
"description='{old_data.remark}' where id = {old_data.id}"
LinkMysql
(
env
.
DB_3YV2
)
.
perform_mysql
(
sql
)
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"修改账户sql:{sql},原因:{str(e)}"
)
def
get_finance_group_by
(
date
,
condition
):
...
...
@@ -286,7 +288,7 @@ def update_account_type(data):
LinkMysql
(
env
.
DB_3YV2
)
.
perform_mysql
(
sql
)
return
True
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"修改账目类型失败sql:{sql},原因:{str(e)}"
)
return
False
...
...
@@ -304,7 +306,7 @@ def create_type(data):
ins_sql
=
f
"insert into fi_account_type(keyName, keyValue, createTime, type) values('{data.keyName}', '{data.keyValue}', {create_time}, {data.type});"
res_data
=
LinkMysql
(
env
.
DB_3YV2
)
.
perform_mysql
(
ins_sql
)
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"创建新账目类型失败sql:{ins_sql},原因:{str(e)}"
)
return
{}
return
res_data
...
...
@@ -510,7 +512,7 @@ class AccountStatistics(object):
mysql_data
=
LinkMysql
(
env
.
DB_3YV2
)
.
query_mysql
(
cp_sql
)
result_list
=
result_list
+
mysql_data
except
Exception
as
e
:
print
(
f
"没有此表{table},或者检查:{cp_sql},是否正确!
"
)
Logger
(
40
)
.
logger
.
error
(
f
"公会质押金处理-没有此表{table},或者检查sql:{cp_sql},是否正确!失败原因{str(e)}
"
)
continue
return
result_list
[
int
(
self
.
page
-
1
)
*
self
.
size
:
self
.
page
*
self
.
size
],
len
(
result_list
)
...
...
app/api/account/views.py
View file @
ac4b41d1
...
...
@@ -8,6 +8,7 @@ from app.api.account.crud import AccountStatistics, SpecificAccountQuery, HomePa
from
app.api.statement
import
crud
as
statement_crud
from
libs
import
functions
from
libs.functions
import
get_date_list
from
libs.log_utils
import
Logger
from
libs.result_format
import
HttpResultResponse
,
HttpMessage
from
libs.token_verify
import
login_required
...
...
app/api/export/crud.py
View file @
ac4b41d1
...
...
@@ -5,6 +5,7 @@ from core.config.env import env
from
libs.business
import
TYPE_NAME
,
query_fi_account_type
from
libs.db_link
import
LinkMysql
from
libs.functions
import
get_now_datetime
from
libs.log_utils
import
Logger
from
libs.orm
import
QueryAllData
from
models.export
import
ExportFile
import
pandas
as
pd
...
...
@@ -32,7 +33,7 @@ def update_export(db: Session, data):
db
.
query
(
ExportFile
)
.
filter
(
ExportFile
.
id
==
data
.
id
)
.
update
({
ExportFile
.
remark
:
data
.
remark
})
db
.
commit
()
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"导出记录表-修改失败:{str(e)}"
)
return
False
return
True
...
...
@@ -43,7 +44,7 @@ def delete_export(db: Session, export_id):
db
.
query
(
ExportFile
)
.
filter
(
ExportFile
.
id
==
export_id
)
.
delete
()
db
.
commit
()
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"删除导出记录失败:{str(e)}"
)
return
False
return
True
...
...
@@ -57,7 +58,7 @@ def create_export_data(db: Session, export, operator):
db
.
commit
()
db
.
refresh
(
db_export
)
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"创建导出记录失败:{str(e)}"
)
return
{}
return
db_export
...
...
@@ -256,15 +257,15 @@ class ReferenceTypeClassification():
future1
=
pool
.
submit
(
LinkMysql
(
env
.
DB_HISTORY
)
.
query_mysql
,
data_sql
)
future2
=
pool
.
submit
(
LinkMysql
(
env
.
DB_3YV2
)
.
query_mysql
,
guild_sql
)
future3
=
pool
.
submit
(
LinkMysql
(
env
.
DB_3YV2
)
.
query_mysql
,
account_sql
)
future4
=
pool
.
submit
(
LinkMysql
(
env
.
DB_3YV2
)
.
query_mysql
,
anchor_sql
)
#
future4 = pool.submit(LinkMysql(env.DB_3YV2).query_mysql, anchor_sql)
data
=
future1
.
result
()
guild
=
future2
.
result
()
account
=
future3
.
result
()
anchor
=
future4
.
result
()
#
anchor = future4.result()
# 公会uuid列表
guild_data
=
[
i
.
get
(
'uuid'
)
for
i
in
guild
]
# 主播uuid列表
anchor_data
=
[
i
.
get
(
'uuid'
)
for
i
in
anchor
]
#
anchor_data = [i.get('uuid') for i in anchor]
# 系统账户格式化{'系统账户uuid':'系统账户名字'}
account_dict
=
{}
for
k
in
account
:
...
...
@@ -287,7 +288,7 @@ class ReferenceTypeClassification():
self
.
outcome
.
append
(
op
)
else
:
self
.
income
.
append
(
op
)
print
(
f
"出账:{self.outcome}, 入账:{self.income}"
)
Logger
()
.
logger
.
info
(
f
"出账:{self.outcome}, 入账:{self.income}"
)
res_list
=
[]
if
self
.
outcome
:
outcome
=
pd
.
DataFrame
(
self
.
outcome
)
...
...
app/api/margin/crud.py
View file @
ac4b41d1
...
...
@@ -6,6 +6,7 @@ from app.api.statement.guild import query_token
from
core.config.env
import
env
from
libs.db_link
import
LinkMysql
from
libs.functions
import
time_str_to_timestamp
,
get_now_timestamp
,
get_order
,
search
,
get_now_datetime
from
libs.log_utils
import
Logger
from
libs.token_verify
import
get_current_user
...
...
@@ -59,7 +60,7 @@ class GuildMargin(object):
agree_sql
=
f
"update guild_margin_history set status=4 where id={param.id}"
LinkMysql
(
env
.
DB_3YV2
)
.
perform_mysql
(
agree_sql
)
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"修改保证金记录-状态-失败:{str(e)}"
)
return
'操作失败'
# 给公会添加保证金
agree_sql
=
f
"update guild set margin={float(guid_info.get('margin')) + param.amount} where id={param.guild_id}"
...
...
@@ -70,7 +71,7 @@ class GuildMargin(object):
f
"values({param.guild_id}, {guid_info.get('margin')}, {float(guid_info.get('margin')) + param.amount}, {get_now_timestamp()}, {get_now_timestamp()}, 0, 1, 0,{param.amount});"
LinkMysql
(
env
.
DB_3YV2
)
.
perform_mysql
(
add_sql
)
except
Exception
as
e
:
print
(
e
)
Logger
(
40
)
.
logger
.
error
(
f
"添加保证金失败:{str(e)}"
)
return
'操作失败'
# 对接财务 充值
self
.
recharge_user
(
guid_info
.
get
(
'ice_uuid'
),
param
.
amount
,
param
.
guild_id
)
...
...
@@ -93,6 +94,7 @@ class GuildMargin(object):
'reference_info'
:
'保证金充值'
,
}
res
=
search
(
request_data
,
'Server.UserExecute.Recharge'
)
Logger
()
.
logger
.
info
(
f
"清算recharge_user结果:{str(res)}"
)
insert_sql
=
f
"insert into all_record_table(user_id, type, status, uuid, reference_number, money, amount_type, money_data, is_add, create_time, errmsg) "
\
f
"values({guild_id}, '{reference_type}', 2, '{ice_uuid}', {reference_number}, {money * 10}, 1, '保证金充值',1,{timestamp}, '{json.dumps(res)}');"
if
res
[
'status'
]
==
9
:
...
...
core/config/env.py
View file @
ac4b41d1
...
...
@@ -10,6 +10,7 @@ from qcloud_cos import CosConfig
from
qcloud_cos
import
CosS3Client
SITE_ROOT
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)))
SITE_ROOT_TOO
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))))
FILE_PATH
=
os
.
path
.
join
(
SITE_ROOT
,
"runtime"
,
"images"
)
region
=
'ap-guangzhou'
...
...
@@ -36,6 +37,8 @@ class Env(BaseSettings):
DATABASE_URI
:
str
=
'sqlite://:memory:'
DATABASE_USER
:
str
=
''
DATABASE_PWD
:
str
=
''
LOG_PATH
=
os
.
path
.
join
(
SITE_ROOT_TOO
,
"bin"
,
"runtime"
,
"logs"
,
"info"
,
""
)
LOG_ERROR_PATH
=
os
.
path
.
join
(
SITE_ROOT_TOO
,
"bin"
,
"runtime"
,
"logs"
,
"error"
,
""
)
DB_HISTORY
:
dict
=
{
"database"
:
"3y_history"
,
"host"
:
"106.55.103.148"
,
...
...
libs/log_utils.py
0 → 100644
View file @
ac4b41d1
import
time
import
logging
import
os
import
socket
from
core.config.env
import
env
hostname
=
socket
.
gethostname
()
current_directory
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
def
get_current_time
():
from
datetime
import
datetime
,
timedelta
,
timezone
utc_dt
=
datetime
.
utcnow
()
.
replace
(
tzinfo
=
timezone
.
utc
)
current_time
=
utc_dt
.
astimezone
(
timezone
(
timedelta
(
hours
=
8
)))
.
strftime
(
'
%
Y-
%
m-
%
d'
)
# 返回当前时间
return
current_time
class
Logger
(
object
):
level_relations
=
{
'debug'
:
logging
.
DEBUG
,
'info'
:
logging
.
INFO
,
'warning'
:
logging
.
WARNING
,
'error'
:
logging
.
ERROR
,
'crit'
:
logging
.
CRITICAL
}
count
=
0
def
__init__
(
self
,
log_level
=
20
):
fmt
=
"[
%(asctime)
s] [
%(process)
d] [
%(levelname)
s] -
%(module)
s.
%(funcName)
s (
%(filename)
s:
%(lineno)
d) -
%(message)
s"
self
.
current_time
=
get_current_time
()
filename
=
env
.
LOG_PATH
+
'operation'
+
"-"
+
get_current_time
()
+
'.log'
self
.
logger
=
logging
.
getLogger
(
filename
)
self
.
format_str
=
logging
.
Formatter
(
fmt
)
# 设置日志格式
self
.
create_handler
(
log_level
)
# Logger.count += 1
def
create_handler
(
self
,
log_level
):
self
.
current_time
=
get_current_time
()
if
log_level
==
40
:
filename
=
env
.
LOG_ERROR_PATH
+
get_current_time
()
+
'.log'
else
:
filename
=
env
.
LOG_PATH
+
get_current_time
()
+
'.log'
self
.
logger
=
logging
.
getLogger
(
filename
)
self
.
logger
.
setLevel
(
logging
.
INFO
)
# 设置日志级别
if
not
self
.
logger
.
handlers
:
sh
=
logging
.
StreamHandler
()
sh
.
setFormatter
(
self
.
format_str
)
th
=
logging
.
FileHandler
(
filename
=
filename
,
encoding
=
'utf-8'
)
th
.
setFormatter
(
self
.
format_str
)
# 设置文件里写入的格式
self
.
logger
.
addHandler
(
sh
)
# 把对象加到logger里
self
.
logger
.
addHandler
(
th
)
def
info
(
self
,
msg
):
current_time
=
get_current_time
()
if
self
.
current_time
!=
current_time
:
self
.
create_handler
()
self
.
logger
.
info
(
msg
)
return
def
warning
(
self
,
msg
):
current_time
=
get_current_time
()
if
self
.
current_time
!=
current_time
:
self
.
create_handler
()
self
.
logger
.
warning
(
msg
)
return
def
error
(
self
,
msg
):
current_time
=
get_current_time
()
if
self
.
current_time
!=
current_time
:
self
.
create_handler
()
self
.
logger
.
error
(
msg
)
return
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