workflow.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package service
  2. import (
  3. "cws-sdk/ng_cw_client"
  4. "cws-sdk/service/request"
  5. "encoding/json"
  6. "errors"
  7. "git.sxidc.com/go-tools/utils/strutils"
  8. "yunji/Gateway/websocket/api/response"
  9. )
  10. var workflowTemplateMap = map[string]string{
  11. "CGJH": "4e0f65ab8547436ba9f744c4dcaef14e",
  12. "CGDD": "5e9bb84779b34d31947107f2c4ead93d",
  13. "CGHT": "d0c7ac374d2a4ed58cd2ee5f1c065110",
  14. "RKZJ": "ffc0b6044e154707ad80d174c08236be",
  15. "RKYS": "bdf8eeaf78c146cd914aef8067dea8b2",
  16. "RK": "2b6338dcdddb4e51b992347e87a1044a",
  17. "XSHT": "2f1997724b4b49c99379a18bf7067cee",
  18. "XSDD": "e73bd99b5761464ea74a612d3eaf3ea7",
  19. "CK": "f82e46c9c4c04862a9babbf3734432e8",
  20. "SCJH": "762685ccfdc3499590d99d3a8d55b78f",
  21. "SCGD": "0d43eaff78bb4abf9d6c5634b74e212e",
  22. "SCZJ": "f5c091e62e6a4cef9a68fda99736fd2e",
  23. "BSD": "0973c19af66546899638d816cf5ee5c6",
  24. "BYD": "9d9762864db14271ad9ada7acc73bacd",
  25. "DBD": "c8aff838c20741758de134903d24934a",
  26. "KHTH": "1e12eb97c9db4e53bb0704bb1c3d93f7",
  27. "GYSTH": "459542e8b07a4cda93d98ba0234c079f",
  28. }
  29. func StartWorkFlowByBusinessType(reqParams *request.StartWorkFlowByBusinessTypeRequest) error {
  30. //根据业务类型获取流程模型ID
  31. workflowTempalteId := workflowTemplateMap[reqParams.BusinessType]
  32. if strutils.IsStringEmpty(workflowTempalteId) {
  33. return errors.New("未配置流程")
  34. }
  35. businessObject := &request.WorkflowBusinessObject{
  36. BusinessType: reqParams.BusinessType,
  37. BusinessObject: reqParams.Data,
  38. }
  39. jsonBytes, err := json.Marshal(businessObject)
  40. if err != nil {
  41. return err
  42. }
  43. businessObjectStr := string(jsonBytes)
  44. err = StartWorkflow(&request.StartWorkflowRequest{
  45. WorkflowTemplateID: workflowTempalteId,
  46. Matter: reqParams.Matter,
  47. BusinessObject: businessObjectStr,
  48. CreateUserID: reqParams.CreateUserID,
  49. TenantID: reqParams.TenantID,
  50. })
  51. if err != nil {
  52. return err
  53. }
  54. return nil
  55. }
  56. func StartWorkflow(reqParams *request.StartWorkflowRequest) error {
  57. requestJson, err := json.Marshal(reqParams)
  58. if err != nil {
  59. return err
  60. }
  61. responseBytes, err := ng_cw_client.GetInvokeAPI().PostJSON(startWorkFlowMethodName, requestJson, nil)
  62. if err != nil {
  63. return err
  64. }
  65. resp := new(response.MsgResponse)
  66. err = json.Unmarshal(responseBytes, resp)
  67. if err != nil {
  68. return err
  69. }
  70. if !resp.Success {
  71. return errors.New(resp.Msg)
  72. }
  73. return nil
  74. }