diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java index 6c07a27..aef4957 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/common/ApiEntity.java @@ -8,7 +8,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; -import java.util.ArrayList; import java.util.Map; /** @@ -21,7 +20,7 @@ public class ApiEntity { private String method;//请求方式 private Map queryParams;//请求参数 private Map headers;//请求头参数 - private JSONObject requestBody;//请求体 + private Object requestBody;//请求体 public String getURL() { return URL; @@ -55,15 +54,15 @@ public class ApiEntity { this.headers = headers; } - public JSONObject getRequestBody() { + public Object getRequestBody() { return requestBody; } - public void setRequestBody(JSONObject requestBody) { + public void setRequestBody(Object requestBody) { this.requestBody = requestBody; } - public ApiEntity(String URL, String method, Map queryParams, Map headers, JSONObject requestBody) { + public ApiEntity(String URL, String method, Map queryParams, Map headers, Object requestBody) { this.URL = URL; this.method = method; this.queryParams = queryParams; @@ -84,7 +83,7 @@ public class ApiEntity { } } - HttpEntity objectHttpEntity = new HttpEntity<>(httpHeaders); + HttpEntity objectHttpEntity = new HttpEntity<>(apiEntity.getRequestBody().toString(), httpHeaders); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(apiEntity.getURL()); Map params = apiEntity.getQueryParams(); if (params != null) { diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java index eb81c6b..c1761da 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/form/ApiMappingBillPlugin.java @@ -11,6 +11,8 @@ import kd.bos.form.control.Toolbar; import kd.bos.form.control.events.ItemClickEvent; import kd.bos.form.plugin.AbstractFormPlugin; import kd.sdk.plugin.Plugin; +import shkd.sys.sys.common.ApiEntity; +import shkd.sys.sys.mservice.ApiService; import java.math.BigDecimal; import java.util.*; @@ -35,8 +37,10 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin { @Override public void itemClick(ItemClickEvent evt) { String itemKey = evt.getItemKey(); + DynamicObject dataEntity = this.getModel().getDataEntity(true); + // 获取代码编辑器控件 + CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap"); if ("shkd_generatejson".equals(itemKey)) { - DynamicObject dataEntity = this.getModel().getDataEntity(true); // 生成JSON DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("entryentity"); @@ -60,8 +64,6 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin { floors.get(tier - 1).add(dynamicObject); } - // 获取代码编辑器控件 - CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap"); // 获取组装body类型 String shkd_bodytype = dataEntity.getString("shkd_bodytype"); if ("数组".equals(shkd_bodytype)) { @@ -102,7 +104,6 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin { } if ("shkd_analyzejson".equals(itemKey)) { - CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap"); String text = codeEdit.getText(); Object obj = JSON.parse(text); if (obj instanceof JSONObject) { @@ -113,6 +114,22 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin { parseJson(jsonArray, 1, null); } } + + if ("shkd_testapi".equals(itemKey)) { + String url = dataEntity.getString("shkd_url"); + ApiEntity apiEntity = new ApiEntity(); + apiEntity.setURL(url); + apiEntity.setMethod("POST"); + Map headMap = new HashMap<>(); + headMap.put("Content-Type", "application/json"); + apiEntity.setHeaders(headMap); + Map paramsMap = new HashMap<>(); + paramsMap.put("access_token", ApiService.getBIPToken()); + apiEntity.setQueryParams(paramsMap); + apiEntity.setRequestBody(codeEdit.getText()); + JSONObject responseBody = ApiEntity.getResponseBody(apiEntity); + this.getView().showTipNotification("返回结果:" + responseBody.toJSONString()); + } } private void processFloor(JSONObject parentJson, String parentKey, List currentFloor, List> floors) {