work/oa/vacation.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 97 CC 7 SCAR 20.8
CC
7
Cov
0%
getcorpconf
12.0
getuservacationquota
12.0
setoneuserquota
12.0
CRAP 8.0
1 package QQ::weixin::work::oa::vacation;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::oa::vacation
8
9 =head1 DESCRIPTION
10
11 审批
12
13 =cut
14
15 use strict;
16 use base qw(QQ::weixin::work::oa);
17 use Encode;
18 use LWP::UserAgent;
19 use JSON;
20 use utf8;
21
22 our $VERSION = '0.10';
23 our @EXPORT = qw/ getcorpconf getuservacationquota setoneuserquota /;
24
25 =head1 FUNCTION
26
27 =head2 getcorpconf(access_token, size_type);
28
29 获取企业假期管理配置
30 最后更新:2023/11/30
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/93375>
35
36 =head3 请求说明:
37
38 通过本接口可以获取可见范围内员工的“假期管理”配置,包括:各个假期的id、名称、请假单位、时长计算方式、发放规则等。
39
40 =head4 参数说明:
41
42 参数 必须 说明
43 access_token 是 调用接口凭证
44
45 =head4 权限说明:
46
47 应用类型 权限要求
48 自建应用 配置到「审批 - 可调用接口的应用」中
49 代开发应用 具有「审批」权限
50 第三方应用 具有「审批」权限
51
52 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
53
54 =head3 RETURN 返回结果:
55
56 {
57 "errcode": 0,
58 "errmsg": "ok",
59 "lists": [
60 {
61 "id": 1,
62 "name": "年假",
63 "time_attr": 0,
64 "duration_type": 0,
65 "quota_attr": {
66 "type": 1,
67 "autoreset_time": 1641010352,
68 "autoreset_duration": 432000,
69 "quota_rule_type": 1,
70 "quota_rules": {
71 "list": [
72 {
73 "quota": 432000,
74 "begin": 0,
75 "end": 1
76 },
77 {
78 "quota": 518400,
79 "begin": 1,
80 "end": 2
81 },
82 {
83 "quota": 604800,
84 "begin": 2,
85 "end": 0
86 }
87 ],
88 "based_on_actual_work_time": true
89 },
90 "at_entry_date": true,
91 "auto_reset_month_day": 0
92 },
93 "perday_duration": 86400
94 "is_newovertime": 0,
95 "enter_comp_time_limit": 0,
96 "expire_rule": {
97 "type": 2,
98 "duration": 2,
99 "date": {
100 "month": 0,
101 "day": 0
102 },
103 "extern_duration_enable": false,
104 "extern_duration": {
105 "month": 0,
106 "day": 0
107 }
108 }
109 }
110 ]
111 }
112
113 =head4 RETURN 参数说明:
114
115 参数 类型 说明
116 errcode int32 错误码,详情见错误码说明
117 errmsg string 错误码对应的错误信息提示
118 lists obj[] 假期列表
119 lists.id uint32 假期id
120 lists.name string 假期名称
121 lists.time_attr uint32 假期时间刻度:0-按天请假;1-按小时请假
122 lists.duration_type uint32 时长计算类型:0-自然日;1-工作日
123 lists.quota_attr obj 假期发放相关配置
124 lists.quota_attr.type uint32 假期发放类型:0-不限额;1-自动按年发放;2-手动发放;3-自动按月发放
125 lists.quota_attr.autoreset_time uint32 自动发放时间戳,若假期发放为自动发放,此参数代表自动发放日期。注:返回时间戳的年份是无意义的,请只使用返回时间的月和日;若at_entry_date为true,该字段则无效,假期发放时间为员工入职时间
126 lists.quota_attr.autoreset_duration uint32 自动发放时长,单位为秒。注:只有自动按年发放和自动按月发放时有效,若选择了按照工龄和司龄发放,该字段无效,发放时长请使用区间中的quota
127 lists.quota_attr.quota_rule_type uint32 额度计算类型,自动按年发放时有效,0-固定额度;1-按工龄计算;2-按司龄计算
128 lists.quota_attr.quota_rules obj 额度计算规则,自动按年发放时有效
129 lists.quota_attr.quota_rules.list obj[] 额度计算规则区间,只有在选择了按照工龄计算或者按照司龄计算时有效
130 lists.quota_attr.quota_rules.list.quota uint32 区间发放时长,单位为s
131 lists.quota_attr.quota_rules.list.begin uint32 区间开始点,单位为年
132 lists.quota_attr.quota_rules.list.end uint32 区间结束点,无穷大则为0,单位为年
133 lists.quota_attr.quota_rules.list.based_on_actual_work_time bool 是否根据实际入职时间计算假期,选择后会根据员工在今年的实际工作时间发放假期
134 lists.quota_attr.at_entry_date bool 是否按照入职日期发放假期,只有在自动按年发放类型有效,选择后发放假期的时间会成为员工入职的日期
135 lists.quota_attr.auto_reset_month_day uint32 自动按月发放的发放时间,只有自动按月发放类型有效
136 lists.perday_duration uint32 单位换算值,即1天对应的秒数,可将此值除以3600得到一天对应的小时。
137 lists.is_newovertime uint32 是否关联加班调休,0-不关联,1-关联,关联后改假期类型变为调休假
138 lists.enter_comp_time_limit uint32 入职时间大于n个月可用该假期,单位为月
139 lists.expire_rule obj 假期过期规则
140 lists.expire_rule.type uint32 过期规则类型,1-按固定时间过期,2-从发放日按年过期,3-从发放日按月过期,4-不过期
141 lists.expire_rule.duration uint64 有效期,按年过期为年,按月过期为月,只有在以上两种情况时有效
142 lists.expire_rule.date obj 失效日期,只有按固定时间过期时有效
143 lists.expire_rule.date.month uint32 失效日期所在月份
144 lists.expire_rule.date.day uint32 失效日期所在日
145 lists.expire_rule.extern_duration_enable bool 是否允许延长有效期
146 lists.expire_rule.extern_duration obj 延长有效期的具体时间,只有在extern_duration_enable为true时有效
147 lists.expire_rule.extern_duration.month uint32 延长月数
148 lists.expire_rule.extern_duration.day uint32 延长天数
149
150 接口频率限制 600次/分钟
151
152 =head4 错误说明:
153
154 错误码 说明
155 301062 没有假勤权限
156 301063 参数错误
157 301064 内部错误
158
159 =cut
160
161 sub getcorpconf {
162 if ( @_ && $_[0] ) {
163 my $access_token = $_[0];
164 my $ua = LWP::UserAgent->new;
165 $ua->timeout(30);
166 $ua->env_proxy;
167
168 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/oa/vacation/getcorpconf?access_token=$access_token");
169 if ($response->is_success) {
170 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
171 }
172
173 }
174 return 0;
175 }
176
177 =head2 getuservacationquota(access_token, hash);
178
179 获取成员假期余额
180 最后更新:2023/12/01
181
182 =head2 SYNOPSIS
183
184 L<https://developer.work.weixin.qq.com/document/path/93376>
185
186 =head3 请求说明:
187
188 通过本接口可获取应用可见范围内各个员工的假期余额数据。
189
190 =head4 请求包结构体为:
191
192 {
193 "userid": "ZhangSan"
194 }
195
196 =head4 参数说明:
197
198 参数 必须 类型 说明
199 access_token 是 string 调用接口凭证。必须使用第三方应用accesstoken获取,获取方式参考:文档-获取access_token
200 userid 是 string 需要获取假期余额的成员的userid
201
202 =head3 权限说明
203
204 应用类型 权限要求
205 自建应用 配置到「审批 - 可调用接口的应用」中
206 代开发应用 具有「审批」权限
207 第三方应用 具有「审批」权限
208
209 1.第三方应用可以获取第三方应用添加的模板详情。
210 2.自建应用的Secret可获取企业自建模板的模板详情。
211 3.接口调用频率限制为600次/分钟。
212 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
213
214 =head3 RETURN 返回结果
215
216 {
217 "errcode": 0,
218 "errmsg": "ok",
219 "lists": [
220 {
221 "id": 1,
222 "assignduration": 0,
223 "usedduration": 0,
224 "leftduration": 604800,
225 "vacationname": "年假",
226 "real_assignduration": 0
227 },
228 {
229 "id": 2,
230 "assignduration": 1296000,
231 "usedduration": 0,
232 "leftduration": 1296000,
233 "vacationname": "事假",
234 "real_assignduration": 1296000
235 },
236 {
237 "id": 3,
238 "assignduration": 1296000,
239 "usedduration": 0,
240 "leftduration": 1296000,
241 "vacationname": "病假",
242 "real_assignduration": 86400
243 }
244 ]
245 }
246
247 =head3 RETURN 参数说明
248
249 参数 类型 说明
250 errcode int32 错误码,详情见错误码说明
251 errmsg string 错误码对应的错误信息提示
252 lists obj[] 假期列表
253 lists.id int32 假期id
254 lists.assignduration uint32 发放时长,单位为秒
255 lists.usedduration uint32 使用时长,单位为秒
256 lists.leftduration uint32 剩余时长,单位为秒
257 lists.vacationname string 假期名称
258 lists.real_assignduration uint32 假期的实际发放时长,通常在设置了按照实际工作时间发放假期后进行计算
259
260 接口频率限制 600次/分钟
261 注:余额的时长单位都为秒,如果假期时间刻度为“按天”,需要除以86400,得到真实假期余额天数;如果假期时间刻度为“按小时”,需要除以3600得到真实假期余额小时数。
262
263 =head3 错误说明:
264
265 错误码 说明
266 301062 没有假勤权限
267 301063 参数错误
268 301064 内部错误
269
270 =cut
271
272 sub getuservacationquota {
273 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
274 my $access_token = $_[0];
275 my $json = $_[1];
276 my $ua = LWP::UserAgent->new;
277 $ua->timeout(30);
278 $ua->env_proxy;
279
280 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/vacation/getuservacationquota?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
281 if ($response->is_success) {
282 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
283 }
284
285 }
286 return 0;
287 }
288
289 =head2 setoneuserquota(access_token, hash);
290
291 修改成员假期余额
292 最后更新:2023/11/30
293
294 =head2 SYNOPSIS
295
296 L<https://developer.work.weixin.qq.com/document/path/93377>
297
298 =head3 请求说明:
299
300 通过本接口可以修改可见范围内员工的“假期余额”。
301
302 =head4 请求包结构体为:
303
304 {
305 "userid": "ZhangSan",
306 "vacation_id": 1,
307 "leftduration": 604800,
308 "time_attr": 1,
309 "remarks": "PLACE_HOLDER"
310 }
311
312 =head4 参数说明:
313
314 参数 必须 类型 说明
315 access_token 是 string 调用接口凭证
316 userid 是 string 需要修改假期余额的成员的userid
317 vacation_id 是 uint32 假期id
318 leftduration 是 uint32 设置的假期余额,单位为秒
319 不能大于1000天或24000小时,当假期时间刻度为按小时请假时,必须为360整倍数,即0.1小时整倍数,按天请假时,必须为8640整倍数,即0.1天整倍数
320 time_attr 是 uint32 假期时间刻度:0-按天请假;1-按小时请假
321 主要用于校验,必须等于企业假期管理配置中设置的假期时间刻度类型
322 remarks 否 string 修改备注,用于显示在假期余额的修改记录当中,可对修改行为作说明,不超过200字符
323
324 注:余额的时长单位都为秒,如果假期时间刻度为“按天”,需要除以86400,得到真实假期余额天数;如果假期时间刻度为“按小时”,需要除以3600得到真实假期余额小时数。
325
326 =head3 权限说明
327
328 应用类型 权限要求
329 自建应用 配置到「审批 - 可调用接口的应用」中
330 代开发应用 具有「审批」权限
331 第三方应用 具有「审批」权限
332
333 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
334
335 =head3 RETURN 返回结果
336
337 {
338 "errcode": 0,
339 "errmsg": "ok"
340 }
341
342 =head3 RETURN 参数说明
343
344 参数 类型 说明
345 errcode int32 返回码
346 errmsg string 错误码描述
347
348 接口频率限制 600次/分钟
349
350 =head3 错误说明:
351
352 错误码 说明
353 301062 没有假勤权限
354 301063 参数错误
355 301064 内部错误
356 301098 成员不在假期的适用范围内
357
358 =cut
359
360 sub setoneuserquota {
361 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
362 my $access_token = $_[0];
363 my $json = $_[1];
364 my $ua = LWP::UserAgent->new;
365 $ua->timeout(30);
366 $ua->env_proxy;
367
368 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/vacation/setoneuserquota?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
369 if ($response->is_success) {
370 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
371 }
372
373 }
374 return 0;
375 }
376
377 1;
378 __END__