修改人:邹江涛

修改内容:API映射公共单据
修改时间:2024/11/20
This commit is contained in:
zoujiangtao 2024-11-20 17:31:12 +08:00
parent c8cf6b1c2f
commit 375b1ba410
2 changed files with 26 additions and 10 deletions

View File

@ -8,7 +8,6 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
/** /**
@ -21,7 +20,7 @@ public class ApiEntity {
private String method;//请求方式 private String method;//请求方式
private Map<String, Object> queryParams;//请求参数 private Map<String, Object> queryParams;//请求参数
private Map<String, Object> headers;//请求头参数 private Map<String, Object> headers;//请求头参数
private JSONObject requestBody;//请求体 private Object requestBody;//请求体
public String getURL() { public String getURL() {
return URL; return URL;
@ -55,15 +54,15 @@ public class ApiEntity {
this.headers = headers; this.headers = headers;
} }
public JSONObject getRequestBody() { public Object getRequestBody() {
return requestBody; return requestBody;
} }
public void setRequestBody(JSONObject requestBody) { public void setRequestBody(Object requestBody) {
this.requestBody = requestBody; this.requestBody = requestBody;
} }
public ApiEntity(String URL, String method, Map<String, Object> queryParams, Map<String, Object> headers, JSONObject requestBody) { public ApiEntity(String URL, String method, Map<String, Object> queryParams, Map<String, Object> headers, Object requestBody) {
this.URL = URL; this.URL = URL;
this.method = method; this.method = method;
this.queryParams = queryParams; this.queryParams = queryParams;
@ -84,7 +83,7 @@ public class ApiEntity {
} }
} }
HttpEntity<Object> objectHttpEntity = new HttpEntity<>(httpHeaders); HttpEntity<Object> objectHttpEntity = new HttpEntity<>(apiEntity.getRequestBody().toString(), httpHeaders);
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(apiEntity.getURL()); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(apiEntity.getURL());
Map<String, Object> params = apiEntity.getQueryParams(); Map<String, Object> params = apiEntity.getQueryParams();
if (params != null) { if (params != null) {

View File

@ -11,6 +11,8 @@ import kd.bos.form.control.Toolbar;
import kd.bos.form.control.events.ItemClickEvent; import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.plugin.AbstractFormPlugin; import kd.bos.form.plugin.AbstractFormPlugin;
import kd.sdk.plugin.Plugin; import kd.sdk.plugin.Plugin;
import shkd.sys.sys.common.ApiEntity;
import shkd.sys.sys.mservice.ApiService;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.*; import java.util.*;
@ -35,8 +37,10 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
@Override @Override
public void itemClick(ItemClickEvent evt) { public void itemClick(ItemClickEvent evt) {
String itemKey = evt.getItemKey(); String itemKey = evt.getItemKey();
DynamicObject dataEntity = this.getModel().getDataEntity(true);
// 获取代码编辑器控件
CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap");
if ("shkd_generatejson".equals(itemKey)) { if ("shkd_generatejson".equals(itemKey)) {
DynamicObject dataEntity = this.getModel().getDataEntity(true);
// 生成JSON // 生成JSON
DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("entryentity"); DynamicObjectCollection dynamicObjectCollection = dataEntity.getDynamicObjectCollection("entryentity");
@ -60,8 +64,6 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
floors.get(tier - 1).add(dynamicObject); floors.get(tier - 1).add(dynamicObject);
} }
// 获取代码编辑器控件
CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap");
// 获取组装body类型 // 获取组装body类型
String shkd_bodytype = dataEntity.getString("shkd_bodytype"); String shkd_bodytype = dataEntity.getString("shkd_bodytype");
if ("数组".equals(shkd_bodytype)) { if ("数组".equals(shkd_bodytype)) {
@ -102,7 +104,6 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
} }
if ("shkd_analyzejson".equals(itemKey)) { if ("shkd_analyzejson".equals(itemKey)) {
CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap");
String text = codeEdit.getText(); String text = codeEdit.getText();
Object obj = JSON.parse(text); Object obj = JSON.parse(text);
if (obj instanceof JSONObject) { if (obj instanceof JSONObject) {
@ -113,6 +114,22 @@ public class ApiMappingBillPlugin extends AbstractFormPlugin implements Plugin {
parseJson(jsonArray, 1, null); 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<String, Object> headMap = new HashMap<>();
headMap.put("Content-Type", "application/json");
apiEntity.setHeaders(headMap);
Map<String, Object> 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<DynamicObject> currentFloor, List<List<DynamicObject>> floors) { private void processFloor(JSONObject parentJson, String parentKey, List<DynamicObject> currentFloor, List<List<DynamicObject>> floors) {