Explorar el Código

封装客户端

张亚军 hace 6 meses
padre
commit
e7c8863315
Se han modificado 1 ficheros con 18 adiciones y 16 borrados
  1. 18 16
      ng_cws_client/ng_cws_client.go

+ 18 - 16
ng_cws_client/ng_cws_client.go

@@ -11,24 +11,23 @@ import (
 	"time"
 )
 
-type NGCwsClient struct {
-	timeout    time.Duration
-	cwsUrl     string
-	httpClient *http_client.Client
-}
+var NGCwsClient *http_client.Client
+var cwsUrl string
+var cwsTimeOut time.Duration
 
-func (svc *NGCwsClient) Init(cwsUrl string) error {
+func Init(url string, timeout time.Duration) error {
 	if utils.IsStringEmpty(cwsUrl) {
 		return errors.New("未配置CWS地址")
 	}
-	svc.cwsUrl = cwsUrl
-	svc.httpClient = http_client.New()
+
+	NGCwsClient = http_client.New()
+	cwsTimeOut = timeout
+	cwsUrl = url
 	return nil
 }
 
-func (svc *NGCwsClient) Destroy() error {
-	http_client.Destroy(svc.httpClient)
-	return nil
+func Destroy() {
+	http_client.Destroy(NGCwsClient)
 }
 
 var workflowTemplateMap = map[string]string{
@@ -51,7 +50,7 @@ var workflowTemplateMap = map[string]string{
 	"GYSTH": "459542e8b07a4cda93d98ba0234c079f",
 }
 
-func (svc *NGCwsClient) StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error {
+func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error {
 	//根据业务类型获取流程模型ID
 	workflowTempalteId := workflowTemplateMap[reqParams.BusinessType]
 	if utils.IsStringEmpty(workflowTempalteId) {
@@ -68,7 +67,7 @@ func (svc *NGCwsClient) StartWorkFlowByBusinessType(reqParams *request.StartWork
 	}
 	businessObjectStr := string(jsonBytes)
 
-	err = svc.StartWorkflow(&request.StartWorkflowRequest{
+	err = StartWorkflow(&request.StartWorkflowRequest{
 		WorkflowTemplateID: workflowTempalteId,
 		Matter:             reqParams.Matter,
 		BusinessObject:     businessObjectStr,
@@ -83,13 +82,16 @@ func (svc *NGCwsClient) StartWorkFlowByBusinessType(reqParams *request.StartWork
 
 }
 
-func (svc *NGCwsClient) StartWorkflow(reqParams *request.StartWorkflowRequest) error {
+func StartWorkflow(reqParams *request.StartWorkflowRequest) error {
+	if utils.IsStringEmpty(cwsUrl) {
+		return errors.New("未配置CWS地址")
+	}
 	requestJson, err := json.Marshal(reqParams)
 	if err != nil {
 		return err
 	}
-	postResponse, err := svc.httpClient.NewRequest(http_client.WithNewRequestTimeout(svc.timeout)).
-		Post(svc.cwsUrl+service.StartWorkFlowMethodName, requestJson)
+	postResponse, err := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut)).
+		Post(cwsUrl+service.StartWorkFlowMethodName, requestJson)
 	if err != nil {
 		return err
 	}