This commit is contained in:
2025-04-14 15:28:51 +08:00
parent f100427f8b
commit 371b89ee8d
93 changed files with 3757 additions and 1038 deletions

View 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
}