第一步、获取汇报记录单号
参考: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
注意:
- 查询条件filters里条件不是必须的,
- creator指定汇报记录提单人的用户id
- department指定提单人所在部门的id(不支持多选查询)
- 一次查询多少条数据限制是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
请求示例{"journaluuid": "41eJejN57EJNzr8HrZfmKyCN7xwKw1qRxCZUxCVuo9fsWVMSKac6nk4q8rARTDaVNdx"}
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;
@Overridepublic Map<String, Object> show(Integer pagenum,Integer pagesize,Long starttime,Long endtime,String creator,String template_id,String deptid) {if (starttime == null) {//参数:开始时间戳(秒)//30天前0:0:0的时间戳(秒)starttime = TjDateUtils.chooseDay(TjDateUtils.getTodayBegin(), -30).getTime() / 1000;}if (endtime == null) {//参数:结束时间戳,当前时间的时间戳(秒)endtime = System.currentTimeMillis() / 1000;}String token = baseNumvarService.getAccessTokenBySecret(baseNumvarService.getSecretRecord());String url = "https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_list?access_token=" + token;//请求体数据,使用hashmap封装HashMap<String, Object> hashMap = MapUtils.newHashMap();hashMap.put("starttime", starttime);hashMap.put("endtime", endtime);hashMap.put("cursor", (pagenum - 1) * pagesize + 1);hashMap.put("limit", pagesize);//其他条件ArrayList<Map> otherList = ListUtils.newArrayList();otherList.clear();//判断用户姓名条件if (creator != null) {LambdaQueryWrapper<WxUserlist> lqwUser = new LambdaQueryWrapper<>();lqwUser.eq(WxUserlist::getName, creator).last("LIMIT 1");//只取1条记录WxUserlist one = wxUserlistService.getOne(lqwUser);if (one != null) {otherListAdd("creator", one.getUserid(), otherList);}}//判断指定模板if (StringUtils.isNotEmpty(template_id)) {otherListAdd("template_id", template_id, otherList);}//部门条件判断if (StringUtils.isNotEmpty(deptid)) {otherListAdd("department", deptid, otherList);}//判断filters里的查询条件if (otherList != null && otherList.size() > 0) {hashMap.put("filters", otherList);}log.info("请求体数据:{}", hashMap);Map map = restTemplate.postForObject(url, hashMap, Map.class);log.info("批量获取汇报记录单号信息:{}", map);//用来缓存返回结果HashMap<String, Object> resMap = MapUtils.newHashMap();//判断是否有下页,记录总页数Integer nextCursor = (Integer) map.get("next_cursor");if (nextCursor != null && nextCursor > 0) {resMap.put("total", nextCursor);log.info("**************有下一页:{}", nextCursor);} else {resMap.put("total", pagenum * pagesize);log.info("**************没有有下一页:{}*{}={}", pagenum, pagesize, pagenum * pagesize);}if ((Integer) map.get("errcode") == 0) {List<String> journaluuidList = (List<String>) map.get("journaluuid_list");if (journaluuidList != null && journaluuidList.size() > 0) {ArrayList<WxRecord> wxRecordList = ListUtils.newArrayList();HashMap<String, Object> postDetailMap = MapUtils.newHashMap();for (String journaluuid : journaluuidList) {postDetailMap.clear();//根据审批单号去查询详情String urlDetail = "https://qyapi.weixin.qq.com/cgi-bin/oa/journal/get_record_detail?access_token=" + token;postDetailMap.put("journaluuid", journaluuid);Map mapDetail = restTemplate.postForObject(urlDetail, postDetailMap, Map.class);log.info("转换后前》》》》汇报记录id:{},详情:{}", journaluuid, mapDetail);if ((Integer) mapDetail.get("errcode") == 0) {WxRecord wxRecord = JSON.parseObject(JSON.toJSONString(mapDetail.get("info")), WxRecord.class);//汇报提交者姓名String userid = (String) wxRecord.getSubmitter().get("userid");wxRecord.setSubmitterName(wxUserlistService.getNameByUserid(userid));// 汇报接收对象姓名(list)List receivers = wxRecord.getReceivers();if (receivers != null && receivers.size() > 0) {wxRecord.setReceiverNames(getNames(receivers));}//已读用户姓名(list)List readedReceivers = wxRecord.getReaded_receivers();if (readedReceivers != null && readedReceivers.size() > 0) {wxRecord.setReadedReceiverNames(getNames(readedReceivers));}log.info("转换后》》》》{}", wxRecord);wxRecordList.add(wxRecord);}}resMap.put("list", wxRecordList);return resMap;}}return null;}/*** 根据list里的userid读取用户的姓名** @param users* @return*/private List<String> getNames(List<Map> users) {ArrayList<String> usernameList = ListUtils.newArrayList();for (Map user : users) {String name = wxUserlistService.getNameByUserid((String) user.get("userid"));usernameList.add(name);}return usernameList;}/*** 审批单号,fiters的条件添加** @param key* @param value* @param otherList*/private void otherListAdd(String key, String value, List otherList) {HashMap<String, String> map = MapUtils.newHashMap();map.put("key", key);map.put("value", value);otherList.add(map);}
}
```
