first commit
This commit is contained in:
59
internal/service/system/sys_user_login_log.go
Normal file
59
internal/service/system/sys_user_login_log.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
db "management/internal/db/sqlc"
|
||||
)
|
||||
|
||||
func CreateSysUserLoginLog(ctx context.Context, arg *db.CreateSysUserLoginLogParams) error {
|
||||
return db.Engine.CreateSysUserLoginLog(ctx, arg)
|
||||
}
|
||||
|
||||
func ListSysUserLoginLog(ctx context.Context, q dto.SearchDto) ([]*db.SysUserLoginLog, int64, error) {
|
||||
start, err := time.ParseInLocation(time.DateTime, q.SearchTimeBegin, time.Local)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
end, err := time.ParseInLocation(time.DateTime, q.SearchTimeEnd, time.Local)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
countArg := &db.CountSysUserLoginLogConditionParams{
|
||||
StartAt: start,
|
||||
EndAt: end,
|
||||
}
|
||||
|
||||
dataArg := &db.ListSysUserLoginLogConditionParams{
|
||||
StartAt: start,
|
||||
EndAt: end,
|
||||
Skip: (int32(q.Page) - 1) * int32(q.Rows),
|
||||
Size: int32(q.Rows),
|
||||
}
|
||||
|
||||
if len(q.SearchKey) > 0 {
|
||||
switch strings.ToLower(q.SearchName) {
|
||||
case "email":
|
||||
countArg.Email = q.SearchKey
|
||||
dataArg.Email = q.SearchKey
|
||||
case "username":
|
||||
countArg.Username = q.SearchKey
|
||||
dataArg.Username = q.SearchKey
|
||||
}
|
||||
}
|
||||
count, err := db.Engine.CountSysUserLoginLogCondition(ctx, countArg)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
logs, err := db.Engine.ListSysUserLoginLogCondition(ctx, dataArg)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return logs, count, nil
|
||||
}
|
||||
Reference in New Issue
Block a user