From ef6e2c8b2b9f1b623818859fc890bc400edc67ea Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Wed, 26 Apr 2023 17:41:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E9=81=97?= =?UTF-8?q?=E7=95=99=E7=BC=BA=E9=99=B7=E5=B1=95=E7=A4=BA=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1025852 --user=宋昌昌 【测试跟踪】首页-测试计划遗留缺陷统计-第三方平台的缺陷状态是空的 https://www.tapd.cn/55049933/s/1366970 --bug=1025825 --user=宋昌昌 【首页】接口首页、测试跟踪首页,浏览器调窄后统计数字显示不全 https://www.tapd.cn/55049933/s/1367280 --- .../io/metersphere/service/TrackService.java | 187 ++++++++---------- .../home/components/chart/CountChart.vue | 2 +- 2 files changed, 87 insertions(+), 102 deletions(-) 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 89a04fb38f..9c1e0251b9 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 @@ -3,9 +3,9 @@ package io.metersphere.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.CustomField; -import io.metersphere.base.mapper.TestPlanMapper; import io.metersphere.base.mapper.ext.*; import io.metersphere.commons.constants.CustomFieldScene; +import io.metersphere.commons.constants.IssuesManagePlatform; import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; @@ -13,17 +13,14 @@ import io.metersphere.constants.IssueStatus; import io.metersphere.constants.SystemCustomField; import io.metersphere.dto.BugStatistics; import io.metersphere.dto.ExecutedCaseInfoResult; -import io.metersphere.dto.TestPlanDTOWithMetric; import io.metersphere.dto.TrackCountResult; import io.metersphere.i18n.Translator; import io.metersphere.plan.dto.ChartsData; -import io.metersphere.plan.service.TestPlanService; import io.metersphere.request.testcase.TrackCount; import io.metersphere.xpack.track.dto.IssuesDao; import io.metersphere.xpack.track.dto.request.IssuesRequest; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -31,7 +28,6 @@ import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.text.DecimalFormat; import java.util.*; -import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) @@ -40,14 +36,10 @@ public class TrackService { @Resource private ExtTestCaseMapper extTestCaseMapper; @Resource - private TestPlanMapper testPlanMapper; - @Resource private CustomFieldIssuesService customFieldIssuesService; @Resource private BaseCustomFieldService baseCustomFieldService; @Resource - private TestPlanService testPlanService; - @Resource private ExtTestPlanTestCaseMapper extTestPlanTestCaseMapper; @Resource private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; @@ -163,29 +155,30 @@ public class TrackService { } private Map getPlanBugSize(String projectId) { - Map bugSizeMap = new HashMap<>(); + Map bugSizeMap = new HashMap<>(2); + if (StringUtils.isEmpty(projectId)) { + bugSizeMap.put("total", 0); + bugSizeMap.put("unClosed", 0); + bugSizeMap.put("thisWeekCount", 0); + return bugSizeMap; + } List issueIds = extIssuesMapper.getTestPlanIssue(projectId); + if (CollectionUtils.isEmpty(issueIds)) { + // 没有测试计划关联缺陷 + bugSizeMap.put("total", 0); + bugSizeMap.put("unClosed", 0); + bugSizeMap.put("thisWeekCount", 0); + return bugSizeMap; + } + bugSizeMap.put("total", issueIds.size()); - Map statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId); + Map statusMap = parseIssueStatusMap(issueIds, projectId); - if (MapUtils.isEmpty(statusMap) && CollectionUtils.isNotEmpty(issueIds)) { - // 未找到自定义字段状态, 则获取平台状态 - IssuesRequest issuesRequest = new IssuesRequest(); - issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); - issuesRequest.setFilterIds(issueIds); - List issues = extIssuesMapper.getIssues(issuesRequest); - statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new"))); - } - - if (MapUtils.isNotEmpty(statusMap)) { - Map tmpStatusMap = statusMap; - issueIds = issueIds.stream() - .filter(id -> !StringUtils.equals(tmpStatusMap.getOrDefault(id, StringUtils.EMPTY).replaceAll("\"", StringUtils.EMPTY), "closed")) - .collect(Collectors.toList()); - } - - bugSizeMap.put("unClosed", issueIds.size()); + // 过滤出未closed的缺陷(遗留) + List unClosedIds = issueIds.stream() + .filter(id -> !StringUtils.equals(statusMap.get(id).replaceAll("\"", StringUtils.EMPTY), "closed")).toList(); + bugSizeMap.put("unClosed", unClosedIds.size()); int thisWeekCount = 0; if (CollectionUtils.isNotEmpty(issueIds)) { @@ -196,71 +189,64 @@ public class TrackService { } private Map getPlanBugStatusSize(String projectId) { + Map bugStatusMap = new HashMap<>(2); + if (StringUtils.isEmpty(projectId)) { + bugStatusMap.put(Translator.get("new"), 0); + return bugStatusMap; + } + + List issueIds = extIssuesMapper.getTestPlanIssue(projectId); + if (CollectionUtils.isEmpty(issueIds)) { + // 没有测试计划关联缺陷 + bugStatusMap.put(Translator.get("new"), 0); + return bugStatusMap; + } + CustomField customField = baseCustomFieldService.getCustomFieldByName(projectId, SystemCustomField.ISSUE_STATUS); JSONArray statusArray = JSONArray.parseArray(customField.getOptions()); - Map bugStatusMap = new HashMap<>(); - if (StringUtils.isNotEmpty(projectId)) { - List issueIds = extIssuesMapper.getTestPlanIssue(projectId); - Map statusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId); - if (MapUtils.isEmpty(statusMap) && CollectionUtils.isNotEmpty(issueIds)) { - // 未找到自定义字段状态, 则获取平台状态 - IssuesRequest issuesRequest = new IssuesRequest(); - issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); - issuesRequest.setFilterIds(issueIds); - List issues = extIssuesMapper.getIssues(issuesRequest); - statusMap = issues.stream().collect(Collectors.toMap(IssuesDao::getId, i -> Optional.ofNullable(i.getPlatformStatus()).orElse("new"))); - } - - if (MapUtils.isEmpty(statusMap)) { - Integer count = bugStatusMap.get(Translator.get("new")); + Map statusMap = parseIssueStatusMap(issueIds, projectId); + // 过滤出未closed的缺陷(遗留) + List unClosedIds = issueIds.stream() + .filter(id -> !StringUtils.equals(statusMap.get(id).replaceAll("\"", StringUtils.EMPTY), "closed")).toList(); + for (String unClosedId : unClosedIds) { + String status = statusMap.get(unClosedId).replaceAll("\"", StringUtils.EMPTY); + // 遗留缺陷状态是否存在枚举 + IssueStatus statusEnum = IssueStatus.getEnumByName(status); + if (statusEnum != null) { + // 存在枚举类型则国际化Key + Integer count = bugStatusMap.get(Translator.get(statusEnum.getI18nKey())); if (count == null) { - bugStatusMap.put(Translator.get("new"), issueIds.size()); + bugStatusMap.put(Translator.get(statusEnum.getI18nKey()), 1); } else { - count += issueIds.size(); - bugStatusMap.put(Translator.get("new"), count); + count += 1; + bugStatusMap.put(Translator.get(statusEnum.getI18nKey()), count); } } else { - Map tmpStatusMap = statusMap; - List unClosedIds = issueIds.stream() - .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); - IssueStatus statusEnum = IssueStatus.getEnumByName(status); - if (statusEnum != null) { - Integer count = bugStatusMap.get(Translator.get(statusEnum.getI18nKey())); + // 不存在枚举类型, 则在自定义状态字段option数组中取文本值 + boolean isInStatusArray = false; + for (Object item : statusArray) { + JSONObject statusObj = (JSONObject) item; + if (StringUtils.equals(status, statusObj.get("value").toString())) { + Integer count = bugStatusMap.get(statusObj.get("text").toString()); if (count == null) { - bugStatusMap.put(Translator.get(statusEnum.getI18nKey()), 1); + bugStatusMap.put(statusObj.get("text").toString(), 1); } else { count += 1; - bugStatusMap.put(Translator.get(statusEnum.getI18nKey()), count); - } - } else { - boolean isInStatusArray = false; - for (Object item : statusArray) { - JSONObject statusObj = (JSONObject) item; - if (StringUtils.equals(status, statusObj.get("value").toString())) { - Integer count = bugStatusMap.get(statusObj.get("text").toString()); - if (count == null) { - bugStatusMap.put(statusObj.get("text").toString(), 1); - } else { - count += 1; - bugStatusMap.put(statusObj.get("text").toString(), count); - } - isInStatusArray = true; - } + bugStatusMap.put(statusObj.get("text").toString(), count); } + isInStatusArray = true; + } + } - if (!isInStatusArray) { - Integer count = bugStatusMap.get(status); - if (count == null) { - bugStatusMap.put(status, 1); - } else { - count += 1; - bugStatusMap.put(status, count); - } - } + if (!isInStatusArray) { + // 如果不在自定义状态字段option数组中, 则直接展示状态 + Integer count = bugStatusMap.get(status); + if (count == null) { + bugStatusMap.put(status, 1); + } else { + count += 1; + bugStatusMap.put(status, count); } } } @@ -268,26 +254,25 @@ public class TrackService { return bugStatusMap; } - private int getAllUnClosedBugSize(String projectId) { - IssuesRequest req = new IssuesRequest(); - req.setProjectId(projectId); - List issues = extIssuesMapper.getIssues(req); - if (CollectionUtils.isEmpty(issues)) { - return 0; - } - List ids = issues.stream().map(IssuesDao::getId).collect(Collectors.toList()); - Map 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) { - TestPlanDTOWithMetric testPlan = new TestPlanDTOWithMetric(); - testPlan.setId(planId); - testPlanService.calcTestPlanRate(testPlan); - return testPlan.getPassRate(); + private Map parseIssueStatusMap(List issueIds, String projectId) { + Map statusMap = new HashMap<>(issueIds.size()); + // 由于缺陷存在自定义状态, 平台状态, 所以遗留缺状态统计需校验平台 + IssuesRequest issuesRequest = new IssuesRequest(); + issuesRequest.setProjectId(projectId); + issuesRequest.setFilterIds(issueIds); + List issues = extIssuesMapper.getIssues(issuesRequest); + Map customStatusMap = customFieldIssuesService.getIssueStatusMap(issueIds, projectId); + issues.forEach(issue -> { + if (StringUtils.equals(issue.getPlatform(), IssuesManagePlatform.Local.name())) { + // Local平台, 取自定义状态(如果为空, 则为新增) + String customStatus = customStatusMap.getOrDefault(issue.getId(), "new"); + statusMap.put(issue.getId(), customStatus); + } else { + // 第三方平台, 取平台状态(如果为空, 则为新增) + statusMap.put(issue.getId(), Optional.ofNullable(issue.getPlatformStatus()).orElse("new")); + } + }); + return statusMap; } public List findFailureCaseInfoByProjectIDAndLimitNumberInSevenDays(String projectId, String versionId) { diff --git a/test-track/frontend/src/business/home/components/chart/CountChart.vue b/test-track/frontend/src/business/home/components/chart/CountChart.vue index 18ee5229ca..cd350abf11 100644 --- a/test-track/frontend/src/business/home/components/chart/CountChart.vue +++ b/test-track/frontend/src/business/home/components/chart/CountChart.vue @@ -150,7 +150,7 @@ export default { fontSize: 14, color: '#646A73', fontWeight: 400, - width: 50, + width: 40, align: 'left', lineHeight: 22, },