diff --git a/internal/database/database.go b/internal/database/database.go index 8142c97..36097dc 100755 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -3,6 +3,7 @@ package database import ( "fmt" "log" + "strings" "wx_service/config" "gorm.io/driver/mysql" @@ -37,5 +38,36 @@ func InitDB() error { } func AutoMigrate(models ...interface{}) error { - return DB.AutoMigrate(models...) + type tableCommenter interface { + TableComment() string + } + + for _, m := range models { + tx := DB + comment := "" + if tc, ok := m.(tableCommenter); ok { + comment = strings.TrimSpace(tc.TableComment()) + if comment != "" { + tx = tx.Set("gorm:table_options", fmt.Sprintf("COMMENT='%s'", escapeSQLComment(comment))) + } + } + + if err := tx.AutoMigrate(m); err != nil { + return err + } + + // 尝试为已存在的表补齐 table comment(即使表已创建,也能更新注释)。 + if comment != "" { + stmt := &gorm.Statement{DB: DB} + if err := stmt.Parse(m); err == nil && stmt.Schema != nil && stmt.Schema.Table != "" { + _ = DB.Exec(fmt.Sprintf("ALTER TABLE `%s` COMMENT = '%s'", stmt.Schema.Table, escapeSQLComment(comment))).Error + } + } + } + return nil +} + +func escapeSQLComment(s string) string { + // MySQL: 单引号用两个单引号转义 + return strings.ReplaceAll(s, "'", "''") } diff --git a/internal/membership/model/redeem_code.go b/internal/membership/model/redeem_code.go index c183eac..4009540 100644 --- a/internal/membership/model/redeem_code.go +++ b/internal/membership/model/redeem_code.go @@ -9,48 +9,55 @@ import ( // MembershipRedeemCode 存储会员兑换码(只存 hash,不存明文 code)。 type MembershipRedeemCode struct { ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` // CodeHash 是 code 的 sha256(hex);避免 DB 泄漏导致所有兑换码被直接使用。 - CodeHash string `gorm:"size:64;uniqueIndex" json:"-"` + CodeHash string `gorm:"size:64;uniqueIndex;comment:兑换码哈希(sha256 hex)" json:"-"` // CodeSuffix 用于展示/审计(例如最后 6 位) - CodeSuffix string `gorm:"size:16;index" json:"code_suffix"` + CodeSuffix string `gorm:"size:16;index;comment:兑换码后缀(展示/审计)" json:"code_suffix"` - Plan string `gorm:"size:30" json:"plan"` - DurationDays int `json:"duration_days"` - ExpiresAt *time.Time `json:"expires_at,omitempty"` + Plan string `gorm:"size:30;comment:会员套餐" json:"plan"` + DurationDays int `gorm:"comment:有效天数(用于延长会员)" json:"duration_days"` + ExpiresAt *time.Time `gorm:"comment:兑换码过期时间" json:"expires_at,omitempty"` - MaxUses int `gorm:"default:1" json:"max_uses"` - UsedUses int `gorm:"default:0" json:"used_uses"` + MaxUses int `gorm:"default:1;comment:最大可使用次数" json:"max_uses"` + UsedUses int `gorm:"default:0;comment:已使用次数" json:"used_uses"` - Status string `gorm:"size:20;default:active" json:"status"` // active/disabled + Status string `gorm:"size:20;default:active;comment:状态(active/disabled)" json:"status"` } func (MembershipRedeemCode) TableName() string { return "membership_redeem_codes" } +func (MembershipRedeemCode) TableComment() string { + return "会员兑换码" +} + type MembershipRedemption struct { ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - MiniProgramID uint `gorm:"index:idx_redeem_user_date,priority:1" json:"mini_program_id"` - UserID uint `gorm:"index:idx_redeem_user_date,priority:2" json:"user_id"` + MiniProgramID uint `gorm:"index:idx_redeem_user_date,priority:1;comment:小程序ID" json:"mini_program_id"` + UserID uint `gorm:"index:idx_redeem_user_date,priority:2;comment:用户ID" json:"user_id"` - RedeemCodeID uint `gorm:"index" json:"redeem_code_id"` - CodeSuffix string `gorm:"size:16" json:"code_suffix"` + RedeemCodeID uint `gorm:"index;comment:兑换码ID" json:"redeem_code_id"` + CodeSuffix string `gorm:"size:16;comment:兑换码后缀(展示/审计)" json:"code_suffix"` - MembershipID uint `gorm:"index" json:"membership_id"` + MembershipID uint `gorm:"index;comment:会员记录ID" json:"membership_id"` - ClientIP string `gorm:"size:64" json:"client_ip,omitempty"` - UserAgent string `gorm:"size:255" json:"user_agent,omitempty"` + ClientIP string `gorm:"size:64;comment:客户端IP" json:"client_ip,omitempty"` + UserAgent string `gorm:"size:255;comment:User-Agent" json:"user_agent,omitempty"` } func (MembershipRedemption) TableName() string { return "membership_redemptions" } +func (MembershipRedemption) TableComment() string { + return "会员兑换流水" +} diff --git a/internal/model/mini_program.go b/internal/model/mini_program.go index 08a05f3..2db7cb3 100644 --- a/internal/model/mini_program.go +++ b/internal/model/mini_program.go @@ -8,16 +8,20 @@ import ( type MiniProgram struct { ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - Name string `gorm:"size:100;not null" json:"name"` - AppID string `gorm:"size:100;uniqueIndex" json:"app_id"` - AppSecret string `gorm:"size:200;not null" json:"-"` - Description string `gorm:"size:255" json:"description"` + Name string `gorm:"size:100;not null;comment:小程序名称" json:"name"` + AppID string `gorm:"size:100;uniqueIndex;comment:小程序AppID" json:"app_id"` + AppSecret string `gorm:"size:200;not null;comment:小程序AppSecret" json:"-"` + Description string `gorm:"size:255;comment:描述" json:"description"` } func (MiniProgram) TableName() string { return "mini_programs" } + +func (MiniProgram) TableComment() string { + return "小程序配置" +} diff --git a/internal/model/product.go b/internal/model/product.go index 7a9fb4a..0c47bdd 100755 --- a/internal/model/product.go +++ b/internal/model/product.go @@ -7,20 +7,24 @@ import ( ) type Product struct { - ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + ID uint `gorm:"primarykey;comment:商品ID" json:"id"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - Name string `gorm:"size:200;not null" json:"name"` - Description string `gorm:"type:text" json:"description"` - Price float64 `gorm:"type:decimal(10,2);not null" json:"price"` - Stock int `gorm:"default:0" json:"stock"` - ImageURL string `gorm:"size:500" json:"image_url"` - Category string `gorm:"size:50" json:"category"` - Status int `gorm:"default:1" json:"status"` + Name string `gorm:"size:200;not null;comment:商品名" json:"name"` + Description string `gorm:"type:text;comment:商品描述" json:"description"` + Price float64 `gorm:"type:decimal(10,2);not null;comment:价格" json:"price"` + Stock int `gorm:"default:0;comment:库存" json:"stock"` + ImageURL string `gorm:"size:500;comment:图片URL" json:"image_url"` + Category string `gorm:"size:50;comment:分类" json:"category"` + Status int `gorm:"default:1;comment:状态(1上架/0下架)" json:"status"` } func (Product) TableName() string { return "products" } + +func (Product) TableComment() string { + return "商品" +} diff --git a/internal/model/user.go b/internal/model/user.go index 0367cc1..92b00bd 100755 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -7,23 +7,27 @@ import ( ) type User struct { - ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + ID uint `gorm:"primarykey;comment:用户ID" json:"id"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - MiniProgramID uint `gorm:"index:idx_mini_open,priority:1" json:"mini_program_id"` + MiniProgramID uint `gorm:"index:idx_mini_open,priority:1;comment:小程序ID" json:"mini_program_id"` MiniProgram MiniProgram `gorm:"foreignKey:MiniProgramID" json:"mini_program,omitempty"` - OpenID string `gorm:"size:100;index:idx_mini_open,priority:2" json:"open_id"` - UnionID string `gorm:"size:100" json:"union_id,omitempty"` - NickName string `gorm:"size:100" json:"nickname"` - AvatarURL string `gorm:"size:500" json:"avatar_url"` - Gender int `gorm:"default:0" json:"gender"` - Phone string `gorm:"size:20" json:"phone,omitempty"` + OpenID string `gorm:"size:100;index:idx_mini_open,priority:2;comment:微信OpenID" json:"open_id"` + UnionID string `gorm:"size:100;comment:微信UnionID" json:"union_id,omitempty"` + NickName string `gorm:"size:100;comment:昵称" json:"nickname"` + AvatarURL string `gorm:"size:500;comment:头像URL" json:"avatar_url"` + Gender int `gorm:"default:0;comment:性别(0未知/1男/2女)" json:"gender"` + Phone string `gorm:"size:20;comment:手机号" json:"phone,omitempty"` - SessionKey string `gorm:"size:100" json:"-"` + SessionKey string `gorm:"size:100;comment:会话key(用于Bearer Token)" json:"-"` } func (User) TableName() string { return "users" } + +func (User) TableComment() string { + return "用户" +} diff --git a/internal/model/user_membership.go b/internal/model/user_membership.go index 0364911..3497d32 100644 --- a/internal/model/user_membership.go +++ b/internal/model/user_membership.go @@ -9,21 +9,24 @@ import ( // UserMembership 表示会员订阅记录(DDL 见 docs/sql/users.sql)。 type UserMembership struct { ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - MiniProgramID uint `gorm:"index:idx_membership_user,priority:1;index:idx_membership_status,priority:1" json:"mini_program_id"` - UserID uint `gorm:"index:idx_membership_user,priority:2;index:idx_membership_status,priority:2" json:"user_id"` + MiniProgramID uint `gorm:"index:idx_membership_user,priority:1;index:idx_membership_status,priority:1;comment:小程序ID" json:"mini_program_id"` + UserID uint `gorm:"index:idx_membership_user,priority:2;index:idx_membership_status,priority:2;comment:用户ID" json:"user_id"` - Plan string `gorm:"size:30" json:"plan"` - Status string `gorm:"size:20;index:idx_membership_status,priority:3" json:"status"` + Plan string `gorm:"size:30;comment:会员套餐" json:"plan"` + Status string `gorm:"size:20;index:idx_membership_status,priority:3;comment:状态(active/canceled/expired)" json:"status"` - StartsAt time.Time `json:"starts_at"` - EndsAt time.Time `gorm:"index:idx_membership_user,priority:3;index:idx_membership_status,priority:4" json:"ends_at"` + StartsAt time.Time `gorm:"comment:开始时间" json:"starts_at"` + EndsAt time.Time `gorm:"index:idx_membership_user,priority:3;index:idx_membership_status,priority:4;comment:结束时间" json:"ends_at"` } func (UserMembership) TableName() string { return "user_memberships" } +func (UserMembership) TableComment() string { + return "用户会员订阅" +} diff --git a/internal/remove_watermark/model/video_parse.go b/internal/remove_watermark/model/video_parse.go index 74d73a6..d1ab222 100644 --- a/internal/remove_watermark/model/video_parse.go +++ b/internal/remove_watermark/model/video_parse.go @@ -8,37 +8,45 @@ import ( type VideoParseLog struct { ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - MiniProgramID uint `gorm:"index:idx_video_parse_user_date,priority:1" json:"mini_program_id"` - UserID uint `gorm:"index:idx_video_parse_user_date,priority:2" json:"user_id"` - RequestContent string `gorm:"type:text" json:"request_content"` - ParsedURL string `gorm:"size:500" json:"parsed_url"` - ThirdPartyStatus int `json:"third_party_status"` - ThirdPartyPayload []byte `gorm:"type:json" json:"third_party_payload"` - FreeQuotaUsed bool `gorm:"default:1" json:"free_quota_used"` - DurationMs int `json:"duration_ms"` - ErrorMessage string `gorm:"size:500" json:"error_message"` + MiniProgramID uint `gorm:"index:idx_video_parse_user_date,priority:1;comment:小程序ID" json:"mini_program_id"` + UserID uint `gorm:"index:idx_video_parse_user_date,priority:2;comment:用户ID" json:"user_id"` + RequestContent string `gorm:"type:text;comment:用户提交原文" json:"request_content"` + ParsedURL string `gorm:"size:500;comment:解析得到的链接" json:"parsed_url"` + ThirdPartyStatus int `gorm:"comment:第三方HTTP状态或业务码" json:"third_party_status"` + ThirdPartyPayload []byte `gorm:"type:json;comment:第三方响应原文" json:"third_party_payload"` + FreeQuotaUsed bool `gorm:"default:1;comment:是否计入免费次数" json:"free_quota_used"` + DurationMs int `gorm:"comment:耗时毫秒" json:"duration_ms"` + ErrorMessage string `gorm:"size:500;comment:错误信息" json:"error_message"` } func (VideoParseLog) TableName() string { return "video_parse_logs" } +func (VideoParseLog) TableComment() string { + return "短视频去水印调用日志" +} + type VideoParseUnlock struct { ID uint `gorm:"primarykey" json:"id"` - CreatedAt time.Time `json:"created_at"` - UpdatedAt time.Time `json:"updated_at"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"` + UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"` + DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"` - MiniProgramID uint `gorm:"index:idx_video_unlock_user_date,priority:1" json:"mini_program_id"` - UserID uint `gorm:"index:idx_video_unlock_user_date,priority:2" json:"user_id"` - UnlockDate time.Time `gorm:"type:date;index:idx_video_unlock_user_date,priority:3" json:"unlock_date"` - AdWatchedAt time.Time `json:"ad_watched_at"` + MiniProgramID uint `gorm:"index:idx_video_unlock_user_date,priority:1;comment:小程序ID" json:"mini_program_id"` + UserID uint `gorm:"index:idx_video_unlock_user_date,priority:2;comment:用户ID" json:"user_id"` + UnlockDate time.Time `gorm:"type:date;index:idx_video_unlock_user_date,priority:3;comment:解锁日期" json:"unlock_date"` + AdWatchedAt time.Time `gorm:"comment:广告完成时间" json:"ad_watched_at"` } func (VideoParseUnlock) TableName() string { return "video_parse_unlocks" } + +func (VideoParseUnlock) TableComment() string { + return "短视频去水印-每日广告解锁" +} diff --git a/internal/smoke/model/smoke_ai.go b/internal/smoke/model/smoke_ai.go index 5934f35..ab7c5bb 100644 --- a/internal/smoke/model/smoke_ai.go +++ b/internal/smoke/model/smoke_ai.go @@ -6,44 +6,52 @@ import "time" // // 注意:沿用旧系统字段(createtime/updatetime/deletetime 为秒级时间戳),不使用 gorm.Model。 type SmokeAIAdvice struct { - ID uint `gorm:"primaryKey;autoIncrement" json:"id"` + ID uint `gorm:"primaryKey;autoIncrement;comment:记录ID" json:"id"` UID int `gorm:"column:uid;index:idx_smoke_ai_advice_uid_date,priority:1;uniqueIndex:uniq_smoke_ai_advice,priority:1" json:"-"` - AdviceDate time.Time `gorm:"column:advice_date;type:date;index:idx_smoke_ai_advice_uid_date,priority:2;uniqueIndex:uniq_smoke_ai_advice,priority:2" json:"advice_date"` - PromptVersion string `gorm:"column:prompt_version;size:30;default:v1;uniqueIndex:uniq_smoke_ai_advice,priority:3" json:"prompt_version"` + AdviceDate time.Time `gorm:"column:advice_date;type:date;index:idx_smoke_ai_advice_uid_date,priority:2;uniqueIndex:uniq_smoke_ai_advice,priority:2;comment:建议日期" json:"advice_date"` + PromptVersion string `gorm:"column:prompt_version;size:30;default:v1;uniqueIndex:uniq_smoke_ai_advice,priority:3;comment:提示词版本" json:"prompt_version"` - Provider string `gorm:"column:provider;size:30" json:"provider,omitempty"` - Model string `gorm:"column:model;size:60" json:"model,omitempty"` + Provider string `gorm:"column:provider;size:30;comment:AI提供方" json:"provider,omitempty"` + Model string `gorm:"column:model;size:60;comment:模型名" json:"model,omitempty"` - InputSnapshot []byte `gorm:"column:input_snapshot;type:json" json:"input_snapshot,omitempty"` - Advice string `gorm:"column:advice;type:mediumtext" json:"advice"` + InputSnapshot []byte `gorm:"column:input_snapshot;type:json;comment:输入快照(JSON)" json:"input_snapshot,omitempty"` + Advice string `gorm:"column:advice;type:mediumtext;comment:AI建议内容" json:"advice"` - TokensIn *int `gorm:"column:tokens_in" json:"tokens_in,omitempty"` - TokensOut *int `gorm:"column:tokens_out" json:"tokens_out,omitempty"` - CostCent *int `gorm:"column:cost_cent" json:"cost_cent,omitempty"` + TokensIn *int `gorm:"column:tokens_in;comment:输入tokens" json:"tokens_in,omitempty"` + TokensOut *int `gorm:"column:tokens_out;comment:输出tokens" json:"tokens_out,omitempty"` + CostCent *int `gorm:"column:cost_cent;comment:成本(分)" json:"cost_cent,omitempty"` - CreateTime *int64 `gorm:"column:createtime" json:"createtime,omitempty"` - UpdateTime *int64 `gorm:"column:updatetime" json:"updatetime,omitempty"` - DeleteTime *int64 `gorm:"column:deletetime" json:"deletetime,omitempty"` + CreateTime *int64 `gorm:"column:createtime;comment:创建时间(秒)" json:"createtime,omitempty"` + UpdateTime *int64 `gorm:"column:updatetime;comment:更新时间(秒)" json:"updatetime,omitempty"` + DeleteTime *int64 `gorm:"column:deletetime;comment:删除时间(秒)" json:"deletetime,omitempty"` } func (SmokeAIAdvice) TableName() string { return "fa_smoke_ai_advice" } +func (SmokeAIAdvice) TableComment() string { + return "每日AI戒烟建议" +} + // SmokeAIAdviceUnlock 对应表 fa_smoke_ai_advice_unlocks(非会员用户的每日广告解锁记录)。 type SmokeAIAdviceUnlock struct { - ID uint `gorm:"primaryKey;autoIncrement" json:"id"` + ID uint `gorm:"primaryKey;autoIncrement;comment:记录ID" json:"id"` UID int `gorm:"column:uid;index:idx_smoke_ai_unlock_uid_date,priority:1;uniqueIndex:uniq_smoke_ai_unlock,priority:1" json:"-"` - UnlockDate time.Time `gorm:"column:unlock_date;type:date;index:idx_smoke_ai_unlock_uid_date,priority:2;uniqueIndex:uniq_smoke_ai_unlock,priority:2" json:"unlock_date"` - AdWatchedAt time.Time `gorm:"column:ad_watched_at" json:"ad_watched_at"` + UnlockDate time.Time `gorm:"column:unlock_date;type:date;index:idx_smoke_ai_unlock_uid_date,priority:2;uniqueIndex:uniq_smoke_ai_unlock,priority:2;comment:解锁日期" json:"unlock_date"` + AdWatchedAt time.Time `gorm:"column:ad_watched_at;comment:广告完成时间" json:"ad_watched_at"` - CreateTime *int64 `gorm:"column:createtime" json:"createtime,omitempty"` - UpdateTime *int64 `gorm:"column:updatetime" json:"updatetime,omitempty"` - DeleteTime *int64 `gorm:"column:deletetime" json:"deletetime,omitempty"` + CreateTime *int64 `gorm:"column:createtime;comment:创建时间(秒)" json:"createtime,omitempty"` + UpdateTime *int64 `gorm:"column:updatetime;comment:更新时间(秒)" json:"updatetime,omitempty"` + DeleteTime *int64 `gorm:"column:deletetime;comment:删除时间(秒)" json:"deletetime,omitempty"` } func (SmokeAIAdviceUnlock) TableName() string { return "fa_smoke_ai_advice_unlocks" } + +func (SmokeAIAdviceUnlock) TableComment() string { + return "AI戒烟建议-广告解锁" +} diff --git a/internal/smoke/model/smoke_log.go b/internal/smoke/model/smoke_log.go index 5bbf465..c3aed11 100644 --- a/internal/smoke/model/smoke_log.go +++ b/internal/smoke/model/smoke_log.go @@ -8,25 +8,29 @@ import "time" // 因此这里不使用 gorm.Model 的 created_at/updated_at/deleted_at。 type SmokeLog struct { // 复合主键(id, uid),其中 id 自增。 - ID int `gorm:"column:id;primaryKey;autoIncrement" json:"id"` + ID int `gorm:"column:id;primaryKey;autoIncrement;comment:记录ID" json:"id"` UID int `gorm:"column:uid;primaryKey" json:"-"` // smoke_time 在库里是 date 类型(只包含日期,不包含时分秒)。 - SmokeTime *time.Time `gorm:"column:smoke_time;type:date" json:"smoke_time,omitempty"` + SmokeTime *time.Time `gorm:"column:smoke_time;type:date;comment:抽烟日期" json:"smoke_time,omitempty"` // smoke_at:真实抽烟时间(可补录,精确到时分秒) - SmokeAt *time.Time `gorm:"column:smoke_at;type:datetime" json:"smoke_at,omitempty"` + SmokeAt *time.Time `gorm:"column:smoke_at;type:datetime;comment:真实抽烟时间(精确到秒)" json:"smoke_at,omitempty"` - Remark string `gorm:"column:remark;type:text" json:"remark,omitempty"` + Remark string `gorm:"column:remark;type:text;comment:原因/备注" json:"remark,omitempty"` // createtime/updatetime/deletetime:秒级 Unix 时间戳(与 gorm 默认字段不同) - CreateTime *int64 `gorm:"column:createtime" json:"createtime,omitempty"` - UpdateTime *int64 `gorm:"column:updatetime" json:"updatetime,omitempty"` - DeleteTime *int64 `gorm:"column:deletetime" json:"deletetime,omitempty"` + CreateTime *int64 `gorm:"column:createtime;comment:创建时间(秒)" json:"createtime,omitempty"` + UpdateTime *int64 `gorm:"column:updatetime;comment:更新时间(秒)" json:"updatetime,omitempty"` + DeleteTime *int64 `gorm:"column:deletetime;comment:删除时间(秒)" json:"deletetime,omitempty"` - Level int64 `gorm:"column:level;default:1" json:"level"` - Num int `gorm:"column:num;default:1" json:"num"` + Level int64 `gorm:"column:level;default:1;comment:烟瘾程度" json:"level"` + Num int `gorm:"column:num;default:1;comment:抽烟数量" json:"num"` } func (SmokeLog) TableName() string { return "fa_smoke_log" } + +func (SmokeLog) TableComment() string { + return "抽烟记录" +}