6cf7eb2294
- Added new API endpoint `GET /api/v1/smoke/next_smoke_time` to provide AI-generated suggestions for the next smoking time based on user data. - Introduced a new database table `fa_smoke_ai_next_smoke` to store structured AI time node suggestions. - Updated smoke handler and service to integrate the new AI next smoke time functionality. - Enhanced documentation to reflect the new API endpoint and its usage, including details on how to generate AI time nodes.
61 lines
3.3 KiB
Go
61 lines
3.3 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// SmokeAIAdvice 对应表 fa_smoke_ai_advice(每日 AI 戒烟建议缓存)。
|
|
//
|
|
// 注意:沿用旧系统字段(createtime/updatetime/deletetime 为秒级时间戳),不使用 gorm.Model。
|
|
type SmokeAIAdvice struct {
|
|
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:"-"`
|
|
|
|
// Type 用于区分 AI 使用场景(例如:daily_advice / next_smoke_time)。
|
|
Type string `gorm:"column:type;size:30;default:daily_advice;index:idx_smoke_ai_advice_uid_date,priority:2;uniqueIndex:uniq_smoke_ai_advice,priority:2;comment:用途类型" json:"type"`
|
|
|
|
AdviceDate time.Time `gorm:"column:advice_date;type:date;index:idx_smoke_ai_advice_uid_date,priority:3;uniqueIndex:uniq_smoke_ai_advice,priority:3;comment:建议日期" json:"advice_date"`
|
|
PromptVersion string `gorm:"column:prompt_version;size:30;default:v1;uniqueIndex:uniq_smoke_ai_advice,priority:4;comment:提示词版本" json:"prompt_version"`
|
|
|
|
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;comment:输入快照(JSON)" json:"input_snapshot,omitempty"`
|
|
Advice string `gorm:"column:advice;type:mediumtext;comment:AI建议内容" json:"advice"`
|
|
|
|
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;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;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;comment:解锁日期" json:"unlock_date"`
|
|
AdWatchedAt time.Time `gorm:"column:ad_watched_at;comment:广告完成时间" json:"ad_watched_at"`
|
|
|
|
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戒烟建议-广告解锁"
|
|
}
|