fix(测试跟踪): 首页遗留缺陷统计总数和占比统计

--bug=1017609 --user=李玉号 【测试跟踪】首页遗留缺陷统计总数和占比有统计错误
https://www.tapd.cn/55049933/s/1285282
This commit is contained in:
shiziyuan9527 2022-11-01 15:54:51 +08:00 committed by lyh
parent 6cf24e5152
commit c3da2a7584
2 changed files with 37 additions and 11 deletions

View File

@ -890,7 +890,14 @@
join issues join issues
on tci.issues_id = issues.id on tci.issues_id = issues.id
where tptc.plan_id = #{planId} where tptc.plan_id = #{planId}
and test_case.status != 'Trash'; and test_case.status != 'Trash'
union distinct
select distinct tci.issues_id
from test_plan_test_case tptc
join test_case_issues tci on tptc.id = tci.resource_id
join issues
on tci.issues_id = issues.id
where tptc.plan_id = #{planId}
</select> </select>
<select id="getTestPlanCase" resultType="int"> <select id="getTestPlanCase" resultType="int">
select count(s) select count(s)

View File

@ -3,14 +3,15 @@ package io.metersphere.service;
import io.metersphere.base.domain.TestPlan; import io.metersphere.base.domain.TestPlan;
import io.metersphere.base.domain.TestPlanExample; import io.metersphere.base.domain.TestPlanExample;
import io.metersphere.base.mapper.TestPlanMapper; import io.metersphere.base.mapper.TestPlanMapper;
import io.metersphere.base.mapper.ext.ExtIssuesMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.DateUtils;
import io.metersphere.dto.BugStatistics; import io.metersphere.dto.*;
import io.metersphere.dto.TestPlanBugCount;
import io.metersphere.dto.TestPlanDTOWithMetric;
import io.metersphere.dto.TrackCountResult;
import io.metersphere.plan.dto.ChartsData; import io.metersphere.plan.dto.ChartsData;
import io.metersphere.plan.service.TestPlanService; import io.metersphere.plan.service.TestPlanService;
import io.metersphere.xpack.track.dto.IssuesDao;
import io.metersphere.xpack.track.dto.request.IssuesRequest;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -23,6 +24,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -37,6 +39,9 @@ public class TrackService {
@Resource @Resource
private TestPlanService testPlanService; private TestPlanService testPlanService;
@Resource
private ExtIssuesMapper extIssuesMapper;
public List<TrackCountResult> countPriority(String projectId) { public List<TrackCountResult> countPriority(String projectId) {
return extTestCaseMapper.countPriority(projectId); return extTestCaseMapper.countPriority(projectId);
} }
@ -111,15 +116,15 @@ public class TrackService {
List<TestPlanBugCount> list = new ArrayList<>(); List<TestPlanBugCount> list = new ArrayList<>();
BugStatistics bugStatistics = new BugStatistics(); BugStatistics bugStatistics = new BugStatistics();
int index = 1; int index = 1;
int totalCaseSize = 0; int totalPlanBugSize = 0;
int totalBugSize = 0; int allUnClosedBugSize = this.getAllUnClosedBugSize(projectId);
for (TestPlan plan : plans) { for (TestPlan plan : plans) {
int planBugSize = getPlanBugSize(plan.getId(), projectId); int planBugSize = getPlanBugSize(plan.getId(), projectId);
// bug为0不记录 // bug为0不记录
if (planBugSize == 0) { if (planBugSize == 0) {
continue; continue;
} }
totalBugSize += planBugSize; totalPlanBugSize += planBugSize;
TestPlanBugCount testPlanBug = new TestPlanBugCount(); TestPlanBugCount testPlanBug = new TestPlanBugCount();
testPlanBug.setIndex(index++); testPlanBug.setIndex(index++);
@ -135,14 +140,13 @@ public class TrackService {
double planPassRage = getPlanPassRage(plan.getId()); double planPassRage = getPlanPassRage(plan.getId());
testPlanBug.setPassRage(planPassRage + "%"); testPlanBug.setPassRage(planPassRage + "%");
list.add(testPlanBug); list.add(testPlanBug);
totalCaseSize += planCaseSize;
} }
bugStatistics.setList(list); bugStatistics.setList(list);
float rage = totalCaseSize == 0 ? 0 : (float) totalBugSize * 100 / totalCaseSize; float rage = allUnClosedBugSize == 0 ? 0 : (float) totalPlanBugSize * 100 / allUnClosedBugSize;
DecimalFormat df = new DecimalFormat("0.0"); DecimalFormat df = new DecimalFormat("0.0");
bugStatistics.setRage(df.format(rage) + "%"); bugStatistics.setRage(df.format(rage) + "%");
bugStatistics.setBugTotalSize(totalBugSize); bugStatistics.setBugTotalSize(allUnClosedBugSize);
return bugStatistics; return bugStatistics;
} }
@ -165,6 +169,21 @@ public class TrackService {
.count(); .count();
} }
private int getAllUnClosedBugSize(String projectId) {
IssuesRequest req = new IssuesRequest();
req.setProjectId(projectId);
List<IssuesDao> issues = extIssuesMapper.getIssues(req);
if (CollectionUtils.isEmpty(issues)) {
return 0;
}
List<String> ids = issues.stream().map(IssuesDao::getId).collect(Collectors.toList());
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(ids, projectId);
return (int) issues.stream()
.filter(i -> !StringUtils.equals(statusMap.getOrDefault(i.getId(), StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed"))
.count();
}
private double getPlanPassRage(String planId) { private double getPlanPassRage(String planId) {
TestPlanDTOWithMetric testPlan = new TestPlanDTOWithMetric(); TestPlanDTOWithMetric testPlan = new TestPlanDTOWithMetric();
testPlan.setId(planId); testPlan.setId(planId);