From 375b1ba4101aa29631f5d4d0a5c443839b20411c Mon Sep 17 00:00:00 2001 From: zoujiangtao Date: Wed, 20 Nov 2024 17:31:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=EF=BC=9A=E9=82=B9?= =?UTF-8?q?=E6=B1=9F=E6=B6=9B=20=E4=BF=AE=E6=94=B9=E5=86=85=E5=AE=B9?= =?UTF-8?q?=EF=BC=9AAPI=E6=98=A0=E5=B0=84=E5=85=AC=E5=85=B1=E5=8D=95?= =?UTF-8?q?=E6=8D=AE=20=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4=EF=BC=9A2024/1?= =?UTF-8?q?1/20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/shkd/sys/sys/common/ApiEntity.java | 11 ++++---- .../sys/plugin/form/ApiMappingBillPlugin.java | 25 ++++++++++++++++--- 2 files changed, 26 insertions(+), 10 deletions(-) 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) {