Skip to content

Commit 7229bb4

Browse files
0katekate0binarywang
authored andcommitted
🆕【企业微信】新增修改成员假期余额的接口
1 parent 6f776bd commit 7229bb4

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import lombok.NonNull;
44
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
56
import me.chanjar.weixin.cp.bean.oa.*;
67

78
import java.util.Date;
@@ -146,13 +147,32 @@ WxCpApprovalInfo getApprovalInfo(@NonNull Date startTime, @NonNull Date endTime,
146147
* 请求方式:POST(HTTPS)
147148
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/oa/vacation/getuservacationquota?access_token=ACCESS_TOKEN
148149
*
149-
* @param userId
150+
* @param userId 需要获取假期余额的成员的userid
150151
* @return
151152
* @throws WxErrorException
152153
*/
153154
WxCpUserVacationQuota getUserVacationQuota(@NonNull String userId) throws WxErrorException;
154155

155156

157+
/**
158+
* 修改成员假期余额
159+
* 企业可通过审批应用或自建应用Secret调用本接口,修改可见范围内员工的“假期余额”。
160+
* 第三方应用可通过应本接口修改应用可见范围内指定员工的“假期余额”。
161+
*
162+
* 请求方式:POST(HTTPS)
163+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/oa/vacation/setoneuserquota?access_token=ACCESS_TOKEN
164+
*
165+
* @param userId 需要修改假期余额的成员的userid
166+
* @param vacationId 假期id
167+
* @param leftDuration 设置的假期余额,单位为秒,不能大于1000天或24000小时,当假期时间刻度为按小时请假时,必须为360整倍数,即0.1小时整倍数,按天请假时,必须为8640整倍数,即0.1天整倍数
168+
* @param timeAttr 假期时间刻度:0-按天请假;1-按小时请假
169+
* @param remarks 修改备注,用于显示在假期余额的修改记录当中,可对修改行为作说明,不超过200字符
170+
* @return
171+
* @throws WxErrorException
172+
*/
173+
WxCpBaseResp setOneUserQuota(@NonNull String userId, @NonNull Integer vacationId, @NonNull Integer leftDuration, @NonNull Integer timeAttr, String remarks) throws WxErrorException;
174+
175+
156176
/**
157177
* 获取公费电话拨打记录
158178
*

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import me.chanjar.weixin.common.util.json.GsonParser;
1212
import me.chanjar.weixin.cp.api.WxCpOaService;
1313
import me.chanjar.weixin.cp.api.WxCpService;
14+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
1415
import me.chanjar.weixin.cp.bean.oa.*;
1516
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
17+
import org.apache.commons.lang3.StringUtils;
1618

1719
import java.util.Date;
1820
import java.util.List;
@@ -181,6 +183,21 @@ public WxCpUserVacationQuota getUserVacationQuota(@NonNull String userId) throws
181183
return WxCpUserVacationQuota.fromJson(responseContent);
182184
}
183185

186+
@Override
187+
public WxCpBaseResp setOneUserQuota(@NonNull String userId, @NonNull Integer vacationId, @NonNull Integer leftDuration, @NonNull Integer timeAttr, String remarks) throws WxErrorException {
188+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(SET_ONE_USER_QUOTA);
189+
JsonObject jsonObject = new JsonObject();
190+
jsonObject.addProperty("userid", userId);
191+
jsonObject.addProperty("vacation_id", vacationId);
192+
jsonObject.addProperty("leftduration", leftDuration);
193+
jsonObject.addProperty("time_attr", timeAttr);
194+
if (StringUtils.isNotEmpty(remarks)) {
195+
jsonObject.addProperty("remarks", remarks);
196+
}
197+
String responseContent = this.mainService.post(url, jsonObject.toString());
198+
return WxCpBaseResp.fromJson(responseContent);
199+
}
200+
184201
@Override
185202
public List<WxCpDialRecord> getDialRecord(Date startTime, Date endTime, Integer offset, Integer limit)
186203
throws WxErrorException {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import java.io.Serializable;
99

1010
/**
11-
* @author yqx
11+
* 返回结果
12+
*
13+
* @author yqx & WangWong
1214
* @date 2020/3/16
1315
*/
1416
@Getter
@@ -30,4 +32,8 @@ public static WxCpBaseResp fromJson(String json) {
3032
return WxCpGsonBuilder.create().fromJson(json, WxCpBaseResp.class);
3133
}
3234

35+
public String toJson() {
36+
return WxCpGsonBuilder.create().toJson(this);
37+
}
38+
3339
}

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import me.chanjar.weixin.common.error.WxErrorException;
77
import me.chanjar.weixin.cp.api.ApiTestModule;
88
import me.chanjar.weixin.cp.api.WxCpService;
9+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
910
import me.chanjar.weixin.cp.bean.oa.*;
1011
import org.apache.commons.lang3.time.DateFormatUtils;
1112
import org.testng.annotations.Guice;
@@ -176,7 +177,7 @@ public void testGetDialRecord() {
176177
* @throws WxErrorException
177178
*/
178179
@Test
179-
public void testGetCorpConf() throws WxErrorException{
180+
public void testGetCorpConf() throws WxErrorException {
180181
WxCpCorpConfInfo corpConf = this.wxService.getOaService().getCorpConf();
181182
log.info(corpConf.toJson());
182183
}
@@ -188,7 +189,7 @@ public void testGetCorpConf() throws WxErrorException{
188189
* @throws WxErrorException
189190
*/
190191
@Test
191-
public void testGetUserVacationQuota() throws WxErrorException{
192+
public void testGetUserVacationQuota() throws WxErrorException {
192193
WxCpUserVacationQuota vacationQuota = this.wxService.getOaService().getUserVacationQuota("WangKai");
193194
log.info(vacationQuota.toJson());
194195

@@ -198,4 +199,21 @@ public void testGetUserVacationQuota() throws WxErrorException{
198199

199200
}
200201

202+
/**
203+
* 修改成员假期余额
204+
* https://developer.work.weixin.qq.com/document/path/93377
205+
*
206+
* @throws WxErrorException
207+
*/
208+
@Test
209+
public void testSetOneUserQuota() throws WxErrorException {
210+
211+
String text = "{\"errcode\":0,\"errmsg\":\"ok\"}";
212+
WxCpBaseResp resp = WxCpBaseResp.fromJson(text);
213+
log.info("返回结果为:{}", resp.toJson());
214+
215+
// WxCpBaseResp wxCpBaseResp = this.wxService.getOaService().setOneUserQuota(, , , , );
216+
217+
}
218+
201219
}

0 commit comments

Comments
 (0)