From 8468a96398f4ed7195defb4ebae1dc74139e7798 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Tue, 9 Sep 2025 20:52:38 +0800 Subject: [PATCH] =?UTF-8?q?model=E4=BF=AE=E6=94=B9:=201.=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AD=90=E8=AE=A1=E5=88=92=E6=94=AF=E6=8C=81=202.=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AD=A5=E9=AA=A4=E5=92=8C=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=AE=8C=E5=90=8E=E7=AD=89=E5=BE=85=E4=B8=80?= =?UTF-8?q?=E6=AE=B5=E6=97=B6=E9=97=B4=E5=86=8D=E6=89=A7=E8=A1=8C=E4=B8=8B?= =?UTF-8?q?=E4=B8=80=E4=B8=AA,=20=E5=A2=9E=E5=8A=A0=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=92=8C=E5=A4=9A=E6=AC=A1=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/model/feeding.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) 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"`