From e95797548bad3757e4ae53aba99f2b9634311848 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Mon, 23 Dec 2024 18:30:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=95=B0=E6=8D=AE=E6=BA=90):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DApi=20post=20=E8=AF=B7=E6=B1=82=E4=BD=93=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datasource/provider/ApiUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java b/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java index e15982f65a..a4451abf20 100644 --- a/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java +++ b/core/core-backend/src/main/java/io/dataease/datasource/provider/ApiUtils.java @@ -335,6 +335,28 @@ public class ApiUtils { String raw = null; if (apiDefinitionRequest.getBody().get("raw") != null) { raw = apiDefinitionRequest.getBody().get("raw").toString(); + + List bodYparams = new ArrayList<>(); + String regex = "\\$\\{(.*?)\\}"; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(raw); + while (matcher.find()) { + bodYparams.add(matcher.group(1)); + } + for (String param : bodYparams) { + for (ApiDefinition definition : paramsList) { + for (int i = 0; i < definition.getFields().size(); i++) { + TableField field = definition.getFields().get(i); + if (field.getOriginName().equalsIgnoreCase(param)) { + String resultStr = execHttpRequest(false, definition, definition.getApiQueryTimeout() == null || apiDefinition.getApiQueryTimeout() <= 0 ? 10 : apiDefinition.getApiQueryTimeout(), null); + List dataList = fetchResult(resultStr, definition); + if (dataList.size() > 0) { + raw = raw.replace("${" + param + "}", dataList.get(0)[i]); + } + } + } + } + } response = HttpClientUtil.post(apiDefinition.getUrl(), raw, httpClientConfig); } }