🆕【企业微信】增加获取审批数据(旧)的接口

This commit is contained in:
Wong 2022-04-21 06:38:47 +00:00 committed by binarywang
parent 6074c846fc
commit fa5cac5e5b
4 changed files with 176 additions and 1 deletions

View File

@ -154,6 +154,23 @@ public interface WxCpOaService {
WxCpUserVacationQuota getUserVacationQuota(@NonNull String userId) throws WxErrorException;
/**
* 获取审批数据
* 提示推荐使用新接口批量获取审批单号获取审批申请详情此接口后续将不再维护逐步下线
* 通过本接口来获取公司一段时间内的审批记录一次拉取调用最多拉取100个审批记录可以通过多次拉取的方式来满足需求但调用频率不可超过600次/
*
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/corp/getapprovaldata?access_token=ACCESS_TOKEN
*
* @param startTime 获取审批记录的开始时间Unix时间戳
* @param endTime 获取审批记录的结束时间Unix时间戳
* @param nextSpNum 第一个拉取的审批单号不填从该时间段的第一个审批单拉取
* @return
* @throws WxErrorException
*/
WxCpGetApprovalData getApprovalData(@NonNull Long startTime, @NonNull Long endTime, Long nextSpNum) throws WxErrorException;
/**
* 修改成员假期余额
* 企业可通过审批应用或自建应用Secret调用本接口修改可见范围内员工的假期余额

View File

@ -183,6 +183,19 @@ public class WxCpOaServiceImpl implements WxCpOaService {
return WxCpUserVacationQuota.fromJson(responseContent);
}
@Override
public WxCpGetApprovalData getApprovalData(@NonNull Long startTime, @NonNull Long endTime, Long nextSpNum) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DATA);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("starttime", startTime);
jsonObject.addProperty("endtime", endTime);
if (nextSpNum != null) {
jsonObject.addProperty("next_spnum", nextSpNum);
}
String responseContent = this.mainService.post(url, jsonObject.toString());
return WxCpGetApprovalData.fromJson(responseContent);
}
@Override
public WxCpBaseResp setOneUserQuota(@NonNull String userId, @NonNull Integer vacationId, @NonNull Integer leftDuration, @NonNull Integer timeAttr, String remarks) throws WxErrorException {
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(SET_ONE_USER_QUOTA);

View File

@ -0,0 +1,130 @@
package me.chanjar.weixin.cp.bean.oa;
import com.google.gson.annotations.SerializedName;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
import java.io.Serializable;
import java.util.List;
/**
* 获取审批数据.
*
* @author Wang_Wong
*/
@Data
public class WxCpGetApprovalData extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = 7387181805254287159L;
@SerializedName("count")
private Integer count;
@SerializedName("total")
private Integer total;
@SerializedName("next_spnum")
private Long nextSpNum;
@SerializedName("data")
private List<ApprovalData> data;
@Getter
@Setter
public static class ApprovalData implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("spname")
private String spName;
@SerializedName("apply_name")
private String applyName;
@SerializedName("apply_org")
private String applyOrg;
@SerializedName("approval_name")
private List<String> approvalName;
@SerializedName("notify_name")
private List<String> notifyName;
@SerializedName("mediaids")
private List<String> mediaIds;
@SerializedName("sp_status")
private Integer spStatus;
@SerializedName("sp_num")
private Long spNum;
@SerializedName("apply_time")
private Long applyTime;
@SerializedName("apply_user_id")
private String applyUserId;
@SerializedName("expense")
private Expense expense;
@SerializedName("comm")
private Comm comm;
}
@Getter
@Setter
public static class Expense implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("expense_type")
private Integer expenseType;
@SerializedName("reason")
private String reason;
@SerializedName("item")
private List<Item> item;
}
@Getter
@Setter
public static class Comm implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("apply_data")
private String applyData;
}
@Getter
@Setter
public static class Item implements Serializable {
private static final long serialVersionUID = -5696099236344075582L;
@SerializedName("expenseitem_type")
private Integer expenseItemType;
@SerializedName("time")
private Long time;
@SerializedName("sums")
private Integer sums;
@SerializedName("reason")
private String reason;
}
public static WxCpGetApprovalData fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpGetApprovalData.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -162,8 +162,23 @@ public class WxCpOaServiceImplTest {
this.wxService.getOaService().apply(new WxCpOaApplyEventRequest().setCreatorUserId("123"));
}
/**
* 获取审批数据
* https://developer.work.weixin.qq.com/document/path/91530
*
* @throws WxErrorException
*/
@Test
public void testGetApprovalData() {
public void testGetApprovalData() throws WxErrorException {
// 提示推荐使用新接口批量获取审批单号获取审批申请详情此接口后续将不再维护逐步下线
// WxCpGetApprovalData approvalData = this.wxService.getOaService().getApprovalData(System.currentTimeMillis(), System.currentTimeMillis() + 3600L, null);
// log.info("返回数据:{}", approvalData.toJson());
String text = "{\"errcode\":0,\"errmsg\":\"ok\",\"count\":3,\"total\":5,\"next_spnum\":201704240001,\"data\":[{\"spname\":\"报销\",\"apply_name\":\"报销测试\",\"apply_org\":\"报销测试企业\",\"approval_name\":[\"审批人测试\"],\"notify_name\":[\"抄送人测试\"],\"sp_status\":1,\"sp_num\":201704200001,\"mediaids\":[\"WWCISP_G8PYgRaOVHjXWUWFqchpBqqqUpGj0OyR9z6WTwhnMZGCPHxyviVstiv_2fTG8YOJq8L8zJT2T2OvTebANV-2MQ\"],\"apply_time\":1499153693,\"apply_user_id\":\"testuser\",\"expense\":{\"expense_type\":1,\"reason\":\"\",\"item\":[{\"expenseitem_type\":6,\"time\":1492617600,\"sums\":9900,\"reason\":\"\"}]},\"comm\":{\"apply_data\":\"{\\\"item-1492610773696\\\":{\\\"title\\\":\\\"abc\\\",\\\"type\\\":\\\"text\\\",\\\"value\\\":\\\"\\\"}}\"}},{\"spname\":\"请假\",\"apply_name\":\"请假测试\",\"apply_org\":\"请假测试企业\",\"approval_name\":[\"审批人测试\"],\"notify_name\":[\"抄送人测试\"],\"sp_status\":1,\"sp_num\":201704200004,\"apply_time\":1499153693,\"apply_user_id\":\"testuser\",\"leave\":{\"timeunit\":0,\"leave_type\":4,\"start_time\":1492099200,\"end_time\":1492790400,\"duration\":144,\"reason\":\"\"},\"comm\":{\"apply_data\":\"{\\\"item-1492610773696\\\":{\\\"title\\\":\\\"abc\\\",\\\"type\\\":\\\"text\\\",\\\"value\\\":\\\"\\\"}}\"}},{\"spname\":\"自定义审批\",\"apply_name\":\"自定义\",\"apply_org\":\"自定义测试企业\",\"approval_name\":[\"自定义审批人\"],\"notify_name\":[\"自定义抄送人\"],\"sp_status\":1,\"sp_num\":201704240001,\"apply_time\":1499153693,\"apply_user_id\":\"testuser\",\"comm\":{\"apply_data\":\"{\\\"item-1492610773696\\\":{\\\"title\\\":\\\"abc\\\",\\\"type\\\":\\\"text\\\",\\\"value\\\":\\\"\\\"}}\"}}]}";
WxCpGetApprovalData wxCpGetApprovalData = WxCpGetApprovalData.fromJson(text);
log.info("返回数据2{}", wxCpGetApprovalData.toJson());
}
@Test