| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package workflow
- import (
- "dashoo.cn/opms_libary/plugin/dingtalk/base"
- "dashoo.cn/opms_libary/plugin/dingtalk/context"
- "encoding/json"
- "fmt"
- "github.com/gogf/gf/frame/g"
- )
- const (
- QuerySchemasUrl = "/v1.0/workflow/forms/schemas/processCodes"
- StartProcessInstanceUrl = "/v1.0/workflow/processInstances"
- RevokeProcessInstanceUrl = "/v1.0/workflow/processInstances/terminate"
- )
- // Workflow OA审批
- type Workflow struct {
- base.Base
- }
- // NewWorkflow init
- func NewWorkflow(context *context.Context) *Workflow {
- material := new(Workflow)
- material.Context = context
- return material
- }
- // QuerySchemaByProcessCode 获取表单 schema
- func (w *Workflow) QuerySchemaByProcessCode(processCode string) (response QuerySchemaByProcessCodeResponse, err error) {
- resp, _ := w.HTTPGetWithAccessToken(QuerySchemasUrl, g.Map{"processCode": processCode})
- if err != nil {
- return
- }
- err = json.Unmarshal(resp, &response)
- return response, err
- }
- // StartProcessInstance 发起审批实例
- func (w *Workflow) StartProcessInstance(request *StartProcessInstanceRequest) (response StartProcessInstanceResponse, err error) {
- resp, _ := w.HTTPPostJSONWithAccessToken(StartProcessInstanceUrl, request)
- if err != nil {
- return
- }
- fmt.Println("StartProcessInstanceResp:", string(resp))
- err = json.Unmarshal(resp, &response)
- return response, err
- }
- // QueryProcessInstanceDetail 获取单个审批实例详情
- func (w *Workflow) QueryProcessInstanceDetail(instId string) (response QueryProcessInstanceResponse, err error) {
- resp, err := w.HTTPGetWithAccessToken(StartProcessInstanceUrl, g.Map{"processInstanceId": instId})
- if err != nil {
- return
- }
- err = json.Unmarshal(resp, &response)
- return
- }
- // RevokeProcessInstance 撤销审批实例
- func (w *Workflow) RevokeProcessInstance(instId, remark, userId string) (response RevokeProcessInstanceResponse, err error) {
- resp, err := w.HTTPGetWithAccessToken(RevokeProcessInstanceUrl,
- g.Map{"processInstanceId": instId,
- "isSystem": true,
- "remark": remark,
- "operatingUserId": userId,
- })
- if err != nil {
- return
- }
- err = json.Unmarshal(resp, &response)
- return
- }
|