Skip to content

Commit 7d4dfad

Browse files
forfunsbinarywang
authored andcommitted
🆕 #1344 企业微信增加新的审批接口: “批量获取审批单号”及“获取审批申请详情”
1 parent aad2e5b commit 7d4dfad

24 files changed

+843
-33
lines changed

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

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package me.chanjar.weixin.cp.api;
22

3+
import lombok.NonNull;
34
import me.chanjar.weixin.common.error.WxErrorException;
4-
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
5-
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
6-
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
7-
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
5+
import me.chanjar.weixin.cp.bean.oa.*;
86

97
import java.util.Date;
108
import java.util.List;
@@ -30,7 +28,8 @@ public interface WxCpOaService {
3028
* @return 打卡数据列表
3129
* @throws WxErrorException 异常
3230
*/
33-
List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime, List<String> userIdList) throws WxErrorException;
31+
List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime,
32+
List<String> userIdList) throws WxErrorException;
3433

3534
/**
3635
* <pre>
@@ -41,24 +40,88 @@ public interface WxCpOaService {
4140
* @param datetime 需要获取规则的当天日期
4241
* @param userIdList 需要获取打卡规则的用户列表
4342
* @return 打卡规则列表
44-
* @throws WxErrorException 异常
43+
* @throws WxErrorException
4544
*/
4645
List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> userIdList) throws WxErrorException;
4746

4847
/**
4948
* <pre>
50-
* 获取审批数据
49+
*
50+
* 批量获取审批单号
51+
*
52+
* 审批应用及有权限的自建应用,可通过Secret调用本接口,以获取企业一段时间内企业微信“审批应用”单据的审批编号,支持按模板类型、申请人、部门、申请单审批状态等条件筛选。
53+
* 自建应用调用此接口,需在“管理后台-应用管理-审批-API-审批数据权限”中,授权应用允许提交审批单据。
54+
*
55+
* 一次拉取调用最多拉取100个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
56+
*
57+
* API doc : https://work.weixin.qq.com/api/doc/90000/90135/91816
58+
* </pre>
59+
*
60+
* @param startTime 开始时间
61+
* @param endTime 结束时间
62+
* @param cursor 分页查询游标,默认为0,后续使用返回的next_cursor进行分页拉取
63+
* @param size 一次请求拉取审批单数量,默认值为100,上限值为100
64+
* @param filters 筛选条件,可对批量拉取的审批申请设置约束条件,支持设置多个条件,nullable
65+
* @return WxCpApprovalInfo
66+
* @throws WxErrorException
67+
*/
68+
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime, Integer cursor, Integer size,
69+
List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException;
70+
71+
/**
72+
* short method
73+
*
74+
* @param startTime 开始时间
75+
* @param endTime 结束时间
76+
* @return WxCpApprovalInfo
77+
* @throws WxErrorException
78+
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
79+
*/
80+
WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException;
81+
82+
/**
83+
* <pre>
84+
* 获取审批申请详情
85+
*
86+
* 企业可通过审批应用或自建应用Secret调用本接口,根据审批单号查询企业微信“审批应用”的审批申请详情。
87+
*
88+
* API Doc : https://work.weixin.qq.com/api/doc/90000/90135/91983
89+
* </pre>
90+
*
91+
* @param spNo 审批单编号。
92+
* @return WxCpApprovaldetail
93+
* @throws WxErrorException
94+
*/
95+
WxCpApprovalDetailResult getApprovalDetail(@NonNull String spNo) throws WxErrorException;
96+
97+
/**
98+
* <pre>
99+
* 获取审批数据 (已过期, 请使用"批量获取审批单号" && "获取审批申请详情")
51100
* 通过本接口来获取公司一段时间内的审批记录。一次拉取调用最多拉取10000个审批记录,可以通过多次拉取的方式来满足需求,但调用频率不可超过600次/分。
52101
* API doc : https://work.weixin.qq.com/api/doc#90000/90135/91530
53102
* </pre>
54103
*
55104
* @param startTime 获取审批记录的开始时间
56105
* @param endTime 获取审批记录的结束时间
57106
* @param nextSpnum 第一个拉取的审批单号,不填从该时间段的第一个审批单拉取
58-
* @throws WxErrorException 异常
107+
* @throws WxErrorException
108+
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalInfo
109+
* @see me.chanjar.weixin.cp.api.WxCpOaService#getApprovalDetail
59110
*/
111+
@Deprecated
60112
WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException;
61113

