Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1ae20bdd
authored
Jan 22, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: update log queries to explicitly reference 'logs' table for clarity and consistency
parent
71c75b4e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
model/log.go
+17
-17
No files found.
model/log.go
View file @
1ae20bdd
...
...
@@ -129,38 +129,38 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
if
logType
==
LogTypeUnknown
{
tx
=
LOG_DB
}
else
{
tx
=
LOG_DB
.
Where
(
"type = ?"
,
logType
)
tx
=
LOG_DB
.
Where
(
"
logs.
type = ?"
,
logType
)
}
tx
=
tx
.
Joins
(
"LEFT JOIN channels ON logs.channel_id = channels.id"
)
tx
=
tx
.
Select
(
"logs.*, channels.name as channel_name"
)
if
modelName
!=
""
{
tx
=
tx
.
Where
(
"model_name like ?"
,
modelName
)
tx
=
tx
.
Where
(
"
logs.
model_name like ?"
,
modelName
)
}
if
username
!=
""
{
tx
=
tx
.
Where
(
"username = ?"
,
username
)
tx
=
tx
.
Where
(
"
logs.
username = ?"
,
username
)
}
if
tokenName
!=
""
{
tx
=
tx
.
Where
(
"token_name = ?"
,
tokenName
)
tx
=
tx
.
Where
(
"
logs.
token_name = ?"
,
tokenName
)
}
if
startTimestamp
!=
0
{
tx
=
tx
.
Where
(
"created_at >= ?"
,
startTimestamp
)
tx
=
tx
.
Where
(
"
logs.
created_at >= ?"
,
startTimestamp
)
}
if
endTimestamp
!=
0
{
tx
=
tx
.
Where
(
"created_at <= ?"
,
endTimestamp
)
tx
=
tx
.
Where
(
"
logs.
created_at <= ?"
,
endTimestamp
)
}
if
channel
!=
0
{
tx
=
tx
.
Where
(
"channel_id = ?"
,
channel
)
tx
=
tx
.
Where
(
"
logs.
channel_id = ?"
,
channel
)
}
if
group
!=
""
{
tx
=
tx
.
Where
(
groupCol
+
" = ?"
,
group
)
tx
=
tx
.
Where
(
"logs."
+
groupCol
+
" = ?"
,
group
)
}
err
=
tx
.
Model
(
&
Log
{})
.
Count
(
&
total
)
.
Error
if
err
!=
nil
{
return
nil
,
0
,
err
}
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Find
(
&
logs
)
.
Error
err
=
tx
.
Order
(
"
logs.
id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Find
(
&
logs
)
.
Error
if
err
!=
nil
{
return
nil
,
0
,
err
}
...
...
@@ -170,34 +170,34 @@ func GetAllLogs(logType int, startTimestamp int64, endTimestamp int64, modelName
func
GetUserLogs
(
userId
int
,
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
tokenName
string
,
startIdx
int
,
num
int
,
group
string
)
(
logs
[]
*
Log
,
total
int64
,
err
error
)
{
var
tx
*
gorm
.
DB
if
logType
==
LogTypeUnknown
{
tx
=
LOG_DB
.
Where
(
"user_id = ?"
,
userId
)
tx
=
LOG_DB
.
Where
(
"
logs.
user_id = ?"
,
userId
)
}
else
{
tx
=
LOG_DB
.
Where
(
"
user_id = ? and
type = ?"
,
userId
,
logType
)
tx
=
LOG_DB
.
Where
(
"
logs.user_id = ? and logs.
type = ?"
,
userId
,
logType
)
}
tx
=
tx
.
Joins
(
"LEFT JOIN channels ON logs.channel_id = channels.id"
)
tx
=
tx
.
Select
(
"logs.*, channels.name as channel_name"
)
if
modelName
!=
""
{
tx
=
tx
.
Where
(
"model_name like ?"
,
modelName
)
tx
=
tx
.
Where
(
"
logs.
model_name like ?"
,
modelName
)
}
if
tokenName
!=
""
{
tx
=
tx
.
Where
(
"token_name = ?"
,
tokenName
)
tx
=
tx
.
Where
(
"
logs.
token_name = ?"
,
tokenName
)
}
if
startTimestamp
!=
0
{
tx
=
tx
.
Where
(
"created_at >= ?"
,
startTimestamp
)
tx
=
tx
.
Where
(
"
logs.
created_at >= ?"
,
startTimestamp
)
}
if
endTimestamp
!=
0
{
tx
=
tx
.
Where
(
"created_at <= ?"
,
endTimestamp
)
tx
=
tx
.
Where
(
"
logs.
created_at <= ?"
,
endTimestamp
)
}
if
group
!=
""
{
tx
=
tx
.
Where
(
groupCol
+
" = ?"
,
group
)
tx
=
tx
.
Where
(
"logs."
+
groupCol
+
" = ?"
,
group
)
}
err
=
tx
.
Model
(
&
Log
{})
.
Count
(
&
total
)
.
Error
if
err
!=
nil
{
return
nil
,
0
,
err
}
err
=
tx
.
Order
(
"id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Find
(
&
logs
)
.
Error
err
=
tx
.
Order
(
"
logs.
id desc"
)
.
Limit
(
num
)
.
Offset
(
startIdx
)
.
Find
(
&
logs
)
.
Error
formatUserLogs
(
logs
)
return
logs
,
total
,
err
}
...
...
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