修复报错
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
|
||||
)
|
||||
|
||||
// RequestContext 封装了审计日志所需的请求上下文信息
|
||||
type RequestContext struct {
|
||||
// AuditRequestContext 封装了审计日志所需的请求上下文信息
|
||||
type AuditRequestContext struct {
|
||||
ClientIP string
|
||||
HTTPPath string
|
||||
HTTPMethod string
|
||||
@@ -19,7 +19,7 @@ type RequestContext struct {
|
||||
|
||||
// AuditService 定义了审计服务的接口
|
||||
type AuditService interface {
|
||||
LogAction(ctx context.Context, user *models.User, reqCtx RequestContext, actionType, description string, targetResource interface{}, status models.AuditStatus, resultDetails string)
|
||||
LogAction(ctx context.Context, user *models.User, reqCtx AuditRequestContext, actionType, description string, targetResource interface{}, status models.AuditStatus, resultDetails string)
|
||||
}
|
||||
|
||||
// auditService 是 AuditService 接口的实现
|
||||
@@ -37,7 +37,7 @@ func NewAuditService(ctx context.Context, repo repository.UserActionLogRepositor
|
||||
}
|
||||
|
||||
// LogAction 记录一个用户操作。它在一个新的 goroutine 中异步执行,以避免阻塞主请求。
|
||||
func (s *auditService) LogAction(ctx context.Context, user *models.User, reqCtx RequestContext, actionType, description string, targetResource interface{}, status models.AuditStatus, resultDetails string) {
|
||||
func (s *auditService) LogAction(ctx context.Context, user *models.User, reqCtx AuditRequestContext, actionType, description string, targetResource interface{}, status models.AuditStatus, resultDetails string) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "LogAction")
|
||||
|
||||
// 不再从 context 中获取用户信息,直接使用传入的 user 对象
|
||||
|
||||
@@ -330,7 +330,7 @@ func (s *pigFarmService) DeletePen(ctx context.Context, id uint) error {
|
||||
func (s *pigFarmService) UpdatePenStatus(ctx context.Context, id uint, newStatus models.PenStatus) (*dto.PenResponse, error) {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "UpdatePenStatus")
|
||||
var updatedPen *models.Pen
|
||||
err := s.uow.ExecuteInTransaction(func(tx *gorm.DB) error {
|
||||
err := s.uow.ExecuteInTransaction(serviceCtx, func(tx *gorm.DB) error {
|
||||
pen, err := s.penRepository.GetPenByIDTx(serviceCtx, tx, id)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
|
||||
@@ -89,7 +89,7 @@ func (s *userService) Login(ctx context.Context, req *dto.LoginRequest) (*dto.Lo
|
||||
}
|
||||
|
||||
// 登录成功,生成 JWT token
|
||||
tokenString, err := s.tokenService.GenerateToken(user.ID)
|
||||
tokenString, err := s.tokenGenerator.GenerateToken(user.ID)
|
||||
if err != nil {
|
||||
logger.Errorf("登录: 生成令牌失败: %v", err)
|
||||
return nil, errors.New("登录失败,无法生成认证信息")
|
||||
|
||||
Reference in New Issue
Block a user