This commit is contained in:
2026-08-16 22:38:44 +08:00
parent 1945d34894
commit 560ae46b82
19 changed files with 345 additions and 112 deletions
+31 -15
View File
@@ -14,13 +14,13 @@ type errorRecordPO struct {
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
Form string `gorm:"type:text"`
Info string `gorm:"type:text"`
Form *string `gorm:"type:text"`
Info *string `gorm:"type:text"`
Level string
RequestID string `gorm:"index"`
TraceID string `gorm:"index"`
Solution string `gorm:"type:text"`
Status string `gorm:"default:未处理"`
RequestID string `gorm:"index"`
TraceID string `gorm:"index"`
Solution *string `gorm:"type:text"`
Status string `gorm:"default:未处理"`
}
func (errorRecordPO) TableName() string { return "sys_error" }
@@ -29,23 +29,39 @@ func errorFromPO(v errorRecordPO) *biz.ErrorRecord {
return &biz.ErrorRecord{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}
}
func (r *auditRecorderRepo) CreateError(ctx context.Context, v *biz.ErrorRecord) error {
if !r.data.databaseReady.Load() {
// GVA silently ignores error records before GVA_DB is initialized.
return nil
}
if v.Status == "" {
v.Status = "未处理"
}
return r.data.gormDB.WithContext(ctx).Create(&errorRecordPO{Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}).Error
return r.data.gormDB.WithContext(ctx).Create(&errorRecordPO{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}).Error
}
func (r *auditQueryRepo) UpdateError(ctx context.Context, v *biz.ErrorRecord) error {
updates := make(map[string]any, 5)
if v.Form != "" {
updates := make(map[string]any, 9)
if v.ID != 0 {
updates["id"] = v.ID
}
if !v.CreatedAt.IsZero() {
updates["created_at"] = v.CreatedAt
}
if v.Form != nil {
updates["form"] = v.Form
}
if v.Info != "" {
if v.Info != nil {
updates["info"] = v.Info
}
if v.Level != "" {
updates["level"] = v.Level
}
if v.Solution != "" {
if v.RequestID != "" {
updates["request_id"] = v.RequestID
}
if v.TraceID != "" {
updates["trace_id"] = v.TraceID
}
if v.Solution != nil {
updates["solution"] = v.Solution
}
if v.Status != "" {
@@ -69,11 +85,11 @@ func (r *auditQueryRepo) ListErrors(ctx context.Context, page, size int, q *biz.
if len(q.CreatedAtRange) == 2 {
db = db.Where("created_at BETWEEN ? AND ?", q.CreatedAtRange[0], q.CreatedAtRange[1])
}
if q.Form != "" {
db = db.Where("form = ?", q.Form)
if q.Form != nil && *q.Form != "" {
db = db.Where("form = ?", *q.Form)
}
if q.Info != "" {
db = db.Where("info LIKE ?", "%"+q.Info+"%")
if q.Info != nil && *q.Info != "" {
db = db.Where("info LIKE ?", "%"+*q.Info+"%")
}
}
var total int64