package workflow import ( "context" "dashoo.cn/micro/app/dao/plat" "dashoo.cn/micro/app/service" "dashoo.cn/opms_libary/plugin/dingtalk" "dashoo.cn/opms_libary/plugin/dingtalk/workflow" "dashoo.cn/opms_libary/utils" "github.com/gogf/gf/frame/g" ) type workflowService struct { *service.ContextService Dao *plat.PlatTaskDao } func NewTaskService(ctx context.Context) (svc *workflowService, err error) { svc = new(workflowService) if svc.ContextService, err = svc.Init(ctx); err != nil { return nil, err } svc.Dao = plat.NewPlatTaskDao(svc.Tenant) return svc, nil } // GetProcessInstanceDetail 获取审批实例详情 func (s *workflowService) GetProcessInstanceDetail(instId string) (*workflow.QueryProcessInstanceResponse, error) { g.Log().Info("搜索值", instId) // 调用钉钉接口 client := dingtalk.NewClient() w := client.GetWorkflow() resp, err := w.QueryProcessInstanceDetail(instId) if err != nil { return nil, err } return &resp, nil } // StartProcessInstance 发起一个新的审批流 // OriginatorUserId = utils.String("当前用户的钉钉中的Id") // ProcessCode = utils.String("每种审批对应固定的code") // bizType:业务类型(10领用20项目创建30合同创建 // 详情参照文档:https://open.dingtalk.com/document/orgapp/create-an-approval-instance func (s *workflowService) StartProcessInstance(bizCode, bizType string, flow *workflow.StartProcessInstanceRequest) (insertId int64, err error) { g.Log().Info("搜索值", flow) // 参数调整 if flow.OriginatorUserId == nil { // TODO s.GetCxtDingId() flow.OriginatorUserId = utils.String("s.GetCxtDingId()") } // 调用钉钉接口 client := dingtalk.NewClient() w := client.GetWorkflow() resp, err := w.StartProcessInstance(flow) if err != nil { return 0, err } return s.saveWorkflowInstance(bizCode, bizType, resp.InstanceId, flow) } // RevokeProcessInstance 撤销审批实例 func (s *workflowService) RevokeProcessInstance(instId, remark string) (string, error) { g.Log().Info("搜索值instId, remark:", instId, remark) // 调用钉钉接口 client := dingtalk.NewClient() w := client.GetWorkflow() // TODO 获取当前用户的钉钉中的Id s.GetCxtDingId() resp, err := w.RevokeProcessInstance(instId, remark, "s.GetCxtDingId()") if err != nil { return "", err } return resp.InstanceId, nil } // 将审批实例同步到数据库中 func (s *workflowService) saveWorkflowInstance(bizCode, bizType, instanceId string, flow *workflow.StartProcessInstanceRequest) (insertId int64, err error) { return 0, nil }