完善日志和审计链路

This commit is contained in:
yml
2026-06-02 21:40:23 +08:00
parent 1325c8fb89
commit 6dcea2d56c
20 changed files with 243 additions and 90 deletions
@@ -5,9 +5,9 @@ import (
"errors"
"strings"
"hfb_sys/backend/internal/auditlog"
"hfb_sys/backend/internal/model"
"gorm.io/datatypes"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
@@ -16,10 +16,7 @@ type Repository struct {
db *gorm.DB
}
type AuditMeta struct {
IP string
UserAgent string
}
type AuditMeta = auditlog.Meta
type defaultConfig struct {
Key string
@@ -249,21 +246,15 @@ func isLegacyPublishOptionsValue(value string) bool {
}
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizID uint64, meta AuditMeta, detail map[string]any) error {
raw, err := json.Marshal(detail)
if err != nil {
return err
}
row := model.AuditLog{
return auditlog.Append(tx, auditlog.Entry{
ActorType: "admin",
ActorID: actorID,
Action: action,
BizType: "system_config",
BizID: &bizID,
IP: meta.IP,
UserAgent: meta.UserAgent,
Detail: datatypes.JSON(raw),
}
return tx.Create(&row).Error
Meta: meta,
Detail: detail,
})
}
func toDTO(row model.SystemConfig) ConfigDTO {