-
Notifications
You must be signed in to change notification settings - Fork 151
/
client.go
284 lines (203 loc) · 9.38 KB
/
client.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
package oa
import (
"context"
"fmt"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/power"
response2 "github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/response"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/request"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/oa/response"
)
type Client struct {
BaseClient *kernel.BaseClient
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 获取企业所有打卡规则
// https://developer.work.weixin.qq.com/document/path/93384
func (comp *Client) GetCorpCheckInOption(ctx context.Context) (*response.ResponseCorpCheckInRules, error) {
result := &response.ResponseCorpCheckInRules{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/getcorpcheckinoption", nil, nil, nil, result)
return result, err
}
// 获取员工打卡规则
// https://developer.work.weixin.qq.com/document/path/90263
func (comp *Client) GetCheckInOption(ctx context.Context, datetime int, userList []string) (*response.ResponseCheckInRules, error) {
result := &response.ResponseCheckInRules{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/getcheckinoption", &object.HashMap{
"datetime": fmt.Sprintf("%d", datetime),
"useridlist": userList,
}, nil, nil, result)
return result, err
}
// 获取打卡记录数据
// https://developer.work.weixin.qq.com/document/path/90262
func (comp *Client) GetCheckinData(ctx context.Context, recordType int, startTime int, endTime int, userList []string) (*response.ResponseCheckInRecords, error) {
result := &response.ResponseCheckInRecords{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/getcheckindata", &object.HashMap{
"opencheckindatatype": fmt.Sprintf("%d", recordType),
"starttime": fmt.Sprintf("%d", startTime),
"endtime": fmt.Sprintf("%d", endTime),
"useridlist": userList,
}, nil, nil, result)
return result, err
}
// 获取打卡日报数据
// https://developer.work.weixin.qq.com/document/path/93374
func (comp *Client) GetCheckinDayData(ctx context.Context, startTime int, endTime int, userIDs []string) (*response.ResponseCheckInDatas, error) {
result := &response.ResponseCheckInDatas{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/getcheckin_daydata", &object.HashMap{
"starttime": fmt.Sprintf("%d", startTime),
"endtime": fmt.Sprintf("%d", endTime),
"useridlist": userIDs,
}, nil, nil, result)
return result, err
}
// 获取打卡月报数据
// https://developer.work.weixin.qq.com/document/path/93387
func (comp *Client) GetCheckInMonthData(ctx context.Context, startTime int, endTime int, userIDs []string) (*response.ResponseCheckInDatas, error) {
result := &response.ResponseCheckInDatas{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/getcheckin_monthdata", &object.HashMap{
"starttime": fmt.Sprintf("%d", startTime),
"endtime": fmt.Sprintf("%d", endTime),
"useridlist": userIDs,
}, nil, nil, result)
return result, err
}
// 获取打卡人员排班信息
// https://developer.work.weixin.qq.com/document/path/93380
func (comp *Client) GetCheckInScheduleList(ctx context.Context, startTime int, endTime int, userIDs []string) (*response.ResponseCheckInSchedulist, error) {
result := &response.ResponseCheckInSchedulist{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/getcheckinschedulist", &object.HashMap{
"starttime": fmt.Sprintf("%d", startTime),
"endtime": fmt.Sprintf("%d", endTime),
"useridlist": userIDs,
}, nil, nil, result)
return result, err
}
// 为打卡人员排班
// https://developer.work.weixin.qq.com/document/path/93385
func (comp *Client) SetCheckInScheduleList(ctx context.Context, options *request.RequestCheckInSetScheduleList) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/setcheckinschedulist", options, nil, nil, result)
return result, err
}
// 录入打卡人员人脸信息
// https://developer.work.weixin.qq.com/document/path/93378
func (comp *Client) AddCheckInUserFace(ctx context.Context, userID string, userFace string) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/addcheckinuserface", &object.HashMap{
"userID": userID,
"userface": userFace,
}, nil, nil, result)
return result, err
}
// 创建打卡规则
// https://developer.work.weixin.qq.com/document/path/98041#创建打卡规则
func (comp *Client) AddCheckinOption(ctx context.Context, data *object.HashMap) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/add_checkin_option", data, nil, nil, result)
return result, err
}
// 修改打卡规则
// https://developer.work.weixin.qq.com/document/path/98041#修改打卡规则
func (comp *Client) UpdateCheckinOption(ctx context.Context, data *object.HashMap) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/update_checkin_option", data, nil, nil, result)
return result, err
}
// 删除打卡规则
// https://developer.work.weixin.qq.com/document/path/98041#删除打卡规则
func (comp *Client) DelCheckinOption(ctx context.Context, groupId int, effectiveNow bool) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/checkin/del_checkin_option", &object.HashMap{
"groupid": groupId,
"effective_now": effectiveNow,
}, nil, nil, result)
return result, err
}
// 获取审批模板详情
// https://developer.work.weixin.qq.com/document/path/91982
func (comp *Client) ApprovalTemplate(ctx context.Context, templateID string) (*response.ResponseApprovalTemplate, error) {
result := &response.ResponseApprovalTemplate{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/gettemplatedetail", &object.HashMap{
"template_id": templateID,
}, nil, nil, result)
return result, err
}
// 提交审批申请
// https://developer.work.weixin.qq.com/document/path/91853
func (comp *Client) CreateApproval(ctx context.Context, data *power.HashMap) (*response.ResponseApprovalCreate, error) {
result := &response.ResponseApprovalCreate{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/applyevent", data, nil, nil, result)
return result, err
}
// 批量获取审批单号
// https://developer.work.weixin.qq.com/document/path/91816
func (comp *Client) GetApprovalInfo(ctx context.Context, startTime int, endTime int, nextCursor int, size int, filters *object.HashMap) (*response.ResponseApprovalNoList, error) {
result := &response.ResponseApprovalNoList{}
if size > 100 {
size = 100
}
options := &object.HashMap{
"starttime": fmt.Sprintf("%d", startTime),
"endtime": fmt.Sprintf("%d", endTime),
"cursor": fmt.Sprintf("%d", nextCursor),
"size": size,
"filters": filters,
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/getapprovalinfo", options, nil, nil, result)
return result, err
}
// 获取审批申请详情
// https://developer.work.weixin.qq.com/document/path/91983
func (comp *Client) GetApprovalDetail(ctx context.Context, number int) (*response.ResponseApprovalDetail, error) {
result := &response.ResponseApprovalDetail{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/getapprovaldetail", &object.HashMap{
"sp_no": fmt.Sprintf("%d", number),
}, nil, nil, result)
return result, err
}
// 获取审批数据(旧)
// https://developer.work.weixin.qq.com/document/path/91530
func (comp *Client) GetApprovalData(ctx context.Context, startTime int, endTime int, nextNumber int) (*response.ResponseApprovalGetData, error) {
result := &response.ResponseApprovalGetData{}
options := &object.HashMap{
"starttime": fmt.Sprintf("%d", startTime),
"endtime": fmt.Sprintf("%d", endTime),
"next_spnum": fmt.Sprintf("%d", nextNumber),
}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/corp/getapprovaldata", options, nil, nil, result)
return result, err
}
// 获取企业假期管理配置
// https://developer.work.weixin.qq.com/document/path/93375
func (comp *Client) GetCorpConfig(ctx context.Context) (*response.ResponseCorpVacationGetConfig, error) {
result := &response.ResponseCorpVacationGetConfig{}
_, err := comp.BaseClient.HttpGet(ctx, "cgi-bin/oa/vacation/getcorpconf", nil, nil, result)
return result, err
}
// 获取成员假期余额
// https://developer.work.weixin.qq.com/document/path/93376
func (comp *Client) GetUserVacationQuota(ctx context.Context, userID string) (*response.ResponseCorpVacationGetQuota, error) {
result := &response.ResponseCorpVacationGetQuota{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/vacation/getuservacationquota", &object.HashMap{
"userid": userID,
}, nil, nil, result)
return result, err
}
// 修改成员假期余额
// https://developer.work.weixin.qq.com/document/path/94213
func (comp *Client) SetOneUserQuota(ctx context.Context, data *object.HashMap) (*response2.ResponseWork, error) {
result := &response2.ResponseWork{}
_, err := comp.BaseClient.HttpPostJson(ctx, "cgi-bin/oa/vacation/setoneuserquota", data, nil, nil, result)
return result, err
}