第一步、获取汇报记录单号

参考:https://developer.work.weixin.qq.com/document/path/93393
请求方式:POST(HTTPS)
请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_list?access_token=ACCESS_TOKEN

注意:

  1. 查询条件filters里条件不是必须的,
  2. creator指定汇报记录提单人的用户id
  3. department指定提单人所在部门的id(不支持多选查询)
  4. 一次查询多少条数据限制是limit,这个地方和审核不一样,审核是size,要注意下。

    第二步、根据单号获取汇报记录详情

    参考:https://developer.work.weixin.qq.com/document/path/93394
    请求方式:POST(HTTPS)
    请求地址:https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_detail?access_token=ACCESS_TOKEN
    请求示例
    1. {
    2. "journaluuid": "41eJejN57EJNzr8HrZfmKyCN7xwKw1qRxCZUxCVuo9fsWVMSKac6nk4q8rARTDaVNdx"
    3. }

    JAVA程序

    ```java package com.tj.qywx.service.impl;

import com.alibaba.excel.util.ListUtils; import com.alibaba.excel.util.MapUtils; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.tj.base.service.BaseNumvarService; import com.tj.qywx.domain.WxApproval; import com.tj.qywx.domain.WxRecord; import com.tj.qywx.domain.WxUserlist; import com.tj.qywx.service.WxApprovalService; import com.tj.qywx.service.WxDepartmentService; import com.tj.qywx.service.WxRecordService; import com.tj.qywx.service.WxUserlistService; import com.tj.utils.TjDateUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate;

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;

@Slf4j @Service public class WxRecordServiceImpl implements WxRecordService { @Autowired private BaseNumvarService baseNumvarService; @Autowired private RestTemplate restTemplate; @Autowired private WxUserlistService wxUserlistService;

  1. @Override
  2. public Map<String, Object> show(Integer pagenum,
  3. Integer pagesize,
  4. Long starttime,
  5. Long endtime,
  6. String creator,
  7. String template_id,
  8. String deptid) {
  9. if (starttime == null) {
  10. //参数:开始时间戳(秒)//30天前0:0:0的时间戳(秒)
  11. starttime = TjDateUtils.chooseDay(TjDateUtils.getTodayBegin(), -30).getTime() / 1000;
  12. }
  13. if (endtime == null) {
  14. //参数:结束时间戳,当前时间的时间戳(秒)
  15. endtime = System.currentTimeMillis() / 1000;
  16. }
  17. String token = baseNumvarService.getAccessTokenBySecret(baseNumvarService.getSecretRecord());
  18. String url = "https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_list?access_token=" + token;
  19. //请求体数据,使用hashmap封装
  20. HashMap<String, Object> hashMap = MapUtils.newHashMap();
  21. hashMap.put("starttime", starttime);
  22. hashMap.put("endtime", endtime);
  23. hashMap.put("cursor", (pagenum - 1) * pagesize + 1);
  24. hashMap.put("limit", pagesize);
  25. //其他条件
  26. ArrayList<Map> otherList = ListUtils.newArrayList();
  27. otherList.clear();
  28. //判断用户姓名条件
  29. if (creator != null) {
  30. LambdaQueryWrapper<WxUserlist> lqwUser = new LambdaQueryWrapper<>();
  31. lqwUser.eq(WxUserlist::getName, creator).last("LIMIT 1");//只取1条记录
  32. WxUserlist one = wxUserlistService.getOne(lqwUser);
  33. if (one != null) {
  34. otherListAdd("creator", one.getUserid(), otherList);
  35. }
  36. }
  37. //判断指定模板
  38. if (StringUtils.isNotEmpty(template_id)) {
  39. otherListAdd("template_id", template_id, otherList);
  40. }
  41. //部门条件判断
  42. if (StringUtils.isNotEmpty(deptid)) {
  43. otherListAdd("department", deptid, otherList);
  44. }
  45. //判断filters里的查询条件
  46. if (otherList != null && otherList.size() > 0) {
  47. hashMap.put("filters", otherList);
  48. }
  49. log.info("请求体数据:{}", hashMap);
  50. Map map = restTemplate.postForObject(url, hashMap, Map.class);
  51. log.info("批量获取汇报记录单号信息:{}", map);
  52. //用来缓存返回结果
  53. HashMap<String, Object> resMap = MapUtils.newHashMap();
  54. //判断是否有下页,记录总页数
  55. Integer nextCursor = (Integer) map.get("next_cursor");
  56. if (nextCursor != null && nextCursor > 0) {
  57. resMap.put("total", nextCursor);
  58. log.info("**************有下一页:{}", nextCursor);
  59. } else {
  60. resMap.put("total", pagenum * pagesize);
  61. log.info("**************没有有下一页:{}*{}={}", pagenum, pagesize, pagenum * pagesize);
  62. }
  63. if ((Integer) map.get("errcode") == 0) {
  64. List<String> journaluuidList = (List<String>) map.get("journaluuid_list");
  65. if (journaluuidList != null && journaluuidList.size() > 0) {
  66. ArrayList<WxRecord> wxRecordList = ListUtils.newArrayList();
  67. HashMap<String, Object> postDetailMap = MapUtils.newHashMap();
  68. for (String journaluuid : journaluuidList) {
  69. postDetailMap.clear();
  70. //根据审批单号去查询详情
  71. String urlDetail = "https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_detail?access_token=" + token;
  72. postDetailMap.put("journaluuid", journaluuid);
  73. Map mapDetail = restTemplate.postForObject(urlDetail, postDetailMap, Map.class);
  74. log.info("转换后前》》》》汇报记录id:{},详情:{}", journaluuid, mapDetail);
  75. if ((Integer) mapDetail.get("errcode") == 0) {
  76. WxRecord wxRecord = JSON.parseObject(JSON.toJSONString(mapDetail.get("info")), WxRecord.class);
  77. //汇报提交者姓名
  78. String userid = (String) wxRecord.getSubmitter().get("userid");
  79. wxRecord.setSubmitterName(wxUserlistService.getNameByUserid(userid));
  80. // 汇报接收对象姓名(list)
  81. List receivers = wxRecord.getReceivers();
  82. if (receivers != null && receivers.size() > 0) {
  83. wxRecord.setReceiverNames(getNames(receivers));
  84. }
  85. //已读用户姓名(list)
  86. List readedReceivers = wxRecord.getReaded_receivers();
  87. if (readedReceivers != null && readedReceivers.size() > 0) {
  88. wxRecord.setReadedReceiverNames(getNames(readedReceivers));
  89. }
  90. log.info("转换后》》》》{}", wxRecord);
  91. wxRecordList.add(wxRecord);
  92. }
  93. }
  94. resMap.put("list", wxRecordList);
  95. return resMap;
  96. }
  97. }
  98. return null;
  99. }
  100. /**
  101. * 根据list里的userid读取用户的姓名
  102. *
  103. * @param users
  104. * @return
  105. */
  106. private List<String> getNames(List<Map> users) {
  107. ArrayList<String> usernameList = ListUtils.newArrayList();
  108. for (Map user : users) {
  109. String name = wxUserlistService.getNameByUserid((String) user.get("userid"));
  110. usernameList.add(name);
  111. }
  112. return usernameList;
  113. }
  114. /**
  115. * 审批单号,fiters的条件添加
  116. *
  117. * @param key
  118. * @param value
  119. * @param otherList
  120. */
  121. private void otherListAdd(String key, String value, List otherList) {
  122. HashMap<String, String> map = MapUtils.newHashMap();
  123. map.put("key", key);
  124. map.put("value", value);
  125. otherList.add(map);
  126. }

}

```