8000 #456 企业微信获取部门列表接口方法listAll修改为list,以支持按部分id获取其下属部门列表 · devandroid/weixin-java-tools@0c7a472 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c7a472

Browse files
committed
binarywang#456 企业微信获取部门列表接口方法listAll修改为list,以支持按部分id获取其下属部门列表
1 parent e3293d1 commit 0c7a472

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

weixin-java-cp/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
<groupId>org.projectlombok</groupId>
7474
<artifactId>lombok</artifactId>
7575
</dependency>
76+
77+
<dependency>
78+
<groupId>org.assertj</groupId>
79+
<artifactId>assertj-guava</artifactId>
80+
<scope>test</scope>
81+
</dependency>
7682
</dependencies>
7783

7884
<build>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ public interface WxCpDepartmentService {
2929

3030
/**
3131
* <pre>
32-
* 部门管理接口 - 查询所有部门
33-
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
32+
* 部门管理接口 - 查询部门
33+
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E9%83%A8%E9%97%A8#.E8.8E.B7.E5.8F.96.E9.83.A8.E9.97.A8.E5.88.97.E8.A1.A8
3434
* </pre>
35+
* @param id 部门id。获取指定部门及其下的子部门。非必需,可为null
3536
*/
36-
List<WxCpDepart> listAll() throws WxErrorException;
37+
List<WxCpDepart> list(Integer id) throws WxErrorException;
3738

3839
/**
3940
* <pre>

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

Lines changed: 5 additions & 5 deletions
< 10000 tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public void delete(Integer departId) throws WxErrorException {
4848
}
4949

5050
@Override
51-
public List<WxCpDepart> listAll() throws WxErrorException {
51+
public List<WxCpDepart> list(Integer id) throws WxErrorException {
5252
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
53+
if (id != null) {
54+
url += "?id=" + id;
55+
}
56+
5357
String responseContent = this.mainService.get(url, null);
54-
/*
55-
* 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
56-
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
57-
*/
5858
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
5959
return WxCpGsonBuilder.INSTANCE.create()
6060
.fromJson(tmpJsonElement.getAsJsonObject().get("department"),

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.List;
1010

11+
import static org.assertj.core.api.Assertions.assertThat;
1112
import static org.testng.Assert.*;
1213

1314
/**
@@ -34,16 +35,24 @@ public void testCreate() throws Exception {
3435
System.out.println(departId);
3536
}
3637

37-
@Test
38-
public void testListAll() throws Exception {
38+
@DataProvider
39+
public Object[][] departIds(){
40+
return new Object[][]{
41+
{null},
42+
{1},
43+
{5}
44+
};
45+
}
46+
47+
@Test(dataProvider = "departIds")
48+
public void testList(Integer id) throws Exception {
3949
System.out.println("=================获取部门");
40-
List<WxCpDepart> departList = this.wxCpService.getDepartmentService().listAll();
41-
assertNotNull(departList);
42-
assertTrue(departList.size() > 0);
50+
List<WxCpDepart> departList = this.wxCpService.getDepartmentService().list(id);
51+
assertThat(departList).isNotEmpty();
4352
for (WxCpDepart g : departList) {
4453
this.depart = g;
4554
System.out.println(this.depart.getId() + ":" + this.depart.getName());
46-
assertNotNull(g.getName());
55+
assertThat(g.getName()).isNotBlank();
4756
}
4857
}
4958

0 commit comments

Comments
 (0)
0