-
Notifications
You must be signed in to change notification settings - Fork 74
/
resource.go
843 lines (809 loc) · 35.1 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
// Code generated by Lark OpenAPI.
package larkapproval
import (
"context"
"github.com/larksuite/oapi-sdk-go/v3/core"
"net/http"
)
type V4 struct {
Approval *approval // 原生审批定义
ExternalApproval *externalApproval // 三方审批定义
ExternalInstance *externalInstance // 三方审批实例
ExternalTask *externalTask // 三方审批任务
Instance *instance // 原生审批实例
InstanceComment *instanceComment // 原生审批评论
Task *task // 审批查询
}
func New(config *larkcore.Config) *V4 {
return &V4{
Approval: &approval{config: config},
ExternalApproval: &externalApproval{config: config},
ExternalInstance: &externalInstance{config: config},
ExternalTask: &externalTask{config: config},
Instance: &instance{config: config},
InstanceComment: &instanceComment{config: config},
Task: &task{config: config},
}
}
type approval struct {
config *larkcore.Config
}
type externalApproval struct {
config *larkcore.Config
}
type externalInstance struct {
config *larkcore.Config
}
type externalTask struct {
config *larkcore.Config
}
type instance struct {
config *larkcore.Config
}
type instanceComment struct {
config *larkcore.Config
}
type task struct {
config *larkcore.Config
}
// Create 创建审批定义
//
// - 用于通过接口创建简单的审批定义,可以灵活指定定义的基础信息、表单和流程等。创建成功后,不支持从审批管理后台删除该定义。不推荐企业自建应用使用,如有需要尽量联系管理员在审批管理后台创建定义。
//
// - 接口谨慎调用,创建后的审批定义无法停用/删除
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/approval/create
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/create_approval.go
func (a *approval) Create(ctx context.Context, req *CreateApprovalReq, options ...larkcore.RequestOptionFunc) (*CreateApprovalResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/approvals"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CreateApprovalResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, a.config)
if err != nil {
return nil, err
}
return resp, err
}
// Get 查看审批定义
//
// - 根据 Approval Code 获取某个审批定义的详情,用于构造创建审批实例的请求。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/approval/get
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/get_approval.go
func (a *approval) Get(ctx context.Context, req *GetApprovalReq, options ...larkcore.RequestOptionFunc) (*GetApprovalResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/approvals/:approval_code"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &GetApprovalResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, a.config)
if err != nil {
return nil, err
}
return resp, err
}
// Subscribe 订阅审批事件
//
// - 应用订阅 approval_code 后,该应用就可以收到该审批定义对应实例的事件通知。同一应用只需要订阅一次,无需重复订阅。;;当应用不希望再收到审批事件时,可以使用取消订阅接口进行取消,取消后将不再给应用推送消息。;;订阅和取消订阅都是应用维度的,多个应用可以同时订阅同一个 approval_code,每个应用都能收到审批事件。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/approval/subscribe
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/subscribe_approval.go
func (a *approval) Subscribe(ctx context.Context, req *SubscribeApprovalReq, options ...larkcore.RequestOptionFunc) (*SubscribeApprovalResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/approvals/:approval_code/subscribe"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &SubscribeApprovalResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, a.config)
if err != nil {
return nil, err
}
return resp, err
}
// Unsubscribe 取消订阅审批事件
//
// - 取消订阅 approval_code 后,无法再收到该审批定义对应实例的事件通知
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/approval/unsubscribe
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/unsubscribe_approval.go
func (a *approval) Unsubscribe(ctx context.Context, req *UnsubscribeApprovalReq, options ...larkcore.RequestOptionFunc) (*UnsubscribeApprovalResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/approvals/:approval_code/unsubscribe"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &UnsubscribeApprovalResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, a.config)
if err != nil {
return nil, err
}
return resp, err
}
// Create 三方审批定义创建
//
// - 审批定义是审批的描述,包括审批名称、图标、描述等基础信息。创建好审批定义,用户就可以在审批应用的发起页中看到审批,如果用户点击发起,则会跳转到配置的发起三方系统地址去发起审批。;;另外,审批定义还配置了审批操作时的回调地址:审批人在待审批列表中进行【同意】【拒绝】操作时,审批中心会调用回调地址通知三方系统。
//
// - 注意,审批中心不负责审批流程的流转,只负责展示、操作、消息通知。因此审批定义创建时没有审批流程的信息。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/external_approval/create
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/create_externalApproval.go
func (e *externalApproval) Create(ctx context.Context, req *CreateExternalApprovalReq, options ...larkcore.RequestOptionFunc) (*CreateExternalApprovalResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/external_approvals"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, e.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CreateExternalApprovalResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, e.config)
if err != nil {
return nil, err
}
return resp, err
}
// Get
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=get&project=approval&resource=external_approval&version=v4
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/get_externalApproval.go
func (e *externalApproval) Get(ctx context.Context, req *GetExternalApprovalReq, options ...larkcore.RequestOptionFunc) (*GetExternalApprovalResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/external_approvals/:approval_code"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, e.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &GetExternalApprovalResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, e.config)
if err != nil {
return nil, err
}
return resp, err
}
// Check 三方审批实例校验
//
// - 校验三方审批实例数据,用于判断服务端数据是否为最新的。用户提交实例最新更新时间,如果服务端不存在该实例,或者服务端实例更新时间不是最新的,则返回对应实例 id。;;例如,用户可以每隔5分钟,将最近5分钟产生的实例使用该接口进行对比。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/external_instance/check
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/check_externalInstance.go
func (e *externalInstance) Check(ctx context.Context, req *CheckExternalInstanceReq, options ...larkcore.RequestOptionFunc) (*CheckExternalInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/external_instances/check"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, e.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CheckExternalInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, e.config)
if err != nil {
return nil, err
}
return resp, err
}
// Create 三方审批实例同步
//
// - 审批中心不负责审批的流转,审批的流转在三方系统,三方系统在审批流转后生成的审批实例、审批任务、审批抄送数据同步到审批中心。;;用户可以在审批中心中浏览三方系统同步过来的实例、任务、抄送信息,并且可以跳转回三方系统进行更详细的查看和操作,其中实例信息在【已发起】列表,任务信息在【待审批】和【已审批】列表,抄送信息在【抄送我】列表;;:::html;<img src="//sf3-cn.feishucdn.com/obj/open-platform-opendoc/9dff4434afbeb0ef69de7f36b9a6e995_z5iwmTzEgg.png" alt="" style="zoom:17%;" />;;;<img src="//sf3-cn.feishucdn.com/obj/open-platform-opendoc/ca6e0e984a7a6d64e1b16a0bac4bf868_tfqjCiaJQM.png" alt="" style="zoom:17%;" />;;;<img src="//sf3-cn.feishucdn.com/obj/open-platform-opendoc/529377e238df78d391bbd22e962ad195_T7eefLI1GA.png" alt="" style="zoom:17%;" />;:::;;对于审批任务,三方系统也可以配置审批任务的回调接口,这样审批人可以在审批中心中直接进行审批操作,审批中心会回调三方系统,三方系统收到回调后更新任务信息,并将新的任务信息同步回审批中心,形成闭环。;;:::html;<img src="//sf3-cn.feishucdn.com/obj/open-platform-opendoc/721c35428bc1187db3318c572f9979ad_je75QpElcg.png" alt="" style="zoom:25%;" />;:::;<br>
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/external_instance/create
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/create_externalInstance.go
func (e *externalInstance) Create(ctx context.Context, req *CreateExternalInstanceReq, options ...larkcore.RequestOptionFunc) (*CreateExternalInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/external_instances"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, e.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CreateExternalInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, e.config)
if err != nil {
return nil, err
}
return resp, err
}
// List 获取三方审批任务状态
//
// - 该接口用于获取三方审批的状态。用户传入查询条件,接口返回满足条件的审批实例的状态。该接口支持多种参数的组合,包括如下组合:;;1.通过 instance_ids 获取指定实例的任务状态;;2.通过 user_ids 获取指定用户的任务状态;;3.通过 status 获取指定状态的所有任务;;4.通过page_token获取下一批数据
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/external_task/list
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/list_externalTask.go
func (e *externalTask) List(ctx context.Context, req *ListExternalTaskReq, options ...larkcore.RequestOptionFunc) (*ListExternalTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/external_tasks"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, e.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &ListExternalTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, e.config)
if err != nil {
return nil, err
}
return resp, err
}
func (e *externalTask) ListByIterator(ctx context.Context, req *ListExternalTaskReq, options ...larkcore.RequestOptionFunc) (*ListExternalTaskIterator, error) {
return &ListExternalTaskIterator{
ctx: ctx,
req: req,
listFunc: e.List,
options: options,
limit: req.Limit}, nil
}
// AddSign
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/ukTM5UjL5ETO14SOxkTN/approval-task-addsign
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/addSign_instance.go
func (i *instance) AddSign(ctx context.Context, req *AddSignInstanceReq, options ...larkcore.RequestOptionFunc) (*AddSignInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/add_sign"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &AddSignInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Cancel 审批实例撤回
//
// - 对于状态为“审批中”的单个审批实例进行撤销操作,撤销后审批流程结束
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/cancel
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/cancel_instance.go
func (i *instance) Cancel(ctx context.Context, req *CancelInstanceReq, options ...larkcore.RequestOptionFunc) (*CancelInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/cancel"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CancelInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Cc 审批实例抄送
//
// - 通过接口可以将当前审批实例抄送给其他人。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/cc
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/cc_instance.go
func (i *instance) Cc(ctx context.Context, req *CcInstanceReq, options ...larkcore.RequestOptionFunc) (*CcInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/cc"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CcInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Create 创建审批实例
//
// - 创建一个审批实例,调用方需对审批定义的表单有详细了解,将按照定义的表单结构,将表单 Value 通过接口传入
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/create
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/create_instance.go
func (i *instance) Create(ctx context.Context, req *CreateInstanceReq, options ...larkcore.RequestOptionFunc) (*CreateInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CreateInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Get 获取单个审批实例详情
//
// - 通过审批实例 Instance Code 获取审批实例详情。Instance Code 由 [批量获取审批实例](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/list) 接口获取。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/get
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/get_instance.go
func (i *instance) Get(ctx context.Context, req *GetInstanceReq, options ...larkcore.RequestOptionFunc) (*GetInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/:instance_id"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &GetInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// List 批量获取审批实例ID
//
// - 根据 approval_code 批量获取审批实例的 instance_code,用于拉取租户下某个审批定义的全部审批实例。默认以审批创建时间先后顺序排列
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/list
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/list_instance.go
func (i *instance) List(ctx context.Context, req *ListInstanceReq, options ...larkcore.RequestOptionFunc) (*ListInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &ListInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
func (i *instance) ListByIterator(ctx context.Context, req *ListInstanceReq, options ...larkcore.RequestOptionFunc) (*ListInstanceIterator, error) {
return &ListInstanceIterator{
ctx: ctx,
req: req,
listFunc: i.List,
options: options,
limit: req.Limit}, nil
}
// Preview
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/ukTM5UjL5ETO14SOxkTN/approval-preview
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/preview_instance.go
func (i *instance) Preview(ctx context.Context, req *PreviewInstanceReq, options ...larkcore.RequestOptionFunc) (*PreviewInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/preview"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &PreviewInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Query 查询实例列表
//
// - 该接口通过不同条件查询审批系统中符合条件的审批实例列表。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/query
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/query_instance.go
func (i *instance) Query(ctx context.Context, req *QueryInstanceReq, options ...larkcore.RequestOptionFunc) (*QueryInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/query"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &QueryInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
func (i *instance) QueryByIterator(ctx context.Context, req *QueryInstanceReq, options ...larkcore.RequestOptionFunc) (*QueryInstanceIterator, error) {
return &QueryInstanceIterator{
ctx: ctx,
req: req,
listFunc: i.Query,
options: options,
limit: req.Limit}, nil
}
// SearchCc 查询抄送列表
//
// - 该接口通过不同条件查询审批系统中符合条件的审批抄送列表。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/search_cc
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/searchCc_instance.go
func (i *instance) SearchCc(ctx context.Context, req *SearchCcInstanceReq, options ...larkcore.RequestOptionFunc) (*SearchCcInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/search_cc"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &SearchCcInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// SpecifiedRollback 审批任务退回
//
// - 从当前审批任务,退回到已审批的一个或多个任务节点。退回后,已审批节点重新生成审批任务
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance/specified_rollback
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/specifiedRollback_instance.go
func (i *instance) SpecifiedRollback(ctx context.Context, req *SpecifiedRollbackInstanceReq, options ...larkcore.RequestOptionFunc) (*SpecifiedRollbackInstanceResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/specified_rollback"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &SpecifiedRollbackInstanceResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Create 创建评论
//
// - 在某审批实例下创建、修改评论或评论回复(不包含审批同意、拒绝、转交等附加的理由或意见)。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance-comment/create
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/create_instanceComment.go
func (i *instanceComment) Create(ctx context.Context, req *CreateInstanceCommentReq, options ...larkcore.RequestOptionFunc) (*CreateInstanceCommentResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/:instance_id/comments"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &CreateInstanceCommentResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Delete 删除评论
//
// - 逻辑删除某审批实例下的一条评论或评论回复(不包含审批同意、拒绝、转交等附加的理由或意见)。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance-comment/delete
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/delete_instanceComment.go
func (i *instanceComment) Delete(ctx context.Context, req *DeleteInstanceCommentReq, options ...larkcore.RequestOptionFunc) (*DeleteInstanceCommentResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/:instance_id/comments/:comment_id"
apiReq.HttpMethod = http.MethodDelete
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &DeleteInstanceCommentResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// List 获取评论
//
// - 根据 Instance Code 获取某个审批实例下的全部评论与评论回复(不包含审批同意、拒绝、转交等附加的理由或意见)。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance-comment/list
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/list_instanceComment.go
func (i *instanceComment) List(ctx context.Context, req *ListInstanceCommentReq, options ...larkcore.RequestOptionFunc) (*ListInstanceCommentResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/:instance_id/comments"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &ListInstanceCommentResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Remove 清空评论
//
// - 删除某审批实例下的全部评论与评论回复。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/instance-comment/remove
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/remove_instanceComment.go
func (i *instanceComment) Remove(ctx context.Context, req *RemoveInstanceCommentReq, options ...larkcore.RequestOptionFunc) (*RemoveInstanceCommentResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/instances/:instance_id/comments/remove"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, i.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &RemoveInstanceCommentResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, i.config)
if err != nil {
return nil, err
}
return resp, err
}
// Approve 审批任务同意
//
// - 对于单个审批任务进行同意操作。同意后审批流程会流转到下一个审批人。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/task/approve
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/approve_task.go
func (t *task) Approve(ctx context.Context, req *ApproveTaskReq, options ...larkcore.RequestOptionFunc) (*ApproveTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/tasks/approve"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &ApproveTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, t.config)
if err != nil {
return nil, err
}
return resp, err
}
// Query 用户角度列出任务
//
// - 根据用户和任务分组查询任务列表
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/task/query
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/query_task.go
func (t *task) Query(ctx context.Context, req *QueryTaskReq, options ...larkcore.RequestOptionFunc) (*QueryTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/tasks/query"
apiReq.HttpMethod = http.MethodGet
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &QueryTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, t.config)
if err != nil {
return nil, err
}
return resp, err
}
func (t *task) QueryByIterator(ctx context.Context, req *QueryTaskReq, options ...larkcore.RequestOptionFunc) (*QueryTaskIterator, error) {
return &QueryTaskIterator{
ctx: ctx,
req: req,
listFunc: t.Query,
options: options,
limit: req.Limit}, nil
}
// Reject 审批任务拒绝
//
// - 对于单个审批任务进行拒绝操作。拒绝后审批流程结束。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/task/reject
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/reject_task.go
func (t *task) Reject(ctx context.Context, req *RejectTaskReq, options ...larkcore.RequestOptionFunc) (*RejectTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/tasks/reject"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &RejectTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, t.config)
if err != nil {
return nil, err
}
return resp, err
}
// Resubmit 审批任务重新提交
//
// - 对于单个退回到发起人的审批任务进行重新发起操作。发起后审批流程会流转到下一个审批人。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/task/resubmit
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/resubmit_task.go
func (t *task) Resubmit(ctx context.Context, req *ResubmitTaskReq, options ...larkcore.RequestOptionFunc) (*ResubmitTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/tasks/resubmit"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &ResubmitTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, t.config)
if err != nil {
return nil, err
}
return resp, err
}
// Search 查询任务列表
//
// - 该接口通过不同条件查询审批系统中符合条件的审批任务列表
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/task/search
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/search_task.go
func (t *task) Search(ctx context.Context, req *SearchTaskReq, options ...larkcore.RequestOptionFunc) (*SearchTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/tasks/search"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &SearchTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, t.config)
if err != nil {
return nil, err
}
return resp, err
}
// Transfer 审批任务转交
//
// - 对于单个审批任务进行转交操作。转交后审批流程流转给被转交人。
//
// - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/task/transfer
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/approvalv4/transfer_task.go
func (t *task) Transfer(ctx context.Context, req *TransferTaskReq, options ...larkcore.RequestOptionFunc) (*TransferTaskResp, error) {
// 发起请求
apiReq := req.apiReq
apiReq.ApiPath = "/open-apis/approval/v4/tasks/transfer"
apiReq.HttpMethod = http.MethodPost
apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant}
apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
if err != nil {
return nil, err
}
// 反序列响应结果
resp := &TransferTaskResp{ApiResp: apiResp}
err = apiResp.JSONUnmarshalBody(resp, t.config)
if err != nil {
return nil, err
}
return resp, err
}