workflow.go 2.1 KB

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