70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
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
|
|
}
|