Skip to content

Commit 1810884

Browse files
committed
binarywang#813 企业微信中部门id类型改为Long,以容纳更大的数值
1 parent 732a38b commit 1810884

File tree

5 files changed

+54
-37
lines changed

5 files changed

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

3+
import java.util.List;
4+
35
import me.chanjar.weixin.common.error.WxErrorException;
46
import me.chanjar.weixin.cp.bean.WxCpDepart;
57

6-
import java.util.List;
7-
88
/**
99
* <pre>
1010
* 部门管理接口
@@ -17,42 +17,47 @@ public interface WxCpDepartmentService {
1717

1818
/**
1919
* <pre>
20-
* 部门管理接口 - 创建部门
20+
* 部门管理接口 - 创建部门.
2121
* 最多支持创建500个部门
2222
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
2323
* </pre>
2424
*
2525
* @param depart 部门
2626
* @return 部门id
27+
* @throws WxErrorException 异常
2728
*/
2829
Integer create(WxCpDepart depart) throws WxErrorException;
2930

3031
/**
3132
* <pre>
32-
* 部门管理接口 - 查询部门
33+
* 部门管理接口 - 查询部门.
3334
* 详情请见: 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
3435
* </pre>
36+
*
3537
* @param id 部门id。获取指定部门及其下的子部门。非必需,可为null
38+
* @throws WxErrorException 异常
3639
*/
37-
List<WxCpDepart> list(Integer id) throws WxErrorException;
40+
List<WxCpDepart> list(Long id) throws WxErrorException;
3841

3942
/**
4043
* <pre>
41-
* 部门管理接口 - 修改部门名
44+
* 部门管理接口 - 修改部门名.
4245
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=部门管理接口
4346
* 如果id为0(未部门),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
4447
* </pre>
4548
*
4649
* @param group 要更新的group,group的id,name必须设置
50+
* @throws WxErrorException 异常
4751
*/
4852
void update(WxCpDepart group) throws WxErrorException;
4953

5054
/**
5155
* <pre>
52-
* 部门管理接口 - 删除部门
56+
* 部门管理接口 - 删除部门.
5357
* </pre>
5458
*
5559
* @param departId 部门id
60+
* @throws WxErrorException 异常
5661
*/
57-
void delete(Integer departId) throws WxErrorException;
62+
void delete(Long departId) throws WxErrorException;
5863
}

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

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

3+
import java.util.List;
4+
35
import com.google.gson.JsonElement;
46
import com.google.gson.JsonParser;
57
import com.google.gson.reflect.TypeToken;
@@ -10,8 +12,6 @@
1012
import me.chanjar.weixin.cp.bean.WxCpDepart;
1113
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
1214

13-
import java.util.List;
14-
1515
/**
1616
* <pre>
1717
* 部门管理接口
@@ -42,13 +42,13 @@ public void update(WxCpDepart group) throws WxErrorException {
4242
}
4343

4444
@Override
45-
public void delete(Integer departId) throws WxErrorException {
45+
public void delete(Long departId) throws WxErrorException {
4646
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/delete?id=" + departId;
4747
this.mainService.get(url, null);
4848
}
4949

5050
@Override
51-
public List<WxCpDepart> list(Integer id) throws WxErrorException {
51+
public List<WxCpDepart> list(Long id) throws WxErrorException {
5252
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
5353
if (id != null) {
5454
url += "?id=" + id;

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpDepart.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package me.chanjar.weixin.cp.bean;
22

3+
import java.io.Serializable;
4+
35
import lombok.Data;
46
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
57

6-
import java.io.Serializable;
7-
88
/**
99
* 微信部门.
1010
*
@@ -14,9 +14,9 @@
1414
public class WxCpDepart implements Serializable {
1515

1616
private static final long serialVersionUID = -5028321625140879571L;
17-
private Integer id;
17+
private Long id;
1818
private String name;
19-
private Integer parentId;
19+
private Long parentId;
2020
private Long order;
2121

2222
public static WxCpDepart fromJson(String json) {

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpDepartGsonAdapter.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,43 @@
88
*/
99
package me.chanjar.weixin.cp.util.json;
1010

11-
import com.google.gson.*;
11+
import java.lang.reflect.Type;
12+
13+
import com.google.gson.JsonDeserializationContext;
14+
import com.google.gson.JsonDeserializer;
15+
import com.google.gson.JsonElement;
16+
import com.google.gson.JsonObject;
17+
import com.google.gson.JsonParseException;
18+
import com.google.gson.JsonSerializationContext;
19+
import com.google.gson.JsonSerializer;
1220
import me.chanjar.weixin.common.util.json.GsonHelper;
1321
import me.chanjar.weixin.cp.bean.WxCpDepart;
1422

