Skip to content

Commit 02d3c16

Browse files
committed
🆕 binarywang#1369 【企业微信】增加效率工具-日程相关接口
1 parent 55e1399 commit 02d3c16

12 files changed

Lines changed: 502 additions & 49 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import me.chanjar.weixin.common.error.WxErrorException;
4+
import me.chanjar.weixin.cp.bean.oa.WxCpOaSchedule;
5+
6+
import java.util.List;
7+
8+
/**
9+
* 企业微信日程接口.
10+
* 官方文档:https://work.weixin.qq.com/api/doc/90000/90135/93648
11+
*
12+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
13+
* @date 2020 -12-25
14+
*/
15+
public interface WxCpOaScheduleService {
16+
/**
17+
* 创建日程
18+
* <p>
19+
* 该接口用于在日历中创建一个日程。
20+
* <p>
21+
* 请求方式: POST(HTTPS)
22+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/add?access_token=ACCESS_TOKEN
23+
*
24+
* @param schedule the schedule
25+
* @param agentId 授权方安装的应用agentid。仅旧的第三方多应用套件需要填此参数
26+
* @return 日程ID string
27+
* @throws WxErrorException the wx error exception
28+
*/
29+
String add(WxCpOaSchedule schedule, Integer agentId) throws WxErrorException;
30+
31+
/**
32+
* 更新日程
33+
* <p>
34+
* 该接口用于在日历中更新指定的日程。
35+
* <p>
36+
* 注意,更新操作是覆盖式,而不是增量式
37+
* 不可更新组织者和日程所属日历ID
38+
* <p>
39+
* 请求方式: POST(HTTPS)
40+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/update?access_token=ACCESS_TOKEN
41+
*
42+
* @param schedule the schedule
43+
* @throws WxErrorException the wx error exception
44+
*/
45+
void update(WxCpOaSchedule schedule) throws WxErrorException;
46+
47+
/**
48+
* 获取日程详情
49+
* <p>
50+
* 该接口用于获取指定的日程详情。
51+
* <p>
52+
* 请求方式: POST(HTTPS)
53+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/get?access_token=ACCESS_TOKEN
54+
*
55+
* @param scheduleIds the schedule ids
56+
* @return the details
57+
* @throws WxErrorException the wx error exception
58+
*/
59+
List<WxCpOaSchedule> getDetails(List<String> scheduleIds) throws WxErrorException;
60+
61+
/**
62+
* 取消日程
63+
* 该接口用于取消指定的日程。
64+
* <p>
65+
* 请求方式: POST(HTTPS)
66+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/del?access_token=ACCESS_TOKEN
67+
*
68+
* @param scheduleId 日程id
69+
* @throws WxErrorException the wx error exception
70+
*/
71+
void delete(String scheduleId) throws WxErrorException;
72+
73+
/**
74+
* 获取日历下的日程列表
75+
* 该接口用于获取指定的日历下的日程列表。
76+
* 仅可获取应用自己创建的日历下的日程。
77+
* <p>
78+
* 请求方式: POST(HTTPS)
79+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/get_by_calendar?access_token=ACCESS_TOKEN
80+
*
81+
* @param calId 日历ID
82+
* @param offset 分页,偏移量, 默认为0
83+
* @param limit 分页,预期请求的数据量,默认为500,取值范围 1 ~ 1000
84+
* @return the string
85+
* @throws WxErrorException the wx error exception
86+
*/
87+
List<WxCpOaSchedule> listByCalendar(String calId, Integer offset, Integer limit) throws WxErrorException;
88+
}

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

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

