package model import "encoding/json" // Correct historical error-log presentation from the already-stored routing // evidence, without rewriting financial history or exposing private metadata. // Consume records always retain their original billed group. func normalizeErrorLogGroup(log *Log) { if log == nil || log.Type != LogTypeError { return } if log.ChannelId <= 0 { log.Group = "" return } var other struct { Admin struct { Events []struct { ChannelID int `json:"channel_id"` Group string `json:"group"` } `json:"request_policy"` } `json:"admin_info"` } if json.Unmarshal([]byte(log.Other), &other) != nil { return } for i := len(other.Admin.Events) - 1; i >= 0; i-- { event := other.Admin.Events[i] if event.ChannelID == log.ChannelId && event.Group != "" && event.Group != "auto" { log.Group = event.Group return } } }