🎨 #2563 【企业微信】优化获取待分配离职成员列表的接口,增加分页查询游标参数

This commit is contained in:
Wong 2022-03-25 09:21:27 +00:00 committed by Binary Wang
parent 1893790aae
commit 62645a4311
4 changed files with 81 additions and 11 deletions

View File

@ -361,14 +361,19 @@ public interface WxCpExternalContactService {
List<String> listFollowers() throws WxErrorException;
/**
* 企业和第三方可通过此接口获取所有离职成员的客户列表并可进一步调用离职成员的外部联系人再分配接口将这些客户重新分配给其他企业成员
* 获取待分配的离职成员列表
* 企业和第三方可通过此接口获取所有离职成员的客户列表并可进一步调用分配离职成员的客户接口将这些客户重新分配给其他企业成员
*
* @param page the page
* @param pageSize the page size
* @return wx cp user external unassign list
* @throws WxErrorException the wx error exception
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_unassigned_list?access_token=ACCESS_TOKEN
*
* @param pageId 分页查询要查询页号从0开始
* @param cursor 分页查询游标字符串类型适用于数据量较大的情况如果使用该参数则无需填写page_id该参数由上一次调用返回
* @param pageSize 每次返回的最大记录数默认为1000最大值为1000
* @return
* @throws WxErrorException
*/
WxCpUserExternalUnassignList listUnassignedList(Integer page, Integer pageSize) throws WxErrorException;
WxCpUserExternalUnassignList listUnassignedList(Integer pageId, String cursor, Integer pageSize) throws WxErrorException;
/**
* 企业可通过此接口将已离职成员的外部联系人分配给另一个成员接替联系

View File

@ -32,7 +32,7 @@ import java.util.List;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.ExternalContact.*;
/**
* @author 曹祖鹏 & yuanqixun & Mr.Pan
* @author 曹祖鹏 & yuanqixun & Mr.Pan & Wang_Wong
*/
@RequiredArgsConstructor
public class WxCpExternalContactServiceImpl implements WxCpExternalContactService {
@ -245,10 +245,13 @@ public class WxCpExternalContactServiceImpl implements WxCpExternalContactServic
}
@Override
public WxCpUserExternalUnassignList listUnassignedList(Integer pageIndex, Integer pageSize) throws WxErrorException {
public WxCpUserExternalUnassignList listUnassignedList(Integer pageIndex, String cursor, Integer pageSize) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("page_id", pageIndex == null ? 0 : pageIndex);
json.addProperty("page_size", pageSize == null ? 100 : pageSize);
if(pageIndex != null){
json.addProperty("page_id", pageIndex);
}
json.addProperty("cursor", StringUtils.isEmpty(cursor) ? "" : cursor);
json.addProperty("page_size", pageSize == null ? 1000 : pageSize);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(LIST_UNASSIGNED_CONTACT);
final String result = this.mainService.post(url, json.toString());
return WxCpUserExternalUnassignList.fromJson(result);

View File

@ -12,7 +12,7 @@ import java.util.List;
/**
* 离职员工外部联系人列表
*
* @author yqx
* @author yqx & Wang_Wong
* @date 2020/3/15
*/
@Getter
@ -25,6 +25,9 @@ public class WxCpUserExternalUnassignList extends WxCpBaseResp {
@SerializedName("is_last")
private boolean isLast;
@SerializedName("next_cursor")
private String nextCursor;
@Getter
@Setter
public static class UnassignInfo implements Serializable {
@ -52,4 +55,9 @@ public class WxCpUserExternalUnassignList extends WxCpBaseResp {
public static WxCpUserExternalUnassignList fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUserExternalUnassignList.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -0,0 +1,54 @@
package me.chanjar.weixin.cp.api;
import com.google.common.collect.Lists;
import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.external.*;
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
import me.chanjar.weixin.cp.bean.external.msg.Image;
import me.chanjar.weixin.cp.bean.external.msg.Video;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import org.testng.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import static org.testng.Assert.assertNotNull;
/**
* 离职继承测试类
*
* 官方文档
* https://developer.work.weixin.qq.com/document/path/92124
*/
@Slf4j
@Guice(modules = ApiTestModule.class)
public class WxCpExternalContactTest {
@Inject
private WxCpService wxCpService;
@Inject
protected ApiTestModule.WxXmlCpInMemoryConfigStorage configStorage;
@Test
public void testGetExternalContact() throws WxErrorException {
String externalUserId = this.configStorage.getExternalUserId();
WxCpUserExternalUnassignList unassignList = this.wxCpService.getExternalContactService().listUnassignedList(null, null, 100);
log.info(unassignList.toJson());
// test str
String result = "{\"errcode\":0,\"errmsg\":\"ok\",\"info\":[{\"handover_userid\":\"zhangsan\",\"external_userid\":\"woAJ2GCAAAd4uL12hdfsdasassdDmAAAAA\",\"dimission_time\":1550838571},{\"handover_userid\":\"lisi\",\"external_userid\":\"wmAJ2GCAAAzLTI123ghsdfoGZNqqAAAA\",\"dimission_time\":1550661468}],\"is_last\":false,\"next_cursor\":\"aSfwejksvhToiMMfFeIGZZ\"}";
WxCpUserExternalUnassignList json = WxCpUserExternalUnassignList.fromJson(result);
log.info(json.toJson());
}
}