work/oa/journal.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 127 CC 9 SCAR 21.6
CC
9
Cov
0%
get_record_list
12.0
get_record_detail
12.0
get_stat_list
12.0
CRAP 8.7
1 package QQ::weixin::work::oa::journal;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::oa::journal
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/ get_record_list get_record_detail get_stat_list
24 download_wedrive_file /;
25
26 =head1 FUNCTION
27
28 =head2 get_record_list(access_token, hash);
29
30 批量获取汇报记录单号
31 最后更新:2023/11/30
32
33 =head2 SYNOPSIS
34
35 L<https://developer.work.weixin.qq.com/document/path/93393>
36
37 =head3 请求说明:
38
39 企业可通过本接口获取企业一段时间内企业微信“汇报应用”汇报记录编号,支持按汇报表单ID、申请人、部门等条件筛选。
40
41 一次拉取调用最多拉取100个汇报记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
42
43 表单ID的获取方式:
44 管理后台--汇报应用--某个汇报的内容设置页--点击“汇报名称”,即可获取
45
46 =head4 请求包结构体为:
47
48 {
49 "starttime": 1606230000,
50 "endtime": 1606361304,
51 "cursor": 0,
52 "limit": 10,
53 "filters": [
54 {
55 "key": "creator",
56 "value": "kele"
57 },
58 {
59 "key": "department",
60 "value": "1"
61 },
62 {
63 "key": "template_id",
64 "value": "3TmALk1ogfgKiQE3e3jRwnTUhMTh8vca1N8zUVNUx"
65 }
66 ]
67 }
68
69 =head4 参数说明:
70
71 参数 必须 类型 说明
72 access_token 是 string 调用接口凭证
73 starttime 是 uint32 开始时间
74 endtime 是 uint32 结束时间,开始时间和结束时间间隔不能超过一个月
75 cursor 是 uint32 游标首次请求传0,非首次请求携带上一次请求返回的next_cursor
76 limit 是 uint32 拉取条数
77 filters 否 obj[] 过滤条件
78 filters.key 否 string -
79 不多于256字节,creator指定汇报记录提单人;department指定提单人所在部门;template_id指定模板
80 filters.value 否 string -
81 不多于256字节
82
83 =head3 权限说明
84
85 应用类型 权限要求
86 自建应用 需要配置到「汇报 - 可调用接口的应用」中
87 代开发应用 暂不支持
88 第三方应用 暂不支持
89
90 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
91
92 =head3 RETURN 返回结果
93
94 {
95 "errcode": 0,
96 "errmsg": "ok",
97 "journaluuid_list": [
98 "41eJejN57EJNzr8HrZfmKyCN7xwKw1qRxCZUxCVuo9fsWVMSKac6nk4q8rARTDaVNdg",
99 "41eJejN57EJNzr8HrZfmKy7rmnZS5HGzpqUefyqCRhjdY9GWQQ6gcaNfaW6GPAdG5cg",
100 "41eJejN57EJNzr8HrZfmKy2mkwnjMJPgE6UZfqnW5qMeZ1ag3qr1Amb98DbtVH89VJx",
101 "41eJejN57EJNzr8HrZfmKyGXVp9cRByeSREpFtReMKpuAPYZYiCU4em8JKJNmCBYmxg",
102 "41eJejN57EJNzr8HrZfmKy3NphvW9E8bYRTAMWcwo9oPhVEFv9cE2jUry8ZNsZYjuUx",
103 "41eJejN57EJNzr8HrZfmKyDqJCnct6mYayM4tiEXGmoYmfUp1nDdNQSyxemtBHZa3ss",
104 "41eJejN57EJNzr8HrZfmKyHr64ZdZa6JHYztDaS6hCmPMKtBN3YvD1FSFmauNU36Wxd",
105 "41eJejN57EJNzr8HrZfmKyChHx58aDhGrvN7yKywBJs33yzUyqUF11sdBFcUBou2NQx",
106 "41eJejN57EJNzr8HrZfmKy4w4AtPJyxQoGWmv7hnrZYwmdWVJQEhvgxT5mjEbC1xP43",
107 "41eJejN57EJNzr8HrZfmKyFcSr1RLmAoBS7fnwiFcQJuVQfYZwcork67DZ36YFijmR2"
108 ],
109 "next_cursor": 34,
110 "endflag": 0
111 }
112
113 =head3 RETURN 参数说明
114
115 参数 类型 说明
116 errcode int32 返回码
117 errmsg string 错误码描述
118 journaluuid_list string[] 汇报记录id列表
119 next_cursor uint32 下一次拉取游标
120 endflag uint32 0代表还有数据,1代表已无数据
121
122 =head3 错误说明:
123
124 错误码 说明
125 301065 无汇报应用数据拉取权限
126 301066 请求参数错误
127 301067 接口内部失败
128
129 =cut
130
131 sub get_record_list {
132 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
133 my $access_token = $_[0];
134 my $json = $_[1];
135 my $ua = LWP::UserAgent->new;
136 $ua->timeout(30);
137 $ua->env_proxy;
138
139 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
140 if ($response->is_success) {
141 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
142 }
143
144 }
145 return 0;
146 }
147
148 =head2 get_record_detail(access_token, hash);
149
150 获取汇报记录详情
151 最后更新:2023/11/30
152
153 =head2 SYNOPSIS
154
155 L<https://developer.work.weixin.qq.com/document/path/93394>
156
157 =head3 请求说明:
158
159 根据汇报记录单号查询企业微信“汇报应用”的汇报详情。
160
161 =head4 请求包结构体为:
162
163 {
164 "journaluuid": "41eJejN57EJNzr8HrZfmKyCN7xwKw1qRxCZUxCVuo9fsWVMSKac6nk4q8rARTDaVNdx"
165 }
166
167 =head4 参数说明:
168
169 参数 必须 类型 说明
170 access_token 是 string 调用接口凭证
171 journaluuid 是 string -不多于256字节
172
173 =head3 权限说明
174
175 应用类型 权限要求
176 自建应用 需要配置到「汇报 - 可调用接口的应用」中
177 代开发应用 暂不支持
178 第三方应用 暂不支持
179
180 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
181
182 =head3 RETURN 返回结果
183
184 {
185 "errcode": 0,
186 "errmsg": "ok",
187 "info": {
188 "journal_uuid": "41eJejN57EJNzr8HrZfmKyJZ6E3W9NQbr94x6QEA6MwvK2sVqFQNWy4BaF4Ptyzk26",
189 "template_name": "今日工作汇报",
190 "report_time": 1606365591,
191 "submitter": {
192 "userid": "LiQiJun"
193 },
194 "receivers": [
195 {
196 "userid": "LiQiJun"
197 }
198 ],
199 "readed_receivers": [
200 {
201 "userid": "LiQiJun"
202 }
203 ],
204 "apply_data": {
205 "contents": [
206 {
207 "control": "Text",
208 "id": "Text-1606365477123",
209 "title": [
210 {
211 "text": "工作内容"
212 }
213 ],
214 "value": {
215 "text": "今日暂无工作",
216 "tips": [],
217 "members": [],
218 "departments": [],
219 "files": [],
220 "children": [],
221 "stat_field": [],
222 "sum_field": [],
223 "related_approval": [],
224 "students": [],
225 "classes": []
226 }
227 }
228 ]
229 },
230 "comments": [
231 {
232 "commentid": 6899287783354824502,
233 "tocommentid": 0,
234 "comment_userinfo": {
235 "userid": "LiYiBo"
236 },
237 "content": "加油",
238 "comment_time": 1606365615
239 }
240 ]
241 }
242 }
243
244 =head3 RETURN 参数说明
245
246 参数 类型 说明
247 errcode int32 返回码
248 errmsg string 错误码描述
249 info obj 汇报详情
250 info.journal_uuid string 汇报记录id
251 info.template_name string 汇报表单名称
252 info.template_id string 汇报表单id
253 info.report_time int32 汇报时间
254 info.submitter obj 汇报提交者
255 info.submitter.userid string 汇报用户id
256 info.receivers obj[] 汇报接收对象
257 info.receivers.userid string 接收用户id
258 info.readed_receivers obj[] 已读用户
259 info.readed_receivers.userid string 已读用户id
260 info.apply_data obj 表单数据
261 info.apply_data.contents obj[] 表单字段列表
262 info.apply_data.contents.control string 控件类型:Text-文本;Textarea-多行文本;Number-数字;Money-金额;Date-日期/日期+时间;Selector-单选/多选;;Contact-成员/部门;Tips-说明文字;File-附件;Table-明细;DateRange-时长;Doc-文档;WedriveFile-微盘附件
263 info.apply_data.contents.id string 控件id
264 info.apply_data.contents.title obj 控件名称 ,若配置了多语言则会包含中英文的控件名称
265 info.apply_data.contents.value obj 控件值 ,包含了申请人在各种类型控件中输入的值,不同控件有不同的值,具体说明详见附录
266 info.sys_journal_data string “汇报”模板数据,内容为富文本。“汇报”模板是一个特殊模板其表单不在apply_data中返回
267 info.comments obj[] 评论
268 info.comments.commentid uint64 评论id
269 info.comments.tocommentid uint64 评论回复id
270 info.comments.comment_userinfo obj 评论用户
271 info.comments.comment_userinfo.userid string 评论用户id
272 info.comments.content string 评论内容
273 info.comments.comment_time uint32 评论时间
274
275 =head3 附录:各控件apply_data/contents/value参数介绍
276
277 L<https://developer.work.weixin.qq.com/document/path/93394#附录:各控件apply-datacontentsvalue参数介绍>
278
279 =head3 错误说明:
280
281 错误码 说明
282 301065 无汇报应用数据拉取权限
283 301066 请求参数错误
284 301067 接口内部失败
285
286 =cut
287
288 sub get_record_detail {
289 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
290 my $access_token = $_[0];
291 my $json = $_[1];
292 my $ua = LWP::UserAgent->new;
293 $ua->timeout(30);
294 $ua->env_proxy;
295
296 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_detail?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
297 if ($response->is_success) {
298 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
299 }
300
301 }
302 return 0;
303 }
304
305 =head2 get_stat_list(access_token, hash);
306
307 获取汇报统计数据
308 最后更新:2023/11/30
309
310 =head2 SYNOPSIS
311
312 L<https://developer.work.weixin.qq.com/document/path/93395>
313
314 =head3 请求说明:
315
316 企业可通过调用本接口,根据汇报表单id查询企业微信“汇报应用”的汇报统计汇总信息。该接口只能拉取到已经汇总的统计数据,对于尚未完成汇总的周期不会返回。
317
318 =head4 请求包结构体为:
319
320 {
321 "template_id": "3TmALk1ogfgKiQE3e3jRwnTUhMTh8vca1N8zUVNUx",
322 "starttime": 1604160000,
323 "endtime": 1606363092
324 }
325
326 =head4 参数说明:
327
328 参数 必须 类型 说明
329 access_token 是 string 调用接口凭证
330 template_id 是 string 汇报表单id,不多于256字节
331 starttime 是 uint64 开始时间
332 endtime 是 uint64 结束时间,时间区间最大长度为一年
333
334 =head3 权限说明
335
336 应用类型 权限要求
337 自建应用 需要配置到「汇报 - 可调用接口的应用」中
338 代开发应用 暂不支持
339 第三方应用 暂不支持
340
341 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
342
343 =head3 RETURN 返回结果
344
345 {
346 "errcode": 0,
347 "errmsg": "ok",
348 "stat_list": [
349 {
350 "template_id": "3TmALk1ogfgKiQE3e3jRwnTUhMTh8vca1N8zUVNU",
351 "template_name": "日报",
352 "report_range": {
353 "user_list": [
354 {
355 "userid": "user1"
356 }
357 ],
358 "party_list": [
359 {
360 "open_partyid": "1"
361 }
362 ],
363 "tag_list": []
364 },
365 "white_range": {
366 "user_list": [],
367 "party_list": [],
368 "tag_list": []
369 },
370 "receivers": {
371 "user_list": [
372 {
373 "userid": "user3"
374 }
375 ],
376 "tag_list": [],
377 "leader_list": []
378 },
379 "cycle_begin_time": 1606147200,
380 "cycle_end_time": 1606233600,
381 "stat_begin_time": 1606147200,
382 "stat_end_time": 1606230000,
383 "report_list": [
384 {
385 "user": {
386 "userid": "user2"
387 },
388 "itemlist": [
389 {
390 "journaluuid": "4U9abSUrpY78VNxeNNv3J5TW5e9VLj8cDymH9py1Efpuj5X8QCDQx3stKr69pia3UL8auRjrCMsiRjgzL8mvKnff",
391 "reporttime": 1606218548,
392 "flag": 0
393 }
394 ]
395 }
396 ],
397 "unreport_list": [
398 {
399 "user": {
400 "userid": "user1"
401 },
402 "itemlist": [
403 {
404 "journaluuid": "",
405 "reporttime": 1606147200,
406 "flag": 0
407 }
408 ]
409 },
410 {
411 "user": {
412 "userid": "user3"
413 },
414 "itemlist": [
415 {
416 "journaluuid": "",
417 "reporttime": 1606147200,
418 "flag": 0
419 }
420 ]
421 }
422 ],
423 "report_type": 2
424 }
425 ]
426 }
427
428 =head3 RETURN 参数说明
429
430 参数 类型 说明
431 errcode int32 返回码
432 errmsg string 错误码描述
433 stat_list obj[] 统计数据列表
434 stat_list.template_id string 汇报表单id
435 stat_list.template_name string 汇报表单名称
436 stat_list.report_range obj 汇报人员范围
437 stat_list.report_range.user_list obj[] 指定人集合
438 stat_list.report_range.user_list.userid string 用户id
439 stat_list.report_range.party_list obj[] 指定部门集合
440 stat_list.report_range.party_list.open_partyid string 部门id
441 stat_list.report_range.tag_list obj[] 指定标签集合
442 stat_list.report_range.tag_list.open_tagid string 标签id
443 stat_list.white_range obj 白名单集合
444 stat_list.white_range.user_list obj[] 指定人集合
445 stat_list.white_range.user_list.userid string 用户id
446 stat_list.white_range.party_list obj[] 指定部门集合
447 stat_list.white_range.party_list.open_partyid string 部门id
448 stat_list.white_range.tag_list obj[] 指定标签集合
449 stat_list.white_range.tag_list.open_tagid string 标签id
450 stat_list.receivers obj 固定汇报对象
451 stat_list.receivers.user_list obj[] 指定人集合
452 stat_list.receivers.user_list.userid string 用户id
453 stat_list.receivers.tag_list obj[] 指定标签集合
454 stat_list.receivers.tag_list.open_tagid string 标签id
455 stat_list.receivers.leader_list obj[] 指定上级集合
456 stat_list.receivers.leader_list.level uint64 上级级别从1开始
457 stat_list.cycle_begin_time uint64 周期开始时间
458 stat_list.cycle_end_time uint64 周期结束时间
459 stat_list.stat_begin_time uint64 统计开始时间
460 stat_list.stat_end_time uint64 统计结束时间
461 stat_list.report_list obj[] 已汇报用户列表
462 stat_list.report_list.user obj 汇报用户
463 stat_list.report_list.user.userid string 用户id
464 stat_list.report_list.itemlist obj[] 汇报记录列表
465 stat_list.report_list.itemlist.journaluuid string 汇报记录id
466 stat_list.report_list.itemlist.reporttime uint32 汇报时间
467 stat_list.report_list.itemlist.flag uint32 是否迟交,1迟交;0非迟交
468 stat_list.unreport_list obj[] 未汇报用户列表
469 stat_list.unreport_list.user obj 未汇报用户
470 stat_list.unreport_list.user.userid string 用户id
471 stat_list.report_type uint32 汇报方式:2按日汇报; 3按周汇报; 4按月汇报
472
473 =head3 错误说明:
474
475 错误码 说明
476 301065 无汇报应用数据拉取权限
477 301066 请求参数错误
478 301067 接口内部失败
479
480 =cut
481
482 sub get_stat_list {
483 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
484 my $access_token = $_[0];
485 my $json = $_[1];
486 my $ua = LWP::UserAgent->new;
487 $ua->timeout(30);
488 $ua->env_proxy;
489
490 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_stat_list?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
491 if ($response->is_success) {
492 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
493 }
494
495 }
496 return 0;
497 }
498
499 =head2 download_wedrive_file(access_token, hash);
500
501 下载微盘文件
502 最后更新:2023/11/30
503
504 =head2 SYNOPSIS
505
506 L<https://developer.work.weixin.qq.com/document/path/98021>
507
508 =head3 请求说明:
509
510 该接口仅可用于下载汇报中关联的微盘文件。
511
512 =head4 请求包结构体为:
513
514 {
515 "journaluuid": "JOURNAL_UUID",
516 "fileid": "FILEID"
517 }
518
519 =head4 参数说明:
520
521 参数 必须 类型 说明
522 access_token 是 string 调用接口凭证
523 journaluuid string 是 汇报记录id
524 fileid string 是 微盘fileid。获取汇报记录详情返回的微盘附件fileid。必须是journaluuid对应的汇报关联的wedrive_files。
525
526 =head3 权限说明
527
528 应用类型 权限要求
529 自建应用 需要配置到「汇报 - 可调用接口的应用」中
530 代开发应用 暂不支持
531 第三方应用 暂不支持
532
533 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
534
535 =head3 RETURN 返回结果
536
537 {
538 "errcode": 0,
539 "errmsg": "ok",
540 "download_url": "DOWNLOAD_URL",
541 "cookie_name": "COOKIE_NAME",
542 "cookie_value": "COOKIE_VALUE"
543 }
544
545 =head3 RETURN 参数说明
546
547 参数 类型 说明
548 errcode int32 返回码
549 errmsg string 错误码描述
550 download_url string 下载请求url (有效期2个小时)
551 cookie_name string 下载请求带cookie的key
552 cookie_value string 下载请求带cookie的value
553
554 =cut
555
556 sub download_wedrive_file {
557 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
558 my $access_token = $_[0];
559 my $json = $_[1];
560 my $ua = LWP::UserAgent->new;
561 $ua->timeout(30);
562 $ua->env_proxy;
563
564 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/oa/journal/download_wedrive_file?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
565 if ($response->is_success) {
566 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
567 }
568
569 }
570 return 0;
571 }
572
573 1;
574 __END__