v1
This commit is contained in:
@@ -8,14 +8,14 @@ import (
|
||||
"time"
|
||||
|
||||
"management/internal/erpserver/model/view"
|
||||
"management/internal/pkg/redis"
|
||||
"management/internal/pkg/cache"
|
||||
)
|
||||
|
||||
func GetCacheExpire() time.Duration {
|
||||
return time.Hour*6 + time.Duration(rand.Intn(600))*time.Second // 6小时±10分钟
|
||||
}
|
||||
|
||||
func GetOrSetCache(ctx context.Context, redis redis.Cache, key string, expire time.Duration, getData func() (any, error), result any) error {
|
||||
func GetOrSetCache(ctx context.Context, redis cache.Cache, key string, expire time.Duration, getData func() (any, error), result any) error {
|
||||
if data, err := redis.GetBytes(ctx, key); err == nil {
|
||||
return json.Unmarshal(data, result)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"management/internal/erpserver/model/system"
|
||||
"management/internal/erpserver/model/view"
|
||||
"management/internal/erpserver/repository"
|
||||
"management/internal/pkg/redis"
|
||||
"management/internal/pkg/cache"
|
||||
"management/internal/pkg/session"
|
||||
|
||||
"github.com/drhin/logger"
|
||||
@@ -18,14 +18,14 @@ type Service struct {
|
||||
Log *logger.Logger
|
||||
Tx repository.Transaction
|
||||
Session session.Manager
|
||||
Redis redis.Cache
|
||||
Redis cache.Cache
|
||||
}
|
||||
|
||||
func NewService(
|
||||
log *logger.Logger,
|
||||
tx repository.Transaction,
|
||||
session session.Manager,
|
||||
redis redis.Cache,
|
||||
redis cache.Cache,
|
||||
) *Service {
|
||||
return &Service{
|
||||
Log: log,
|
||||
@@ -72,6 +72,7 @@ type LoginLogService interface {
|
||||
|
||||
type AuditLogService interface {
|
||||
Create(ctx context.Context, req *system.AuditLog) error
|
||||
BatchCreate(ctx context.Context, objs []*system.AuditLog) error
|
||||
List(ctx context.Context, q dto.SearchDto) ([]*system.AuditLog, int64, error)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ func (b *auditLogService) Create(ctx context.Context, req *system.AuditLog) erro
|
||||
return b.repo.Create(ctx, req)
|
||||
}
|
||||
|
||||
func (b *auditLogService) BatchCreate(ctx context.Context, objs []*system.AuditLog) error {
|
||||
return b.repo.BatchCreate(ctx, objs)
|
||||
}
|
||||
|
||||
func (b *auditLogService) List(ctx context.Context, q dto.SearchDto) ([]*system.AuditLog, int64, error) {
|
||||
return b.repo.List(ctx, q)
|
||||
}
|
||||
|
||||
@@ -179,11 +179,12 @@ func (s *userService) login(ctx context.Context, req *form.Login) error {
|
||||
}
|
||||
|
||||
func (s *userService) loginSuccess(ctx context.Context, user *system.User, req *form.Login) error {
|
||||
return s.Session.PutUser(ctx, know.StoreName, &dto.AuthorizeUser{
|
||||
return s.Session.PutUser(ctx, know.StoreName, dto.AuthorizeUser{
|
||||
ID: user.ID,
|
||||
Uuid: user.Uuid,
|
||||
Email: user.Email,
|
||||
Username: user.Username,
|
||||
Avatar: user.Avatar,
|
||||
RoleID: user.Role.ID,
|
||||
RoleName: user.Role.DisplayName,
|
||||
OS: req.Os,
|
||||
|
||||
Reference in New Issue
Block a user