diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanMessageService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanMessageService.java index 3e95935824..3bb60cf398 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanMessageService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanMessageService.java @@ -30,6 +30,7 @@ import javax.annotation.Resource; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Optional; @Service @Transactional @@ -61,8 +62,10 @@ public class TestPlanMessageService { if (!report.getIsApiCaseExecuting() && !report.getIsPerformanceExecuting() && !report.getIsScenarioExecuting() && !report.getIsUiScenarioExecuting()) { //更新TestPlan状态为完成 TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(report.getTestPlanId()); - if (testPlan != null && !StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) { - testPlan.setStatus(TestPlanStatus.Completed.name()); + if (testPlan != null + && !StringUtils.equalsAny(testPlan.getStatus(), TestPlanStatus.Completed.name(), TestPlanStatus.Finished.name())) { + + testPlan.setStatus(calcTestPlanStatusWithPassRate(testPlan)); testPlanService.editTestPlan(testPlan); } try { @@ -80,6 +83,27 @@ public class TestPlanMessageService { } } + public String calcTestPlanStatusWithPassRate(TestPlanWithBLOBs testPlan) { + try { + // 计算通过率 + TestPlanDTOWithMetric testPlanDTOWithMetric = BeanUtils.copyBean(new TestPlanDTOWithMetric(), testPlan); + testPlanService.calcTestPlanRate(Collections.singletonList(testPlanDTOWithMetric)); + //测试进度 + Double testRate = Optional.ofNullable(testPlanDTOWithMetric.getTestRate()).orElse(0.0); + //通过率 + Double passRate = Optional.ofNullable(testPlanDTOWithMetric.getPassRate()).orElse(0.0); + + //只有通过率 与 测试进度 都为100% 才为已完成状态 + if (testRate >= 100 && passRate >= 100) { + return TestPlanStatus.Completed.name(); + } + } catch (Exception e) { + LogUtil.error("计算通过率失败!", e); + } + + return TestPlanStatus.Finished.name(); + } + @Async public void sendMessage(TestPlan testPlan, TestPlanReport testPlanReport, String projectId) { assert testPlan != null; diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index d82febe019..7f4188a8ca 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit d82febe01920178e5bcdbdc8364c347e14886d26 +Subproject commit 7f4188a8cabb24551e53eaf86bde1fbb5c63564a diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 99c2acebdf..70264ea85d 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 99c2acebdffef28a5b1a71299c1552095a2976b3 +Subproject commit 70264ea85d57f9951c4655c537011a5db3f4164b