feat: 【数据源】API 数据源支持添加时间戳参数。 #17244

This commit is contained in:
taojinlong
2025-11-10 15:57:33 +08:00
committed by taojinlong
parent 3d06803bde
commit 470f407451
6 changed files with 24 additions and 0 deletions

View File

@@ -274,6 +274,9 @@ public class ApiUtils {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat.split(" ")[1]);
httpClientConfig.addHeader(header.get("name").toString(), simpleDateFormat.format(date));
}
if (StringUtils.isNotEmpty(timeFormat) && timeFormat.split(" ")[0].equalsIgnoreCase("timestamp")) {
httpClientConfig.addHeader(header.get("name").toString(), String.valueOf(System.currentTimeMillis()));
}
} else {
httpClientConfig.addHeader(header.get("name").toString(), header.get("value").toString());
}
@@ -338,6 +341,9 @@ public class ApiUtils {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat.split(" ")[1]);
params.add(argument.get("name") + "=" + simpleDateFormat.format(date));
}
if (StringUtils.isNotEmpty(timeFormat) && timeFormat.split(" ")[0].equalsIgnoreCase("timestamp")) {
params.add(argument.get("name") + "=" + System.currentTimeMillis());
}
} else {
params.add(argument.get("name") + "=" + URLEncoder.encode(argument.get("value")));
}
@@ -369,6 +375,10 @@ public class ApiUtils {
bodYparams.add(matcher.group(1));
}
for (String param : bodYparams) {
if (param.equalsIgnoreCase("currentTimestamp")) {
raw = raw.replace("${" + param + "}", String.valueOf(System.currentTimeMillis()));
continue;
}
for (ApiDefinition definition : paramsList) {
for (int i = 0; i < definition.getFields().size(); i++) {
TableField field = definition.getFields().get(i);
@@ -470,6 +480,9 @@ public class ApiUtils {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timeFormat.split(" ")[1]);
body.put(jsonNode.get("name").toString(), simpleDateFormat.format(date));
}
if (StringUtils.isNotEmpty(timeFormat) && timeFormat.split(" ")[0].equalsIgnoreCase("timestamp")) {
body.put(jsonNode.get("name").toString(), String.valueOf(System.currentTimeMillis()));
}
} else {
body.put(jsonNode.get("name").asText(), jsonNode.get("value").asText());
}

View File

@@ -316,6 +316,7 @@ export default {
time_function: 'Time function',
customize: 'Customize',
that_day: 'That day',
timestamp: 'current time (timestamp)',
value: 'Value',
name_use_parameters: "You can use ${'{'}parameter name{'}'}, use parameters",
add_parameters: 'Add parameters',

View File

@@ -305,6 +305,7 @@ export default {
time_function: '時間函數',
customize: '自訂',
that_day: '當天',
timestamp: '當前時間時間戳',
value: '值',
name_use_parameters: "可用${'{'}參數名稱{'}'},使用參數",
add_parameters: '新增參數',

View File

@@ -306,6 +306,7 @@ export default {
time_function: '时间函数',
customize: '自定义',
that_day: '当天',
timestamp: '当前时间时间戳',
value: '值',
name_use_parameters: "可用${'{'}参数名{'}'},使用参数",
add_parameters: '添加参数',

View File

@@ -111,6 +111,10 @@ const timeFunLists = [
{
label: t('data_source.that_day') + 'yyyy/MM/dd',
value: 'currentDay yyyy/MM/dd'
},
{
label: t('data_source.timestamp'),
value: 'timestamp'
}
]
</script>

View File

@@ -148,6 +148,10 @@ const timeFunLists = [
{
label: t('data_source.that_day') + 'yyyy/MM/dd',
value: 'currentDay yyyy/MM/dd'
},
{
label: t('data_source.timestamp'),
value: 'timestamp'
}
]
</script>