diff --git a/test-track/backend/src/main/java/io/metersphere/constants/IssueStatus.java b/test-track/backend/src/main/java/io/metersphere/constants/IssueStatus.java index f5171f0767..cee2045c8f 100644 --- a/test-track/backend/src/main/java/io/metersphere/constants/IssueStatus.java +++ b/test-track/backend/src/main/java/io/metersphere/constants/IssueStatus.java @@ -4,6 +4,7 @@ import org.apache.commons.lang3.StringUtils; public enum IssueStatus { status_new("new", "new"), + status_created("created", "new"), status_resolved("resolved", "resolved"), status_closed("closed", "closed"), status_active("active", "active"), diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index 0d22dda47f..616d0ac928 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -1699,12 +1699,22 @@ public class IssuesService { } Map statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, request.getProjectId()); + if (MapUtils.isEmpty(statusMap)) { + // 未找到自定义字段状态, 则获取平台状态 + IssuesRequest issuesRequest = new IssuesRequest(); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); + issuesRequest.setFilterIds(issueIds); + List issues = extIssuesMapper.getIssues(issuesRequest); + statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, IssuesDao::getPlatformStatus)); + } + if (MapUtils.isEmpty(statusMap)) { request.setFilterIds(issueIds); } else { if (request.getThisWeekUnClosedTestPlanIssue() || request.getUnClosedTestPlanIssue()) { + Map tmpStatusMap = statusMap; List unClosedIds = issueIds.stream() - .filter(id -> !StringUtils.equals(statusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) + .filter(id -> !StringUtils.equals(tmpStatusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) .collect(Collectors.toList()); request.setFilterIds(unClosedIds); } else { diff --git a/test-track/backend/src/main/java/io/metersphere/service/TrackService.java b/test-track/backend/src/main/java/io/metersphere/service/TrackService.java index e142e179d6..d68f22aa0b 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TrackService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TrackService.java @@ -199,12 +199,22 @@ public class TrackService { bugSizeMap.put("total", issueIds.size()); // 缺陷是否有状态 List unClosedIds; + if (MapUtils.isEmpty(statusMap)) { + // 未找到自定义字段状态, 则获取平台状态 + IssuesRequest issuesRequest = new IssuesRequest(); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); + issuesRequest.setFilterIds(issueIds); + List issues = extIssuesMapper.getIssues(issuesRequest); + statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, IssuesDao::getPlatformStatus)); + } + if (MapUtils.isEmpty(statusMap)) { unClosedIds = issueIds; bugSizeMap.put("unClosed", issueIds.size()); } else { + Map tmpStatusMap = statusMap; unClosedIds = issueIds.stream() - .filter(id -> !StringUtils.equals(statusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) + .filter(id -> !StringUtils.equals(tmpStatusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) .collect(Collectors.toList()); bugSizeMap.put("unClosed", unClosedIds.size()); } @@ -222,9 +232,18 @@ public class TrackService { JSONArray statusArray = JSONArray.parseArray(customField.getOptions()); Map bugStatusMap = new HashMap<>(); if (CollectionUtils.isNotEmpty(planIds)) { - planIds.forEach(planId -> { + for (String planId : planIds) { List issueIds = extTestCaseMapper.getTestPlanBug(planId); Map statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId); + if (MapUtils.isEmpty(statusMap)) { + // 未找到自定义字段状态, 则获取平台状态 + IssuesRequest issuesRequest = new IssuesRequest(); + issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); + issuesRequest.setFilterIds(issueIds); + List issues = extIssuesMapper.getIssues(issuesRequest); + statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, IssuesDao::getPlatformStatus)); + } + if (MapUtils.isEmpty(statusMap)) { Integer count = bugStatusMap.get(Translator.get("new")); if (count == null) { @@ -234,8 +253,9 @@ public class TrackService { bugStatusMap.put(Translator.get("new"), count); } } else { + Map tmpStatusMap = statusMap; List unClosedIds = issueIds.stream() - .filter(id -> !StringUtils.equals(statusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) + .filter(id -> !StringUtils.equals(tmpStatusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) .collect(Collectors.toList()); for (String unClosedId : unClosedIds) { String status = statusMap.getOrDefault(unClosedId, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY); @@ -264,7 +284,7 @@ public class TrackService { } } } - }); + } } if (MapUtils.isEmpty(bugStatusMap)) { for (IssueStatus statusEnum : IssueStatus.values()) {