workflow.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package workflow
  2. import (
  3. "dashoo.cn/opms_libary/plugin/dingtalk/base"
  4. "dashoo.cn/opms_libary/plugin/dingtalk/context"
  5. "encoding/json"
  6. "github.com/gogf/gf/frame/g"
  7. )
  8. const (
  9. QuerySchemasUrl = "/v1.0/workflow/forms/schemas/processCodes"
  10. StartProcessInstanceUrl = "/v1.0/workflow/processInstances"
  11. RevokeProcessInstanceUrl = "/v1.0/workflow/processInstances/terminate"
  12. )
  13. //Workflow OA审批
  14. type Workflow struct {
  15. base.Base
  16. }
  17. //NewWorkflow init
  18. func NewWorkflow(context *context.Context) *Workflow {
  19. material := new(Workflow)
  20. material.Context = context
  21. return material
  22. }
  23. //QuerySchemaByProcessCode 获取表单 schema
  24. func (w *Workflow) QuerySchemaByProcessCode(processCode string) (response QuerySchemaByProcessCodeResponse, err error) {
  25. resp, _ := w.HTTPGetWithAccessToken(QuerySchemasUrl, g.Map{"processCode": processCode})
  26. if err != nil {
  27. return
  28. }
  29. err = json.Unmarshal(resp, &response)
  30. return response, err
  31. }
  32. //StartProcessInstance 发起审批实例
  33. func (w *Workflow) StartProcessInstance(request *StartProcessInstanceRequest) (response StartProcessInstanceResponse, err error) {
  34. resp, _ := w.HTTPPostJSONWithAccessToken(StartProcessInstanceUrl, request)
  35. if err != nil {
  36. return
  37. }
  38. err = json.Unmarshal(resp, &response)
  39. return response, err
  40. }
  41. //QueryProcessInstanceDetail 获取单个审批实例详情
  42. func (w *Workflow) QueryProcessInstanceDetail(instId string) (response QueryProcessInstanceResponse, err error) {
  43. resp, err := w.HTTPGetWithAccessToken(RevokeProcessInstanceUrl, g.Map{"processInstanceId": instId})
  44. if err != nil {
  45. return
  46. }
  47. err = json.Unmarshal(resp, &response)
  48. return
  49. }
  50. //RevokeProcessInstance 撤销审批实例
  51. func (w *Workflow) RevokeProcessInstance(instId, remark, userId string) (response RevokeProcessInstanceResponse, err error) {
  52. resp, err := w.HTTPGetWithAccessToken(RevokeProcessInstanceUrl,
  53. g.Map{"processInstanceId": instId,
  54. "isSystem": true,
  55. "remark": remark,
  56. "operatingUserId": userId,
  57. })
  58. if err != nil {
  59. return
  60. }
  61. err = json.Unmarshal(resp, &response)
  62. return
  63. }