package model import ( "encoding/json" "time" ) // OutboxEvent 可靠事件箱;业务事务内写入,worker 发送并重试。 type OutboxEvent struct { ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"` EventID string `gorm:"column:event_id;size:128;uniqueIndex" json:"eventId"` EventType string `gorm:"column:event_type;size:64" json:"eventType"` AggregateType *string `gorm:"column:aggregate_type;size:64" json:"aggregateType,omitempty"` AggregateID *string `gorm:"column:aggregate_id;size:128" json:"aggregateId,omitempty"` Payload json.RawMessage `gorm:"type:jsonb;default:'{}'" json:"payload"` Status string `gorm:"size:16;default:pending;index:idx_outbox_events_status_next,priority:1" json:"status"` Attempts int `gorm:"default:0" json:"attempts"` MaxAttempts int `gorm:"column:max_attempts;default:5" json:"maxAttempts"` NextAttemptAt time.Time `gorm:"column:next_attempt_at;type:timestamptz;default:now();index:idx_outbox_events_status_next,priority:2" json:"nextAttemptAt"` LastError *string `gorm:"column:last_error;type:text" json:"lastError,omitempty"` CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"` UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"` } func (OutboxEvent) TableName() string { return "outbox_events" } // Notification 持久化通知记录;状态 pending/sending/sent/retry/failed/cancelled。 type Notification struct { ID string `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"` UserID *string `gorm:"column:user_id;type:uuid;index:idx_notifications_user_created,priority:1" json:"userId,omitempty"` Channel string `gorm:"size:32" json:"channel"` Target string `gorm:"size:128" json:"target"` Title string `gorm:"size:128" json:"title"` Body string `gorm:"type:text" json:"body"` Status string `gorm:"size:16;default:pending;index:idx_notifications_status_next,priority:1" json:"status"` Attempts int `gorm:"default:0" json:"attempts"` NextAttemptAt time.Time `gorm:"column:next_attempt_at;type:timestamptz;default:now();index:idx_notifications_status_next,priority:2" json:"nextAttemptAt"` LastError *string `gorm:"column:last_error;type:text" json:"lastError,omitempty"` TemplateID *string `gorm:"column:template_id;size:128" json:"templateId,omitempty"` OpenID *string `gorm:"column:open_id;size:128" json:"openId,omitempty"` Authorized bool `gorm:"default:false" json:"authorized"` ProviderResponse json.RawMessage `gorm:"column:provider_response;type:jsonb" json:"providerResponse,omitempty"` Data json.RawMessage `gorm:"type:jsonb" json:"data,omitempty"` BusinessType *string `gorm:"column:business_type;size:64" json:"businessType,omitempty"` BusinessID *string `gorm:"column:business_id;size:128" json:"businessId,omitempty"` EventID *string `gorm:"column:event_id;size:128;uniqueIndex" json:"eventId,omitempty"` CreatedAt time.Time `gorm:"type:timestamptz" json:"createdAt"` UpdatedAt time.Time `gorm:"type:timestamptz" json:"updatedAt"` } func (Notification) TableName() string { return "notifications" }