topfans/backend/services/assetService/model/share_event.go

31 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"github.com/topfans/backend/pkg/models"
)
// ShareEvent 分享事件落库模型spec § 3.5
//
// 注意:
// - 表结构与 backend/migrations/2026_06_25_001_share_events.sql 一致。
// 原任务模板中的 CreatedAt/UpdatedAt/DeletedAt 在迁移中并不存在,
// 本文件未包含,以避免 GORM 在 AutoMigrate 时尝试添加这些列。
// - JSONB 复用 pkg/models 中定义的 models.JSONB([]byte + Scanner/Valuer)。
// - 时间字段统一使用 int64 毫秒时间戳,与项目内其它服务保持一致。
type ShareEvent struct {
ID int64 `json:"id" gorm:"primaryKey;column:id"`
AssetID int64 `json:"asset_id" gorm:"column:asset_id;not null;index"`
SharerUserID int64 `json:"sharer_user_id" gorm:"column:sharer_user_id;not null;index"`
SystemType string `json:"system_type" gorm:"column:system_type;type:varchar(32);not null;index"`
ShareTarget string `json:"share_target" gorm:"column:share_target;type:varchar(32);not null"`
Result string `json:"result" gorm:"column:result;type:varchar(32);not null"`
ClientTs int64 `json:"client_ts" gorm:"column:client_ts;not null"`
// ServerTs 服务端接收时间戳(毫秒);DB 列已设置 DEFAULT (EXTRACT(EPOCH FROM NOW()) * 1000)::BIGINT,INSERT 时无需手动赋值。
ServerTs int64 `json:"server_ts" gorm:"column:server_ts;not null"`
// Extra 扩展字段,存储 app_version / os_version / device_id 等附加信息(spec § 3.5 line 280)。
Extra models.JSONB `json:"extra" gorm:"column:extra;type:jsonb;default:'{}'::jsonb"`
}
// TableName 指定表名
func (ShareEvent) TableName() string { return "public.share_events" }