Skip to content

Commit e6923cd

Browse files
authored
🎨 #3187【企业微信】 批量获取审批单号接口方法增加对新分页字段的支持
1 parent 8abb34b commit e6923cd

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaService.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime
9393
* @return WxCpApprovalInfo approval info
9494
* @throws WxErrorException .
9595
*/
96+
@Deprecated
9697
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime, Integer cursor, Integer size,
9798
List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException;
9899

@@ -106,9 +107,39 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
106107
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo me.chanjar.weixin.cp.api
107108
* .WxCpOaService#getApprovalInfome.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
108109
*/
110+
@Deprecated
109111
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException;
110112

111113

114+
/**
115+
* <pre>
116+
*
117+
* 批量获取审批单号
118+
*
119+
* 审批应用及有权限的自建应用,可通过Secret调用本接口,以获取企业一段时间内企业微信“审批应用”单据的审批编号,支持按模板类型、申请人、部门、申请单审批状态等条件筛选。
120+
* 自建应用调用此接口,需在“管理后台-应用管理-审批-API-审批数据权限”中,授权应用允许提交审批单据。
121+
*
122+
* 一次拉取调用最多拉取100个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
123+
*
124+
* API doc : https://work.weixin.qq.com/api/doc/90000/90135/91816
125+
*
126+
* 1 接口频率限制 600次/分钟
127+
* 2 请求的参数endtime需要大于startime, 起始时间跨度不能超过31天;
128+
* 3 老的分页游标字段cursor和next_cursor待废弃,请开发者使用新字段new_cursor和new_next_cursor。
129+
* </pre>
130+
*
131+
* @param startTime 开始时间
132+
* @param endTime 结束时间
133+
* @param newCursor 分页查询游标,默认为0,后续使用返回的next_cursor进行分页拉取
134+
* @param size 一次请求拉取审批单数量,默认值为100,上限值为100
135+
* @param filters 筛选条件,可对批量拉取的审批申请设置约束条件,支持设置多个条件,nullable
136+
* @return WxCpApprovalInfo approval info
137+
* @throws WxErrorException .
138+
*/
139+
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime, String newCursor, Integer size,
140+
List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException;
141+
142+
112143
/**
113144
* <pre>
114145
* 获取审批申请详情

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImpl.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,43 @@ public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date e
153153

154154
@Override
155155
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException {
156-
return this.getApprovalInfo(startTime, endTime, null, null, null);
156+
return this.getApprovalInfo(startTime, endTime, 0, null, null);
157+
}
158+
159+
@Override
160+
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime, String newCursor,
161+
Integer size, List<WxCpApprovalInfoQueryFilter> filters)
162+
throws WxErrorException {
163+
if (newCursor == null) {
164+
newCursor = "";
165+
}
166+
167+
if (size == null) {
168+
size = 100;
169+
}
170+
171+
if (size < 0 || size > 100) {
172+
throw new IllegalArgumentException("size参数错误,请使用[1-100]填充,默认100");
173+
}
174+
175+
JsonObject jsonObject = new JsonObject();
176+
jsonObject.addProperty("starttime", startTime.getTime() / 1000L);
177+
jsonObject.addProperty("endtime", endTime.getTime() / 1000L);
178+
jsonObject.addProperty("size", size);
179+
jsonObject.addProperty("new_cursor", newCursor);
180+
181+
if (filters != null && !filters.isEmpty()) {
182+
JsonArray filterJsonArray = new JsonArray();
183+
for (WxCpApprovalInfoQueryFilter filter : filters) {
184+
filterJsonArray.add(new JsonParser().parse(filter.toJson()));
185+
}
186+
jsonObject.add("filters", filterJsonArray);
187+
}
188+
189+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_INFO);
190+
String responseContent = this.mainService.post(url, jsonObject.toString());
191+
192+
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalInfo.class);
157193
}
158194

159195
@Override

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpApprovalInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ public class WxCpApprovalInfo implements Serializable {
2727
@SerializedName("next_cursor")
2828
private Integer nextCursor;
2929

30+
@SerializedName("new_next_cursor")
31+
private String newNextCursor;
3032
}

0 commit comments

Comments
 (0)