|
@@ -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 {
|
|
|
|
|
|
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
|
|
|
}
|