From 3928bde3c3be14d765b66397db37c3d78977e565 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 15 Jul 2022 17:09:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E6=88=90=E7=9A=84=E6=B5=8B=E8=AF=95=E8=AE=A1?= =?UTF-8?q?=E5=88=92=E6=8A=A5=E5=91=8A=E7=AC=AC=E4=B8=80=E6=AC=A1=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=97=B6=E8=AE=B0=E5=BD=95=E7=BB=9F=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1007420 --user=宋天阳 【中金】【测试计划报告查询慢】查看测试计划执行报告,个别报告查询慢 https://www.tapd.cn/55049933/s/1202814 --- .../dto/TestPlanReportBuildResultDTO.java | 15 +++++++++ .../track/service/TestPlanReportService.java | 29 ++++++++++------ .../track/service/TestPlanService.java | 33 ++++++++++++++++--- 3 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/track/dto/TestPlanReportBuildResultDTO.java diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanReportBuildResultDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanReportBuildResultDTO.java new file mode 100644 index 0000000000..01f50ccb7f --- /dev/null +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanReportBuildResultDTO.java @@ -0,0 +1,15 @@ +package io.metersphere.track.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class TestPlanReportBuildResultDTO { + private TestPlanSimpleReportDTO testPlanSimpleReportDTO; + /** + * 判断testPlanReportContent中,APIBaseInfo字段是否改变。 + * 如果改变过,则需要更新testPlanReportContent数据 + */ + private boolean apiBaseInfoChanged = false; +} diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java index 9231626284..6975b58fc4 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanReportService.java @@ -466,16 +466,33 @@ public class TestPlanReportService { } public TestPlanReportContentWithBLOBs updateReport(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) { - if (testPlanReport == null) { + if (testPlanReport == null || reportContent == null) { return null; } TestPlanService testPlanService = CommonBeanFactory.getBean(TestPlanService.class); - TestPlanSimpleReportDTO reportDTO = testPlanService.buildPlanReport(testPlanReport, reportContent); + TestPlanReportBuildResultDTO reportBuildResult = testPlanService.buildPlanReport(testPlanReport, reportContent); + TestPlanSimpleReportDTO reportDTO = reportBuildResult.getTestPlanSimpleReportDTO(); reportDTO.setStartTime(testPlanReport.getStartTime()); reportContent = parseReportDaoToReportContent(testPlanReport.getStatus(), reportDTO, reportContent); + this.updatePassRateAndApiBaseInfoFromReportContent(testPlanReport.getStatus(), reportDTO, reportContent, reportBuildResult.isApiBaseInfoChanged()); return reportContent; } + private void updatePassRateAndApiBaseInfoFromReportContent(String status, TestPlanSimpleReportDTO reportDTO, TestPlanReportContentWithBLOBs reportContent, boolean apiBaseInfoChanged) { + // 如果报告已结束,则更新测试计划报告通过率字段 passRate + if (!StringUtils.equalsIgnoreCase(status, "running") && (Double.compare(reportContent.getPassRate(), reportDTO.getPassRate()) != 0 || apiBaseInfoChanged)) { + TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); + contentExample.createCriteria().andTestPlanReportIdEqualTo(reportContent.getTestPlanReportId()); + TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs(); + content.setPassRate(reportDTO.getPassRate()); + if (apiBaseInfoChanged) { + content.setApiBaseCount(reportContent.getApiBaseCount()); + } + testPlanReportContentMapper.updateByExampleSelective(content, contentExample); + } + + } + public TestPlanReport finishedTestPlanReport(String testPlanReportId, String status) { TestPlanReport testPlanReport = this.getTestPlanReport(testPlanReportId); if (testPlanReport != null && StringUtils.equalsIgnoreCase(testPlanReport.getStatus(), "stopped")) { @@ -670,14 +687,6 @@ public class TestPlanReportService { testPlanReportContentWithBLOBs.setUnExecuteScenarios(JSONObject.toJSONString(reportDTO.getUnExecuteScenarios())); } - // 如果报告已结束,则更新测试计划报告通过率字段 passRate - if (!StringUtils.equalsIgnoreCase(testPlanReportStatus, "running")) { - TestPlanReportContentExample contentExample = new TestPlanReportContentExample(); - contentExample.createCriteria().andTestPlanReportIdEqualTo(testPlanReportId); - TestPlanReportContentWithBLOBs content = new TestPlanReportContentWithBLOBs(); - content.setPassRate(reportDTO.getPassRate()); - testPlanReportContentMapper.updateByExampleSelective(content, contentExample); - } return testPlanReportContentWithBLOBs; } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index e6b9b36fe2..d8d470fd6f 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -1682,7 +1682,14 @@ public class TestPlanService { } } - public TestPlanSimpleReportDTO buildPlanReport(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) { + /** + * @param testPlanReport 测试计划报告 + * @param testPlanReportContentWithBLOBs 测试计划报告内容 + * @param isReportContenChanged 测试计划报告是否已经修改过 + * @return + */ + public TestPlanReportBuildResultDTO buildPlanReport(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) { + TestPlanReportBuildResultDTO returnDTO = new TestPlanReportBuildResultDTO(); TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(testPlanReport.getTestPlanId()); if (testPlan != null) { String reportConfig = testPlan.getReportConfig(); @@ -1691,13 +1698,31 @@ public class TestPlanService { config = JSONObject.parseObject(reportConfig); } TestPlanExecuteReportDTO testPlanExecuteReportDTO = testPlanReportService.genTestPlanExecuteReportDTOByTestPlanReportContent(testPlanReportContentWithBLOBs); - TestPlanSimpleReportDTO report = getReport(testPlanReport.getTestPlanId(), testPlanExecuteReportDTO); + TestPlanSimpleReportDTO report = null; + if (StringUtils.isEmpty(testPlanReportContentWithBLOBs.getApiBaseCount())) { + report = getReport(testPlanReport.getTestPlanId(), testPlanExecuteReportDTO); + testPlanReportContentWithBLOBs.setApiBaseCount(JSONObject.toJSONString(report)); + returnDTO.setApiBaseInfoChanged(true); + } else { + try { + report = JSONObject.parseObject(testPlanReportContentWithBLOBs.getApiBaseCount(), TestPlanSimpleReportDTO.class); + } catch (Exception e) { + LogUtil.info("解析接口统计数据出错!数据:" + testPlanReportContentWithBLOBs.getApiBaseCount(), e); + } + if (report == null) { + report = getReport(testPlanReport.getTestPlanId(), testPlanExecuteReportDTO); + testPlanReportContentWithBLOBs.setApiBaseCount(JSONObject.toJSONString(report)); + returnDTO.setApiBaseInfoChanged(true); + } + } buildFunctionalReport(report, config, testPlanReport.getTestPlanId()); buildApiReport(report, config, testPlanExecuteReportDTO); buildLoadReport(report, config, testPlanExecuteReportDTO.getTestPlanLoadCaseIdAndReportIdMap(), false); - return report; + returnDTO.setTestPlanSimpleReportDTO(report); + return returnDTO; } else { - return null; + returnDTO.setTestPlanSimpleReportDTO(new TestPlanSimpleReportDTO()); + return returnDTO; } }