work_flow.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package workflow
  2. import (
  3. "context"
  4. "dashoo.cn/micro/app/dao/plat"
  5. "dashoo.cn/micro/app/service"
  6. "dashoo.cn/opms_libary/plugin/dingtalk"
  7. "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
  8. "dashoo.cn/opms_libary/utils"
  9. "github.com/gogf/gf/frame/g"
  10. )
  11. type workflowService struct {
  12. *service.ContextService
  13. Dao *plat.PlatTaskDao
  14. }
  15. func NewTaskService(ctx context.Context) (svc *workflowService, err error) {
  16. svc = new(workflowService)
  17. if svc.ContextService, err = svc.Init(ctx); err != nil {
  18. return nil, err
  19. }
  20. svc.Dao = plat.NewPlatTaskDao(svc.Tenant)
  21. return svc, nil
  22. }
  23. // GetProcessInstanceDetail 获取审批实例详情
  24. func (s *workflowService) GetProcessInstanceDetail(instId string) (*workflow.QueryProcessInstanceResponse, error) {
  25. g.Log().Info("搜索值", instId)
  26. // 调用钉钉接口
  27. client := dingtalk.NewClient()
  28. w := client.GetWorkflow()
  29. resp, err := w.QueryProcessInstanceDetail(instId)
  30. if err != nil {
  31. return nil, err
  32. }
  33. return &resp, nil
  34. }
  35. // StartProcessInstance 发起一个新的审批流
  36. // OriginatorUserId = utils.String("当前用户的钉钉中的Id")
  37. // ProcessCode = utils.String("每种审批对应固定的code")
  38. // bizType:业务类型(10领用20项目创建30合同创建
  39. // 详情参照文档:https://open.dingtalk.com/document/orgapp/create-an-approval-instance
  40. func (s *workflowService) StartProcessInstance(bizCode, bizType string, flow *workflow.StartProcessInstanceRequest) (insertId int64, err error) {
  41. g.Log().Info("搜索值", flow)
  42. // 参数调整
  43. if flow.OriginatorUserId == nil {
  44. // TODO s.GetCxtDingId()
  45. flow.OriginatorUserId = utils.String("s.GetCxtDingId()")
  46. }
  47. // 调用钉钉接口
  48. client := dingtalk.NewClient()
  49. w := client.GetWorkflow()
  50. resp, err := w.StartProcessInstance(flow)
  51. if err != nil {
  52. return 0, err
  53. }
  54. return s.saveWorkflowInstance(bizCode, bizType, resp.InstanceId, flow)
  55. }
  56. // RevokeProcessInstance 撤销审批实例
  57. func (s *workflowService) RevokeProcessInstance(instId, remark string) (string, error) {
  58. g.Log().Info("搜索值instId, remark:", instId, remark)
  59. // 调用钉钉接口
  60. client := dingtalk.NewClient()
  61. w := client.GetWorkflow()
  62. // TODO 获取当前用户的钉钉中的Id s.GetCxtDingId()
  63. resp, err := w.RevokeProcessInstance(instId, remark, "s.GetCxtDingId()")
  64. if err != nil {
  65. return "", err
  66. }
  67. return resp.InstanceId, nil
  68. }
  69. // 将审批实例同步到数据库中
  70. func (s *workflowService) saveWorkflowInstance(bizCode, bizType, instanceId string, flow *workflow.StartProcessInstanceRequest) (insertId int64, err error) {
  71. return 0, nil
  72. }