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 2e2687a114..f3889216e1 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 @@ -8,10 +8,7 @@ import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; -import io.metersphere.commons.constants.ApiRunMode; -import io.metersphere.commons.constants.CommonConstants; -import io.metersphere.commons.constants.NoticeConstants; -import io.metersphere.commons.constants.TriggerMode; +import io.metersphere.commons.constants.*; import io.metersphere.commons.enums.ApiReportStatus; import io.metersphere.commons.enums.ExecutionExecuteTypeEnum; import io.metersphere.commons.utils.*; @@ -20,6 +17,7 @@ import io.metersphere.dto.RequestResult; import io.metersphere.dto.ResultDTO; import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.service.NoticeSendService; +import io.metersphere.service.MicroService; import io.metersphere.service.ServiceUtils; import io.metersphere.utils.LoggerUtil; import org.apache.commons.beanutils.BeanMap; @@ -64,6 +62,8 @@ public class ApiDefinitionExecResultService { private ApiCaseExecutionInfoService apiCaseExecutionInfoService; @Resource private ExtApiTestCaseMapper extApiTestCaseMapper; + @Resource + private MicroService microService; /** * API/CASE 重试结果保留一条 @@ -103,6 +103,15 @@ public class ApiDefinitionExecResultService { if (apiTestCase != null) { apiTestCase.setLastResultId(dto.getReportId()); apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCase); + try { + HttpHeaderUtils.runAsUser(result.getUserId()); + microService.getForData(MicroServiceName.TEST_TRACK, + String.format("/test/plan/case/update/case/status/%s/%s/%s/%s", + testPlanApiCase.getApiCaseId(), apiTestCase.getName(), testPlanApiCase.getTestPlanId(), "testcase")); + HttpHeaderUtils.clearUser(); + } catch (Exception e) { + LogUtil.error("auto update test plan api case error.", e); + } } } // 发送通知 @@ -335,6 +344,17 @@ public class ApiDefinitionExecResultService { if (apiTestCase != null) { apiTestCase.setLastResultId(dto.getReportId()); apiTestCaseMapper.updateByPrimaryKeySelective(apiTestCase); + + try { + HttpHeaderUtils.runAsUser(reportResult.getUserId()); + microService.getForData(MicroServiceName.TEST_TRACK, + String.format("/test/plan/case/update/case/status/%s/%s/%s/%s", + apiTestCase.getId(), apiTestCase.getName(), apiCase.getTestPlanId(), "testcase")); + HttpHeaderUtils.clearUser(); + } catch (Exception e) { + LogUtil.error("auto update test plan api case error.", e); + } + } } } else { diff --git a/test-track/backend/src/main/java/io/metersphere/controller/TestPlanTestCaseController.java b/test-track/backend/src/main/java/io/metersphere/controller/TestPlanTestCaseController.java index dc44375e1a..a8f0b562a1 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/TestPlanTestCaseController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/TestPlanTestCaseController.java @@ -130,6 +130,11 @@ public class TestPlanTestCaseController { testPlanTestCaseService.deleteTestCaseBath(request); } + @GetMapping("/update/case/status/{testId}/{testName}/{planId}/{testType}") + public void updateCaseStatus(@PathVariable String testId, @PathVariable String testName,@PathVariable String planId,@PathVariable String testType) { + testPlanTestCaseService.updateTestCaseStates(testId, testName, planId, testType); + } + @PostMapping("/delete/{id}") @MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.UN_ASSOCIATE_CASE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = TestPlanTestCaseService.class) public int deleteTestCase(@PathVariable String id) {