From bad4a9800b5d1efecda809626879c07e2f46135c Mon Sep 17 00:00:00 2001 From: zhanghan Date: Sat, 11 Oct 2025 17:18:30 +0800 Subject: [PATCH] Provide workflow template publishing interface --- automation/server/automation.yaml | 2 +- .../module/job_workflow/controller/template.go | 16 ++++++++++++++++ .../internal/module/job_workflow/dao/template.go | 10 ++++++++++ .../internal/module/job_workflow/router.go | 1 + .../module/job_workflow/service/template.go | 4 ++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/automation/server/automation.yaml b/automation/server/automation.yaml index 62edcd46..e9fe4d90 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 d380d4c8..606b875b 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 4ad146cd..15248ef1 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 0fd110b4..3010406f 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 9758ab83..e250ec5e 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) +} -- Gitee