提交 2515fefb 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

增加排他网关和包容网关

上级 7eb7c730
......@@ -46,7 +46,7 @@ func Routers() *gin.Engine {
router.InitSysOperationRecordRouter(PrivateGroup) // 操作记录
router.InitSysDictionaryDetailRouter(PrivateGroup) // 字典详情管理
router.InitFileUploadAndDownloadRouter(PrivateGroup) // 文件上传下载功能路由
router.InitWorkflowProcessRouter(PrivateGroup) // 工作流创建相关接口
router.InitWorkflowProcessRouter(PrivateGroup) // 工作流相关接口
}
global.GVA_LOG.Info("router register success")
return Router
......
......@@ -231,21 +231,28 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
}
if len(Edges) == 1 {
txErr = tx.Model(&returnWfm).Update("param", wfm.Param).Update("is_active", false).Update("action", wfm.Action).Update("operator_id", wfm.OperatorID).Error
newWfm := createNewWorkflowMove(&returnWfm, Edges[0].Target)
txErr = tx.Create(newWfm).Error
if txErr != nil {
return txErr
}
txErr,newWfm := createNewWorkflowMove(tx,&returnWfm, Edges[0].Target)
if txErr != nil {
return txErr
}
if len(newWfm)>0{
txErr = tx.Create(&newWfm).Error
if txErr != nil {
return txErr
}
}
// 当target为自动节点时候 需要做一些事情 这里暂时先不处理 后续慢慢完善
}
if len(Edges) > 1 {
var needUseTargetNodeID string
txErr = tx.Model(&returnWfm).Update("param", wfm.Param).Update("is_active", false).Update("action", wfm.Action).Update("operator_id", wfm.OperatorID).Error
if txErr != nil {
return txErr
}
txErr = tx.Model(&returnWfm).Update("param", wfm.Param).Update("is_active", false).Update("action", wfm.Action).Update("operator_id", wfm.OperatorID).Error
for _, v := range Edges {
if v.ConditionExpression == wfm.Param {
needUseTargetNodeID = v.Target
......@@ -255,12 +262,16 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
if needUseTargetNodeID == "" {
return errors.New("未发现流转参数,流转失败")
}
newWfm := createNewWorkflowMove(&returnWfm, needUseTargetNodeID)
txErr = tx.Create(newWfm).Error
txErr,newWfm := createNewWorkflowMove(tx,&returnWfm, needUseTargetNodeID)
if txErr != nil {
return txErr
}
// 当target为自动节点时候 需要做一些事情 这里暂时先不处理 后续慢慢完善
if len(newWfm)>0{
txErr = tx.Create(&newWfm).Error
if txErr != nil {
return txErr
}
}
}
} else if nodeInfo.Clazz == model.EXCLUSIVE_GATEWAY {
return errors.New("目前只支持start节点和userTask功能,其他功能正在开发中")
......@@ -274,18 +285,108 @@ func complete(tx *gorm.DB, wfm *model.WorkflowMove) (err error) {
return nil
}
func createNewWorkflowMove(oldWfm *model.WorkflowMove, targetNodeID string) (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{}
}
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{
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
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{}
}
var sourceIds []string
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{}
}
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.PARELLEL_GATEWAY:
// 当为并行网关时候 找出所有线路创建并行节点
txErr := tx.Find(&edges, "workflow_process_id = ? and source = ?", oldWfm.WorkflowProcessID, nodeInfo.ID).Error
if txErr !=nil{
return txErr, []model.WorkflowMove{}
}
for _,v := range edges{
newWfm = append(newWfm, model.WorkflowMove{
BusinessID: oldWfm.BusinessID,
BusinessType: oldWfm.BusinessType,
PromoterID: oldWfm.PromoterID,
OperatorID: 0,
WorkflowNodeID: v.Target,
WorkflowProcessID: oldWfm.WorkflowProcessID,
Param: "",
Action: "",
IsActive: true,})
}
return nil,newWfm
return &model.WorkflowMove{
BusinessID: oldWfm.BusinessID,
BusinessType: oldWfm.BusinessType,
PromoterID: oldWfm.PromoterID,
OperatorID: 0,
WorkflowNodeID: targetNodeID,
WorkflowProcessID: oldWfm.WorkflowProcessID,
Param: "",
Action: "",
IsActive: true,
default:
newWfm = append(newWfm, model.WorkflowMove{
BusinessID: oldWfm.BusinessID,
BusinessType: oldWfm.BusinessType,
PromoterID: oldWfm.PromoterID,
OperatorID: 0,
WorkflowNodeID: targetNodeID,
WorkflowProcessID: oldWfm.WorkflowProcessID,
Param: "",
Action: "",
IsActive: true,})
return nil, newWfm
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册