Browse Source

Merge branch 'v2' of https://git.i2erp.cn/packages/light-apiengine into v2

double.huang 5 years ago
parent
commit
3b528b21ef
4 changed files with 115 additions and 80 deletions
  1. 13 13
      controllers/partial/SysWfController.go
  2. 1 1
      models/Sql_SysUser.go
  3. 49 0
      wfclient/callback.go
  4. 52 66
      wfclient/client.go

+ 13 - 13
controllers/partial/SysWfController.go

@@ -28,7 +28,7 @@ func SysWf_WfInstanceList(c *entitys.CtrlContext) {
 	sord := c.Ctx.DefaultQuery("sord", "")
 	sord := c.Ctx.DefaultQuery("sord", "")
 	filter := c.Ctx.Query("filters")
 	filter := c.Ctx.Query("filters")
 
 
-	bytess, err := wfclient.Instance().FetchWFINstances(page, rows, filter, sidx, sord)
+	bytess, err := wfclient.NewWFClient(c).FetchWFINstances(page, rows, filter, sidx, sord)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -47,7 +47,7 @@ func SysWf_WfInstanceList(c *entitys.CtrlContext) {
 func SysWf_InstanceStepCurrent(c *entitys.CtrlContext) {
 func SysWf_InstanceStepCurrent(c *entitys.CtrlContext) {
 	instanceId := c.Ctx.Query("instance_id")
 	instanceId := c.Ctx.Query("instance_id")
 
 
-	bytess, err := wfclient.Instance().FetchCurrentStepByLoginUser(instanceId)
+	bytess, err := wfclient.NewWFClient(c).FetchCurrentStepByLoginUser(instanceId)
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 	} else {
 	} else {
@@ -70,7 +70,7 @@ func SysWf_Prerun(c *entitys.CtrlContext) {
 		return
 		return
 	}
 	}
 
 
-	bytess, err := wfclient.Instance().PreRun(obj.InstanceId, obj.Choice)
+	bytess, err := wfclient.NewWFClient(c).PreRun(obj.InstanceId, obj.Choice)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -97,7 +97,7 @@ func SysWf_Run(c *entitys.CtrlContext) {
 		return
 		return
 	}
 	}
 
 
-	bytess, err := wfclient.Instance().Run(obj.InstanceId, obj.Users, obj.Choice, obj.Opinion, obj.NextStep, c)
+	bytess, err := wfclient.NewWFClient(c).Run(obj.InstanceId, obj.Users, obj.Choice, obj.Opinion, obj.NextStep, c)
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 	} else {
 	} else {
@@ -114,7 +114,7 @@ func SysWf_Run(c *entitys.CtrlContext) {
 func SysWf_WfDefinesTag(c *entitys.CtrlContext) {
 func SysWf_WfDefinesTag(c *entitys.CtrlContext) {
 	tag := c.Ctx.Query("tag")
 	tag := c.Ctx.Query("tag")
 
 
-	bytess, err := wfclient.Instance().FetchDefinesByTag(tag)
+	bytess, err := wfclient.NewWFClient(c).FetchDefinesByTag(tag)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -154,7 +154,7 @@ func SysWf_Recall(c *entitys.CtrlContext) {
 		return
 		return
 	}
 	}
 
 
-	bytess, err := wfclient.Instance().Recall(obj.InstanceId)
+	bytess, err := wfclient.NewWFClient(c).Recall(obj.InstanceId)
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 	} else {
 	} else {
@@ -193,7 +193,7 @@ func SysWf_Interrupt(c *entitys.CtrlContext) {
 func SysWf_Designer(c *entitys.CtrlContext) {
 func SysWf_Designer(c *entitys.CtrlContext) {
 	define_id := c.Ctx.Query("define_id")
 	define_id := c.Ctx.Query("define_id")
 
 
-	bytess, err := wfclient.Instance().FetchDesignDiagram(define_id)
+	bytess, err := wfclient.NewWFClient(c).FetchDesignDiagram(define_id)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -212,7 +212,7 @@ func SysWf_DefineSave(c *entitys.CtrlContext) {
 	PostData := models.WfDefine{}
 	PostData := models.WfDefine{}
 	err := c.Ctx.Bind(&PostData)
 	err := c.Ctx.Bind(&PostData)
 
 
-	bytess, err := wfclient.Instance().CreateOrUpdateDefine(PostData.DefineId, PostData.Name, PostData.Descript, PostData.Data, PostData.Form, PostData.Tag, PostData.Code)
+	bytess, err := wfclient.NewWFClient(c).CreateOrUpdateDefine(PostData.DefineId, PostData.Name, PostData.Descript, PostData.Data, PostData.Form, PostData.Tag, PostData.Code)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -231,7 +231,7 @@ func SysWf_DefineCreate(c *entitys.CtrlContext) {
 	PostData := models.WfDefine{}
 	PostData := models.WfDefine{}
 	err := c.Ctx.Bind(&PostData)
 	err := c.Ctx.Bind(&PostData)
 
 
-	bytess, err := wfclient.Instance().CreateOrUpdateDefine(PostData.DefineId, PostData.Name, PostData.Descript, PostData.Data, PostData.Form, PostData.Tag, PostData.Code)
+	bytess, err := wfclient.NewWFClient(c).CreateOrUpdateDefine(PostData.DefineId, PostData.Name, PostData.Descript, PostData.Data, PostData.Form, PostData.Tag, PostData.Code)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -259,7 +259,7 @@ func SysWf_CreateInstance(c *entitys.CtrlContext) {
 		return
 		return
 	}
 	}
 
 
-	bytess, err := wfclient.Instance().CreateInstance(InstanceInfo.DefineId, InstanceInfo.Name, InstanceInfo.FormData)
+	bytess, err := wfclient.NewWFClient(c).CreateInstance(InstanceInfo.DefineId, InstanceInfo.Name, InstanceInfo.FormData)
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -277,7 +277,7 @@ func SysWf_CreateInstance(c *entitys.CtrlContext) {
 func SysWf_Define(c *entitys.CtrlContext) {
 func SysWf_Define(c *entitys.CtrlContext) {
 	define_id := c.Ctx.Query("define_id")
 	define_id := c.Ctx.Query("define_id")
 
 
-	bytess, err := wfclient.Instance().FetchDefine(define_id)
+	bytess, err := wfclient.NewWFClient(c).FetchDefine(define_id)
 	fmt.Println(string(bytess))
 	fmt.Println(string(bytess))
 
 
 	if err == nil {
 	if err == nil {
@@ -294,7 +294,7 @@ func SysWf_Define(c *entitys.CtrlContext) {
 // @Failure 403 :id is empty
 // @Failure 403 :id is empty
 func SysWf_AllDefine(c *entitys.CtrlContext) {
 func SysWf_AllDefine(c *entitys.CtrlContext) {
 
 
-	bytess, err := wfclient.Instance().FetchAllDefines()
+	bytess, err := wfclient.NewWFClient(c).FetchAllDefines()
 
 
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
@@ -320,7 +320,7 @@ func SysWf_UpdateIntanceForm(c *entitys.CtrlContext) {
 		return
 		return
 	}
 	}
 
 
-	bytess, err := wfclient.Instance().UpdateInstanceForm(data.InstanceId, data.FormData)
+	bytess, err := wfclient.NewWFClient(c).UpdateInstanceForm(data.InstanceId, data.FormData)
 	if err == nil {
 	if err == nil {
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 		c.Ctx.JSON(200, sysmodel.SysReturn{200, "", string(bytess)})
 	} else {
 	} else {

+ 1 - 1
models/Sql_SysUser.go

@@ -4,7 +4,7 @@ var SqlUserLogin = `
         select
         select
 			id,login_id,password,name,full_name,mobile,email,org_id,type,status,domain,create_by,create_time,last_update_by,last_update_time,del_flag
 			id,login_id,password,name,full_name,mobile,email,org_id,type,status,domain,create_by,create_time,last_update_by,last_update_time,del_flag
         from sys_user
         from sys_user
-		where %v = ? and del_flag=0`
+		where %v = ? and del_flag = 0 and status = 0`
 
 
 var SqlUserInfoPage = `SELECT
 var SqlUserInfoPage = `SELECT
   sys_user.*,
   sys_user.*,

+ 49 - 0
wfclient/callback.go

@@ -0,0 +1,49 @@
+package wfclient
+
+import (
+	"fmt"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+)
+
+type CallbackArg struct {
+	DefineId     string
+	InstanceId   string
+	DefineName   string
+	InstanceName string
+	FormData     string
+	Choice       string
+	Executor     string
+	UserId       string
+	Context      *entitys.CtrlContext
+}
+
+var _callbackMap   map[string]func(*CallbackArg)
+
+func init(){
+	_callbackMap = make(map[string]func(*CallbackArg))
+}
+
+
+/**
+ * @brief: add callback
+ * @param1: key
+ * @param2: callback
+ */
+func AddWFCallback(key string, cb func(*CallbackArg)) {
+	if _, ok := _callbackMap[key]; !ok {
+		_callbackMap[key] = cb
+	} else {
+		fmt.Println("callback", key, "does already exist")
+	}
+}
+
+/**
+ * @brief:调用calblack
+ * @param1 key:key
+ * @param2 arg:参数
+ */
+func callWFCallback(key string, arg *CallbackArg){
+	if callback, ok := _callbackMap[key]; ok{
+		callback(arg)
+	}
+}

+ 52 - 66
wfclient/client.go

@@ -6,6 +6,12 @@ import (
 	"encoding/xml"
 	"encoding/xml"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
+<<<<<<< HEAD
+=======
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/config"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/entitys"
+	"git.qianqiusoft.com/qianqiusoft/light-apiengine/utils"
+>>>>>>> b2a2f0295784e7da9317b8929a3c7fbcb11218da
 	"net/http"
 	"net/http"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
@@ -25,18 +31,6 @@ type FilterField struct {
 	Data  string `json:"data"`
 	Data  string `json:"data"`
 }
 }
 
 
-type CallbackArg struct {
-	DefineId     string
-	InstanceId   string
-	DefineName   string
-	InstanceName string
-	FormData     string
-	Choice       string
-	Executor     string
-	UserId       string
-	Context      *entitys.CtrlContext
-}
-
 type WFClient struct {
 type WFClient struct {
 	endpoint      string
 	endpoint      string
 	authorization string
 	authorization string
@@ -44,24 +38,26 @@ type WFClient struct {
 	username      string
 	username      string
 	token         string
 	token         string
 	domain        string
 	domain        string
-	callbackMap   map[string]func(CallbackArg)
 }
 }
 
 
-var instance *WFClient = nil
+var _wfendpoint = ""
+
+func init(){
+	_wfendpoint = config.AppConfig.GetKey("wfendpoint")
+}
 
 
 /**
 /**
  * @brief: single instance
  * @brief: single instance
  */
  */
-func Instance() *WFClient {
-	if instance == nil {
-		instance = &WFClient{}
-		instance.endpoint = ""
-		instance.authorization = ""
-		instance.userId = ""
-		instance.token = ""
-		instance.callbackMap = make(map[string]func(CallbackArg))
-		HttpClientInstance().setRequestInterseptor(instance.wfReqInterseptor)
-	}
+func NewWFClient(c *entitys.CtrlContext) *WFClient {
+	tk, _ := c.Ctx.Get("token")
+	token := tk.(*entitys.Token)
+	instance := &WFClient{}
+	instance.endpoint = _wfendpoint
+	instance.authorization, _ = instance.createAuthorization(token.LoginID, token.AccessToken, token.Domain)
+	instance.userId = token.UserId
+	instance.token = token.AccessToken
+	HttpClientInstance().setRequestInterseptor(instance.wfReqInterseptor)
 	return instance
 	return instance
 }
 }
 
 
@@ -92,19 +88,6 @@ func (w *WFClient) Init(endpoint, userId, username, token, domain string) error
 	}
 	}
 }
 }
 
 
-/**
- * @brief: add callback
- * @param1: key
- * @param2: callback
- */
-func (w *WFClient) AddCallback(key string, cb func(CallbackArg)) {
-	if _, ok := w.callbackMap[key]; !ok {
-		w.callbackMap[key] = cb
-	} else {
-		fmt.Println("callback", key, "does already exist")
-	}
-}
-
 /**
 /**
  * @brief: create or update the define,
  * @brief: create or update the define,
  * @param1 defineId: id of define, if the define with id does already exist, update the define
  * @param1 defineId: id of define, if the define with id does already exist, update the define
@@ -279,21 +262,17 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string, c *
 	// 节点回调
 	// 节点回调
 	callbacks := strings.Split(RunRespInfo.StartCallback, ",")
 	callbacks := strings.Split(RunRespInfo.StartCallback, ",")
 	for _, callbackKye := range callbacks {
 	for _, callbackKye := range callbacks {
-		callback, ok := w.callbackMap[callbackKye]
-		if ok {
-			fmt.Println("------------------------------------->121")
-			callback(CallbackArg{
-				DefineId:     RunRespInfo.DefineId,
-				InstanceId:   RunRespInfo.DefineId,
-				DefineName:   RunRespInfo.DefineName,
-				InstanceName: RunRespInfo.InstanceName,
-				FormData:     RunRespInfo.FormData,
-				Choice:       choice,
-				Executor:     RunRespInfo.Executor,
-				UserId:       w.userId,
-				Context:      c,
-			})
-		}
+		callWFCallback(callbackKye, &CallbackArg{
+			DefineId:     RunRespInfo.DefineId,
+			InstanceId:   RunRespInfo.DefineId,
+			DefineName:   RunRespInfo.DefineName,
+			InstanceName: RunRespInfo.InstanceName,
+			FormData:     RunRespInfo.FormData,
+			Choice:       choice,
+			Executor:     RunRespInfo.Executor,
+			UserId:       w.userId,
+			Context:      c,
+		})
 	}
 	}
 
 
 	// 连线回调
 	// 连线回调
@@ -309,20 +288,17 @@ func (w *WFClient) Run(instanceId, userId, choice, options, nextStep string, c *
 	}
 	}
 
 
 	for _, callbackKye := range linkCallbacks {
 	for _, callbackKye := range linkCallbacks {
-		callback, ok := w.callbackMap[callbackKye]
-		if ok {
-			callback(CallbackArg{
-				DefineId:     RunRespInfo.DefineId,
-				InstanceId:   instanceId,
-				DefineName:   RunRespInfo.DefineName,
-				InstanceName: RunRespInfo.InstanceName,
-				FormData:     RunRespInfo.FormData,
-				Choice:       choice,
-				Executor:     RunRespInfo.Executor,
-				UserId:       w.userId,
-				Context:      c,
-			})
-		}
+		callWFCallback(callbackKye, &CallbackArg{
+			DefineId:     RunRespInfo.DefineId,
+			InstanceId:   RunRespInfo.DefineId,
+			DefineName:   RunRespInfo.DefineName,
+			InstanceName: RunRespInfo.InstanceName,
+			FormData:     RunRespInfo.FormData,
+			Choice:       choice,
+			Executor:     RunRespInfo.Executor,
+			UserId:       w.userId,
+			Context:      c,
+		})
 	}
 	}
 
 
 	return []byte{}, nil
 	return []byte{}, nil
@@ -533,3 +509,13 @@ func (w *WFClient) Interrupt(definedId string, formData map[string]interface{},
 	}
 	}
 	return bytess, err
 	return bytess, err
 }
 }
+
+//撤回
+func (w *WFClient) Delete(definedId string) ([]byte, error) {
+	url := w.getFullUrl("/api/wf_define/delete")
+
+	params := make(map[string]string)
+	params["define_id"] = definedId
+
+	return HttpClientInstance().post(url, params, nil)
+}