-
Notifications
You must be signed in to change notification settings - Fork 14
/
edu_parent.go
142 lines (131 loc) · 4.24 KB
/
edu_parent.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
package wework
import (
"fmt"
"github.com/go-laoji/wecom-go-sdk/v2/internal"
"strings"
)
type Parent struct {
ParentUserId string `json:"parent_userid" validate:"required"`
NewParentUserId string `json:"new_parent_userid,omitempty"`
Mobile string `json:"mobile,omitempty" validate:"required"`
ToInvite bool `json:"to_invite,omitempty"`
Children []struct {
StudentUserId string `json:"student_userid"`
Relation string `json:"relation"`
} `json:"children,omitempty" validate:"required,max=10"`
}
// CreateParent 创建家长
// https://open.work.weixin.qq.com/api/doc/90001/90143/92077
func (ww *weWork) CreateParent(corpId uint, parent Parent) (resp internal.BizResponse) {
if ok := validate.Struct(parent); ok != nil {
resp.ErrCode = 500
resp.ErrorMsg = ok.Error()
return
}
_, err := ww.getRequest(corpId).SetBody(parent).SetResult(&resp).
Post("/cgi-bin/school/user/create_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type BatchParentResponse struct {
internal.BizResponse
ResultList []struct {
ParentUserId string `json:"parent_userid"`
internal.BizResponse
} `json:"result_list"`
}
// BatchCreateParent 批量创建家长
// https://open.work.weixin.qq.com/api/doc/90001/90143/92078
func (ww *weWork) BatchCreateParent(corpId uint, parents []Parent) (resp BatchParentResponse) {
h := H{}
h["parents"] = parents
_, err := ww.getRequest(corpId).SetBody(h).SetResult(&resp).
Post("/cgi-bin/school/user/batch_create_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
// DeleteParent 删除家长
// https://open.work.weixin.qq.com/api/doc/90001/90143/92079
func (ww *weWork) DeleteParent(corpId uint, userId string) (resp internal.BizResponse) {
_, err := ww.getRequest(corpId).SetResult(&resp).SetQueryParam("userid", userId).
Get("/cgi-bin/school/user/delete_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
// BatchDeleteParent 批量删除家长
// https://open.work.weixin.qq.com/api/doc/90001/90143/92080
func (ww *weWork) BatchDeleteParent(corpId uint, userIdList []string) (resp BatchParentResponse) {
h := H{}
h["useridlist"] = userIdList
_, err := ww.getRequest(corpId).SetBody(h).SetResult(&resp).
Post("/cgi-bin/school/user/batch_delete_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
// UpdateParent 更新家长
// https://open.work.weixin.qq.com/api/doc/90001/90143/92081
func (ww *weWork) UpdateParent(corpId uint, parent Parent) (resp internal.BizResponse) {
if strings.TrimSpace(parent.ParentUserId) == "" {
resp.ErrCode = 500
resp.ErrorMsg = "parent userid can not be empty"
return
}
_, err := ww.getRequest(corpId).SetBody(parent).SetResult(&resp).
Post("/cgi-bin/school/user/update_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
// BatchUpdateParent 批量更新家长
// https://open.work.weixin.qq.com/api/doc/90001/90143/92082
func (ww *weWork) BatchUpdateParent(corpId uint, parents []Parent) (resp BatchParentResponse) {
h := H{}
h["parents"] = parents
_, err := ww.getRequest(corpId).SetBody(h).SetResult(&resp).
Post("/cgi-bin/school/user/batch_update_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}
type ListParentWithDepartmentIdResponse struct {
internal.BizResponse
Parents []struct {
ParentUserid string `json:"parent_userid"`
Mobile string `json:"mobile"`
IsSubscribe int `json:"is_subscribe"`
ExternalUserid string `json:"external_userid,omitempty"`
Children []struct {
StudentUserid string `json:"student_userid"`
Relation string `json:"relation"`
Name string `json:"name"`
} `json:"children"`
} `json:"parents"`
}
// ListParentWithDepartmentId 获取部门家长详情
// https://open.work.weixin.qq.com/api/doc/90001/90143/92627
func (ww *weWork) ListParentWithDepartmentId(corpId uint, departmentId int32) (resp ListParentWithDepartmentIdResponse) {
_, err := ww.getRequest(corpId).SetResult(&resp).
SetQueryParam("department_id", fmt.Sprintf("%v", departmentId)).
Get("/cgi-bin/school/user/list_parent")
if err != nil {
resp.ErrCode = 500
resp.ErrorMsg = err.Error()
}
return
}