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 65b030a817..4274ead6fa 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()) { //更新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 830bad0961..2ca4ff0b6d 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 830bad0961b3ec2eaff21e9eac382d16f0521639 +Subproject commit 2ca4ff0b6d771d280eba6958345426e56d1d15a4 diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 12370ba86a..be7591f7f5 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 12370ba86adfdf31b11a30d48a59c3715490b351 +Subproject commit be7591f7f5077a77ee5abce16461af30f3ac8666