62-
List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit) throws WxErrorException;
114+
/**
115+
* 获取公费电话拨打记录
116+
*
117+
* @param startTime 查询的起始时间戳
118+
* @param endTime 查询的结束时间戳
119+
* @param offset 分页查询的偏移量
120+
* @param limit 分页查询的每页大小,默认为100条,如该参数大于100则按100处理
121+
* @return
122+
* @throws WxErrorException
123+
*/
124+
List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset,
125+
Integer limit) throws WxErrorException;
63126

64127
}

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

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
import com.google.gson.JsonObject;
66
import com.google.gson.JsonParser;
77
import com.google.gson.reflect.TypeToken;
8+
import lombok.NonNull;
89
import lombok.RequiredArgsConstructor;
910
import me.chanjar.weixin.common.error.WxErrorException;
1011
import me.chanjar.weixin.cp.api.WxCpOaService;
1112
import me.chanjar.weixin.cp.api.WxCpService;
12-
import me.chanjar.weixin.cp.bean.WxCpApprovalDataResult;
13-
import me.chanjar.weixin.cp.bean.WxCpCheckinData;
14-
import me.chanjar.weixin.cp.bean.WxCpCheckinOption;
15-
import me.chanjar.weixin.cp.bean.WxCpDialRecord;
16-
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
13+
import me.chanjar.weixin.cp.bean.oa.*;
1714
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1815

1916
import java.util.Date;
@@ -22,7 +19,7 @@
2219
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
2320

