测试功能query参数类型支持传集合
This commit is contained in:
1 parent
d99350bdfb
commit
907765831a
1 file changed
+32
-1
+32
-1
@@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -68,14 +69,21 @@ public class ApiTestController {
|
||||
Object requestParams = params.getRequestParams();
|
||||
if (requestParams instanceof Map) {
|
||||
Map<String, Object> queryParam = (Map<String, Object>) requestParams;
|
||||
// 校验参数
|
||||
if (!splitAarry(queryParam)) {
|
||||
return Result.error(ErrorStatusEnum.PARAM_NOT_FOUNT.getCode(), ErrorStatusEnum.PARAM_NOT_FOUNT.getMassage());
|
||||
}
|
||||
paramsMap.putAll(queryParam);
|
||||
}else if (requestParams instanceof List) {
|
||||
List<Map<String,Object>> paramsList = (List<Map<String, Object>>) requestParams;
|
||||
for (Map<String, Object> entry : paramsList) {
|
||||
// 校验参数
|
||||
if (!splitAarry(entry)) {
|
||||
return Result.error(ErrorStatusEnum.PARAM_NOT_FOUNT.getCode(), ErrorStatusEnum.PARAM_NOT_FOUNT.getMassage());
|
||||
}
|
||||
paramsMap.put(entry.get("name").toString(), entry.get("value"));
|
||||
}
|
||||
}
|
||||
|
||||
String sql = params.getSqlScript();
|
||||
Object data = baseDataService.execute(params.getDatasourceId(),params.getDatasourceType(), params.getSchemaName(),sql, paramsMap);
|
||||
if (ResultTypeEnum.ONE.getName().equals(params.getResultType()) && data instanceof List) {
|
||||
@@ -90,4 +98,27 @@ public class ApiTestController {
|
||||
}
|
||||
return Result.success(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验参数
|
||||
*
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public boolean splitAarry(Map<String, Object> queryParam) {
|
||||
if (queryParam == null ||queryParam.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
String paramType = queryParam.get("paramType")+"";
|
||||
Object paramValue = queryParam.get("value");
|
||||
|
||||
// Array类型的拼接参数 进行拆分
|
||||
if ("Array".equalsIgnoreCase(paramType) && paramValue != null) {
|
||||
String[] values = paramValue.toString().split(",");
|
||||
queryParam.put("value", Arrays.asList(values));
|
||||
}else if ("Array".equalsIgnoreCase(paramType) && "".equals(paramValue)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user