54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
|
|
"management/internal/erpserver/model/dto"
|
|
"management/internal/erpserver/model/system"
|
|
"management/internal/erpserver/service/v1"
|
|
)
|
|
|
|
type loginLogService struct {
|
|
*v1.Service
|
|
repo system.LoginLogRepository
|
|
}
|
|
|
|
func NewLoginLogService(service *v1.Service, repo system.LoginLogRepository) v1.LoginLogService {
|
|
return &loginLogService{
|
|
Service: service,
|
|
repo: repo,
|
|
}
|
|
}
|
|
|
|
func (s *loginLogService) Create(ctx context.Context, req *system.LoginLog) error {
|
|
return s.repo.Create(ctx, req)
|
|
}
|
|
|
|
func (s *loginLogService) List(ctx context.Context, q dto.SearchDto) ([]*system.LoginLog, int64, error) {
|
|
return s.repo.List(ctx, q)
|
|
}
|
|
|
|
func (s *loginLogService) LoginTime(ctx context.Context, email string) (dto.LoginTimeDto, error) {
|
|
var res dto.LoginTimeDto
|
|
logs, err := s.repo.GetLatest(ctx, email)
|
|
if err != nil {
|
|
return res, err
|
|
}
|
|
if len(logs) == 2 {
|
|
res.ThisLoginTime = logs[0].CreatedAt
|
|
res.LastLoginTime = logs[1].CreatedAt
|
|
} else if len(logs) == 1 {
|
|
res.ThisLoginTime = logs[0].CreatedAt
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func (s *loginLogService) LoginCount(ctx context.Context, email string) int64 {
|
|
count, err := s.repo.Count(ctx, email)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
return count
|
|
}
|