Skip to content

Commit b00e938

Browse files
0katekate0binarywang
authored andcommitted
🆕【企业微信】 新增获取成员假期余额的接口
1 parent 8bcafdc commit b00e938

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
138138
WxCpCorpConfInfo getCorpConf() throws WxErrorException;
139139

140140

141+
/**
142+
* 获取成员假期余额
143+
* 企业可通过审批应用或自建应用Secret调用本接口,获取可见范围内各个员工的假期余额数据。
144+
* 第三方应用可获取应用可见范围内各个员工的假期余额数据。
145+
*
146+
* 请求方式:POST(HTTPS)
147+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/oa/vacation/getuservacationquota?access_token=ACCESS_TOKEN
148+
*
149+
* @param userId
150+
* @return
151+
* @throws WxErrorException
152+
*/
153+
WxCpUserVacationQuota getUserVacationQuota(@NonNull String userId) throws WxErrorException;
154+
155+
141156
/**
142157
* 获取公费电话拨打记录
143158
*

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ public WxCpCorpConfInfo getCorpConf() throws WxErrorException {
172172
return WxCpCorpConfInfo.fromJson(responseContent);
173173
}
174174

175+
@Override
176+
public WxCpUserVacationQuota getUserVacationQuota(@NonNull String userId) throws WxErrorException {
177+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_VACATION_QUOTA);
178+
JsonObject jsonObject = new JsonObject();
179+
jsonObject.addProperty("userid", userId);
180+
String responseContent = this.mainService.post(url, jsonObject.toString());
181+
return WxCpUserVacationQuota.fromJson(responseContent);
182+
}
183+
175184
@Override
176185
public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit)
177186
throws WxErrorException {

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpBaseResp.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ public boolean success() {
2929
public static WxCpBaseResp fromJson(String json) {
3030
return WxCpGsonBuilder.create().fromJson(json, WxCpBaseResp.class);
3131
}
32+
3233
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package me.chanjar.weixin.cp.bean.oa;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 成员假期余额信息.
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpUserVacationQuota extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = 7387181805254287157L;
21+
22+
@SerializedName("lists")
23+
private List<VacationQuota> lists;
24+
25+
@Getter
26+
@Setter
27+
public static class VacationQuota implements Serializable {
28+
private static final long serialVersionUID = -5696099236344075582L;
29+
30+
@SerializedName("id")
31+
private Integer id;
32+
33+
@SerializedName("assignduration")
34+
private Integer assignDuration;
35+
36+
@SerializedName("usedduration")
37+
private Integer usedDuration;
38+
39+
@SerializedName("leftduration")
40+
private Integer leftDuration;
41+
42+
@SerializedName("vacationname")
43+
private String vacationName;
44+
45+
}
46+
47+
public static WxCpUserVacationQuota fromJson(String json) {
48+
return WxCpGsonBuilder.create().fromJson(json, WxCpUserVacationQuota.class);
49+
}
50+
51+
public String toJson() {
52+
return WxCpGsonBuilder.create().toJson(this);
53+
}
54+
55+
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpOaServiceImplTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ public void testGetDialRecord() {
170170
}
171171

172172
/**
173+
* 获取企业假期管理配置
173174
* https://developer.work.weixin.qq.com/document/path/93375
175+
*
174176
* @throws WxErrorException
175177
*/
176178
@Test
@@ -179,4 +181,21 @@ public void testGetCorpConf() throws WxErrorException{
179181
log.info(corpConf.toJson());
180182
}
181183

184+
/**
185+
* 获取成员假期余额
186+
* https://developer.work.weixin.qq.com/document/path/93376
187+
*
188+
* @throws WxErrorException
189+
*/
190+
@Test
191+
public void testGetUserVacationQuota() throws WxErrorException{
192+
WxCpUserVacationQuota vacationQuota = this.wxService.getOaService().getUserVacationQuota("WangKai");
193+
log.info(vacationQuota.toJson());
194+
195+
String text = "{\"errcode\":0,\"errmsg\":\"ok\",\"lists\":[{\"id\":1,\"assignduration\":0,\"usedduration\":0,\"leftduration\":604800,\"vacationname\":\"年假\"},{\"id\":2,\"assignduration\":0,\"usedduration\":0,\"leftduration\":1296000,\"vacationname\":\"事假\"},{\"id\":3,\"assignduration\":0,\"usedduration\":0,\"leftduration\":0,\"vacationname\":\"病假\"}]}";
196+
WxCpUserVacationQuota json = WxCpUserVacationQuota.fromJson(text);
197+
log.info("数据为:{}", json.toJson());
198+
199+
}
200+
182201
}

0 commit comments

Comments
 (0)