This commit is contained in:
2025-03-31 11:59:42 +08:00
parent 963e1e005e
commit 6fb06c456c
52 changed files with 2244 additions and 753 deletions

View File

@@ -0,0 +1,69 @@
package system
import (
"context"
"time"
"management/internal/db/model/dto"
db "management/internal/db/sqlc"
)
type LoginLogBiz interface {
Create(ctx context.Context, arg *db.CreateSysUserLoginLogParams) error
List(ctx context.Context, q dto.SearchDto) ([]*db.SysUserLoginLog, int64, error)
}
type loginLogBiz struct {
store db.Store
}
var _ LoginLogBiz = (*loginLogBiz)(nil)
func NewLoginLog(store db.Store) *loginLogBiz {
return &loginLogBiz{
store: store,
}
}
func (b *loginLogBiz) Create(ctx context.Context, arg *db.CreateSysUserLoginLogParams) error {
return b.store.CreateSysUserLoginLog(ctx, arg)
}
func (b *loginLogBiz) List(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,
Email: q.SearchEmail,
Username: q.SearchName,
}
dataArg := &db.ListSysUserLoginLogConditionParams{
StartAt: start,
EndAt: end,
Email: q.SearchEmail,
Username: q.SearchName,
Skip: (int32(q.Page) - 1) * int32(q.Rows),
Size: int32(q.Rows),
}
count, err := b.store.CountSysUserLoginLogCondition(ctx, countArg)
if err != nil {
return nil, 0, err
}
logs, err := b.store.ListSysUserLoginLogCondition(ctx, dataArg)
if err != nil {
return nil, 0, err
}
return logs, count, nil
}