From 1dbef11a8c3c77ec70ea6fbe675439b869dce218 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sun, 14 Sep 2025 14:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E4=B9=89plan=5Fcontroller=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=92=8C=E5=93=8D=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/plan/plan_controller.go | 64 +++++++++++++++---- 1 file changed, 52 insertions(+), 12 deletions(-) diff --git a/internal/app/controller/plan/plan_controller.go b/internal/app/controller/plan/plan_controller.go index 40fbe3b..8ad767b 100644 --- a/internal/app/controller/plan/plan_controller.go +++ b/internal/app/controller/plan/plan_controller.go @@ -3,6 +3,7 @@ package plan import ( "git.huangwc.com/pig/pig-farm-controller/internal/app/controller" "git.huangwc.com/pig/pig-farm-controller/internal/infra/logs" + "git.huangwc.com/pig/pig-farm-controller/internal/infra/models" "git.huangwc.com/pig/pig-farm-controller/internal/infra/repository" "github.com/gin-gonic/gin" ) @@ -11,19 +12,25 @@ import ( // CreatePlanRequest 定义创建计划请求的结构体 type CreatePlanRequest struct { - Name string `json:"name" binding:"required" example:"猪舍温度控制计划"` - Description string `json:"description" example:"根据温度自动调节风扇和加热器"` - // 更多计划基本信息字段 - // SubPlans 或 Tasks 可以在这里嵌套定义,以支持一次性创建 + Name string `json:"name" binding:"required" example:"猪舍温度控制计划"` + Description string `json:"description" example:"根据温度自动调节风扇和加热器"` + ExecutionType models.PlanExecutionType `json:"execution_type" binding:"required" example:"automatic"` + CronExpression string `json:"cron_expression" example:"0 0 6 * * *"` + ContentType models.PlanContentType `json:"content_type" binding:"required" example:"tasks"` + SubPlanIDs []uint `json:"sub_plan_ids,omitempty"` + Tasks []TaskRequest `json:"tasks,omitempty"` } // PlanResponse 定义计划详情响应的结构体 type PlanResponse struct { - ID uint `json:"id" example:"1"` - Name string `json:"name" example:"猪舍温度控制计划"` - Description string `json:"description" example:"根据温度自动调节风扇和加热器"` - // 更多计划基本信息字段 - // SubPlans 或 Tasks 也可以在这里返回 + ID uint `json:"id" example:"1"` + Name string `json:"name" example:"猪舍温度控制计划"` + Description string `json:"description" example:"根据温度自动调节风扇和加热器"` + ExecutionType models.PlanExecutionType `json:"execution_type" example:"automatic"` + CronExpression string `json:"cron_expression" example:"0 0 6 * * *"` + ContentType models.PlanContentType `json:"content_type" example:"tasks"` + SubPlans []SubPlanResponse `json:"sub_plans,omitempty"` + Tasks []TaskResponse `json:"tasks,omitempty"` } // ListPlansResponse 定义获取计划列表响应的结构体 @@ -34,9 +41,42 @@ type ListPlansResponse struct { // UpdatePlanRequest 定义更新计划请求的结构体 type UpdatePlanRequest struct { - Name string `json:"name" example:"猪舍温度控制计划V2"` - Description string `json:"description" example:"更新后的描述"` - // 更多可更新字段 + Name string `json:"name" example:"猪舍温度控制计划V2"` + Description string `json:"description" example:"更新后的描述"` + ExecutionType models.PlanExecutionType `json:"execution_type" example:"automatic"` + CronExpression string `json:"cron_expression" example:"0 0 6 * * *"` + ContentType models.PlanContentType `json:"content_type" example:"tasks"` + SubPlanIDs []uint `json:"sub_plan_ids,omitempty"` + Tasks []TaskRequest `json:"tasks,omitempty"` +} + +// SubPlanResponse 定义子计划响应结构体 +type SubPlanResponse struct { + ID uint `json:"id" example:"1"` + ParentPlanID uint `json:"parent_plan_id" example:"1"` + ChildPlanID uint `json:"child_plan_id" example:"2"` + ExecutionOrder int `json:"execution_order" example:"1"` + ChildPlan *PlanResponse `json:"child_plan,omitempty"` +} + +// TaskRequest 定义任务请求结构体 +type TaskRequest struct { + Name string `json:"name" example:"打开风扇"` + Description string `json:"description" example:"打开1号风扇"` + ExecutionOrder int `json:"execution_order" example:"1"` + Type models.TaskType `json:"type" example:"waiting"` + Parameters controller.Properties `json:"parameters,omitempty"` +} + +// TaskResponse 定义任务响应结构体 +type TaskResponse struct { + ID uint `json:"id" example:"1"` + PlanID uint `json:"plan_id" example:"1"` + Name string `json:"name" example:"打开风扇"` + Description string `json:"description" example:"打开1号风扇"` + ExecutionOrder int `json:"execution_order" example:"1"` + Type models.TaskType `json:"type" example:"waiting"` + Parameters controller.Properties `json:"parameters,omitempty"` } // --- Controller 定义 ---