15-
import java.lang.reflect.Type;
16-
1723
/**
24+
* WxCpDepart的gson适配器.
25+
*
1826
* @author Daniel Qian
1927
*/
2028
public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDeserializer<WxCpDepart> {
29+
private static final String ID = "id";
30+
private static final String NAME = "name";
31+
private static final String PARENT_ID = "parentid";
32+
private static final String ORDER = "order";
2133

2234
@Override
2335
public JsonElement serialize(WxCpDepart group, Type typeOfSrc, JsonSerializationContext context) {
2436
JsonObject json = new JsonObject();
2537
if (group.getId() != null) {
26-
json.addProperty("id", group.getId());
38+
json.addProperty(ID, group.getId());
2739
}
2840
if (group.getName() != null) {
29-
json.addProperty("name", group.getName());
41+
json.addProperty(NAME, group.getName());
3042
}
3143
if (group.getParentId() != null) {
32-
json.addProperty("parentid", group.getParentId());
44+
json.addProperty(PARENT_ID, group.getParentId());
3345
}
3446
if (group.getOrder() != null) {
35-
json.addProperty("order", String.valueOf(group.getOrder()));
47+
json.addProperty(ORDER, String.valueOf(group.getOrder()));
3648
}
3749
return json;
3850
}
@@ -42,17 +54,17 @@ public WxCpDepart deserialize(JsonElement json, Type typeOfT, JsonDeserializatio
4254
throws JsonParseException {
4355
WxCpDepart depart = new WxCpDepart();
4456
JsonObject departJson = json.getAsJsonObject();
45-
if (departJson.get("id") != null && !departJson.get("id").isJsonNull()) {
46-
depart.setId(GsonHelper.getAsInteger(departJson.get("id")));
57+
if (departJson.get(ID) != null && !departJson.get(ID).isJsonNull()) {
58+
depart.setId(GsonHelper.getAsLong(departJson.get(ID)));
4759
}
48-
if (departJson.get("name") != null && !departJson.get("name").isJsonNull()) {
49-
depart.setName(GsonHelper.getAsString(departJson.get("name")));
60+
if (departJson.get(NAME) != null && !departJson.get(NAME).isJsonNull()) {
61+
depart.setName(GsonHelper.getAsString(departJson.get(NAME)));
5062
}
51-
if (departJson.get("order") != null && !departJson.get("order").isJsonNull()) {
52-
depart.setOrder(GsonHelper.getAsLong(departJson.get("order")));
63+
if (departJson.get(ORDER) != null && !departJson.get(ORDER).isJsonNull()) {
64+
depart.setOrder(GsonHelper.getAsLong(departJson.get(ORDER)));
5365
}
54-
if (departJson.get("parentid") != null && !departJson.get("parentid").isJsonNull()) {
55-
depart.setParentId(GsonHelper.getAsInteger(departJson.get("parentid")));
66+
if (departJson.get(PARENT_ID) != null && !departJson.get(PARENT_ID).isJsonNull()) {
67+
depart.setParentId(GsonHelper.getAsLong(departJson.get(PARENT_ID)));
5668
}
5769
return depart;
5870
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package me.chanjar.weixin.cp.api.impl;
22

3+
import java.util.List;
4+
5+
import org.testng.annotations.*;
6+
37
import com.google.inject.Inject;
48
import me.chanjar.weixin.cp.api.ApiTestModule;
59
import me.chanjar.weixin.cp.api.WxCpService;
610
import me.chanjar.weixin.cp.bean.WxCpDepart;
7-
import org.testng.annotations.*;
8-
9-
import java.util.List;
1011

1112
import static org.assertj.core.api.Assertions.assertThat;
12-
import static org.testng.Assert.*;
1313

1414
/**
1515
* <pre>
@@ -29,7 +29,7 @@ public class WxCpDepartmentServiceImplTest {
2929
public void testCreate() throws Exception {
3030
WxCpDepart cpDepart = new WxCpDepart();
3131
cpDepart.setName("子部门" + System.currentTimeMillis());
32-
cpDepart.setParentId(1);
32+
cpDepart.setParentId(1L);
3333
cpDepart.setOrder(1L);
3434
Integer departId = this.wxCpService.getDepartmentService().create(cpDepart);
3535
System.out.println(departId);
@@ -45,7 +45,7 @@ public Object[][] departIds(){
4545
}
4646

4747
@Test(dataProvider = "departIds")
48-
public void testList(Integer id) throws Exception {
48+
public void testList(Long id) throws Exception {
4949
System.out.println("=================获取部门");
5050
List<WxCpDepart> departList = this.wxCpService.getDepartmentService().list(id);
5151
assertThat(departList).isNotEmpty();

0 commit comments

Comments
 (0)