mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-04 15:01:24 +08:00
🆕 #3529 【企业微信】增加批量设置应用在用户工作台展示的数据的接口
This commit is contained in:
parent
8f101b5642
commit
a113746ca8
@ -36,4 +36,12 @@ public interface WxCpAgentWorkBenchService {
|
||||
* @throws WxErrorException the wx error exception
|
||||
*/
|
||||
void setWorkBenchData(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* Batch sets work bench data.
|
||||
*
|
||||
* @param wxCpAgentWorkBench the wx cp agent work bench
|
||||
* @throws WxErrorException the wx error exception
|
||||
*/
|
||||
void batchSetWorkBenchData(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException;
|
||||
}
|
||||
|
@ -38,4 +38,10 @@ public class WxCpAgentWorkBenchServiceImpl implements WxCpAgentWorkBenchService
|
||||
final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WORKBENCH_DATA_SET));
|
||||
this.mainService.post(url, wxCpAgentWorkBench.toUserDataString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batchSetWorkBenchData(WxCpAgentWorkBench wxCpAgentWorkBench) throws WxErrorException {
|
||||
final String url = String.format(this.mainService.getWxCpConfigStorage().getApiUrl(WORKBENCH_BATCH_DATA_SET));
|
||||
this.mainService.post(url, wxCpAgentWorkBench.toBatchUserDataString());
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,14 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
import me.chanjar.weixin.cp.bean.workbench.WorkBenchKeyData;
|
||||
import me.chanjar.weixin.cp.bean.workbench.WorkBenchList;
|
||||
import me.chanjar.weixin.cp.constant.WxCpConsts;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The type Wx cp agent work bench.
|
||||
@ -33,6 +35,10 @@ public class WxCpAgentWorkBench implements Serializable {
|
||||
* 用户的userid
|
||||
*/
|
||||
private String userId;
|
||||
/**
|
||||
* 用户的userIds
|
||||
*/
|
||||
private Set<String> userIds;
|
||||
/**
|
||||
* 应用id
|
||||
*/
|
||||
@ -93,6 +99,20 @@ public class WxCpAgentWorkBench implements Serializable {
|
||||
return userDataObject.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成批量用户数据Json字符串
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String toBatchUserDataString() {
|
||||
JsonObject userDataObject = new JsonObject();
|
||||
userDataObject.addProperty("agentid", this.agentId);
|
||||
JsonArray useridList = WxGsonBuilder.create().toJsonTree(this.userIds).getAsJsonArray();
|
||||
userDataObject.add("userid_list", useridList);
|
||||
this.handleBatch(userDataObject);
|
||||
return userDataObject.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理不用类型的工作台数据
|
||||
*/
|
||||
@ -152,4 +172,75 @@ public class WxCpAgentWorkBench implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理不用类型的工作台数据
|
||||
*/
|
||||
private void handleBatch(JsonObject templateObject) {
|
||||
switch (this.getType()) {
|
||||
case WxCpConsts.WorkBenchType.KEYDATA: {
|
||||
JsonArray keyDataArray = new JsonArray();
|
||||
JsonObject itemsObject = new JsonObject();
|
||||
for (WorkBenchKeyData keyDataItem : this.keyDataList) {
|
||||
JsonObject keyDataObject = new JsonObject();
|
||||
keyDataObject.addProperty("key", keyDataItem.getKey());
|
||||
keyDataObject.addProperty("data", keyDataItem.getData());
|
||||
keyDataObject.addProperty("jump_url", keyDataItem.getJumpUrl());
|
||||
keyDataObject.addProperty("pagepath", keyDataItem.getPagePath());
|
||||
keyDataArray.add(keyDataObject);
|
||||
}
|
||||
itemsObject.add("items", keyDataArray);
|
||||
JsonObject dataObject = new JsonObject();
|
||||
dataObject.addProperty("type", WxCpConsts.WorkBenchType.KEYDATA);
|
||||
dataObject.add("keydata", itemsObject);
|
||||
templateObject.add("data", dataObject);
|
||||
break;
|
||||
}
|
||||
case WxCpConsts.WorkBenchType.IMAGE: {
|
||||
JsonObject image = new JsonObject();
|
||||
image.addProperty("url", this.url);
|
||||
image.addProperty("jump_url", this.jumpUrl);
|
||||
image.addProperty("pagepath", this.pagePath);
|
||||
JsonObject dataObject = new JsonObject();
|
||||
dataObject.addProperty("type", WxCpConsts.WorkBenchType.IMAGE);
|
||||
dataObject.add("image", image);
|
||||
templateObject.add("data", dataObject);
|
||||
break;
|
||||
}
|
||||
case WxCpConsts.WorkBenchType.LIST: {
|
||||
JsonArray listArray = new JsonArray();
|
||||
JsonObject itemsObject = new JsonObject();
|
||||
for (WorkBenchList listItem : this.lists) {
|
||||
JsonObject listObject = new JsonObject();
|
||||
listObject.addProperty("title", listItem.getTitle());
|
||||
listObject.addProperty("jump_url", listItem.getJumpUrl());
|
||||
listObject.addProperty("pagepath", listItem.getPagePath());
|
||||
listArray.add(listObject);
|
||||
}
|
||||
itemsObject.add("items", listArray);
|
||||
JsonObject dataObject = new JsonObject();
|
||||
dataObject.addProperty("type", WxCpConsts.WorkBenchType.LIST);
|
||||
dataObject.add("list", itemsObject);
|
||||
templateObject.add("data", dataObject);
|
||||
break;
|
||||
}
|
||||
case WxCpConsts.WorkBenchType.WEBVIEW: {
|
||||
JsonObject webview = new JsonObject();
|
||||
webview.addProperty("url", this.url);
|
||||
webview.addProperty("jump_url", this.jumpUrl);
|
||||
webview.addProperty("pagepath", this.pagePath);
|
||||
if (null != this.enableWebviewClick) {
|
||||
webview.addProperty("enable_webview_click", this.enableWebviewClick);
|
||||
}
|
||||
JsonObject dataObject = new JsonObject();
|
||||
dataObject.addProperty("type", WxCpConsts.WorkBenchType.WEBVIEW);
|
||||
dataObject.add("webview", webview);
|
||||
templateObject.add("data", dataObject);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,6 +130,10 @@ public interface WxCpApiPathConsts {
|
||||
* The constant WORKBENCH_DATA_SET.
|
||||
*/
|
||||
String WORKBENCH_DATA_SET = "/cgi-bin/agent/set_workbench_data";
|
||||
/**
|
||||
* The constant WORKBENCH_BATCH_DATA_SET.
|
||||
*/
|
||||
String WORKBENCH_BATCH_DATA_SET = "/cgi-bin/agent/batch_set_workbench_data";
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user