fix(测试跟踪): 遗留缺陷统计加载有误

--bug=1020216,1020228 --user=宋昌昌 【测试跟踪】首页-测试计划遗留缺陷统计-加载失败 https://www.tapd.cn/55049933/s/1304145
This commit is contained in:
song-cc-rock 2022-11-24 12:06:08 +08:00 committed by jianxing
parent 2bcd6c5089
commit eaa1f9dd26
2 changed files with 47 additions and 4 deletions

View File

@ -2,8 +2,11 @@ package io.metersphere.service;
import com.alibaba.excel.EasyExcelFactory; import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.util.DateUtils; import com.alibaba.excel.util.DateUtils;
import com.alibaba.fastjson.JSONArray;
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.platform.api.Platform;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.*;
@ -1705,17 +1708,37 @@ public class IssuesService {
issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); issuesRequest.setProjectId(SessionUtils.getCurrentProjectId());
issuesRequest.setFilterIds(issueIds); issuesRequest.setFilterIds(issueIds);
List<IssuesDao> issues = extIssuesMapper.getIssues(issuesRequest); List<IssuesDao> issues = extIssuesMapper.getIssues(issuesRequest);
statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, IssuesDao::getPlatformStatus)); statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new")));
} }
if (MapUtils.isEmpty(statusMap)) { if (MapUtils.isEmpty(statusMap)) {
request.setFilterIds(issueIds); request.setFilterIds(issueIds);
} else { } else {
if (request.getThisWeekUnClosedTestPlanIssue() || request.getUnClosedTestPlanIssue()) { if (request.getThisWeekUnClosedTestPlanIssue() || request.getUnClosedTestPlanIssue()) {
CustomField customField = baseCustomFieldService.getCustomFieldByName(SessionUtils.getCurrentProjectId(), SystemCustomField.ISSUE_STATUS);
JSONArray statusArray = JSONArray.parseArray(customField.getOptions());
Map<String, String> tmpStatusMap = statusMap; Map<String, String> tmpStatusMap = statusMap;
List<String> unClosedIds = issueIds.stream() List<String> unClosedIds = 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();
while (iterator.hasNext()) {
String unClosedId = iterator.next();
String status = statusMap.getOrDefault(unClosedId, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY);
IssueStatus statusEnum = IssueStatus.getEnumByName(status);
if (statusEnum == null) {
boolean exist = false;
for (int i = 0; i < statusArray.size(); i++) {
JSONObject statusObj = (JSONObject) statusArray.get(i);
if (StringUtils.equals(status, statusObj.get("value").toString())) {
exist = true;
}
}
if (!exist) {
iterator.remove();
}
}
}
request.setFilterIds(unClosedIds); request.setFilterIds(unClosedIds);
} else { } else {
request.setFilterIds(issueIds); request.setFilterIds(issueIds);

View File

@ -193,6 +193,8 @@ public class TrackService {
} }
private Map<String, Integer> getPlanBugSize(String planId, String projectId) { private Map<String, Integer> getPlanBugSize(String planId, String projectId) {
CustomField customField = baseCustomFieldService.getCustomFieldByName(projectId, SystemCustomField.ISSUE_STATUS);
JSONArray statusArray = JSONArray.parseArray(customField.getOptions());
List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId); List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId);
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId); Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId);
Map<String, Integer> bugSizeMap = new HashMap<>(); Map<String, Integer> bugSizeMap = new HashMap<>();
@ -205,7 +207,7 @@ public class TrackService {
issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); issuesRequest.setProjectId(SessionUtils.getCurrentProjectId());
issuesRequest.setFilterIds(issueIds); issuesRequest.setFilterIds(issueIds);
List<IssuesDao> issues = extIssuesMapper.getIssues(issuesRequest); List<IssuesDao> issues = extIssuesMapper.getIssues(issuesRequest);
statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, IssuesDao::getPlatformStatus)); statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new")));
} }
if (MapUtils.isEmpty(statusMap)) { if (MapUtils.isEmpty(statusMap)) {
@ -216,6 +218,24 @@ public class TrackService {
unClosedIds = issueIds.stream() unClosedIds = 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();
while (iterator.hasNext()) {
String unClosedId = iterator.next();
String status = statusMap.getOrDefault(unClosedId, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY);
IssueStatus statusEnum = IssueStatus.getEnumByName(status);
if (statusEnum == null) {
boolean exist = false;
for (int i = 0; i < statusArray.size(); i++) {
JSONObject statusObj = (JSONObject) statusArray.get(i);
if (StringUtils.equals(status, statusObj.get("value").toString())) {
exist = true;
}
}
if (!exist) {
iterator.remove();
}
}
}
bugSizeMap.put("unClosed", unClosedIds.size()); bugSizeMap.put("unClosed", unClosedIds.size());
} }
@ -235,13 +255,13 @@ public class TrackService {
for (String planId : planIds) { for (String planId : planIds) {
List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId); List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId);
Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId); Map<String, String> statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId);
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());
issuesRequest.setFilterIds(issueIds); issuesRequest.setFilterIds(issueIds);
List<IssuesDao> issues = extIssuesMapper.getIssues(issuesRequest); List<IssuesDao> issues = extIssuesMapper.getIssues(issuesRequest);
statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, IssuesDao::getPlatformStatus)); statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new")));
} }
if (MapUtils.isEmpty(statusMap)) { if (MapUtils.isEmpty(statusMap)) {