mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-02 21:26:01 +08:00
🎨 优化代码
This commit is contained in:
@ -98,9 +98,9 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
if (GsonHelper.isNotNull(o.get(EXTERNAL_PROFILE))) {
|
if (GsonHelper.isNotNull(o.get(EXTERNAL_PROFILE))) {
|
||||||
user.setExternalCorpName(GsonHelper.getString(o.getAsJsonObject().get(EXTERNAL_PROFILE).getAsJsonObject(), EXTERNAL_CORP_NAME));
|
user.setExternalCorpName(GsonHelper.getString(o.getAsJsonObject().get(EXTERNAL_PROFILE).getAsJsonObject(), EXTERNAL_CORP_NAME));
|
||||||
JsonElement jsonElement = o.get(EXTERNAL_PROFILE).getAsJsonObject().get(WECHAT_CHANNELS);
|
JsonElement jsonElement = o.get(EXTERNAL_PROFILE).getAsJsonObject().get(WECHAT_CHANNELS);
|
||||||
if(jsonElement !=null){
|
if (jsonElement != null) {
|
||||||
JsonObject asJsonObject = jsonElement.getAsJsonObject();
|
JsonObject asJsonObject = jsonElement.getAsJsonObject();
|
||||||
user.setWechatChannels(WechatChannels.builder().nickname(GsonHelper.getString(asJsonObject,"nickname")).status(GsonHelper.getInteger(asJsonObject,"status")).build());
|
user.setWechatChannels(WechatChannels.builder().nickname(GsonHelper.getString(asJsonObject, "nickname")).status(GsonHelper.getInteger(asJsonObject, "status")).build());
|
||||||
}
|
}
|
||||||
this.buildExternalAttrs(o, user);
|
this.buildExternalAttrs(o, user);
|
||||||
}
|
}
|
||||||
@ -140,7 +140,12 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buildExternalAttrs(JsonObject o, WxCpUser user) {
|
private void buildExternalAttrs(JsonObject o, WxCpUser user) {
|
||||||
JsonArray attrJsonElements = o.get(EXTERNAL_PROFILE).getAsJsonObject().get(EXTERNAL_ATTR).getAsJsonArray();
|
JsonElement jsonElement = o.get(EXTERNAL_PROFILE).getAsJsonObject().get(EXTERNAL_ATTR);
|
||||||
|
if (jsonElement == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonArray attrJsonElements = jsonElement.getAsJsonArray();
|
||||||
for (JsonElement element : attrJsonElements) {
|
for (JsonElement element : attrJsonElements) {
|
||||||
final Integer type = GsonHelper.getInteger(element.getAsJsonObject(), "type");
|
final Integer type = GsonHelper.getInteger(element.getAsJsonObject(), "type");
|
||||||
final String name = GsonHelper.getString(element.getAsJsonObject(), "name");
|
final String name = GsonHelper.getString(element.getAsJsonObject(), "name");
|
||||||
@ -328,8 +333,8 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
attrsJson.addProperty(EXTERNAL_CORP_NAME, user.getExternalCorpName());
|
attrsJson.addProperty(EXTERNAL_CORP_NAME, user.getExternalCorpName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user.getWechatChannels() != null){
|
if (user.getWechatChannels() != null) {
|
||||||
attrsJson.add(WECHAT_CHANNELS,GsonHelper.buildJsonObject("nickname", user.getWechatChannels().getNickname(), "status", user.getWechatChannels().getStatus()));
|
attrsJson.add(WECHAT_CHANNELS, GsonHelper.buildJsonObject("nickname", user.getWechatChannels().getNickname(), "status", user.getWechatChannels().getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.getExternalAttrs().isEmpty()) {
|
if (!user.getExternalAttrs().isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user