Browse Source

添加工作流连线回调事件

huangyh 6 năm trước cách đây
mục cha
commit
e6ec3a7c50
1 tập tin đã thay đổi với 68 bổ sung12 xóa
  1. 68 12
      wfclient/client.go

+ 68 - 12
wfclient/client.go

@@ -3,6 +3,7 @@ package wfclient
 import (
 	"encoding/base64"
 	"encoding/json"
+	"encoding/xml"
 	"errors"
 	"fmt"
 	"git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
@@ -186,6 +187,28 @@ func (w *WFClient) CreateInstance(defineId, name, formData string) ([]byte, erro
 	return HttpClientInstance().post(url, params, nil)
 }
 
+type Choice struct {
+	XMLName xml.Name   `xml:"choice"json:"-"`
+	Name    string     `json:"name"xml:"name"`
+	Trans   Transition `json:"trans"xml:"transition"`
+}
+
+type Transition struct {
+	XMLName    xml.Name     `xml:"transition"json:"-"`
+	Name       string       `json:"name"xml:"name"`
+	To         string       `json:"to"xml:"to"`
+	Points     string       `json:"-"xml:"points"`
+	Conditions []*Condition `json:"conditions,omitempty"`
+	Callback   string       `json:"callback"xml:"callback"`
+}
+
+type Condition struct {
+	Operator string `json:"operator"xml:"operator"`
+	DataKey  string `json:"data_key"xml:"data_key"`
+	Value    string `json:"value"xml:"value"`
+	Logic    string `json:"logic"xml:"logic"`
+}
+
 /**
  * @brief: run the wf instance
  * @param1 instanceId: id of instance
@@ -212,22 +235,24 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string) ([]
 	}
 
 	var RunRespInfo struct {
-		DefineId      string `json:"define_id"`
-		InstanceId    string `json:"instance_id"`
-		DefineName    string `json:"define_name"`
-		Choice        string `json:"choice"`
-		FormData      string `json:"form_data"`
-		StepName      string `json:"step_name"`
-		ActorType     string `json:"actor_type"`
-		Executor      string `json:"executor"`
-		StartCallback string `json:"start_callback"`
+		DefineId      string        `json:"define_id"`
+		InstanceId    string        `json:"instance_id"`
+		DefineName    string        `json:"define_name"`
+		Choices       []*Choice     `json:"choices"`
+		Transition    []*Transition `json:"transition"`
+		StepType      string        `json:"step_type"`
+		FormData      string        `json:"form_data"`
+		StepName      string        `json:"step_name"`
+		ActorType     string        `json:"actor_type"`
+		Executor      string        `json:"executor"`
+		StartCallback string        `json:"start_callback"`
 	}
 
 	bytess, err := HttpClientInstance().post(url, params, nil)
 	if err != nil {
 		return nil, err
 	}
-
+	fmt.Println("------------->>>>>--------", string(bytess))
 	err = json.Unmarshal(bytess, &RunRespInfo)
 	if err != nil {
 		return nil, err
@@ -235,8 +260,8 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string) ([]
 
 	fmt.Println("------------------------------------->121", RunRespInfo.StartCallback)
 
+	// 节点回调
 	callbacks := strings.Split(RunRespInfo.StartCallback, ",")
-
 	for _, callbackKye := range callbacks {
 		callback, ok := w.callbackMap[callbackKye]
 		if ok {
@@ -246,7 +271,38 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string) ([]
 				InstanceId: RunRespInfo.InstanceId,
 				DefineName: RunRespInfo.DefineName,
 				FormData:   RunRespInfo.FormData,
-				Choice:     RunRespInfo.Choice,
+				Choice:     choice,
+				Executor:   RunRespInfo.Executor,
+				UserId:     w.userId,
+			})
+		}
+	}
+
+	// 连线回调
+	linkCallbacks := []string{}
+	if RunRespInfo.StepType == "begin" || RunRespInfo.StepType == "normal" {
+		for _, c := range RunRespInfo.Transition {
+			if c.Name == choice {
+				linkCallbacks = strings.Split(c.Callback, ",")
+			}
+		}
+	} else {
+		for _, c := range RunRespInfo.Choices {
+			if c.Name == choice {
+				linkCallbacks = strings.Split(c.Trans.Callback, ",")
+			}
+		}
+	}
+
+	for _, callbackKye := range linkCallbacks {
+		callback, ok := w.callbackMap[callbackKye]
+		if ok {
+			callback(CallbackArg{
+				DefineId:   RunRespInfo.DefineId,
+				InstanceId: RunRespInfo.InstanceId,
+				DefineName: RunRespInfo.DefineName,
+				FormData:   RunRespInfo.FormData,
+				Choice:     choice,
 				Executor:   RunRespInfo.Executor,
 				UserId:     w.userId,
 			})