issue_10 #12
31
docs/docs.go
31
docs/docs.go
@@ -741,22 +741,26 @@ const docTemplate = `{
|
|||||||
"enum": [
|
"enum": [
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2
|
2,
|
||||||
|
3
|
||||||
],
|
],
|
||||||
"x-enum-comments": {
|
"x-enum-comments": {
|
||||||
"PlanStatusDisabled": "禁用计划",
|
"PlanStatusDisabled": "禁用计划",
|
||||||
"PlanStatusEnabled": "启用计划",
|
"PlanStatusEnabled": "启用计划",
|
||||||
|
"PlanStatusFailed": "执行失败",
|
||||||
"PlanStatusStopeed": "执行完毕"
|
"PlanStatusStopeed": "执行完毕"
|
||||||
},
|
},
|
||||||
"x-enum-descriptions": [
|
"x-enum-descriptions": [
|
||||||
"启用计划",
|
|
||||||
"禁用计划",
|
"禁用计划",
|
||||||
"执行完毕"
|
"启用计划",
|
||||||
|
"执行完毕",
|
||||||
|
"执行失败"
|
||||||
],
|
],
|
||||||
"x-enum-varnames": [
|
"x-enum-varnames": [
|
||||||
"PlanStatusEnabled",
|
|
||||||
"PlanStatusDisabled",
|
"PlanStatusDisabled",
|
||||||
"PlanStatusStopeed"
|
"PlanStatusEnabled",
|
||||||
|
"PlanStatusStopeed",
|
||||||
|
"PlanStatusFailed"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"models.TaskType": {
|
"models.TaskType": {
|
||||||
@@ -781,19 +785,10 @@ const docTemplate = `{
|
|||||||
"plan.CreatePlanRequest": {
|
"plan.CreatePlanRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"content_type",
|
|
||||||
"execution_type",
|
"execution_type",
|
||||||
"name"
|
"name"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"content_type": {
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/definitions/models.PlanContentType"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"example": "tasks"
|
|
||||||
},
|
|
||||||
"cron_expression": {
|
"cron_expression": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "0 0 6 * * *"
|
"example": "0 0 6 * * *"
|
||||||
@@ -1005,14 +1000,6 @@ const docTemplate = `{
|
|||||||
"plan.UpdatePlanRequest": {
|
"plan.UpdatePlanRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"content_type": {
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/definitions/models.PlanContentType"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"example": "tasks"
|
|
||||||
},
|
|
||||||
"cron_expression": {
|
"cron_expression": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "0 0 6 * * *"
|
"example": "0 0 6 * * *"
|
||||||
|
|||||||
@@ -730,22 +730,26 @@
|
|||||||
"enum": [
|
"enum": [
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2
|
2,
|
||||||
|
3
|
||||||
],
|
],
|
||||||
"x-enum-comments": {
|
"x-enum-comments": {
|
||||||
"PlanStatusDisabled": "禁用计划",
|
"PlanStatusDisabled": "禁用计划",
|
||||||
"PlanStatusEnabled": "启用计划",
|
"PlanStatusEnabled": "启用计划",
|
||||||
|
"PlanStatusFailed": "执行失败",
|
||||||
"PlanStatusStopeed": "执行完毕"
|
"PlanStatusStopeed": "执行完毕"
|
||||||
},
|
},
|
||||||
"x-enum-descriptions": [
|
"x-enum-descriptions": [
|
||||||
"启用计划",
|
|
||||||
"禁用计划",
|
"禁用计划",
|
||||||
"执行完毕"
|
"启用计划",
|
||||||
|
"执行完毕",
|
||||||
|
"执行失败"
|
||||||
],
|
],
|
||||||
"x-enum-varnames": [
|
"x-enum-varnames": [
|
||||||
"PlanStatusEnabled",
|
|
||||||
"PlanStatusDisabled",
|
"PlanStatusDisabled",
|
||||||
"PlanStatusStopeed"
|
"PlanStatusEnabled",
|
||||||
|
"PlanStatusStopeed",
|
||||||
|
"PlanStatusFailed"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"models.TaskType": {
|
"models.TaskType": {
|
||||||
@@ -770,19 +774,10 @@
|
|||||||
"plan.CreatePlanRequest": {
|
"plan.CreatePlanRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
"content_type",
|
|
||||||
"execution_type",
|
"execution_type",
|
||||||
"name"
|
"name"
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"content_type": {
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/definitions/models.PlanContentType"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"example": "tasks"
|
|
||||||
},
|
|
||||||
"cron_expression": {
|
"cron_expression": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "0 0 6 * * *"
|
"example": "0 0 6 * * *"
|
||||||
@@ -994,14 +989,6 @@
|
|||||||
"plan.UpdatePlanRequest": {
|
"plan.UpdatePlanRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"content_type": {
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/definitions/models.PlanContentType"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"example": "tasks"
|
|
||||||
},
|
|
||||||
"cron_expression": {
|
"cron_expression": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "0 0 6 * * *"
|
"example": "0 0 6 * * *"
|
||||||
|
|||||||
@@ -129,20 +129,24 @@ definitions:
|
|||||||
- 0
|
- 0
|
||||||
- 1
|
- 1
|
||||||
- 2
|
- 2
|
||||||
|
- 3
|
||||||
format: int32
|
format: int32
|
||||||
type: integer
|
type: integer
|
||||||
x-enum-comments:
|
x-enum-comments:
|
||||||
PlanStatusDisabled: 禁用计划
|
PlanStatusDisabled: 禁用计划
|
||||||
PlanStatusEnabled: 启用计划
|
PlanStatusEnabled: 启用计划
|
||||||
|
PlanStatusFailed: 执行失败
|
||||||
PlanStatusStopeed: 执行完毕
|
PlanStatusStopeed: 执行完毕
|
||||||
x-enum-descriptions:
|
x-enum-descriptions:
|
||||||
- 启用计划
|
|
||||||
- 禁用计划
|
- 禁用计划
|
||||||
|
- 启用计划
|
||||||
- 执行完毕
|
- 执行完毕
|
||||||
|
- 执行失败
|
||||||
x-enum-varnames:
|
x-enum-varnames:
|
||||||
- PlanStatusEnabled
|
|
||||||
- PlanStatusDisabled
|
- PlanStatusDisabled
|
||||||
|
- PlanStatusEnabled
|
||||||
- PlanStatusStopeed
|
- PlanStatusStopeed
|
||||||
|
- PlanStatusFailed
|
||||||
models.TaskType:
|
models.TaskType:
|
||||||
enum:
|
enum:
|
||||||
- plan_analysis
|
- plan_analysis
|
||||||
@@ -159,10 +163,6 @@ definitions:
|
|||||||
- TaskTypeWaiting
|
- TaskTypeWaiting
|
||||||
plan.CreatePlanRequest:
|
plan.CreatePlanRequest:
|
||||||
properties:
|
properties:
|
||||||
content_type:
|
|
||||||
allOf:
|
|
||||||
- $ref: '#/definitions/models.PlanContentType'
|
|
||||||
example: tasks
|
|
||||||
cron_expression:
|
cron_expression:
|
||||||
example: 0 0 6 * * *
|
example: 0 0 6 * * *
|
||||||
type: string
|
type: string
|
||||||
@@ -188,7 +188,6 @@ definitions:
|
|||||||
$ref: '#/definitions/plan.TaskRequest'
|
$ref: '#/definitions/plan.TaskRequest'
|
||||||
type: array
|
type: array
|
||||||
required:
|
required:
|
||||||
- content_type
|
|
||||||
- execution_type
|
- execution_type
|
||||||
- name
|
- name
|
||||||
type: object
|
type: object
|
||||||
@@ -306,10 +305,6 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
plan.UpdatePlanRequest:
|
plan.UpdatePlanRequest:
|
||||||
properties:
|
properties:
|
||||||
content_type:
|
|
||||||
allOf:
|
|
||||||
- $ref: '#/definitions/models.PlanContentType'
|
|
||||||
example: tasks
|
|
||||||
cron_expression:
|
cron_expression:
|
||||||
example: 0 0 6 * * *
|
example: 0 0 6 * * *
|
||||||
type: string
|
type: string
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ type CreatePlanRequest struct {
|
|||||||
ExecutionType models.PlanExecutionType `json:"execution_type" binding:"required" example:"automatic"`
|
ExecutionType models.PlanExecutionType `json:"execution_type" binding:"required" example:"automatic"`
|
||||||
ExecuteNum uint `json:"execute_num,omitempty" example:"10"`
|
ExecuteNum uint `json:"execute_num,omitempty" example:"10"`
|
||||||
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
|
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"`
|
SubPlanIDs []uint `json:"sub_plan_ids,omitempty"`
|
||||||
Tasks []TaskRequest `json:"tasks,omitempty"`
|
Tasks []TaskRequest `json:"tasks,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -55,7 +54,6 @@ type UpdatePlanRequest struct {
|
|||||||
ExecutionType models.PlanExecutionType `json:"execution_type" example:"automatic"`
|
ExecutionType models.PlanExecutionType `json:"execution_type" example:"automatic"`
|
||||||
ExecuteNum uint `json:"execute_num,omitempty" example:"10"`
|
ExecuteNum uint `json:"execute_num,omitempty" example:"10"`
|
||||||
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
|
CronExpression string `json:"cron_expression" example:"0 0 6 * * *"`
|
||||||
ContentType models.PlanContentType `json:"content_type" example:"tasks"`
|
|
||||||
SubPlanIDs []uint `json:"sub_plan_ids,omitempty"`
|
SubPlanIDs []uint `json:"sub_plan_ids,omitempty"`
|
||||||
Tasks []TaskRequest `json:"tasks,omitempty"`
|
Tasks []TaskRequest `json:"tasks,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -132,6 +130,14 @@ func (c *Controller) CreatePlan(ctx *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- 自动判断 ContentType ---
|
||||||
|
if len(req.SubPlanIDs) > 0 {
|
||||||
|
planToCreate.ContentType = models.PlanContentTypeSubPlans
|
||||||
|
} else {
|
||||||
|
// 如果 SubPlanIDs 未提供,则默认为 Tasks 类型(即使 Tasks 字段也未提供)
|
||||||
|
planToCreate.ContentType = models.PlanContentTypeTasks
|
||||||
|
}
|
||||||
|
|
||||||
// 调用仓库方法创建计划
|
// 调用仓库方法创建计划
|
||||||
if err := c.planRepo.CreatePlan(planToCreate); err != nil {
|
if err := c.planRepo.CreatePlan(planToCreate); err != nil {
|
||||||
controller.SendErrorResponse(ctx, controller.CodeBadRequest, "创建计划失败: "+err.Error())
|
controller.SendErrorResponse(ctx, controller.CodeBadRequest, "创建计划失败: "+err.Error())
|
||||||
@@ -269,6 +275,14 @@ func (c *Controller) UpdatePlan(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
planToUpdate.ID = uint(id) // 确保ID被设置
|
planToUpdate.ID = uint(id) // 确保ID被设置
|
||||||
|
|
||||||
|
// --- 自动判断 ContentType ---
|
||||||
|
if len(req.SubPlanIDs) > 0 {
|
||||||
|
planToUpdate.ContentType = models.PlanContentTypeSubPlans
|
||||||
|
} else {
|
||||||
|
// 如果 SubPlanIDs 未提供,则默认为 Tasks 类型(即使 Tasks 字段也未提供)
|
||||||
|
planToUpdate.ContentType = models.PlanContentTypeTasks
|
||||||
|
}
|
||||||
|
|
||||||
// 4. 检查计划是否存在
|
// 4. 检查计划是否存在
|
||||||
_, err = c.planRepo.GetBasicPlanByID(uint(id))
|
_, err = c.planRepo.GetBasicPlanByID(uint(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user