2421
/**
25-
* .
22+
* 企业微信 OA 接口实现
2623
*
2724
* @author Element
2825
* @date 2019-04-06 11:20
@@ -31,21 +28,24 @@
3128
public class WxCpOaServiceImpl implements WxCpOaService {
3229
private final WxCpService mainService;
3330

31+
private static final int MONTH_SECONDS = 30 * 24 * 60 * 60;
32+
private static final int USER_IDS_LIMIT = 100;
33+
3434
@Override
3535
public List<WxCpCheckinData> getCheckinData(Integer openCheckinDataType, Date startTime, Date endTime,
3636
List<String> userIdList) throws WxErrorException {
3737
if (startTime == null || endTime == null) {
3838
throw new RuntimeException("starttime and endtime can't be null");
3939
}
4040

41-
if (userIdList == null || userIdList.size() > 100) {
42-
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
41+
if (userIdList == null || userIdList.size() > USER_IDS_LIMIT) {
42+
throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取");
4343
}
4444

4545
long endtimestamp = endTime.getTime() / 1000L;
4646
long starttimestamp = startTime.getTime() / 1000L;
4747

48-
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
48+
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS) {
4949
throw new RuntimeException("获取记录时间跨度不超过一个月");
5050
}
5151

@@ -79,8 +79,8 @@ public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> user
7979
throw new RuntimeException("datetime can't be null");
8080
}
8181

82-
if (userIdList == null || userIdList.size() > 100) {
83-
throw new RuntimeException("用户列表不能为空,不超过100个,若用户超过100个,请分批获取");
82+
if (userIdList == null || userIdList.size() > USER_IDS_LIMIT) {
83+
throw new RuntimeException("用户列表不能为空,不超过 " + USER_IDS_LIMIT + " 个,若用户超过 " + USER_IDS_LIMIT + " 个,请分批获取");
8484
}
8585

8686
JsonArray jsonArray = new JsonArray();
@@ -104,6 +104,59 @@ public List<WxCpCheckinOption> getCheckinOption(Date datetime, List<String> user
104104
);
105105
}
106106

107+
@Override
108+
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
109+
Integer cursor, Integer size, List<WxCpApprovalInfoQueryFilter> filters) throws WxErrorException {
110+
111+
if (cursor == null) {
112+
cursor = 0;
113+
}
114+
115+
if (size == null) {
116+
size = 100;
117+
}
118+
119+
if (size < 0 || size > 100) {
120+
throw new IllegalArgumentException("size参数错误,请使用[1-100]填充,默认100");
121+
}
122+
123+
JsonObject jsonObject = new JsonObject();
124+
jsonObject.addProperty("starttime", startTime.getTime() / 1000L);
125+
jsonObject.addProperty("endtime", endTime.getTime() / 1000L);
126+
jsonObject.addProperty("size", size);
127+
jsonObject.addProperty("cursor", cursor);
128+
129+
if (filters != null && !filters.isEmpty()) {
130+
JsonArray filterJsonArray = new JsonArray();
131+
for (WxCpApprovalInfoQueryFilter filter : filters) {
132+
filterJsonArray.add(new JsonParser().parse(filter.toJson()));
133+
}
134+
jsonObject.add("filters", filterJsonArray);
135+
}
136+
137+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_INFO);
138+
String responseContent = this.mainService.post(url, jsonObject.toString());
139+
140+
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalInfo.class);
141+
}
142+
143+
@Override
144+
public WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime) throws WxErrorException {
145+
return this.getApprovalInfo(startTime, endTime, null, null, null);
146+
}
147+
148+
@Override
149+
public WxCpApprovalDetailResult getApprovalDetail(@NonNull String spNo) throws WxErrorException {
150+
151+
JsonObject jsonObject = new JsonObject();
152+
jsonObject.addProperty("sp_no", spNo);
153+
154+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_APPROVAL_DETAIL);
155+
String responseContent = this.mainService.post(url, jsonObject.toString());
156+
157+
return WxCpGsonBuilder.create().fromJson(responseContent, WxCpApprovalDetailResult.class);
158+
}
159+
107160
@Override
108161
public WxCpApprovalDataResult getApprovalData(Date startTime, Date endTime, Long nextSpnum) throws WxErrorException {
109162
JsonObject jsonObject = new JsonObject();
@@ -139,7 +192,7 @@ public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer
139192
long endtimestamp = endTime.getTime() / 1000L;
140193
long starttimestamp = startTime.getTime() / 1000L;
141194

142-
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= 30 * 24 * 60 * 60) {
195+
if (endtimestamp - starttimestamp < 0 || endtimestamp - starttimestamp >= MONTH_SECONDS) {
143196
throw new RuntimeException("受限于网络传输,起止时间的最大跨度为30天,如超过30天,则以结束时间为基准向前取30天进行查询");
144197
}
145198

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package me.chanjar.weixin.cp.bean.oa;
2+
3+
import lombok.Data;
4+
import me.chanjar.weixin.cp.bean.oa.applydata.Content;
5+
6+
import java.io.Serializable;
7+
import java.util.List;
8+
9+
/**
10+
* 审批申请数据
11+
*
12+
* @author element
13+
*/
14+
@Data
15+
public class WxCpApprovalApplyData implements Serializable {
16+
17+
private static final long serialVersionUID = 4061352949894274704L;
18+
19+
private List<Content> contents;
20+
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package me.chanjar.weixin.cp.bean.oa;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* 申请人信息
10+
* @author element
11+
*/
12+
@Data
13+
public class WxCpApprovalApplyer extends WxCpOperator implements Serializable {
14+
15+
private static final long serialVersionUID = -8974662568286821271L;
16+
17+
/**
18+
* 申请人所在部门id
19+
*/
20+
@SerializedName("partyid")
21+
private String partyId;
22+
23+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package me.chanjar.weixin.cp.bean.oa;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
import java.util.List;
8+
9+
/**
10+
* 审批申请备注信息
11+
*
12+
* @author element
13+
*/
14+
@Data
15+
public class WxCpApprovalComment implements Serializable {
16+
17+
private static final long serialVersionUID = -5430367411926856292L;
18+
19+
/**
20+
* 备注人信息
21+
*/
22+
private WxCpOperator commentUserInfo;
23+
24+
/**
25+
* 备注提交时间戳,Unix时间戳
26+
*/
27+
@SerializedName("commenttime")
28+
private Long commentTime;
29+
30+
/**
31+
* 备注id
32+
*/
33+
@SerializedName("commentid")
34+
private String commentId;
35+
36+
/**
37+
* 备注文本内容
38+
*/
39+
@SerializedName("commentcontent")
40+
private String commentContent;
41+
42+
/**
43+
* 备注附件id,可能有多个
44+
*/
45+
@SerializedName("media_id")
46+
private List<String> mediaIds;
47+
48+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpApprovalDataResult.java renamed to weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/WxCpApprovalDataResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.chanjar.weixin.cp.bean;
1+
package me.chanjar.weixin.cp.bean.oa;
22

33
import com.google.gson.annotations.SerializedName;
44
import lombok.Data;
@@ -12,6 +12,7 @@
1212
* @author Element
1313
* @date 2019-04-06 14:36
1414
*/
15+
@Deprecated
1516
@Data
1617
public class WxCpApprovalDataResult implements Serializable {
1718
private static final long serialVersionUID = -1046940445840716590L;

0 commit comments

Comments
 (0)