parent
c8cf6b1c2f
commit
375b1ba410
|
@ -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<String, Object> queryParams;//请求参数
|
||||
private Map<String, Object> 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<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.method = method;
|
||||
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());
|
||||
Map<String, Object> params = apiEntity.getQueryParams();
|
||||
if (params != null) {
|
||||
|
|
|
@ -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();
|
||||
if ("shkd_generatejson".equals(itemKey)) {
|
||||
DynamicObject dataEntity = this.getModel().getDataEntity(true);
|
||||
// 获取代码编辑器控件
|
||||
CodeEdit codeEdit = this.getView().getControl("shkd_codeeditap");
|
||||
if ("shkd_generatejson".equals(itemKey)) {
|
||||
// 生成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<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) {
|
||||
|
|
Loading…
Reference in New Issue