From 91fd0658697b06e5653b4c80381038d296818c75 Mon Sep 17 00:00:00 2001 From: QM303176530 <303176530@qq.com> Date: Sat, 31 Oct 2020 00:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E5=A2=9E=E5=88=A0?= =?UTF-8?q?=E6=94=B9=E6=9F=A5=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/cmd/datas/init.go | 49 --- server/model/wf_process.go | 6 +- server/service/wk_process.go | 62 ++- .../workflowCreate/workflowCreate.vue | 355 +++++++++--------- .../workflowProcess/workflowProcess.vue | 176 ++++----- 5 files changed, 314 insertions(+), 334 deletions(-) diff --git a/server/cmd/datas/init.go b/server/cmd/datas/init.go index 264383d4..d37bc013 100644 --- a/server/cmd/datas/init.go +++ b/server/cmd/datas/init.go @@ -56,52 +56,3 @@ func InitMysqlTables(db *gorm.DB) { } color.Info.Println("[Mysql]-->初始化数据表成功") } - -func InitPostgresqlData(db *gorm.DB) { - var err error - err = InitSysApi(db) - err = InitSysUser(db) - err = InitExaCustomer(db) - err = InitCasbinModel(db) - err = InitSysAuthority(db) - err = InitSysBaseMenus(db) - err = InitAuthorityMenu(db) - err = InitSysAuthorityMenus(db) - err = InitSysDataAuthorityId(db) - err = InitSysDictionaryDetail(db) - err = InitExaFileUploadAndDownload(db) - err = InitSysDictionaryToPostgresql(db) - if err != nil { - color.Error.Printf("[Postgresql]-->初始化数据失败,err: %v\n", err) - os.Exit(0) - } - color.Info.Println("[Postgresql]-->初始化数据成功") -} - -func InitPostgresqlTables(db *gorm.DB) { - var err error - if !db.Migrator().HasTable("casbin_rule") { - err = db.Migrator().CreateTable(&gormadapter.CasbinRule{}) - } - err = db.AutoMigrate( - model.SysApi{}, - model.SysUser{}, - model.ExaFile{}, - model.ExaCustomer{}, - model.SysBaseMenu{}, - model.SysAuthority{}, - model.JwtBlacklist{}, - model.ExaFileChunk{}, - model.ExaSimpleUploader{}, - model.SysOperationRecord{}, - model.SysDictionaryDetail{}, - model.SysBaseMenuParameter{}, - model.ExaFileUploadAndDownload{}, - SysDictionaryToPostgresql{}, - ) - if err != nil { - color.Error.Printf("[Postgresql]-->初始化数据表失败,err: %v\n", err) - os.Exit(0) - } - color.Info.Println("[Postgresql]-->初始化数据表成功") -} diff --git a/server/model/wf_process.go b/server/model/wf_process.go index e31f0194..735608a5 100644 --- a/server/model/wf_process.go +++ b/server/model/wf_process.go @@ -10,7 +10,7 @@ type WorkflowProcess struct { ID string `json:"id" form:"id" gorm:"comment:流程标识;primaryKey;unique;not null"` CreatedAt time.Time UpdatedAt time.Time - DeletedAt gorm.DeletedAt `gorm:"index"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` Name string `json:"name" gorm:"comment:流程名称"` Category string `json:"category" gorm:"comment:分类"` Clazz string `json:"clazz" gorm:"comment:类型"` @@ -25,7 +25,7 @@ type WorkflowNode struct { ID string `json:"id" form:"id" gorm:"comment:节点id;primaryKey;unique;not null"` CreatedAt time.Time UpdatedAt time.Time - DeletedAt gorm.DeletedAt `gorm:"index"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` WorkflowProcessID string `json:"-" gorm:"comment:流程标识"` Clazz string `json:"clazz" gorm:"comment:节点类型"` Label string `json:"label" gorm:"comment:节点名称"` @@ -48,7 +48,7 @@ type WorkflowEdge struct { ID string `json:"id" form:"id" gorm:"comment:唯一标识;primaryKey;unique;not null"` CreatedAt time.Time UpdatedAt time.Time - DeletedAt gorm.DeletedAt `gorm:"index"` + DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` WorkflowProcessID string `json:"-" gorm:"comment:流程标识"` Clazz string `json:"clazz" gorm:"comment:类型(线)"` Source string `json:"source" gorm:"comment:起点节点"` diff --git a/server/service/wk_process.go b/server/service/wk_process.go index 8dfd82fe..18bff313 100644 --- a/server/service/wk_process.go +++ b/server/service/wk_process.go @@ -4,6 +4,7 @@ import ( "gin-vue-admin/global" "gin-vue-admin/model" "gin-vue-admin/model/request" + "gorm.io/gorm" ) // @title CreateWorkflowProcess @@ -24,7 +25,27 @@ func CreateWorkflowProcess(workflowProcess model.WorkflowProcess) (err error) { // @return error func DeleteWorkflowProcess(workflowProcess model.WorkflowProcess) (err error) { - err = global.GVA_DB.Delete(workflowProcess).Error + err = global.GVA_DB.Transaction(func(tx *gorm.DB) error { + var txErr error + txErr = tx.Delete(workflowProcess).Error + if txErr != nil { + return txErr + } + var edges []model.WorkflowEdge + txErr = tx.Delete(model.WorkflowNode{}, "workflow_process_id = ?", workflowProcess.ID).Error + if txErr != nil { + return txErr + } + txErr = tx.Find(&edges, "workflow_process_id = ?", workflowProcess.ID).Error + if txErr != nil { + return txErr + } + txErr = tx.Select("StartPoint", "EndPoint").Delete(&edges).Error + if txErr != nil { + return txErr + } + return nil + }) return err } @@ -46,8 +67,43 @@ func DeleteWorkflowProcessByIds(ids request.IdsReq) (err error) { // @return error func UpdateWorkflowProcess(workflowProcess *model.WorkflowProcess) (err error) { - err = global.GVA_DB.Save(workflowProcess).Error - return err + return global.GVA_DB.Transaction(func(tx *gorm.DB) error { + var txErr error + var edges []model.WorkflowEdge + var edgesIds []string + txErr = tx.Unscoped().Delete(workflowProcess).Error + if txErr != nil { + return txErr + } + txErr = tx.Unscoped().Delete(model.WorkflowNode{}, "workflow_process_id = ?", workflowProcess.ID).Error + if txErr != nil { + return txErr + } + txErr = tx.Unscoped().Find(&edges, "workflow_process_id = ?", workflowProcess.ID).Error + if txErr != nil { + return txErr + } + txErr = tx.Unscoped().Delete(&edges).Error + if txErr != nil { + return txErr + } + for _, v := range edges { + edgesIds = append(edgesIds, v.ID) + } + txErr = tx.Unscoped().Delete(model.WorkflowStartPoint{}, "workflow_edge_id in ?", edgesIds).Error + if txErr != nil { + return txErr + } + txErr = tx.Unscoped().Delete(model.WorkflowEndPoint{}, "workflow_edge_id in ?", edgesIds).Error + if txErr != nil { + return txErr + } + txErr = tx.Create(&workflowProcess).Error + if txErr != nil { + return txErr + } + return nil + }) } // @title GetWorkflowProcess diff --git a/web/src/view/workflow/workflowCreate/workflowCreate.vue b/web/src/view/workflow/workflowCreate/workflowCreate.vue index c8cc87e9..495fbea2 100644 --- a/web/src/view/workflow/workflowCreate/workflowCreate.vue +++ b/web/src/view/workflow/workflowCreate/workflowCreate.vue @@ -51,7 +51,8 @@