mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 #2537 【企业微信】部门管理增加获取子部门ID列表和获取单个部门详情的接口
This commit is contained in:
parent
94bd262694
commit
2a169bacad
@ -28,6 +28,18 @@ public interface WxCpDepartmentService {
|
|||||||
*/
|
*/
|
||||||
Long create(WxCpDepart depart) throws WxErrorException;
|
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>
|
* <pre>
|
||||||
* 部门管理接口 - 获取部门列表.
|
* 部门管理接口 - 获取部门列表.
|
||||||
@ -40,6 +52,18 @@ public interface WxCpDepartmentService {
|
|||||||
*/
|
*/
|
||||||
List<WxCpDepart> list(Long id) throws WxErrorException;
|
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>
|
* <pre>
|
||||||
* 部门管理接口 - 更新部门.
|
* 部门管理接口 - 更新部门.
|
||||||
|
@ -35,6 +35,18 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
|
|||||||
return GsonHelper.getAsLong(tmpJsonObject.get("id"));
|
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
|
@Override
|
||||||
public void update(WxCpDepart group) throws WxErrorException {
|
public void update(WxCpDepart group) throws WxErrorException {
|
||||||
String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
|
String url = this.mainService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE);
|
||||||
@ -62,4 +74,20 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
|
|||||||
}.getType()
|
}.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()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,8 +71,10 @@ public interface WxCpApiPathConsts {
|
|||||||
interface Department {
|
interface Department {
|
||||||
String DEPARTMENT_CREATE = "/cgi-bin/department/create";
|
String DEPARTMENT_CREATE = "/cgi-bin/department/create";
|
||||||
String DEPARTMENT_UPDATE = "/cgi-bin/department/update";
|
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_DELETE = "/cgi-bin/department/delete?id=%d";
|
||||||
String DEPARTMENT_LIST = "/cgi-bin/department/list";
|
String DEPARTMENT_LIST = "/cgi-bin/department/list";
|
||||||
|
String DEPARTMENT_SIMPLE_LIST = "/cgi-bin/department/simplelist";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Media {
|
interface Media {
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
package me.chanjar.weixin.cp.api.impl;
|
package me.chanjar.weixin.cp.api.impl;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.testng.annotations.*;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
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.ApiTestModule;
|
||||||
import me.chanjar.weixin.cp.api.WxCpService;
|
import me.chanjar.weixin.cp.api.WxCpService;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
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;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@ -36,11 +38,11 @@ public class WxCpDepartmentServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
public Object[][] departIds(){
|
public Object[][] departIds() {
|
||||||
return new Object[][]{
|
return new Object[][]{
|
||||||
{null},
|
{null},
|
||||||
{1},
|
{12L},
|
||||||
{5}
|
{5L}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,4 +72,22 @@ public class WxCpDepartmentServiceImplTest {
|
|||||||
this.wxCpService.getDepartmentService().delete(this.depart.getId());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user