-
Notifications
You must be signed in to change notification settings - Fork 10
/
api_dept_caller.go
105 lines (93 loc) · 2.71 KB
/
api_dept_caller.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
package sdk
import (
"github.com/polaris-team/dingtalk-sdk-golang/http"
"github.com/polaris-team/dingtalk-sdk-golang/json"
)
//获取子部门ID列表
//https://open-doc.dingtalk.com/microapp/serverapi3/fuqv8x#hvdqc
func (client *DingTalkClient) GetSubDept(id string) (GetSubdeptResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"id": id,
}
body, err := http.Get("https://oapi.dingtalk.com/department/list_ids", params)
resp := GetSubdeptResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//获取部门列表
//https://open-doc.dingtalk.com/microapp/serverapi3/fuqv8x#-1
func (client *DingTalkClient) GetDeptList(lang *string, fetchChild bool, id string) (GetDeptListResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
}
if id != "" {
params["id"] = id
}
if lang != nil {
params["lang"] = *lang
}
if fetchChild {
params["fetch_child"] = "true"
} else {
params["fetch_child"] = "false"
}
body, err := http.Get("https://oapi.dingtalk.com/department/list", params)
resp := GetDeptListResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//获取部门详情
//https://open-doc.dingtalk.com/microapp/serverapi3/fuqv8x#-2
func (client *DingTalkClient) GetDeptDetail(id string, lang *string) (GetDeptDetailResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"id": id,
}
if lang != nil {
params["lang"] = *lang
}
body, err := http.Get("https://oapi.dingtalk.com/department/get", params)
resp := GetDeptDetailResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//查询部门的所有上级父部门路径
//https://open-doc.dingtalk.com/microapp/serverapi3/fuqv8x#-3
func (client *DingTalkClient) ListParentDeptsByDept(id string) (ListParentDeptsByDeptResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"id": id,
}
body, err := http.Get("https://oapi.dingtalk.com/department/list_parent_depts_by_dept", params)
resp := ListParentDeptsByDeptResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//查询指定用户的所有上级父部门路径
//https://open-doc.dingtalk.com/microapp/serverapi3/fuqv8x#-4
func (client *DingTalkClient) ListParentDepts(userId string) (ListParentDeptsResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"userId": userId,
}
body, err := http.Get("https://oapi.dingtalk.com/department/list_parent_depts", params)
resp := ListParentDeptsResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}