diff --git a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java index c1c56d090f..cf2eb6b29e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java @@ -7,7 +7,6 @@ import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.Project; -import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioMapper; @@ -39,8 +38,6 @@ public class MsHashTreeService { @Resource private ApiDefinitionService apiDefinitionService; @Resource - private ApiDefinitionMapper apiDefinitionMapper; - @Resource private ExtApiScenarioMapper extApiScenarioMapper; @Resource private BaseProjectApplicationService baseProjectApplicationService; diff --git a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java index e99828591f..3d4ef3aa7f 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/TestResultService.java @@ -14,7 +14,6 @@ import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.enums.ExecutionExecuteTypeEnum; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.DateUtils; -import io.metersphere.commons.utils.HttpHeaderUtils; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.dto.ResultDTO; @@ -27,7 +26,6 @@ import io.metersphere.service.scenario.ApiScenarioReportStructureService; import io.metersphere.service.scenario.ApiScenarioService; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -88,17 +86,6 @@ public class TestResultService { * @param dto 执行结果 */ public void saveResults(ResultDTO dto) { - String userId = null; - if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("userId")) { - userId = dto.getExtendedParameters().get("userId").toString(); - } - if (StringUtils.isNotEmpty(userId)) { - User user = new User(); - user.setId(userId); - user.setName(userId); - HttpHeaderUtils.runAsUser(user); - } - // 处理环境 List environmentList = new LinkedList<>(); if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("ENV")) { @@ -119,10 +106,6 @@ public class TestResultService { // 场景报告结果处理 apiScenarioReportService.saveResult(dto); } - - if (StringUtils.isNotEmpty(userId)) { - HttpHeaderUtils.clearUser(); - } } /** @@ -151,14 +134,11 @@ public class TestResultService { } } //测试计划定时任务-接口执行逻辑的话,需要同步测试计划的报告数据 - if (StringUtils.equals(key, "schedule-task")) { - apiDefinitionExecResultService.batchSaveApiResult(resultDTOS, true); - } else if (StringUtils.equals(key, "api-test-case-task")) { - apiDefinitionExecResultService.batchSaveApiResult(resultDTOS, false); + if (StringUtils.equalsAny(key, "schedule-task", "api-test-case-task")) { + apiDefinitionExecResultService.batchSaveApiResult(resultDTOS); } else if (StringUtils.equalsAny(key, "api-scenario-task")) { apiScenarioReportService.batchSaveResult(resultDTOS); } - } } diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java index 3c51d9384c..edbf26289e 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java @@ -123,7 +123,7 @@ public class ApiDefinitionExecResultService { } } - public void batchSaveApiResult(List resultDTOS, boolean isSchedule) { + public void batchSaveApiResult(List resultDTOS) { if (CollectionUtils.isEmpty(resultDTOS)) { return; } @@ -134,17 +134,6 @@ public class ApiDefinitionExecResultService { ApiTestCaseMapper batchApiTestCaseMapper = sqlSession.getMapper(ApiTestCaseMapper.class); for (ResultDTO dto : resultDTOS) { - String userId = null; - if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("userId")) { - userId = dto.getExtendedParameters().get("userId").toString(); - } - if (StringUtils.isNotEmpty(userId)) { - User user = new User(); - user.setId(userId); - user.setName(userId); - HttpHeaderUtils.runAsUser(user); - } - this.mergeRetryResults(dto); if (CollectionUtils.isNotEmpty(dto.getRequestResults())) { for (RequestResult item : dto.getRequestResults()) { @@ -168,10 +157,6 @@ public class ApiDefinitionExecResultService { } } } - - if (StringUtils.isNotEmpty(userId)) { - HttpHeaderUtils.clearUser(); - } } sqlSession.flushStatements(); if (sqlSession != null && sqlSessionFactory != null) { @@ -403,8 +388,8 @@ public class ApiDefinitionExecResultService { if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals("CASE")) { saveResult.setTriggerMode(TriggerMode.MANUAL.name()); } + editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); if (batchMapper == null) { - editStatus(saveResult, type, status, saveResult.getCreateTime(), saveResult.getId(), testId); apiDefinitionExecResultMapper.updateByPrimaryKeySelective(saveResult); } else { batchMapper.updateByPrimaryKeySelective(saveResult);