From 77965714c69312c67f3dabe177272e85ffd240ce Mon Sep 17 00:00:00 2001 From: zhanghan Date: Fri, 26 Sep 2025 09:29:54 +0800 Subject: [PATCH] Modify the receiving parameters of the entrance for creating homework templates --- .../module/job_workflow/model/template.go | 38 ++++++++++--------- .../script_library/controller/script.go | 2 +- .../module/script_library/model/script.go | 5 +++ .../module/script_library/service/script.go | 30 +++++++-------- automation/server/internal/service/mysql.go | 5 +++ 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/automation/server/internal/module/job_workflow/model/template.go b/automation/server/internal/module/job_workflow/model/template.go index 31d20c30..1fbb5b44 100644 --- a/automation/server/internal/module/job_workflow/model/template.go +++ b/automation/server/internal/module/job_workflow/model/template.go @@ -1,5 +1,7 @@ package model +import "encoding/json" + type TaskTemplate struct { ID int `json:"id" gorm:"primaryKey;autoIncrement;comment:作业编排Id"` Name string `json:"name" gorm:"type:varchar(255);comment:作业编排名称"` @@ -14,14 +16,14 @@ type TaskTemplate struct { } type TaskTemplateVariable struct { - ID int `json:"id" gorm:"primaryKey;autoIncrement"` - TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` - Name string `json:"name" gorm:"type:varchar(255);comment:变量名称"` - Type string `json:"type" gorm:"comment:变量类型(字符串、命名空间、数组等)"` - DefaultVaue string `json:"default_value" gorm:"comment:变量默认值"` - Description string `json:"description" gorm:"comment:变量描述"` - IsChangeable bool `json:"is_changeable" gorm:"comment:赋值可变"` - IsRequired string `json:"is_required" gorm:"comment:是否必需"` + ID int `json:"id" gorm:"primaryKey;autoIncrement"` + TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` + Name string `json:"name" gorm:"type:varchar(255);comment:变量名称"` + Type string `json:"type" gorm:"comment:变量类型(字符串、命名空间、数组等)"` + DefaultVaue json.RawMessage `json:"default_value" gorm:"comment:变量默认值"` + Description string `json:"description" gorm:"comment:变量描述"` + IsChangeable bool `json:"is_changeable" gorm:"comment:赋值可变"` + IsRequired bool `json:"is_required" gorm:"comment:是否必需"` } type TaskTemplateStep struct { @@ -35,16 +37,16 @@ type TaskTemplateStep struct { } type TaskTemplateStepScript struct { - ID int `json:"id" gorm:"primaryKey;autoIncrement"` - TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` - StepId int `json:"step_id" gorm:"comment:作业编排步骤Id"` - ScriptType string `json:"script_type" gorm:"comment:脚本类型"` - ScriptId string `json:"script_id" gorm:"comment:引用脚本Id"` - ScriptVersionId string `json:"script_version_id" gorm:"comment:引用脚本版本Id"` - ScriptContent string `json:"script_content" gorm:"comment:脚本内容"` - ScriptParam string `json:"script_param" gorm:"comment:脚本执行参数"` - ScriptTimeout string `json:"script_timeout" gorm:"comment:脚本超时"` - DestinationHostList string `json:"destination_host_list" gorm:"comment:远程执行主机列表"` + ID int `json:"id" gorm:"primaryKey;autoIncrement"` + TemplateId int `json:"template_id" gorm:"comment:作业编排Id"` + StepId int `json:"step_id" gorm:"comment:作业编排步骤Id"` + ScriptType string `json:"script_type" gorm:"comment:脚本类型"` + ScriptId string `json:"script_id" gorm:"comment:引用脚本Id"` + ScriptVersionId string `json:"script_version_id" gorm:"comment:引用脚本版本Id"` + ScriptContent string `json:"script_content" gorm:"comment:脚本内容"` + ScriptParam string `json:"script_param" gorm:"comment:脚本执行参数"` + ScriptTimeout int `json:"script_timeout" gorm:"comment:脚本超时"` + DestinationHostList json.RawMessage `json:"destination_host_list" gorm:"comment:远程执行主机列表"` } type TaskTemplateDTO struct { diff --git a/automation/server/internal/module/script_library/controller/script.go b/automation/server/internal/module/script_library/controller/script.go index e76f53f0..b8f78e7a 100644 --- a/automation/server/internal/module/script_library/controller/script.go +++ b/automation/server/internal/module/script_library/controller/script.go @@ -8,7 +8,7 @@ import ( ) func AddScriptHandler(c *gin.Context) { - var script model.ScriptWithVersion + var script model.AddScriptDTO if err := c.ShouldBindJSON(&script); err != nil { response.Fail(c, nil, err.Error()) return diff --git a/automation/server/internal/module/script_library/model/script.go b/automation/server/internal/module/script_library/model/script.go index c9a96977..0e791d2e 100644 --- a/automation/server/internal/module/script_library/model/script.go +++ b/automation/server/internal/module/script_library/model/script.go @@ -44,3 +44,8 @@ type ScriptResponse struct { LastModifyUser string `json:"last_modify_user"` LastModifyUpdatedAt string `json:"last_modify_updated_at"` } + +type AddScriptDTO struct { + Script Script `json:"script"` + FirstVersion ScriptVersion `json:"first_version"` +} diff --git a/automation/server/internal/module/script_library/service/script.go b/automation/server/internal/module/script_library/service/script.go index f02f1737..a3773e7d 100644 --- a/automation/server/internal/module/script_library/service/script.go +++ b/automation/server/internal/module/script_library/service/script.go @@ -13,7 +13,7 @@ func generateScriptId() string { return uuid.NewString() } -func AddScript(s *model.ScriptWithVersion) error { +func AddScript(s *model.AddScriptDTO) error { scriptId := generateScriptId() // decodedContent, err := utils.DecodeScriptContent(s.Content) @@ -23,28 +23,28 @@ func AddScript(s *model.ScriptWithVersion) error { script := &model.Script{ ID: scriptId, - Name: s.Name, - ScriptName: s.ScriptName, - ScriptType: s.ScriptType, - Description: s.Description, - Tags: s.Tags, - IsPublic: s.IsPublic, - Creator: s.Creator, + Name: s.Script.Name, + ScriptName: s.Script.ScriptName, + ScriptType: s.Script.ScriptType, + Description: s.Script.Description, + Tags: s.Script.Tags, + IsPublic: s.Script.IsPublic, + Creator: s.Script.Creator, CreatedAt: time.Now().Format("2006-01-02 15:04:05"), - LastModifyUser: s.Creator, + LastModifyUser: s.Script.Creator, LastModifyUpdatedAt: time.Now().Format("2006-01-02 15:04:05"), } scriptVersion := &model.ScriptVersion{ ScriptID: scriptId, // Content: decodedContent, - Content: s.Content, - Params: s.Params, - Version: s.Version, - VersionDesc: s.VersionDesc, - Creator: s.Creator, + Content: s.FirstVersion.Content, + Params: s.FirstVersion.Params, + Version: s.FirstVersion.Version, + VersionDesc: s.FirstVersion.VersionDesc, + Creator: s.Script.Creator, CreatedAt: time.Now().Format("2006-01-02 15:04:05"), - LastModifyUser: s.Creator, + LastModifyUser: s.Script.Creator, LastModifyUpdatedAt: time.Now().Format("2006-01-02 15:04:05"), } diff --git a/automation/server/internal/service/mysql.go b/automation/server/internal/service/mysql.go index f3a10aeb..7d2cac8c 100644 --- a/automation/server/internal/service/mysql.go +++ b/automation/server/internal/service/mysql.go @@ -8,6 +8,7 @@ import ( "gorm.io/gorm/schema" "openeuler.org/PilotGo/PilotGo-plugin-automation/cmd/config/options" dangerousRule "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/dangerous_rule/model" + jobworkflow "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/job_workflow/model" scriptLibrary "openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/script_library/model" ) @@ -45,6 +46,10 @@ func (m *MySQLService) Init(ctx *AppContext) error { db.AutoMigrate(&scriptLibrary.Tag{}) db.AutoMigrate(&scriptLibrary.Script{}) db.AutoMigrate(&scriptLibrary.ScriptVersion{}) + db.AutoMigrate(&jobworkflow.TaskTemplate{}) + db.AutoMigrate(&jobworkflow.TaskTemplateVariable{}) + db.AutoMigrate(&jobworkflow.TaskTemplateStep{}) + db.AutoMigrate(&jobworkflow.TaskTemplateStepScript{}) ctx.MySQL = db return nil -- Gitee