package ng_cws_client import ( "encoding/json" "errors" "git.sxidc.com/service-supports/cws-sdk/service" "git.sxidc.com/service-supports/cws-sdk/service/request" "git.sxidc.com/service-supports/cws-sdk/service/response" "git.sxidc.com/service-supports/cws-sdk/utils" "git.sxidc.com/service-supports/cws-sdk/utils/http_client" "time" ) var NGCwsClient *http_client.Client var cwsUrl string var cwsTimeOut time.Duration func Init(url string, timeout time.Duration) error { if utils.IsStringEmpty(url) { return errors.New("未配置CWS地址") } NGCwsClient = http_client.New() cwsTimeOut = timeout cwsUrl = url return nil } func Destroy() { http_client.Destroy(NGCwsClient) } var workflowTemplateMap = map[string]string{ "CGJH": "4e0f65ab8547436ba9f744c4dcaef14e", "CGDD": "5e9bb84779b34d31947107f2c4ead93d", "CGHT": "d0c7ac374d2a4ed58cd2ee5f1c065110", "RKZJ": "ffc0b6044e154707ad80d174c08236be", "RKYS": "bdf8eeaf78c146cd914aef8067dea8b2", "RK": "2b6338dcdddb4e51b992347e87a1044a", "XSHT": "2f1997724b4b49c99379a18bf7067cee", "XSDD": "e73bd99b5761464ea74a612d3eaf3ea7", "CK": "f82e46c9c4c04862a9babbf3734432e8", "SCJH": "762685ccfdc3499590d99d3a8d55b78f", "SCGD": "0d43eaff78bb4abf9d6c5634b74e212e", "SCZJ": "f5c091e62e6a4cef9a68fda99736fd2e", "BSD": "0973c19af66546899638d816cf5ee5c6", "BYD": "9d9762864db14271ad9ada7acc73bacd", "DBD": "c8aff838c20741758de134903d24934a", "KHTH": "1e12eb97c9db4e53bb0704bb1c3d93f7", "GYSTH": "459542e8b07a4cda93d98ba0234c079f", } func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error { //根据业务类型获取流程模型ID workflowTemplateId, err := getWorkTemplateInfoByBusinessType(reqParams.BusinessType, reqParams.TenantID) if err != nil { return err } if utils.IsStringEmpty(workflowTemplateId) { return errors.New("该业务类型未配置流程") } businessObject := &request.WorkflowBusinessObject{ BusinessType: reqParams.BusinessType, BusinessObject: reqParams.Data, } jsonBytes, err := json.Marshal(businessObject) if err != nil { return err } businessObjectStr := string(jsonBytes) err = StartWorkflow(&request.StartWorkflowRequest{ LaunchUserName: reqParams.LaunchUserName, WorkflowTemplateID: workflowTemplateId, Matter: reqParams.Matter, BusinessObject: businessObjectStr, CreateUserID: reqParams.CreateUserID, TenantID: reqParams.TenantID, }) if err != nil { return err } return nil } 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 := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut)). Post(cwsUrl+service.StartWorkFlowMethodName, requestJson) if err != nil { return err } resp := new(response.MsgResponse) err = postResponse.Json(resp) if err != nil { return err } if !resp.Success { return errors.New(resp.Msg) } return nil } func getWorkTemplateInfoByBusinessType(businessType string, tenantId string) (string, error) { //查询业务类型配置 queryParams := map[string]string{ "code": businessType, "tenantId": tenantId, } newRequest := NGCwsClient.NewRequest(http_client.WithNewRequestTimeout(cwsTimeOut)) newRequest.SetQueryParams(queryParams) resp, err := newRequest.Get(cwsUrl + service.GetWorkTemplateByCodeMethodName) if err != nil { return "", err } respInfo := new(response.InfoResponse[response.BusinessCatalogsInfoWithWorkflowTemplate]) err = resp.Json(respInfo) if err != nil { return "", err } if !respInfo.Success { return "", errors.New(respInfo.Msg) } return respInfo.Info.WorkTemplateId, nil }