Files
pig-farm-controller/internal/app/dto/plan_dto.go

87 lines
4.7 KiB
Go
Raw Normal View History

2025-10-03 23:02:43 +08:00
package dto
2025-10-29 18:56:05 +08:00
import (
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
)
2025-10-03 23:02:43 +08:00
2025-10-29 16:25:39 +08:00
// ListPlansQuery 定义了获取计划列表时的查询参数
type ListPlansQuery struct {
2025-11-07 16:02:16 +08:00
PlanType repository.PlanTypeFilter `json:"plan_type" query:"plan_type"` // 计划类型
2025-10-31 18:14:12 +08:00
Page int `json:"page" query:"page"` // 页码
PageSize int `json:"page_size" query:"page_size"` // 每页大小
2025-10-29 16:25:39 +08:00
}
2025-10-03 23:02:43 +08:00
// CreatePlanRequest 定义创建计划请求的结构体
type CreatePlanRequest struct {
2025-10-30 17:39:05 +08:00
Name string `json:"name" validate:"required" example:"猪舍温度控制计划"`
2025-10-03 23:02:43 +08:00
Description string `json:"description" example:"根据温度自动调节风扇和加热器"`
2025-10-30 17:39:05 +08:00
ExecutionType models.PlanExecutionType `json:"execution_type" validate:"required" example:"自动"`
2025-11-10 22:23:31 +08:00
ExecuteNum uint32 `json:"execute_num,omitempty" validate:"omitempty,min=0" example:"10"`
2025-10-30 17:39:05 +08:00
CronExpression string `json:"cron_expression" validate:"omitempty,cron" example:"0 0 6 * * *"`
2025-11-10 22:23:31 +08:00
SubPlanIDs []uint32 `json:"sub_plan_ids,omitempty" validate:"omitempty,dive"`
2025-10-30 17:39:05 +08:00
Tasks []TaskRequest `json:"tasks,omitempty" validate:"omitempty,dive"`
2025-10-03 23:02:43 +08:00
}
// PlanResponse 定义计划详情响应的结构体
type PlanResponse struct {
2025-11-10 22:23:31 +08:00
ID uint32 `json:"id" example:"1"`
2025-10-03 23:02:43 +08:00
Name string `json:"name" example:"猪舍温度控制计划"`
Description string `json:"description" example:"根据温度自动调节风扇和加热器"`
2025-10-29 16:25:39 +08:00
PlanType models.PlanType `json:"plan_type" example:"自定义任务"`
2025-10-03 23:02:43 +08:00
ExecutionType models.PlanExecutionType `json:"execution_type" example:"自动"`
Status models.PlanStatus `json:"status" example:"已启用"`
2025-11-10 22:23:31 +08:00
ExecuteNum uint32 `json:"execute_num" example:"10"`
ExecuteCount uint32 `json:"execute_count" example:"0"`
2025-10-03 23:02:43 +08:00
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
ContentType models.PlanContentType `json:"content_type" example:"任务"`
SubPlans []SubPlanResponse `json:"sub_plans,omitempty"`
Tasks []TaskResponse `json:"tasks,omitempty"`
}
// ListPlansResponse 定义获取计划列表响应的结构体
type ListPlansResponse struct {
Plans []PlanResponse `json:"plans"`
2025-10-29 16:25:39 +08:00
Total int64 `json:"total" example:"100"`
2025-10-03 23:02:43 +08:00
}
// UpdatePlanRequest 定义更新计划请求的结构体
type UpdatePlanRequest struct {
Name string `json:"name" example:"猪舍温度控制计划V2"`
Description string `json:"description" example:"更新后的描述"`
2025-10-30 17:39:05 +08:00
ExecutionType models.PlanExecutionType `json:"execution_type" validate:"required" example:"自动"`
2025-11-10 22:23:31 +08:00
ExecuteNum uint32 `json:"execute_num,omitempty" validate:"omitempty,min=0" example:"10"`
2025-10-30 17:39:05 +08:00
CronExpression string `json:"cron_expression" validate:"omitempty,cron" example:"0 0 6 * * *"`
2025-11-10 22:23:31 +08:00
SubPlanIDs []uint32 `json:"sub_plan_ids,omitempty" validate:"omitempty,dive"`
2025-10-30 17:39:05 +08:00
Tasks []TaskRequest `json:"tasks,omitempty" validate:"omitempty,dive"`
2025-10-03 23:02:43 +08:00
}
// SubPlanResponse 定义子计划响应结构体
type SubPlanResponse struct {
2025-11-10 22:23:31 +08:00
ID uint32 `json:"id" example:"1"`
ParentPlanID uint32 `json:"parent_plan_id" example:"1"`
ChildPlanID uint32 `json:"child_plan_id" example:"2"`
2025-10-03 23:02:43 +08:00
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:"等待"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}
// TaskResponse 定义任务响应结构体
type TaskResponse struct {
ID int `json:"id" example:"1"`
2025-11-10 22:23:31 +08:00
PlanID uint32 `json:"plan_id" example:"1"`
2025-10-03 23:02:43 +08:00
Name string `json:"name" example:"打开风扇"`
Description string `json:"description" example:"打开1号风扇"`
ExecutionOrder int `json:"execution_order" example:"1"`
Type models.TaskType `json:"type" example:"等待"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
}