From 26349c15d36051bb865fa0ee2d8bbdd7ff73650e Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 30 Apr 2026 20:58:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=BA=94=E7=94=A8=E5=88=97=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加LogOperationWithApp方法支持传入ApplicationID - 创建/更新/删除卡密类型时记录ApplicationID - 创建/更新应用时记录ApplicationID --- .../internal/router/developer/applications.go | 4 ++-- backend/internal/router/developer/cards.go | 6 ++--- backend/internal/service/log_service.go | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/internal/router/developer/applications.go b/backend/internal/router/developer/applications.go index 785a9fb..f0a65f3 100644 --- a/backend/internal/router/developer/applications.go +++ b/backend/internal/router/developer/applications.go @@ -242,7 +242,7 @@ func handleCreateApplication(c *gin.Context) { } } - service.LogOperation(c, "create", "application", &app.ID, fmt.Sprintf("创建应用: %s", app.Name), nil) + service.LogOperationWithApp(c, &app.ID, "create", "application", &app.ID, fmt.Sprintf("创建应用: %s", app.Name), nil) response.Success(c, gin.H{ "application": app, @@ -405,7 +405,7 @@ func handleUpdateApplication(c *gin.Context) { return } - service.LogOperation(c, "update", "application", &app.ID, fmt.Sprintf("更新应用: %s", app.Name), nil) + service.LogOperationWithApp(c, &app.ID, "update", "application", &app.ID, fmt.Sprintf("更新应用: %s", app.Name), nil) response.Success(c, app) } diff --git a/backend/internal/router/developer/cards.go b/backend/internal/router/developer/cards.go index fad0a52..03a5fc9 100644 --- a/backend/internal/router/developer/cards.go +++ b/backend/internal/router/developer/cards.go @@ -262,7 +262,7 @@ func handleCreateCardType(c *gin.Context) { return } - service.LogOperation(c, "create", "card_type", &cardType.ID, fmt.Sprintf("创建卡密类型: %s", cardType.Name), nil) + service.LogOperationWithApp(c, &cardType.ApplicationID, "create", "card_type", &cardType.ID, fmt.Sprintf("创建卡密类型: %s", cardType.Name), nil) response.Success(c, cardType) } @@ -329,7 +329,7 @@ func handleUpdateCardType(c *gin.Context) { return } - service.LogOperation(c, "update", "card_type", &cardType.ID, fmt.Sprintf("更新卡密类型: %s", cardType.Name), nil) + service.LogOperationWithApp(c, &cardType.ApplicationID, "update", "card_type", &cardType.ID, fmt.Sprintf("更新卡密类型: %s", cardType.Name), nil) response.Success(c, cardType) } @@ -349,7 +349,7 @@ func handleDeleteCardType(c *gin.Context) { return } - service.LogOperation(c, "delete", "card_type", &cardType.ID, fmt.Sprintf("删除卡密类型: %s", cardType.Name), nil) + service.LogOperationWithApp(c, &cardType.ApplicationID, "delete", "card_type", &cardType.ID, fmt.Sprintf("删除卡密类型: %s", cardType.Name), nil) response.Success(c, nil) } diff --git a/backend/internal/service/log_service.go b/backend/internal/service/log_service.go index 069b620..407375f 100644 --- a/backend/internal/service/log_service.go +++ b/backend/internal/service/log_service.go @@ -94,6 +94,25 @@ func (s *LogService) LogOperation(c *gin.Context, action, resource string, resou return s.CreateLogFromContext(c, params) } +func (s *LogService) LogOperationWithApp(c *gin.Context, applicationID *uint, action, resource string, resourceID *uint, details string, err error) error { + params := LogParams{ + LogType: "operation", + ApplicationID: applicationID, + Action: action, + Resource: resource, + ResourceID: resourceID, + Details: details, + } + + if err != nil { + params.Status = "failed" + params.Level = "error" + params.ErrorMessage = err.Error() + } + + return s.CreateLogFromContext(c, params) +} + func (s *LogService) LogVerification(c *gin.Context, applicationID *uint, appUserID *uint, action, details string, deviceID string, err error) error { params := LogParams{ LogType: "verification", @@ -142,6 +161,10 @@ func LogOperation(c *gin.Context, action, resource string, resourceID *uint, det return logService.LogOperation(c, action, resource, resourceID, details, err) } +func LogOperationWithApp(c *gin.Context, applicationID *uint, action, resource string, resourceID *uint, details string, err error) error { + return logService.LogOperationWithApp(c, applicationID, action, resource, resourceID, details, err) +} + func LogVerification(c *gin.Context, applicationID *uint, appUserID *uint, action, details string, DeviceFingerprint string, err error) error { return logService.LogVerification(c, applicationID, appUserID, action, details, DeviceFingerprint, err) }