60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
|
|
"management/internal/db/model/dto"
|
|
db "management/internal/db/sqlc"
|
|
)
|
|
|
|
func CreateSysAuditLog(ctx context.Context, arg *db.CreateSysAuditLogParams) error {
|
|
return db.Engine.CreateSysAuditLog(ctx, arg)
|
|
}
|
|
|
|
func ListSysAuditLog(ctx context.Context, q dto.SearchDto) ([]*db.SysAuditLog, 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.CountSysAuditLogConditionParams{
|
|
StartAt: start,
|
|
EndAt: end,
|
|
}
|
|
|
|
dataArg := &db.ListSysAuditLogConditionParams{
|
|
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.CountSysAuditLogCondition(ctx, countArg)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
audits, err := db.Engine.ListSysAuditLogCondition(ctx, dataArg)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
return audits, count, nil
|
|
}
|