From fa5cac5e5bf5630a56e8b712ec092901688d169e Mon Sep 17 00:00:00 2001 From: Wong <1960779692@qq.com> Date: Thu, 21 Apr 2022 06:38:47 +0000 Subject: [PATCH] =?UTF-8?q?:new:=E3=80=90=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E3=80=91=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=AE=A1?= =?UTF-8?q?=E6=89=B9=E6=95=B0=E6=8D=AE=EF=BC=88=E6=97=A7=EF=BC=89=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/cp/api/WxCpOaService.java | 17 +++ .../weixin/cp/api/impl/WxCpOaServiceImpl.java | 13 ++ .../cp/bean/oa/WxCpGetApprovalData.java | 130 ++++++++++++++++++ .../cp/api/impl/WxCpOaServiceImplTest.java | 17 ++- 4 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpGetApprovalData.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java index 6b2a3c9d8..9dcea5174 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java @@ -154,6 +154,23 @@ public interface WxCpOaService { WxCpUserVacationQuota getUserVacationQuota(@NonNull String userId) throws WxErrorException; + /** + * 获取审批数据(旧) + * 提示:推荐使用新接口“批量获取审批单号”及“获取审批申请详情”,此接口后续将不再维护、逐步下线。 + * 通过本接口来获取公司一段时间内的审批记录。一次拉取调用最多拉取100个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。 + * + * 请求方式:POST(HTTPS) + * 请求地址: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调用本接口,修改可见范围内员工的“假期余额”。 diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java index 7c0f866dd..0e227c887 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java @@ -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); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpGetApprovalData.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpGetApprovalData.java new file mode 100644 index 000000000..8385ab037 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpGetApprovalData.java @@ -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 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 approvalName; + + @SerializedName("notify_name") + private List notifyName; + + @SerializedName("mediaids") + private List 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; + + } + + @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); + } + +} diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java index b5b7ce9f0..16f53893f 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java @@ -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