From 1d124b57f4c83b18514ea543eda1ba7bde3daf2e Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 16 Mar 2023 18:26:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8A=A5=E8=A1=A8=E7=BB=9F=E8=AE=A1):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A5=BC=E7=8A=B6=E5=9B=BE=E7=9A=84=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=96=B9=E5=BC=8F=E4=BB=A5=E5=8F=8A=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1021171 --user=宋天阳 【报表统计】github#20870,测试用例统计图,报表展示数值重叠,导出后缺少图表 https://www.tapd.cn/55049933/s/1351691 --- .../sdk-parent/frontend/src/utils/index.js | 23 +- .../service/TestCaseCountService.java | 13 +- .../reportstatistics/utils/DiscoveryUtil.java | 30 ++ .../src/business/base/ReportHeader.vue | 89 +++--- .../projectstatistics/ProjectStatistics.vue | 144 +++++++--- .../casecount/TestCaseCountContainer.vue | 231 +++++++++------ .../casecount/chart/TestCaseCountChart.vue | 265 +++++++++++++----- .../casecount/table/TestCaseCountTable.vue | 73 +++-- .../track/TestAnalysisContainer.vue | 155 ++++++---- .../track/chart/TestAnalysisChart.vue | 123 +++++--- 10 files changed, 780 insertions(+), 366 deletions(-) create mode 100644 report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/DiscoveryUtil.java diff --git a/framework/sdk-parent/frontend/src/utils/index.js b/framework/sdk-parent/frontend/src/utils/index.js index 3b278d4350..8b22d5f89d 100644 --- a/framework/sdk-parent/frontend/src/utils/index.js +++ b/framework/sdk-parent/frontend/src/utils/index.js @@ -8,6 +8,14 @@ import { import i18n from "../i18n"; import html2canvas from "html2canvas"; import JsPDF from "jspdf"; +/** + * 同一行的多个文本框高度保持一致 + * 同时支持 autosize 的功能 + * @param size 同一行中文本框的个数 + * @param index 编辑行的下标 + * 如果编辑某一行,则只调整某一行,提升效率 + */ +import calcTextareaHeight from "element-ui/packages/input/src/calcTextareaHeight"; export function setCustomizeColor(color) { // 自定义主题风格 @@ -309,10 +317,10 @@ export function sizeToByte(size) { let k = 1024, sizeUnits = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"]; let i = 1; - for (i++; i < sizeUnits.length;) { + for (i++; i < sizeUnits.length; ) { let unit = sizeUnits[i]; if (size.indexOf(unit) !== -1) { - return size.toString().replace(unit, "") * Math.pow(k, i) + return size.toString().replace(unit, "") * Math.pow(k, i); } } } @@ -325,15 +333,6 @@ export function getTypeByFileName(filename) { return type.toUpperCase(); } -/** - * 同一行的多个文本框高度保持一致 - * 同时支持 autosize 的功能 - * @param size 同一行中文本框的个数 - * @param index 编辑行的下标 - * 如果编辑某一行,则只调整某一行,提升效率 - */ -import calcTextareaHeight from "element-ui/packages/input/src/calcTextareaHeight"; - export function resizeTextarea(size = 2, index) { let textareaList = document.querySelectorAll( ".sync-textarea .el-textarea__inner" @@ -404,7 +403,7 @@ export function downloadPDF(ele, pdfName) { let scale = canvas.height / ((canvas.width / 592.28) * 841.89); scale = scale > 3 ? 1 : 2; context.translate(-eleOffsetLeft - abs, -eleOffsetTop); - let scrollWidth = document.getElementById("apiTestReport").scrollWidth; + let scrollWidth = ele.scrollWidth; html2canvas(ele, { scale: scale, // 背景灰色 background: "#FFFFFF", diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/TestCaseCountService.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/TestCaseCountService.java index 2b909e3bff..005123e034 100644 --- a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/TestCaseCountService.java +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/service/TestCaseCountService.java @@ -2,6 +2,7 @@ package io.metersphere.reportstatistics.service; import io.metersphere.base.domain.CustomField; import io.metersphere.base.domain.User; +import io.metersphere.commons.constants.MicroServiceName; import io.metersphere.commons.utils.DateUtils; import io.metersphere.commons.utils.JSON; import io.metersphere.i18n.Translator; @@ -15,15 +16,16 @@ import io.metersphere.reportstatistics.service.remote.apitest.ScenarioRemoteServ import io.metersphere.reportstatistics.service.remote.performance.PerformanceRemoteService; import io.metersphere.reportstatistics.service.remote.projectmanagement.TestCaseTemplateRemoteService; import io.metersphere.reportstatistics.service.remote.track.TestCaseRemoteService; +import io.metersphere.reportstatistics.utils.DiscoveryUtil; import io.metersphere.request.member.QueryMemberRequest; import io.metersphere.service.BaseUserService; +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; -import jakarta.annotation.Resource; import java.util.*; @Service @@ -126,7 +128,6 @@ public class TestCaseCountService { } else if (StringUtils.equalsIgnoreCase(request.getTimeRangeUnit(), "year")) { dateCountType = Calendar.YEAR; } - if (dateCountType != 0 && request.getTimeRange() != 0) { long startTime = DateUtils.dateSum(new Date(), (0 - request.getTimeRange()), dateCountType).getTime(); request.setStartTime(startTime); @@ -246,7 +247,7 @@ public class TestCaseCountService { } - if (yAxisSelectTestCase) { + if (yAxisSelectTestCase && DiscoveryUtil.hasService(MicroServiceName.TEST_TRACK)) { functionCaseCountResult = testCaseRemoteService.countTestCaseByRequest(request); if (functionCaseCountResult.isEmpty() && StringUtils.equalsIgnoreCase(request.getXaxis(), "casetype")) { TestCaseCountChartResult result = new TestCaseCountChartResult(); @@ -255,7 +256,7 @@ public class TestCaseCountService { functionCaseCountResult.add(result); } } - if (yAxisSelectApi) { + if (yAxisSelectApi && DiscoveryUtil.hasService(MicroServiceName.API_TEST)) { Map> apiCaseFilterList = new HashMap<>(); if (MapUtils.isNotEmpty(request.getFilterSearchList())) { for (Map.Entry> entry : request.getFilterSearchList().entrySet()) { @@ -274,7 +275,7 @@ public class TestCaseCountService { apiCaseCountResult.add(result); } } - if (yAxisSelectScenarioCase) { + if (yAxisSelectScenarioCase && DiscoveryUtil.hasService(MicroServiceName.API_TEST)) { scenarioCaseCount = scenarioRemoteService.countTestCaseByRequest(request); if (scenarioCaseCount.isEmpty() && StringUtils.equalsIgnoreCase(request.getXaxis(), "casetype")) { TestCaseCountChartResult result = new TestCaseCountChartResult(); @@ -283,7 +284,7 @@ public class TestCaseCountService { scenarioCaseCount.add(result); } } - if (yAxisSelectLoad) { + if (yAxisSelectLoad && DiscoveryUtil.hasService(MicroServiceName.PERFORMANCE_TEST)) { Map> loadCaseFilterMap = new HashMap<>(); if (MapUtils.isNotEmpty(request.getFilterSearchList())) { for (Map.Entry> entry : request.getFilterSearchList().entrySet()) { diff --git a/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/DiscoveryUtil.java b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/DiscoveryUtil.java new file mode 100644 index 0000000000..c220b45c41 --- /dev/null +++ b/report-stat/backend/src/main/java/io/metersphere/reportstatistics/utils/DiscoveryUtil.java @@ -0,0 +1,30 @@ +package io.metersphere.reportstatistics.utils; + +import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.dto.ServiceDTO; +import org.springframework.cloud.client.discovery.DiscoveryClient; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class DiscoveryUtil { + + public static boolean hasService(String serviceId) { + return getServiceIdSet().contains(serviceId); + } + + public static Set getServiceIdSet() { + DiscoveryClient discoveryClient = CommonBeanFactory.getBean(DiscoveryClient.class); + return discoveryClient.getServices() + .stream() + .collect(Collectors.toSet()); + } + + public static List getServices() { + DiscoveryClient discoveryClient = CommonBeanFactory.getBean(DiscoveryClient.class); + return discoveryClient.getServices().stream() + .map(service -> new ServiceDTO(service, discoveryClient.getInstances(service).get(0).getPort())) + .collect(Collectors.toList()); + } +} diff --git a/report-stat/frontend/src/business/base/ReportHeader.vue b/report-stat/frontend/src/business/base/ReportHeader.vue index 05771e2b84..2aadac48b8 100644 --- a/report-stat/frontend/src/business/base/ReportHeader.vue +++ b/report-stat/frontend/src/business/base/ReportHeader.vue @@ -1,35 +1,55 @@ diff --git a/report-stat/frontend/src/business/projectstatistics/casecount/chart/TestCaseCountChart.vue b/report-stat/frontend/src/business/projectstatistics/casecount/chart/TestCaseCountChart.vue index 549e0322f1..46d8dcdf52 100644 --- a/report-stat/frontend/src/business/projectstatistics/casecount/chart/TestCaseCountChart.vue +++ b/report-stat/frontend/src/business/projectstatistics/casecount/chart/TestCaseCountChart.vue @@ -1,12 +1,20 @@