v2_2
This commit is contained in:
69
internal/erpserver/biz/v1/system/login_log.go
Normal file
69
internal/erpserver/biz/v1/system/login_log.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user