ng_cws_client.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package ng_cws_client
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "git.sxidc.com/service-supports/cws-sdk/service"
  6. "git.sxidc.com/service-supports/cws-sdk/service/request"
  7. "git.sxidc.com/service-supports/cws-sdk/service/response"
  8. "git.sxidc.com/service-supports/cws-sdk/utils"
  9. "git.sxidc.com/service-supports/cws-sdk/utils/http_client"
  10. "time"
  11. )
  12. type NGCwsClient struct {
  13. timeout time.Duration
  14. cwsUrl string
  15. httpClient *http_client.Client
  16. }
  17. func (svc *NGCwsClient) Init(cwsUrl string) error {
  18. if utils.IsStringEmpty(cwsUrl) {
  19. return errors.New("未配置CWS地址")
  20. }
  21. svc.cwsUrl = cwsUrl
  22. svc.httpClient = http_client.New()
  23. return nil
  24. }
  25. func (svc *NGCwsClient) Destroy() error {
  26. http_client.Destroy(svc.httpClient)
  27. return nil
  28. }
  29. var workflowTemplateMap = map[string]string{
  30. "CGJH": "4e0f65ab8547436ba9f744c4dcaef14e",
  31. "CGDD": "5e9bb84779b34d31947107f2c4ead93d",
  32. "CGHT": "d0c7ac374d2a4ed58cd2ee5f1c065110",
  33. "RKZJ": "ffc0b6044e154707ad80d174c08236be",
  34. "RKYS": "bdf8eeaf78c146cd914aef8067dea8b2",
  35. "RK": "2b6338dcdddb4e51b992347e87a1044a",
  36. "XSHT": "2f1997724b4b49c99379a18bf7067cee",
  37. "XSDD": "e73bd99b5761464ea74a612d3eaf3ea7",
  38. "CK": "f82e46c9c4c04862a9babbf3734432e8",
  39. "SCJH": "762685ccfdc3499590d99d3a8d55b78f",
  40. "SCGD": "0d43eaff78bb4abf9d6c5634b74e212e",
  41. "SCZJ": "f5c091e62e6a4cef9a68fda99736fd2e",
  42. "BSD": "0973c19af66546899638d816cf5ee5c6",
  43. "BYD": "9d9762864db14271ad9ada7acc73bacd",
  44. "DBD": "c8aff838c20741758de134903d24934a",
  45. "KHTH": "1e12eb97c9db4e53bb0704bb1c3d93f7",
  46. "GYSTH": "459542e8b07a4cda93d98ba0234c079f",
  47. }
  48. func (svc *NGCwsClient) StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error {
  49. //根据业务类型获取流程模型ID
  50. workflowTempalteId := workflowTemplateMap[reqParams.BusinessType]
  51. if utils.IsStringEmpty(workflowTempalteId) {
  52. return errors.New("未配置流程")
  53. }
  54. businessObject := &request.WorkflowBusinessObject{
  55. BusinessType: reqParams.BusinessType,
  56. BusinessObject: reqParams.Data,
  57. }
  58. jsonBytes, err := json.Marshal(businessObject)
  59. if err != nil {
  60. return err
  61. }
  62. businessObjectStr := string(jsonBytes)
  63. err = svc.StartWorkflow(&request.StartWorkflowRequest{
  64. WorkflowTemplateID: workflowTempalteId,
  65. Matter: reqParams.Matter,
  66. BusinessObject: businessObjectStr,
  67. CreateUserID: reqParams.CreateUserID,
  68. TenantID: reqParams.TenantID,
  69. })
  70. if err != nil {
  71. return err
  72. }
  73. return nil
  74. }
  75. func (svc *NGCwsClient) StartWorkflow(reqParams *request.StartWorkflowRequest) error {
  76. requestJson, err := json.Marshal(reqParams)
  77. if err != nil {
  78. return err
  79. }
  80. postResponse, err := svc.httpClient.NewRequest(http_client.WithNewRequestTimeout(svc.timeout)).
  81. Post(svc.cwsUrl+service.StartWorkFlowMethodName, requestJson)
  82. if err != nil {
  83. return err
  84. }
  85. resp := new(response.MsgResponse)
  86. err = postResponse.Json(resp)
  87. if err != nil {
  88. return err
  89. }
  90. if !resp.Success {
  91. return errors.New(resp.Msg)
  92. }
  93. return nil
  94. }