From 9e6b8ff0ef110122d0907aaa592d4657eda22b05 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Tue, 24 Nov 2020 14:57:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=85=E5=AE=B9=E7=BD=91=E5=85=B3=20?= =?UTF-8?q?=E6=B5=81=E8=BD=AC=E5=8F=82=E6=95=B0=E6=A8=A1=E5=BC=8F=E8=AE=BE?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/resource/template/server/api.go.tpl | 2 +- .../resource/template/server/service.go.tpl | 4 +- server/service/wk_process.go | 111 ++++++++++-------- 3 files changed, 62 insertions(+), 55 deletions(-) diff --git a/server/resource/template/server/api.go.tpl b/server/resource/template/server/api.go.tpl index 59cfeb2a..fc6dd04a 100644 --- a/server/resource/template/server/api.go.tpl +++ b/server/resource/template/server/api.go.tpl @@ -78,7 +78,7 @@ func Delete{{.StructName}}ByIds(c *gin.Context) { func Update{{.StructName}}(c *gin.Context) { var {{.Abbreviation}} model.{{.StructName}} _ = c.ShouldBindJSON(&{{.Abbreviation}}) - if err := service.Update{{.StructName}}(&{{.Abbreviation}}); err != nil { + if err := service.Update{{.StructName}}({{.Abbreviation}}); err != nil { global.GVA_LOG.Error("更新失败!", zap.Any("err", err)) response.FailWithMessage("更新失败", c) } else { diff --git a/server/resource/template/server/service.go.tpl b/server/resource/template/server/service.go.tpl index 9e3bfaab..d4a90558 100644 --- a/server/resource/template/server/service.go.tpl +++ b/server/resource/template/server/service.go.tpl @@ -45,8 +45,8 @@ func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) { //@param: {{.Abbreviation}} *model.{{.StructName}} //@return: err error -func Update{{.StructName}}({{.Abbreviation}} *model.{{.StructName}}) (err error) { - err = global.GVA_DB.Save({{.Abbreviation}}).Error +func Update{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) { + err = global.GVA_DB.Save(&{{.Abbreviation}}).Error return err } diff --git a/server/service/wk_process.go b/server/service/wk_process.go index f7659327..f16e626e 100644 --- a/server/service/wk_process.go +++ b/server/service/wk_process.go @@ -234,11 +234,11 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) { if txErr != nil { return txErr } - txErr,newWfm := createNewWorkflowMove(tx,&returnWfm, Edges[0].Target) + txErr, newWfm := createNewWorkflowMove(tx, &returnWfm, Edges[0].Target) if txErr != nil { return txErr } - if len(newWfm)>0{ + if len(newWfm) > 0 { txErr = tx.Create(&newWfm).Error if txErr != nil { return txErr @@ -262,11 +262,11 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) { if needUseTargetNodeID == "" { return errors.New("未发现流转参数,流转失败") } - txErr,newWfm := createNewWorkflowMove(tx,&returnWfm, needUseTargetNodeID) + txErr, newWfm := createNewWorkflowMove(tx, &returnWfm, needUseTargetNodeID) if txErr != nil { return txErr } - if len(newWfm)>0{ + if len(newWfm) > 0 { txErr = tx.Create(&newWfm).Error if txErr != nil { return txErr @@ -285,61 +285,68 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) { return nil } -func createNewWorkflowMove(tx *gorm.DB,oldWfm *model.WorkflowMove, targetNodeID string) (err error,newWfm []model.WorkflowMove) { +func createNewWorkflowMove(tx *gorm.DB, oldWfm *model.WorkflowMove, targetNodeID string) (err error, newWfm []model.WorkflowMove) { // 以下所有非 default的节点的下一步流转均应该处理为递归形式 - var nodeInfo model.WorkflowNode - var edge model.WorkflowEdge - var edges []model.WorkflowEdge - var wfms []model.WorkflowMove - txErr := tx.First(&nodeInfo,"id = ?",targetNodeID).Error - if txErr!=nil{ - return txErr,[]model.WorkflowMove{} + var nodeInfo model.WorkflowNode + var edge model.WorkflowEdge + var edges []model.WorkflowEdge + var wfms []model.WorkflowMove + txErr := tx.First(&nodeInfo, "id = ?", targetNodeID).Error + if txErr != nil { + return txErr, []model.WorkflowMove{} } - switch nodeInfo.Clazz{ + switch nodeInfo.Clazz { case model.EXCLUSIVE_GATEWAY: // 当为排他网关时候 选择一个参数进行排他线路选择 - txErr := tx.First(&edge, "workflow_process_id = ? and source = ? and condition_expression = ?", oldWfm.WorkflowProcessID, nodeInfo.ID,oldWfm.Param).Error - if txErr !=nil{ + txErr := tx.First(&edge, "workflow_process_id = ? and source = ? and condition_expression = ?", oldWfm.WorkflowProcessID, nodeInfo.ID, oldWfm.Param).Error + if txErr != nil { return txErr, []model.WorkflowMove{} } - newWfm = append(newWfm, model.WorkflowMove{ - BusinessID: oldWfm.BusinessID, - BusinessType: oldWfm.BusinessType, - PromoterID: oldWfm.PromoterID, - OperatorID: 0, - WorkflowNodeID: edge.Target, - WorkflowProcessID: oldWfm.WorkflowProcessID, - Param: "", - Action: "", - IsActive: true,}) - return nil,newWfm + newWfm = append(newWfm, model.WorkflowMove{ + BusinessID: oldWfm.BusinessID, + BusinessType: oldWfm.BusinessType, + PromoterID: oldWfm.PromoterID, + OperatorID: 0, + WorkflowNodeID: edge.Target, + WorkflowProcessID: oldWfm.WorkflowProcessID, + Param: "", + Action: "", + IsActive: true}) + return nil, newWfm case model.INCLUSIVE_GATEWAY: // 当为包容网关时,需要等待其他网关执行结束才进行创建 - txErr := tx.Find(&edges, "workflow_process_id = ? and target = ?", oldWfm.WorkflowProcessID, nodeInfo.ID).Error - if txErr!=nil{ - return txErr,[]model.WorkflowMove{} + if txErr != nil { + return txErr, []model.WorkflowMove{} } var sourceIds []string - for _,v := range edges{ + for _, v := range edges { sourceIds = append(sourceIds, v.Source) } - txErr = tx.Find(&wfms,"workflow_process_id = ? and business_id = ? and workflow_node_id in (?) and is_active = ?",oldWfm.WorkflowProcessID,oldWfm.BusinessID,sourceIds,false).Error - if txErr!=nil{ - return txErr,[]model.WorkflowMove{} - } - if len(wfms) != len(edges){ - return nil,[]model.WorkflowMove{} - } - if len(wfms) == len(edges){ - //var params string - //for _,v := range wfms{ - // params += v.Param - //} - //参数携带模式暂时未定 - txErr := tx.First(&edge, "workflow_process_id = ? and source = ?", oldWfm.WorkflowProcessID, nodeInfo.ID).Error - if txErr!=nil{ - return txErr,[]model.WorkflowMove{} + txErr = tx.Find(&wfms, "workflow_process_id = ? and business_id = ? and workflow_node_id in (?) and is_active = ?", oldWfm.WorkflowProcessID, oldWfm.BusinessID, sourceIds, false).Error + if txErr != nil { + return txErr, []model.WorkflowMove{} + } + if len(wfms) != len(edges) { + return nil, []model.WorkflowMove{} + } + if len(wfms) == len(edges) { + params := make(map[string]int) + var param string + var temp int + for _, v := range wfms { + params[v.Param]++ + } + for k, v := range params { + if temp < v { + temp = v + param = k + } + } + //参数携带模式暂时未定 暂时为少数服从多数原则 后续会增加原则配置 (少数服从多数,仅一关键字即为关键字,所有关键字才为关键字 三种方案) + txErr := tx.First(&edge, "workflow_process_id = ? and source = ? and condition_expression = ?", oldWfm.WorkflowProcessID, nodeInfo.ID, param).Error + if txErr != nil { + return txErr, []model.WorkflowMove{} } newWfm = append(newWfm, model.WorkflowMove{ BusinessID: oldWfm.BusinessID, @@ -350,17 +357,17 @@ func createNewWorkflowMove(tx *gorm.DB,oldWfm *model.WorkflowMove, targetNodeID WorkflowProcessID: oldWfm.WorkflowProcessID, Param: "", Action: "", - IsActive: true,}) + IsActive: true}) } return nil, newWfm case model.PARELLEL_GATEWAY: // 当为并行网关时候 找出所有线路创建并行节点 txErr := tx.Find(&edges, "workflow_process_id = ? and source = ?", oldWfm.WorkflowProcessID, nodeInfo.ID).Error - if txErr !=nil{ + if txErr != nil { return txErr, []model.WorkflowMove{} } - for _,v := range edges{ + for _, v := range edges { newWfm = append(newWfm, model.WorkflowMove{ BusinessID: oldWfm.BusinessID, BusinessType: oldWfm.BusinessType, @@ -370,10 +377,10 @@ func createNewWorkflowMove(tx *gorm.DB,oldWfm *model.WorkflowMove, targetNodeID WorkflowProcessID: oldWfm.WorkflowProcessID, Param: "", Action: "", - IsActive: true,}) + IsActive: true}) } - return nil,newWfm + return nil, newWfm default: newWfm = append(newWfm, model.WorkflowMove{ @@ -385,7 +392,7 @@ func createNewWorkflowMove(tx *gorm.DB,oldWfm *model.WorkflowMove, targetNodeID WorkflowProcessID: oldWfm.WorkflowProcessID, Param: "", Action: "", - IsActive: true,}) + IsActive: true}) return nil, newWfm } }