refactor(测试跟踪): 优化遗留缺陷统计逻辑
--bug=1020216,1020228 --user=宋昌昌 【测试跟踪】首页-测试计划遗留缺陷统计-加载失败 https://www.tapd.cn/55049933/s/1304145
This commit is contained in:
parent
5c59dc4aa2
commit
a3e15b8524
|
@ -91,7 +91,7 @@ public interface ExtTestCaseMapper {
|
||||||
|
|
||||||
List<String> getTestPlanBug(@Param("planId") String planId);
|
List<String> getTestPlanBug(@Param("planId") String planId);
|
||||||
|
|
||||||
Long getTestPlanThisWeekBugCount(@Param("planId") String planId, @Param("ids") List<String> ids);
|
Long getTestPlanThisWeekBugCount(@Param("projectId") String projectId, @Param("ids") List<String> ids);
|
||||||
|
|
||||||
int getTestPlanCase(@Param("planId") String planId);
|
int getTestPlanCase(@Param("planId") String planId);
|
||||||
|
|
||||||
|
|
|
@ -897,8 +897,9 @@
|
||||||
<select id="getTestPlanThisWeekBugCount" resultType="java.lang.Long">
|
<select id="getTestPlanThisWeekBugCount" resultType="java.lang.Long">
|
||||||
select count(distinct tci.issues_id)
|
select count(distinct tci.issues_id)
|
||||||
from test_plan_test_case tptc
|
from test_plan_test_case tptc
|
||||||
|
join test_plan tp on tp.id = tptc.plan_id
|
||||||
join test_case_issues tci on tptc.id = tci.resource_id
|
join test_case_issues tci on tptc.id = tci.resource_id
|
||||||
where tptc.plan_id = #{planId} and tptc.is_del != 1 and date_sub(curdate(), interval 7 day) <= from_unixtime(round(tci.relate_time / 1000, 0))
|
where tp.project_id = #{projectId} and tptc.is_del != 1 and date_sub(curdate(), interval 7 day) <= from_unixtime(round(tci.relate_time / 1000, 0))
|
||||||
and tci.issues_id in
|
and tci.issues_id in
|
||||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
#{id}
|
#{id}
|
||||||
|
|
|
@ -6,8 +6,6 @@ import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.github.pagehelper.Page;
|
import com.github.pagehelper.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import io.metersphere.constants.IssueStatus;
|
|
||||||
import io.metersphere.platform.api.Platform;
|
|
||||||
import io.metersphere.base.domain.*;
|
import io.metersphere.base.domain.*;
|
||||||
import io.metersphere.base.mapper.*;
|
import io.metersphere.base.mapper.*;
|
||||||
import io.metersphere.base.mapper.ext.ExtIssueCommentMapper;
|
import io.metersphere.base.mapper.ext.ExtIssueCommentMapper;
|
||||||
|
@ -16,8 +14,8 @@ import io.metersphere.commons.constants.*;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.constants.AttachmentType;
|
import io.metersphere.constants.AttachmentType;
|
||||||
|
import io.metersphere.constants.IssueStatus;
|
||||||
import io.metersphere.constants.SystemCustomField;
|
import io.metersphere.constants.SystemCustomField;
|
||||||
import io.metersphere.platform.domain.*;
|
|
||||||
import io.metersphere.dto.*;
|
import io.metersphere.dto.*;
|
||||||
import io.metersphere.excel.constants.IssueExportHeadField;
|
import io.metersphere.excel.constants.IssueExportHeadField;
|
||||||
import io.metersphere.excel.domain.ExcelErrData;
|
import io.metersphere.excel.domain.ExcelErrData;
|
||||||
|
@ -38,6 +36,8 @@ import io.metersphere.plan.dto.TestPlanSimpleReportDTO;
|
||||||
import io.metersphere.plan.service.TestPlanService;
|
import io.metersphere.plan.service.TestPlanService;
|
||||||
import io.metersphere.plan.service.TestPlanTestCaseService;
|
import io.metersphere.plan.service.TestPlanTestCaseService;
|
||||||
import io.metersphere.plan.utils.TestPlanStatusCalculator;
|
import io.metersphere.plan.utils.TestPlanStatusCalculator;
|
||||||
|
import io.metersphere.platform.api.Platform;
|
||||||
|
import io.metersphere.platform.domain.*;
|
||||||
import io.metersphere.request.IntegrationRequest;
|
import io.metersphere.request.IntegrationRequest;
|
||||||
import io.metersphere.request.attachment.AttachmentRequest;
|
import io.metersphere.request.attachment.AttachmentRequest;
|
||||||
import io.metersphere.request.issues.IssueExportRequest;
|
import io.metersphere.request.issues.IssueExportRequest;
|
||||||
|
@ -1700,10 +1700,12 @@ public class IssuesService {
|
||||||
issueIds = extIssuesMapper.getTestPlanThisWeekIssue(request.getProjectId());
|
issueIds = extIssuesMapper.getTestPlanThisWeekIssue(request.getProjectId());
|
||||||
} else if (request.getAllTestPlanIssue() || request.getUnClosedTestPlanIssue()) {
|
} else if (request.getAllTestPlanIssue() || request.getUnClosedTestPlanIssue()) {
|
||||||
issueIds = extIssuesMapper.getTestPlanIssue(request.getProjectId());
|
issueIds = extIssuesMapper.getTestPlanIssue(request.getProjectId());
|
||||||
|
} else {
|
||||||
|
issueIds = Collections.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, request.getProjectId());
|
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, request.getProjectId());
|
||||||
if (MapUtils.isEmpty(statusMap)) {
|
if (MapUtils.isEmpty(statusMap) && CollectionUtils.isNotEmpty(issueIds)) {
|
||||||
// 未找到自定义字段状态, 则获取平台状态
|
// 未找到自定义字段状态, 则获取平台状态
|
||||||
IssuesRequest issuesRequest = new IssuesRequest();
|
IssuesRequest issuesRequest = new IssuesRequest();
|
||||||
issuesRequest.setProjectId(SessionUtils.getCurrentProjectId());
|
issuesRequest.setProjectId(SessionUtils.getCurrentProjectId());
|
||||||
|
|
|
@ -141,41 +141,13 @@ public class TrackService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public BugStatistics getBugStatistics(String projectId) {
|
public BugStatistics getBugStatistics(String projectId) {
|
||||||
List<TestPlanBugCount> list = new ArrayList<>();
|
|
||||||
BugStatistics bugStatistics = new BugStatistics();
|
BugStatistics bugStatistics = new BugStatistics();
|
||||||
TestPlanExample example = new TestPlanExample();
|
Map<String, Integer> bugStatusMap = getPlanBugStatusSize(projectId);
|
||||||
example.createCriteria().andProjectIdEqualTo(projectId);
|
Map<String, Integer> bugSizeMap = getPlanBugSize(projectId);
|
||||||
List<TestPlan> plans = testPlanMapper.selectByExample(example);
|
int totalPlanBugSize = bugSizeMap.get("total") == null ? 0 : bugSizeMap.get("total");
|
||||||
List<String> planIds = plans.stream().map(TestPlan::getId).collect(Collectors.toList());
|
int totalUnClosedPlanBugSize = bugSizeMap.get("unClosed") == null ? 0 : bugSizeMap.get("unClosed");
|
||||||
int index = 1;
|
int thisWeekCount = bugSizeMap.get("thisWeekCount") == null ? 0 : bugSizeMap.get("thisWeekCount");
|
||||||
int totalUnClosedPlanBugSize = 0;
|
|
||||||
int totalPlanBugSize = 0;
|
|
||||||
int thisWeekCount = 0;
|
|
||||||
Map<String, Integer> bugStatusMap = getPlanBugStatusSize(planIds, projectId);
|
|
||||||
for (TestPlan plan : plans) {
|
|
||||||
Map<String, Integer> bugSizeMap = getPlanBugSize(plan.getId(), projectId);
|
|
||||||
int planBugSize = bugSizeMap.get("total");
|
|
||||||
int unClosedPlanBugSize = bugSizeMap.get("unClosed");
|
|
||||||
thisWeekCount += bugSizeMap.get("thisWeekCount");
|
|
||||||
totalUnClosedPlanBugSize += unClosedPlanBugSize;
|
|
||||||
totalPlanBugSize += planBugSize;
|
|
||||||
// bug为0不记录
|
|
||||||
if (unClosedPlanBugSize == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
TestPlanBugCount testPlanBug = new TestPlanBugCount();
|
|
||||||
testPlanBug.setIndex(index++);
|
|
||||||
testPlanBug.setPlanName(plan.getName());
|
|
||||||
testPlanBug.setCreateTime(plan.getCreateTime());
|
|
||||||
testPlanBug.setStatus(plan.getStatus());
|
|
||||||
testPlanBug.setPlanId(plan.getId());
|
|
||||||
testPlanBug.setCaseSize(getPlanCaseSize(plan.getId()));
|
|
||||||
testPlanBug.setBugSize(unClosedPlanBugSize);
|
|
||||||
double planPassRage = getPlanPassRage(plan.getId());
|
|
||||||
testPlanBug.setPassRage(planPassRage + "%");
|
|
||||||
list.add(testPlanBug);
|
|
||||||
}
|
|
||||||
bugStatistics.setList(list);
|
|
||||||
bugStatistics.setBugUnclosedCount(totalUnClosedPlanBugSize);
|
bugStatistics.setBugUnclosedCount(totalUnClosedPlanBugSize);
|
||||||
bugStatistics.setBugTotalCount(totalPlanBugSize);
|
bugStatistics.setBugTotalCount(totalPlanBugSize);
|
||||||
|
|
||||||
|
@ -192,16 +164,16 @@ public class TrackService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Integer> getPlanBugSize(String planId, String projectId) {
|
private Map<String, Integer> getPlanBugSize(String projectId) {
|
||||||
CustomField customField = baseCustomFieldService.getCustomFieldByName(projectId, SystemCustomField.ISSUE_STATUS);
|
CustomField customField = baseCustomFieldService.getCustomFieldByName(projectId, SystemCustomField.ISSUE_STATUS);
|
||||||
JSONArray statusArray = JSONArray.parseArray(customField.getOptions());
|
JSONArray statusArray = JSONArray.parseArray(customField.getOptions());
|
||||||
List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId);
|
|
||||||
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId);
|
|
||||||
Map<String, Integer> bugSizeMap = new HashMap<>();
|
Map<String, Integer> bugSizeMap = new HashMap<>();
|
||||||
|
|
||||||
|
List<String> issueIds = extIssuesMapper.getTestPlanIssue(projectId);
|
||||||
bugSizeMap.put("total", issueIds.size());
|
bugSizeMap.put("total", issueIds.size());
|
||||||
// 缺陷是否有状态
|
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId);
|
||||||
List<String> unClosedIds;
|
|
||||||
if (MapUtils.isEmpty(statusMap)) {
|
if (MapUtils.isEmpty(statusMap) && CollectionUtils.isNotEmpty(issueIds)) {
|
||||||
// 未找到自定义字段状态, 则获取平台状态
|
// 未找到自定义字段状态, 则获取平台状态
|
||||||
IssuesRequest issuesRequest = new IssuesRequest();
|
IssuesRequest issuesRequest = new IssuesRequest();
|
||||||
issuesRequest.setProjectId(SessionUtils.getCurrentProjectId());
|
issuesRequest.setProjectId(SessionUtils.getCurrentProjectId());
|
||||||
|
@ -210,15 +182,12 @@ public class TrackService {
|
||||||
statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new")));
|
statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MapUtils.isEmpty(statusMap)) {
|
if (MapUtils.isNotEmpty(statusMap)) {
|
||||||
unClosedIds = issueIds;
|
|
||||||
bugSizeMap.put("unClosed", issueIds.size());
|
|
||||||
} else {
|
|
||||||
Map<String, String> tmpStatusMap = statusMap;
|
Map<String, String> tmpStatusMap = statusMap;
|
||||||
unClosedIds = issueIds.stream()
|
issueIds = issueIds.stream()
|
||||||
.filter(id -> !StringUtils.equals(tmpStatusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed"))
|
.filter(id -> !StringUtils.equals(tmpStatusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed"))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
Iterator<String> iterator = unClosedIds.iterator();
|
Iterator<String> iterator = issueIds.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
String unClosedId = iterator.next();
|
String unClosedId = iterator.next();
|
||||||
String status = statusMap.getOrDefault(unClosedId, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY);
|
String status = statusMap.getOrDefault(unClosedId, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY);
|
||||||
|
@ -236,24 +205,25 @@ public class TrackService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bugSizeMap.put("unClosed", unClosedIds.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bugSizeMap.put("unClosed", issueIds.size());
|
||||||
|
|
||||||
int thisWeekCount = 0;
|
int thisWeekCount = 0;
|
||||||
if (CollectionUtils.isNotEmpty(unClosedIds)) {
|
if (CollectionUtils.isNotEmpty(issueIds)) {
|
||||||
thisWeekCount = extTestCaseMapper.getTestPlanThisWeekBugCount(planId, unClosedIds).intValue();
|
thisWeekCount = extTestCaseMapper.getTestPlanThisWeekBugCount(projectId, issueIds).intValue();
|
||||||
}
|
}
|
||||||
bugSizeMap.put("thisWeekCount", thisWeekCount);
|
bugSizeMap.put("thisWeekCount", thisWeekCount);
|
||||||
return bugSizeMap;
|
return bugSizeMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Integer> getPlanBugStatusSize(List<String> planIds, String projectId) {
|
private Map<String, Integer> getPlanBugStatusSize(String projectId) {
|
||||||
CustomField customField = baseCustomFieldService.getCustomFieldByName(projectId, SystemCustomField.ISSUE_STATUS);
|
CustomField customField = baseCustomFieldService.getCustomFieldByName(projectId, SystemCustomField.ISSUE_STATUS);
|
||||||
JSONArray statusArray = JSONArray.parseArray(customField.getOptions());
|
JSONArray statusArray = JSONArray.parseArray(customField.getOptions());
|
||||||
Map<String, Integer> bugStatusMap = new HashMap<>();
|
Map<String, Integer> bugStatusMap = new HashMap<>();
|
||||||
if (CollectionUtils.isNotEmpty(planIds)) {
|
|
||||||
for (String planId : planIds) {
|
if (StringUtils.isNotEmpty(projectId)) {
|
||||||
List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId);
|
List<String> issueIds = extIssuesMapper.getTestPlanIssue(projectId);
|
||||||
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId);
|
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId);
|
||||||
if (MapUtils.isEmpty(statusMap) && CollectionUtils.isNotEmpty(issueIds)) {
|
if (MapUtils.isEmpty(statusMap) && CollectionUtils.isNotEmpty(issueIds)) {
|
||||||
// 未找到自定义字段状态, 则获取平台状态
|
// 未找到自定义字段状态, 则获取平台状态
|
||||||
|
@ -305,7 +275,6 @@ public class TrackService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (MapUtils.isEmpty(bugStatusMap)) {
|
if (MapUtils.isEmpty(bugStatusMap)) {
|
||||||
for (IssueStatus statusEnum : IssueStatus.values()) {
|
for (IssueStatus statusEnum : IssueStatus.values()) {
|
||||||
bugStatusMap.put(Translator.get(statusEnum.getI18nKey()), 0);
|
bugStatusMap.put(Translator.get(statusEnum.getI18nKey()), 0);
|
||||||
|
|
Loading…
Reference in New Issue