From 19d284a399b4754481d37677a1b8f2b3b2e0df68 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 15 Mar 2021 17:24:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtTestCaseMapper.java | 5 ++ .../base/mapper/ext/ExtTestCaseMapper.xml | 49 +++++++++++++++- .../track/controller/TrackController.java | 4 +- .../track/response/TestPlanBugCount.java | 2 +- .../track/response/TrackStatisticsDTO.java | 6 +- .../track/service/TrackService.java | 58 +++++++++---------- .../track/home/components/BugCountCard.vue | 18 ++++-- 7 files changed, 101 insertions(+), 41 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java index 5ed9e3a7fa..17ae2078b3 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java @@ -71,5 +71,10 @@ public interface ExtTestCaseMapper { List countRelevanceMaintainer(@Param("projectId") String projectId); + int getTestPlanBug(@Param("planId") String planId); + int getTestPlanCase(@Param("planId") String planId); + int getTestPlanPassCase(@Param("planId") String planId); + + } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 17d5c37a6e..72d3a06e38 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -342,8 +342,9 @@ + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/controller/TrackController.java b/backend/src/main/java/io/metersphere/track/controller/TrackController.java index 2b0d66bfb0..c010d94bc2 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TrackController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TrackController.java @@ -87,7 +87,7 @@ public class TrackController { } @GetMapping("/bug/count/{projectId}") - public BugStatustics getBugStatustics(@PathVariable String projectId) { - return trackService.getBugStatustics(projectId); + public BugStatustics getBugStatistics(@PathVariable String projectId) { + return trackService.getBugStatistics(projectId); } } diff --git a/backend/src/main/java/io/metersphere/track/response/TestPlanBugCount.java b/backend/src/main/java/io/metersphere/track/response/TestPlanBugCount.java index 4c8a75b272..6802673d16 100644 --- a/backend/src/main/java/io/metersphere/track/response/TestPlanBugCount.java +++ b/backend/src/main/java/io/metersphere/track/response/TestPlanBugCount.java @@ -8,7 +8,7 @@ import lombok.Setter; public class TestPlanBugCount { private int index; private String planName; - private long creatTime; + private long createTime; private String status; private int caseSize; private int bugSize; diff --git a/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java b/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java index cb3aeffc88..264e0cf9cb 100644 --- a/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java +++ b/backend/src/main/java/io/metersphere/track/response/TrackStatisticsDTO.java @@ -144,20 +144,22 @@ public class TrackStatisticsDTO { public void countRelevance(List relevanceResults) { for (TrackCountResult countResult : relevanceResults) { - switch (countResult.getGroupField().toUpperCase()){ + switch (countResult.getGroupField()){ case TrackCount.API: this.apiCaseCount += countResult.getCountNumber(); + this.allRelevanceCaseCount += countResult.getCountNumber(); break; case TrackCount.PERFORMANCE: this.performanceCaseCount += countResult.getCountNumber(); + this.allRelevanceCaseCount += countResult.getCountNumber(); break; case TrackCount.AUTOMATION: this.scenarioCaseCount += countResult.getCountNumber(); + this.allRelevanceCaseCount += countResult.getCountNumber(); break; default: break; } - this.allRelevanceCaseCount += countResult.getCountNumber(); } } diff --git a/backend/src/main/java/io/metersphere/track/service/TrackService.java b/backend/src/main/java/io/metersphere/track/service/TrackService.java index b2a01371bd..3bcdf1cf79 100644 --- a/backend/src/main/java/io/metersphere/track/service/TrackService.java +++ b/backend/src/main/java/io/metersphere/track/service/TrackService.java @@ -12,6 +12,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; +import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -110,59 +111,58 @@ public class TrackService { return charts; } - public BugStatustics getBugStatustics(String projectId) { + public BugStatustics getBugStatistics(String projectId) { TestPlanExample example = new TestPlanExample(); example.createCriteria().andProjectIdEqualTo(projectId); List plans = testPlanMapper.selectByExample(example); List list = new ArrayList<>(); BugStatustics bugStatustics = new BugStatustics(); int index = 1; + int totalBugSize = 0; + int totalCaseSize = 0; for (TestPlan plan : plans) { TestPlanBugCount testPlanBug = new TestPlanBugCount(); testPlanBug.setIndex(index++); testPlanBug.setPlanName(plan.getName()); - testPlanBug.setCreatTime(plan.getCreateTime()); + testPlanBug.setCreateTime(plan.getCreateTime()); testPlanBug.setStatus(plan.getStatus()); - testPlanBug.setCaseSize(getPlanCaseSize(plan.getId())); - testPlanBug.setBugSize(getPlanBugSize(plan.getId())); - testPlanBug.setPassRage(getPlanPassRage(plan.getId())); + + int planCaseSize = getPlanCaseSize(plan.getId()); + testPlanBug.setCaseSize(planCaseSize); + + int planBugSize = getPlanBugSize(plan.getId()); + testPlanBug.setBugSize(planBugSize); + testPlanBug.setPassRage(getPlanPassRage(plan.getId(), planCaseSize)); list.add(testPlanBug); + + totalBugSize += planBugSize; + totalCaseSize += planCaseSize; } - // todo bugStatustics.setList(list); - bugStatustics.setRage("1"); - bugStatustics.setBugTotalSize(2); + float rage =totalCaseSize == 0 ? 0 : (float) totalBugSize * 100 / totalCaseSize; + DecimalFormat df = new DecimalFormat("0.0"); + bugStatustics.setRage(df.format(rage) + "%"); + bugStatustics.setBugTotalSize(totalBugSize); return bugStatustics; } private int getPlanCaseSize(String planId) { - TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); - testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(planId); - List testPlanTestCases = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample); - - TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample(); - testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(planId); - List testPlanApiCases = testPlanApiCaseMapper.selectByExample(testPlanApiCaseExample); - - TestPlanLoadCaseExample example = new TestPlanLoadCaseExample(); - example.createCriteria().andTestPlanIdEqualTo(planId); - List testPlanLoadCases = testPlanLoadCaseMapper.selectByExample(example); - - TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample(); - testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(planId); - List testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(testPlanApiScenarioExample); - - - return testPlanTestCases.size() + testPlanApiCases.size() + testPlanLoadCases.size() + testPlanApiScenarios.size(); + return extTestCaseMapper.getTestPlanCase(planId); } private int getPlanBugSize(String planId) { - return 1; + return extTestCaseMapper.getTestPlanBug(planId); } - private String getPlanPassRage(String planId) { - return "10%"; + private String getPlanPassRage(String planId, int totalSize) { + if (totalSize == 0) { + return "-"; + } + int passSize = extTestCaseMapper.getTestPlanPassCase(planId); + float rage = (float) passSize * 100 / totalSize; + DecimalFormat df = new DecimalFormat("0.0"); + return df.format(rage) + "%"; } } diff --git a/frontend/src/business/components/track/home/components/BugCountCard.vue b/frontend/src/business/components/track/home/components/BugCountCard.vue index 6f5efb8dd1..d0e09fcbe4 100644 --- a/frontend/src/business/components/track/home/components/BugCountCard.vue +++ b/frontend/src/business/components/track/home/components/BugCountCard.vue @@ -15,18 +15,19 @@ {{ $t('api_test.home_page.unit_of_measurement') }}
- 占比: - {{ rage }} - + 占比 + + {{rage}} +
+ width="60" show-overflow-tooltip/> - + @@ -35,6 +36,7 @@ prop="status" column-key="status" :label="$t('test_track.plan.plan_status')" + width="100" show-overflow-tooltip>