93bcc6c787
- 新增 Model 层: SmokeQuitPlan, SmokeQuitPlanDay 结构体 - 新增 Service 层: GenerateQuitPlan, GetActivePlan, GetPlanDays, ResetPlan - 新增 Handler 层: POST /generate, GET /, GET /days, POST /reset - 集成 AI 生成 30 天个性化戒烟减量方案 - 支持重置计划功能
122 lines
5.7 KiB
Go
122 lines
5.7 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// QuitPlanStatus 戒烟计划状态
|
|
type QuitPlanStatus string
|
|
|
|
const (
|
|
QuitPlanStatusActive QuitPlanStatus = "active" // 进行中
|
|
QuitPlanStatusPaused QuitPlanStatus = "paused" // 已暂停
|
|
QuitPlanStatusDone QuitPlanStatus = "done" // 已完成
|
|
QuitPlanStatusFailed QuitPlanStatus = "failed" // 已失败
|
|
)
|
|
|
|
// QuitPlanStage 戒烟计划阶段
|
|
type QuitPlanStage string
|
|
|
|
const (
|
|
QuitPlanStageRecording QuitPlanStage = "recording" // 记录期 (Day 1-7)
|
|
QuitPlanStageReducing QuitPlanStage = "reducing" // 减量期 (Day 8-21)
|
|
QuitPlanStage巩固ing QuitPlanStage = "consolidating" // 巩固期 (Day 22-30)
|
|
)
|
|
|
|
// SmokeQuitPlan 对应表 fa_smoke_quit_plan(戒烟计划主表)。
|
|
type SmokeQuitPlan struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement;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:"-"`
|
|
|
|
UID int `gorm:"uniqueIndex:idx_quit_plan_uid;comment:用户ID" json:"-"`
|
|
|
|
// 计划基本信息
|
|
Status QuitPlanStatus `gorm:"column:status;size:20;default:active;index:idx_quit_plan_uid;comment:计划状态" json:"status"`
|
|
StartDate time.Time `gorm:"column:start_date;type:date;comment:计划开始日期" json:"start_date"`
|
|
EndDate time.Time `gorm:"column:end_date;type:date;comment:计划结束日期" json:"end_date"`
|
|
|
|
// 用户画像(生成计划时的快照)
|
|
BaselineCigsPerDay int `gorm:"column:baseline_cigs_per_day;comment:日均吸烟量" json:"baseline_cigs_per_day"`
|
|
SmokingYears float64 `gorm:"column:smoking_years;type:decimal(6,2);comment:烟龄" json:"smoking_years"`
|
|
PackPriceCent int `gorm:"column:pack_price_cent;comment:单包价格(分)" json:"pack_price_cent"`
|
|
|
|
// 阶段进度
|
|
CurrentStage QuitPlanStage `gorm:"column:current_stage;size:20;default:recording;comment:当前阶段" json:"current_stage"`
|
|
CurrentDay int `gorm:"column:current_day;default:1;comment:当前天数(1-30)" json:"current_day"`
|
|
CompletedDays int `gorm:"column:completed_days;default:0;comment:已完成天数" json:"completed_days"`
|
|
|
|
// AI 生成信息
|
|
PromptVersion string `gorm:"column:prompt_version;size:30;default:v1;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"`
|
|
|
|
// Token 消耗
|
|
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"`
|
|
|
|
// 摘要(AI 生成的 30 天计划概述)
|
|
Summary string `gorm:"column:summary;type:mediumtext;comment:计划摘要" json:"summary,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 (SmokeQuitPlan) TableName() string {
|
|
return "fa_smoke_quit_plan"
|
|
}
|
|
|
|
func (SmokeQuitPlan) TableComment() string {
|
|
return "戒烟计划主表"
|
|
}
|
|
|
|
// SmokeQuitPlanDay 对应表 fa_smoke_quit_plan_day(每日计划明细)。
|
|
type SmokeQuitPlanDay struct {
|
|
ID uint `gorm:"primaryKey;autoIncrement;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:"-"`
|
|
|
|
PlanID uint `gorm:"uniqueIndex:idx_quit_plan_day_plan_day;index:idx_quit_plan_day_uid;comment:计划ID" json:"plan_id"`
|
|
UID int `gorm:"uniqueIndex:idx_quit_plan_day_plan_day;index:idx_quit_plan_day_uid;comment:用户ID" json:"-"`
|
|
|
|
// 计划日期
|
|
PlanDate time.Time `gorm:"column:plan_date;type:date;uniqueIndex:idx_quit_plan_day_plan_day;comment:计划日期" json:"plan_date"`
|
|
|
|
// 阶段
|
|
Stage QuitPlanStage `gorm:"column:stage;size:20;comment:所属阶段" json:"stage"`
|
|
Day int `gorm:"column:day;comment:计划第几天(1-30)" json:"day"`
|
|
|
|
// 目标
|
|
TargetCigs int `gorm:"column:target_cigs;comment:目标吸烟量" json:"target_cigs"`
|
|
TargetReduced bool `gorm:"column:target_reduced;default:false;comment:是否比昨天减少" json:"target_reduced"`
|
|
|
|
// 建议内容(AI 生成)
|
|
Advice string `gorm:"column:advice;type:mediumtext;comment:每日建议" json:"advice,omitempty"`
|
|
|
|
// 实际执行结果
|
|
ActualCigs *int `gorm:"column:actual_cigs;comment:实际吸烟量" json:"actual_cigs,omitempty"`
|
|
ResistedCnt *int `gorm:"column:resisted_cnt;comment:忍住的次数" json:"resisted_cnt,omitempty"`
|
|
Achieved *bool `gorm:"column:achieved;comment:是否达成目标" json:"achieved,omitempty"`
|
|
CompletedAt *time.Time `gorm:"column:completed_at;comment:完成时间" json:"completed_at,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 (SmokeQuitPlanDay) TableName() string {
|
|
return "fa_smoke_quit_plan_day"
|
|
}
|
|
|
|
func (SmokeQuitPlanDay) TableComment() string {
|
|
return "戒烟计划每日明细"
|
|
}
|