package model import ( "time" "gorm.io/gorm" ) // FeedingPlanType 喂料计划类型枚举 type FeedingPlanType string const ( // FeedingPlanTypeManual 手动触发 FeedingPlanTypeManual FeedingPlanType = "manual" // FeedingPlanTypeAuto 自动触发 FeedingPlanTypeAuto FeedingPlanType = "auto" ) // FeedingPlan 喂料计划主表 type FeedingPlan struct { // ID 计划ID ID uint `gorm:"primaryKey;column:id" json:"id"` // Name 计划名称 Name string `gorm:"not null;column:name" json:"name"` // Description 计划描述 Description string `gorm:"column:description" json:"description"` // Type 计划类型(手动触发/自动触发) Type FeedingPlanType `gorm:"not null;column:type" json:"type"` // Enabled 是否启用 Enabled bool `gorm:"not null;default:true;column:enabled" json:"enabled"` // 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"` // CreatedAt 创建时间 CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` // UpdatedAt 更新时间 UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` // DeletedAt 删除时间(用于软删除) DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at" json:"-"` // Steps 计划步骤列表 Steps []FeedingPlanStep `gorm:"foreignKey:PlanID" json:"-"` // SubPlans 子计划列表 SubPlans []FeedingPlan `gorm:"foreignKey:ParentID" json:"-"` } // TableName 指定FeedingPlan模型对应的数据库表名 func (FeedingPlan) TableName() string { return "feeding_plans" } // FeedingPlanStep 喂料计划步骤表,表示计划中的每个设备动作 type FeedingPlanStep struct { // ID 步骤ID ID uint `gorm:"primaryKey;column:id" json:"id"` // PlanID 关联的计划ID PlanID uint `gorm:"not null;column:plan_id;index" json:"plan_id"` // StepOrder 步骤顺序 StepOrder int `gorm:"not null;column:step_order" json:"step_order"` // DeviceID 关联的设备ID DeviceID uint `gorm:"not null;column:device_id;index" json:"device_id"` // TargetValue 目标值(达到该值后停止工作切换到下一个设备) TargetValue float64 `gorm:"not null;column:target_value" json:"target_value"` // 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"` // UpdatedAt 更新时间 UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` // DeletedAt 删除时间(用于软删除) DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at" json:"-"` } // TableName 指定FeedingPlanStep模型对应的数据库表名 func (FeedingPlanStep) TableName() string { return "feeding_plan_steps" } // FeedingExecution 喂料执行记录表 type FeedingExecution struct { // ID 执行记录ID ID uint `gorm:"primaryKey;column:id" json:"id"` // 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"` // Status 执行状态(进行中/已完成/已取消/失败) Status string `gorm:"not null;column:status" json:"status"` // StartedAt 开始执行时间 StartedAt *time.Time `gorm:"column:started_at" json:"started_at,omitempty"` // FinishedAt 完成时间 FinishedAt *time.Time `gorm:"column:finished_at" json:"finished_at,omitempty"` // CreatedAt 创建时间 CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` // UpdatedAt 更新时间 UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` // DeletedAt 删除时间(用于软删除) DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at" json:"-"` // Steps 执行步骤详情 Steps []FeedingExecutionStep `gorm:"foreignKey:ExecutionID" json:"-"` } // TableName 指定FeedingExecution模型对应的数据库表名 func (FeedingExecution) TableName() string { return "feeding_executions" } // FeedingExecutionStep 喂料执行步骤详情表 type FeedingExecutionStep struct { // ID 执行步骤ID ID uint `gorm:"primaryKey;column:id" json:"id"` // ExecutionID 关联的执行记录ID ExecutionID uint `gorm:"not null;column:execution_id;index" json:"execution_id"` // StepID 关联的计划步骤ID StepID uint `gorm:"not null;column:step_id;index" json:"step_id"` // DeviceID 关联的设备ID DeviceID uint `gorm:"not null;column:device_id;index" json:"device_id"` // TargetValue 目标值 TargetValue float64 `gorm:"not null;column:target_value" json:"target_value"` // ActualValue 实际值 ActualValue *float64 `gorm:"column:actual_value" json:"actual_value,omitempty"` // Status 步骤状态(待执行/执行中/已完成/失败) Status string `gorm:"not null;column:status" json:"status"` // StartedAt 开始执行时间 StartedAt *time.Time `gorm:"column:started_at" json:"started_at,omitempty"` // FinishedAt 完成时间 FinishedAt *time.Time `gorm:"column:finished_at" json:"finished_at,omitempty"` // CreatedAt 创建时间 CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` // UpdatedAt 更新时间 UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` // DeletedAt 删除时间(用于软删除) DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at" json:"-"` } // TableName 指定FeedingExecutionStep模型对应的数据库表名 func (FeedingExecutionStep) TableName() string { return "feeding_execution_steps" }