diff --git a/internal/model/feeding.go b/internal/model/feeding.go index 624dfd4..05d4b80 100644 --- a/internal/model/feeding.go +++ b/internal/model/feeding.go @@ -12,10 +12,8 @@ type FeedingPlanType string const ( // FeedingPlanTypeManual 手动触发 FeedingPlanTypeManual FeedingPlanType = "manual" - // FeedingPlanTypeAutoOnce 自动触发一次 - FeedingPlanTypeAutoOnce FeedingPlanType = "auto_once" - // FeedingPlanTypeAutoScheduled 定时自动触发 - FeedingPlanTypeAutoScheduled FeedingPlanType = "auto_scheduled" + // FeedingPlanTypeAuto 自动触发 + FeedingPlanTypeAuto FeedingPlanType = "auto" ) // FeedingPlan 喂料计划主表 @@ -29,15 +27,27 @@ type FeedingPlan struct { // Description 计划描述 Description string `gorm:"column:description" json:"description"` - // Type 计划类型(手动触发/自动触发一次/定时自动触发) + // Type 计划类型(手动触发/自动触发) Type FeedingPlanType `gorm:"not null;column:type" json:"type"` // Enabled 是否启用 Enabled bool `gorm:"not null;default:true;column:enabled" json:"enabled"` - // ScheduleCron 定时任务表达式, 当类型为 FeedingPlanTypeAutoOnce 时只会触发第一次 + // ScheduleCron 定时任务表达式(仅当Type为auto时有效) ScheduleCron *string `gorm:"column:schedule_cron" json:"schedule_cron,omitempty"` + // ExecutionLimit 执行次数限制(0表示无限制,仅当Type为auto时有效) + ExecutionLimit int `gorm:"not null;default:0;column:execution_limit" json:"execution_limit"` + + // ParentID 父计划ID(用于支持子计划结构) + ParentID *uint `gorm:"column:parent_id;index" json:"parent_id,omitempty"` + + // OrderInParent 在父计划中的执行顺序 + OrderInParent *int `gorm:"column:order_in_parent" json:"order_in_parent,omitempty"` + + // IsMaster 是否为主计划(主计划可以包含子计划) + IsMaster bool `gorm:"not null;default:false;column:is_master" json:"is_master"` + // CreatedAt 创建时间 CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` @@ -49,6 +59,9 @@ type FeedingPlan struct { // Steps 计划步骤列表 Steps []FeedingPlanStep `gorm:"foreignKey:PlanID" json:"-"` + + // SubPlans 子计划列表 + SubPlans []FeedingPlan `gorm:"foreignKey:ParentID" json:"-"` } // TableName 指定FeedingPlan模型对应的数据库表名 @@ -76,6 +89,12 @@ type FeedingPlanStep struct { // Action 动作(如:打开设备) Action string `gorm:"not null;column:action" json:"action"` + // ScheduleCron 步骤定时任务表达式(可选) + ScheduleCron *string `gorm:"column:schedule_cron" json:"schedule_cron,omitempty"` + + // ExecutionLimit 步骤执行次数限制(0表示无限制) + ExecutionLimit int `gorm:"not null;default:0;column:execution_limit" json:"execution_limit"` + // CreatedAt 创建时间 CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` @@ -99,6 +118,9 @@ type FeedingExecution struct { // PlanID 关联的计划ID PlanID uint `gorm:"not null;column:plan_id;index" json:"plan_id"` + // MasterPlanID 主计划ID(如果是子计划执行,记录主计划ID) + MasterPlanID *uint `gorm:"column:master_plan_id;index" json:"master_plan_id,omitempty"` + // TriggerType 触发类型(手动/自动) TriggerType FeedingPlanType `gorm:"not null;column:trigger_type" json:"trigger_type"`