🎨 #2537 【企业微信】部门管理增加获取子部门ID列表和获取单个部门详情的接口

This commit is contained in:
Binary Wang 2022-03-31 21:59:46 +08:00
parent 94bd262694
commit 2a169bacad
4 changed files with 81 additions and 7 deletions

View File

@ -28,6 +28,18 @@ public interface WxCpDepartmentService {
*/
Long create(WxCpDepart depart) throws WxErrorException;
/**
* <pre>
* 部门管理接口 - 获取单个部门详情.
* 详情请见: https://developer.work.weixin.qq.com/document/path/95351
* </pre>
*
* @param id 部门id
* @return 部门信息
* @throws WxErrorException 异常
*/
WxCpDepart get(Long id) throws WxErrorException;
/**
* <pre>
* 部门管理接口 - 获取部门列表.
@ -40,6 +52,18 @@ public interface WxCpDepartmentService {
*/
List<WxCpDepart> list(Long id) throws WxErrorException;
/**
* <pre>
* 部门管理接口 - 获取子部门ID列表.
* 详情请见: https://developer.work.weixin.qq.com/document/path/95350
* </pre>
*
* @param id 部门id获取指定部门及其下的子部门以及子部门的子部门等等递归 如果不填默认获取全量组织架构
* @return 子部门ID列表
* @throws WxErrorException 异常
*/
List<WxCpDepart> simpleList(Long id) throws WxErrorException;
/**
* <pre>
* 部门管理接口 - 更新部门.

View File

@ -35,6 +35,18 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
return GsonHelper.getAsLong(tmpJsonObject.get("id"));
}
@Override
public WxCpDepart get(Long id) throws WxErrorException {
String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_GET), id);
String responseContent = this.mainService.get(url, null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(tmpJsonObject.get("department"),
new TypeToken<WxCpDepart>() {
}.getType()
);
}
@Override
public void update(WxCpDepart group) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
@ -62,4 +74,20 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
}.getType()
);
}
@Override
public List<WxCpDepart> simpleList(Long id) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_SIMPLE_LIST);
if (id != null) {
url += "?id=" + id;
}
String responseContent = this.mainService.get(url, null);
JsonObject tmpJsonObject = GsonParser.parse(responseContent);
return WxCpGsonBuilder.create()
.fromJson(tmpJsonObject.get("department_id"),
new TypeToken<List<WxCpDepart>>() {
}.getType()
);
}
}

View File

@ -71,8 +71,10 @@ public interface WxCpApiPathConsts {
interface Department {
String DEPARTMENT_CREATE = "/cgi-bin/department/create";
String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
String DEPARTMENT_GET = "/cgi-bin/department/get?id=%d";
String DEPARTMENT_DELETE = "/cgi-bin/department/delete?id=%d";
String DEPARTMENT_LIST = "/cgi-bin/department/list";
String DEPARTMENT_SIMPLE_LIST = "/cgi-bin/department/simplelist";
}
interface Media {

View File

@ -1,13 +1,15 @@
package me.chanjar.weixin.cp.api.impl;
import java.util.List;
import org.testng.annotations.*;
import com.google.inject.Inject;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.ApiTestModule;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@ -36,11 +38,11 @@ public class WxCpDepartmentServiceImplTest {
}
@DataProvider
public Object[][] departIds(){
public Object[][] departIds() {
return new Object[][]{
{null},
{1},
{5}
{12L},
{5L}
};
}
@ -70,4 +72,22 @@ public class WxCpDepartmentServiceImplTest {
this.wxCpService.getDepartmentService().delete(this.depart.getId());
}
@Test(dataProvider = "departIds")
public void testSimpleList(Long id) throws WxErrorException {
System.out.println("=================获取子部门ID列表");
List<WxCpDepart> departList = this.wxCpService.getDepartmentService().simpleList(id);
assertThat(departList).isNotEmpty();
departList.forEach(System.out::println);
}
@Test(dataProvider = "departIds")
public void testGet(Long id) throws WxErrorException {
if (id == null) {
return;
}
WxCpDepart depart = this.wxCpService.getDepartmentService().get(id);
assertThat(depart).isNotNull();
System.out.println(depart);
}
}