package cardobservation import ( "context" "time" "gorm.io/gorm" ) type suppressSeriesTriggerKey struct{} // SuppressSeriesTriggerContext 标记观测结果驱动的业务评估,避免形成反向触发环。 func SuppressSeriesTriggerContext(ctx context.Context) context.Context { return context.WithValue(ctx, suppressSeriesTriggerKey{}, true) } // IsSeriesTriggerSuppressed 判断当前业务调用是否来自观测结果消费。 func IsSeriesTriggerSuppressed(ctx context.Context) bool { value, _ := ctx.Value(suppressSeriesTriggerKey{}).(bool) return value } // SeriesRequestedEvent 是业务成功边界可靠请求观测序列的事实。 type SeriesRequestedEvent struct { EventID string `json:"event_id"` Scene string `json:"scene"` ResourceType string `json:"resource_type"` ResourceID uint `json:"resource_id"` ResourceIDs []uint `json:"resource_ids,omitempty"` SyncTypes []string `json:"sync_types"` ExpectedValue string `json:"expected_value,omitempty"` Source string `json:"source"` OccurredAt time.Time `json:"occurred_at"` RequestID string `json:"request_id,omitempty"` CorrelationID string `json:"correlation_id,omitempty"` } // SeriesEventWriter 在原业务事务中追加观测序列请求事件。 type SeriesEventWriter interface { AppendSeriesRequested(ctx context.Context, tx *gorm.DB, event SeriesRequestedEvent) error }