diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseResult.java b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseResult.java index 3a6934aa3e..2440bc5e8b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseResult.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/ApiTestCaseResult.java @@ -11,6 +11,7 @@ public class ApiTestCaseResult extends ApiTestCaseWithBLOBs { private String createUser; private String updateUser; private String execResult; + private String apiMethod; private Long execTime; private boolean active = false; private boolean responseActive = false; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index a6cc7ed85e..70be9377cb 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -792,7 +792,7 @@ public class ApiDefinitionService { res.setCaseStatus("-"); } - if (StringUtils.equals("ESB", res.getMethod())) { + if (StringUtils.equalsIgnoreCase("esb", res.getMethod())) { esbApiParamService.handleApiEsbParams(res); } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 2540a207c9..a5d9666588 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -85,7 +85,9 @@ public class ApiTestCaseService { List returnList = extApiTestCaseMapper.list(request); for (ApiTestCaseResult res : returnList) { - esbApiParamService.handleApiEsbParams(res); + if(StringUtils.equalsIgnoreCase(res.getApiMethod(),"esb")){ + esbApiParamService.handleApiEsbParams(res); + } } return returnList; } @@ -145,9 +147,13 @@ public class ApiTestCaseService { } public ApiTestCaseWithBLOBs get(String id) { - ApiTestCaseWithBLOBs returnBlobs = apiTestCaseMapper.selectByPrimaryKey(id); - esbApiParamService.handleApiEsbParams(returnBlobs); - return returnBlobs; +// ApiTestCaseWithBLOBs returnBlobs = apiTestCaseMapper.selectByPrimaryKey(id); + ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(id); + if(StringUtils.equalsIgnoreCase(model.getApiMethod(),"esb")){ + esbApiParamService.handleApiEsbParams(model); + } + + return model; } public ApiTestCase create(SaveApiTestCaseRequest request, List bodyFiles) { @@ -440,9 +446,11 @@ public class ApiTestCaseService { } public Map getRequest(ApiTestCaseRequest request) { - List list = extApiTestCaseMapper.getRequest(request); - for (ApiTestCaseWithBLOBs model : list) { - esbApiParamService.handleApiEsbParams(model); + List list = extApiTestCaseMapper.getRequest(request); + for (ApiTestCaseInfo model : list) { + if(StringUtils.equalsIgnoreCase(model.getApiMethod(),"esb")){ + esbApiParamService.handleApiEsbParams(model); + } } return list.stream().collect(Collectors.toMap(ApiTestCaseWithBLOBs::getId, ApiTestCaseWithBLOBs::getRequest)); } diff --git a/backend/src/main/java/io/metersphere/api/service/EsbApiParamService.java b/backend/src/main/java/io/metersphere/api/service/EsbApiParamService.java index 09a80dda05..06ae6dd45f 100644 --- a/backend/src/main/java/io/metersphere/api/service/EsbApiParamService.java +++ b/backend/src/main/java/io/metersphere/api/service/EsbApiParamService.java @@ -107,6 +107,9 @@ public class EsbApiParamService { } public void handleApiEsbParams(ApiDefinitionResult res) { + if(res == null){ + return; + } EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId()); if (esbParamBlobs == null) { return; @@ -141,6 +144,9 @@ public class EsbApiParamService { } public void handleApiEsbParams(ApiTestCaseWithBLOBs res) { + if(res==null){ + return; + } EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId()); if (esbParamBlobs == null) { return; @@ -184,6 +190,9 @@ public class EsbApiParamService { } public void handleApiEsbParams(ApiTestCaseResult res) { + if(res == null){ + return; + } EsbApiParamsWithBLOBs esbParamBlobs = this.getEsbParamBLOBsByResourceID(res.getId()); if (esbParamBlobs == null) { return; @@ -195,20 +204,6 @@ public class EsbApiParamService { } } -// try { -// if (StringUtils.isNotEmpty(res.getRequest())) { -// JSONObject jsonObj = JSONObject.parseObject(res.getRequest()); -// JSONArray esbDataArray = JSONArray.parseArray(esbParamBlobs.getDataStruct()); -// jsonObj.put("esbDataStruct", esbDataArray); -// jsonObj.put("esbFrontedScript", esbParamBlobs.getFrontedScript()); -// -// JSONArray responseDataArray = JSONArray.parseArray(esbParamBlobs.getResponseDataStruct()); -// jsonObj.put("backEsbDataStruct", responseDataArray); -// -// res.setRequest(jsonObj.toJSONString()); -// } -// } catch (Exception e) { -// } } public SaveApiDefinitionRequest updateEsbRequest(SaveApiDefinitionRequest request) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java index 0457a6a710..4e1ad1b010 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java @@ -2,16 +2,13 @@ package io.metersphere.base.mapper.ext; import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.ApiTestCaseDTO; +import io.metersphere.api.dto.definition.ApiTestCaseInfo; import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.ApiTestCaseResult; import io.metersphere.base.domain.ApiTestCase; -import io.metersphere.base.domain.ApiTestCaseWithBLOBs; -import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; import java.util.List; -import java.util.Map; public interface ExtApiTestCaseMapper { @@ -27,7 +24,9 @@ public interface ExtApiTestCaseMapper { long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); - List getRequest(@Param("request") ApiTestCaseRequest request); + List getRequest(@Param("request") ApiTestCaseRequest request); ApiTestCase getNextNum(@Param("definitionId") String definitionId); + + ApiTestCaseInfo selectApiCaseInfoByPrimaryKey(String id); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index 1c560eb664..0cea320af6 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -196,13 +196,25 @@ + + + - + select t1.id, t1.request,a.method AS apiMethod + from api_test_case t1 + inner join api_definition a on t1.api_definition_id = a.id where 1 - and id = #{request.id} + and t1.id = #{request.id} - and id in + and t1.id in #{caseId}