diff --git a/automation/server/automation.yaml b/automation/server/automation.yaml index 62edcd46507a3a226e4e9b7d19f76316fac64574..e9fe4d90fbaa2c4deac6a385f765c81e85ce04b1 100755 --- a/automation/server/automation.yaml +++ b/automation/server/automation.yaml @@ -3,7 +3,7 @@ http_server: log: level: debug # 可选stdout和file.stdout:输出到终端控制台;file:输出到path下的指定文件。 - driver: file + driver: stdout path: ./log/plugin_automation.log max_file: 1 max_size: 10485760 diff --git a/automation/server/internal/module/job_workflow/controller/template.go b/automation/server/internal/module/job_workflow/controller/template.go index d380d4c8f8fd1f33148139052643408a8b983f60..606b875ba89b3c170826af3fd24c8eba2f03f4cd 100644 --- a/automation/server/internal/module/job_workflow/controller/template.go +++ b/automation/server/internal/module/job_workflow/controller/template.go @@ -72,3 +72,19 @@ func GetTemplateById(c *gin.Context) { } response.Success(c, info, "success") } + +func PublishTemplate(c *gin.Context) { + var id struct { + ID int `json:"id"` + NewStatus string `json:"new_status"` + } + if err := c.ShouldBindJSON(&id); err != nil { + response.Fail(c, nil, err.Error()) + return + } + if err := service.PublishTemplate(id.ID, id.NewStatus); err != nil { + response.Fail(c, nil, err.Error()) + return + } + response.Success(c, nil, "success") +} diff --git a/automation/server/internal/module/job_workflow/dao/template.go b/automation/server/internal/module/job_workflow/dao/template.go index 4ad146cdf0fd27af32a7e1d7668e30654d71dc02..15248ef1157d952db14f84542aa238096d37617c 100644 --- a/automation/server/internal/module/job_workflow/dao/template.go +++ b/automation/server/internal/module/job_workflow/dao/template.go @@ -6,6 +6,7 @@ import ( "gorm.io/gorm" "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/global" + "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/common/enum/script" "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/job_workflow/model" "openeuler.org/PilotGo/PilotGo-plugin-automation/pkg/response" ) @@ -266,3 +267,12 @@ func GetTemplateById(id string) (interface{}, error) { data["steps"] = steps return data, nil } + +func PublishTemplate(id int, newStatus string) error { + return global.App.MySQL.Transaction(func(tx *gorm.DB) error { + if err := tx.Model(&model.TaskTemplate{}).Where("id = ?", id).Update("publish_status", script.ParseScriptPublishStatus(newStatus)).Error; err != nil { + return err + } + return nil + }) +} diff --git a/automation/server/internal/module/job_workflow/router.go b/automation/server/internal/module/job_workflow/router.go index 0fd110b43849d53be7d78eca4587486d8c16da8b..3010406ff81a0d8c7b9269f1125c6a9f3d0d4561 100644 --- a/automation/server/internal/module/job_workflow/router.go +++ b/automation/server/internal/module/job_workflow/router.go @@ -13,5 +13,6 @@ func WorkflowHandler(router *gin.RouterGroup) { api.POST("/update", controller.UpdateTemplate) api.GET("/query", controller.QueryTemplate) api.GET("/get", controller.GetTemplateById) + api.POST("/publish", controller.PublishTemplate) } } diff --git a/automation/server/internal/module/job_workflow/service/template.go b/automation/server/internal/module/job_workflow/service/template.go index 9758ab83f219d635b8d29cb48a44701ccb1ad34a..e250ec5ef1dfb36d401b6e4e76b3a27d54e59004 100644 --- a/automation/server/internal/module/job_workflow/service/template.go +++ b/automation/server/internal/module/job_workflow/service/template.go @@ -42,3 +42,7 @@ func GetTemplateById(id string) (interface{}, error) { } return info, nil } + +func PublishTemplate(id int, newStatus string) error { + return dao.PublishTemplate(id, newStatus) +}