3-
import com.google.gson.JsonObject;
4-
import me.chanjar.weixin.common.bean.ToJson;
53
import me.chanjar.weixin.common.bean.WxJsapiSignature;
64
import me.chanjar.weixin.common.error.WxErrorException;
75
import me.chanjar.weixin.common.service.WxService;
@@ -39,7 +37,7 @@ public interface WxCpService extends WxService {
3937
*
4038
* @return the access token
4139
* @throws WxErrorException the wx error exception
42-
* @see #getAccessToken(boolean) #getAccessToken(boolean)
40+
* @see #getAccessToken(boolean) #getAccessToken(boolean)#getAccessToken(boolean)
4341
*/
4442
String getAccessToken() throws WxErrorException;
4543

@@ -63,7 +61,7 @@ public interface WxCpService extends WxService {
6361
*
6462
* @return the jsapi ticket
6563
* @throws WxErrorException the wx error exception
66-
* @see #getJsapiTicket(boolean) #getJsapiTicket(boolean)
64+
* @see #getJsapiTicket(boolean) #getJsapiTicket(boolean)#getJsapiTicket(boolean)
6765
*/
6866
String getJsapiTicket() throws WxErrorException;
6967

@@ -90,7 +88,7 @@ public interface WxCpService extends WxService {
9088
*
9189
* @return the agent jsapi ticket
9290
* @throws WxErrorException the wx error exception
93-
* @see #getJsapiTicket(boolean) #getJsapiTicket(boolean)
91+
* @see #getJsapiTicket(boolean) #getJsapiTicket(boolean)#getJsapiTicket(boolean)
9492
*/
9593
String getAgentJsapiTicket() throws WxErrorException;
9694

@@ -376,22 +374,29 @@ public interface WxCpService extends WxService {
376374
/**
377375
* 获取日历相关接口的服务类对象
378376
*
379-
* @return the menu service
377+
* @return the oa calendar service
380378
*/
381379
WxCpOaCalendarService getOaCalendarService();
382380

381+
/**
382+
* 获取日程相关接口的服务类对象
383+
*
384+
* @return the oa schedule service
385+
*/
386+
WxCpOaScheduleService getOaScheduleService();
387+
383388
/**
384389
* 获取群机器人消息推送服务
385390
*
386391
* @return 群机器人消息推送服务 group robot service
387392
*/
388393
WxCpGroupRobotService getGroupRobotService();
389394

390-
/*
395+
/**
391396
* 获取工作台服务
392397
*
393398
* @return the workbench service
394-
* */
399+
*/
395400
WxCpAgentWorkBenchService getWorkBenchService();
396401

397402
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
5555
private WxCpGroupRobotService groupRobotService = new WxCpGroupRobotServiceImpl(this);
5656
private WxCpMessageService messageService = new WxCpMessageServiceImpl(this);
5757
private WxCpOaCalendarService oaCalendarService = new WxCpOaCalendarServiceImpl(this);
58+
private WxCpOaScheduleService oaScheduleService = new WxCpOaOaScheduleServiceImpl(this);
5859
private WxCpAgentWorkBenchService workBenchService = new WxCpAgentWorkBenchServiceImpl(this);
5960

6061
/**
@@ -512,4 +513,9 @@ public WxCpMessageService getMessageService() {
512513
public void setAgentService(WxCpAgentService agentService) {
513514
this.agentService = agentService;
514515
}
516+
517+
@Override
518+
public WxCpOaScheduleService getOaScheduleService() {
519+
return this.oaScheduleService;
520+
}
515521
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import com.google.gson.reflect.TypeToken;
5+
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
7+
import me.chanjar.weixin.common.error.WxErrorException;
8+
import me.chanjar.weixin.common.util.json.GsonParser;
9+
import me.chanjar.weixin.cp.api.WxCpOaScheduleService;
10+
import me.chanjar.weixin.cp.api.WxCpService;
11+
import me.chanjar.weixin.cp.bean.oa.WxCpOaSchedule;
12+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
13+
14+
import java.io.Serializable;
15+
import java.util.HashMap;
16+
import java.util.List;
17+
import java.util.Map;
18+
19+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
20+
21+
/**
22+
* 企业微信日程接口实现类.
23+
*
24+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
25+
* @date 2020-12-25
26+
*/
27+
@Slf4j
28+
@RequiredArgsConstructor
29+
public class WxCpOaOaScheduleServiceImpl implements WxCpOaScheduleService {
30+
private final WxCpService cpService;
31+
32+
@Override
33+
public String add(WxCpOaSchedule schedule, Integer agentId) throws WxErrorException {
34+
Map<String, Serializable> param;
35+
if (agentId == null) {
36+
param = ImmutableMap.of("schedule", schedule);
37+
} else {
38+
param = ImmutableMap.of("schedule", schedule, "agentid", agentId);
39+
}
40+
41+
return this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(SCHEDULE_ADD),
42+
WxCpGsonBuilder.create().toJson(param));
43+
}
44+
45+
@Override
46+
public void update(WxCpOaSchedule schedule) throws WxErrorException {
47+
this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(SCHEDULE_UPDATE),
48+
WxCpGsonBuilder.create().toJson(ImmutableMap.of("schedule", schedule)));
49+
}
50+
51+
@Override
52+
public List<WxCpOaSchedule> getDetails(List<String> scheduleIds) throws WxErrorException {
53+
final String response = this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(SCHEDULE_GET),
54+
WxCpGsonBuilder.create().toJson(ImmutableMap.of("schedule_id_list", scheduleIds)));
55+
return WxCpGsonBuilder.create().fromJson(GsonParser.parse(response).get("schedule_list"),
56+
new TypeToken<List<WxCpOaSchedule>>() {
57+
}.getType());
58+
}
59+
60+
@Override
61+
public void delete(String scheduleId) throws WxErrorException {
62+
this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(SCHEDULE_DEL),
63+
WxCpGsonBuilder.create().toJson(ImmutableMap.of("schedule_id", scheduleId)));
64+
}
65+
66+
@Override
67+
public List<WxCpOaSchedule> listByCalendar(String calId, Integer offset, Integer limit) throws WxErrorException {
68+
final Map<String, Object> param = new HashMap<>(3);
69+
param.put("cal_id", calId);
70+
if (offset != null) {
71+
param.put("offset", offset);
72+
}
73+
if (limit != null) {
74+
param.put("limit", limit);
75+
}
76+
final String response = this.cpService.post(this.cpService.getWxCpConfigStorage().getApiUrl(SCHEDULE_LIST),
77+
WxCpGsonBuilder.create().toJson(param));
78+
return WxCpGsonBuilder.create().fromJson(GsonParser.parse(response).get("schedule_list"),
79+
new TypeToken<List<WxCpOaSchedule>>() {
80+
}.getType());
81+
}
82+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public String toJson() {
199199
if (this.getDuplicateCheckInterval() != null) {
200200
messageJson.addProperty("duplicate_check_interval", this.getDuplicateCheckInterval());
201201
}
202-
202+
203203
this.handleMsgType(messageJson);
204204

205205
if (StringUtils.isNotBlank(this.getSafe())) {

0 commit comments

Comments
 (0)