🎨 #2452 【企业微信】获取部门列表接口添加返回字段 departmentLeader(部门负责人的UserID)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 企业微信的部门.
|
||||
*
|
||||
@@ -17,6 +17,7 @@ public class WxCpDepart implements Serializable {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String enName;
|
||||
private String[] departmentLeader;
|
||||
private Long parentId;
|
||||
private Long order;
|
||||
|
||||
|
||||
@@ -8,18 +8,12 @@
|
||||
*/
|
||||
package me.chanjar.weixin.cp.util.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.*;
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* WxCpDepart的gson适配器.
|
||||
*
|
||||
@@ -29,6 +23,7 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
|
||||
private static final String ID = "id";
|
||||
private static final String NAME = "name";
|
||||
private static final String EN_NAME = "name_en";
|
||||
private static final String DEPARTMENT_LEADER = "department_leader";
|
||||
private static final String PARENT_ID = "parentid";
|
||||
private static final String ORDER = "order";
|
||||
|
||||
@@ -44,6 +39,13 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
|
||||
if (group.getEnName() != null) {
|
||||
json.addProperty(EN_NAME, group.getEnName());
|
||||
}
|
||||
if (group.getDepartmentLeader() != null) {
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String department : group.getDepartmentLeader()) {
|
||||
jsonArray.add(new JsonPrimitive(department));
|
||||
}
|
||||
json.add(DEPARTMENT_LEADER, jsonArray);
|
||||
}
|
||||
if (group.getParentId() != null) {
|
||||
json.addProperty(PARENT_ID, group.getParentId());
|
||||
}
|
||||
@@ -67,6 +69,15 @@ public class WxCpDepartGsonAdapter implements JsonSerializer<WxCpDepart>, JsonDe
|
||||
if (departJson.get(EN_NAME) != null && !departJson.get(EN_NAME).isJsonNull()) {
|
||||
depart.setEnName(GsonHelper.getAsString(departJson.get(EN_NAME)));
|
||||
}
|
||||
if (departJson.getAsJsonArray(DEPARTMENT_LEADER) != null && !departJson.get(DEPARTMENT_LEADER).isJsonNull()) {
|
||||
JsonArray jsonArray = departJson.getAsJsonArray(DEPARTMENT_LEADER);
|
||||
String[] departments = new String[jsonArray.size()];
|
||||
int i = 0;
|
||||
for (JsonElement jsonElement : jsonArray) {
|
||||
departments[i++] = jsonElement.getAsString();
|
||||
}
|
||||
depart.setDepartmentLeader(departments);
|
||||
}
|
||||
if (departJson.get(ORDER) != null && !departJson.get(ORDER).isJsonNull()) {
|
||||
depart.setOrder(GsonHelper.getAsLong(departJson.get(ORDER)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user