2
This commit is contained in:
58
internal/erpserver/store/system/login_log.go
Normal file
58
internal/erpserver/store/system/login_log.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"management/internal/db/model/dto"
|
||||
"management/internal/erpserver/model/system"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type LoginLogStore interface {
|
||||
Create(ctx context.Context, obj *system.LoginLog) error
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*system.LoginLog, int64, error)
|
||||
}
|
||||
|
||||
type loginLogStore struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
var _ LoginLogStore = (*loginLogStore)(nil)
|
||||
|
||||
func NewLoginLogStore(db *gorm.DB) *loginLogStore {
|
||||
return &loginLogStore{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *loginLogStore) Create(ctx context.Context, obj *system.LoginLog) error {
|
||||
return s.db.WithContext(ctx).Create(obj).Error
|
||||
}
|
||||
|
||||
func (s *loginLogStore) List(ctx context.Context, q dto.SearchDto) ([]*system.LoginLog, int64, error) {
|
||||
query := s.db.WithContext(ctx).
|
||||
Model(&system.LoginLog{}).
|
||||
Where("created_at BETWEEN ? AND ?", q.SearchTimeBegin, q.SearchTimeEnd)
|
||||
if q.SearchEmail != "" {
|
||||
query = query.Where("email LIKE ?", "%"+q.SearchEmail+"%")
|
||||
}
|
||||
|
||||
var count int64
|
||||
err := query.Count(&count).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var logs []*system.LoginLog
|
||||
err = query.
|
||||
Order("id DESC").
|
||||
Offset((q.Page - 1) * q.Rows).
|
||||
Limit(q.Rows).
|
||||
Find(&logs).
|
||||
Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return logs, count, nil
|
||||
}
|
||||
Reference in New Issue
Block a user