From 1051ab591a23cce0ce1ac25b195d1ce828dba610 Mon Sep 17 00:00:00 2001 From: "nathan.liu" Date: Wed, 21 Sep 2022 16:48:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(UI=E8=87=AA=E5=8A=A8=E5=8C=96):=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=AE=9A=E6=97=B6=E5=88=A0=E9=99=A4UI=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1017072 --user=刘瑶 【UI测试】定时删除报告失败 https://www.tapd.cn/55049933/s/1248763 --- .../constants/ProjectApplicationType.java | 8 +++++ .../controller/request/AddProjectRequest.java | 2 ++ .../service/ProjectApplicationService.java | 4 +++ .../metersphere/service/ProjectService.java | 34 +++++++++++-------- backend/src/main/java/io/metersphere/xpack | 2 +- frontend/src/business/components/xpack | 2 +- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/io/metersphere/commons/constants/ProjectApplicationType.java b/backend/src/main/java/io/metersphere/commons/constants/ProjectApplicationType.java index 02116f9e4d..4498e779ad 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/ProjectApplicationType.java +++ b/backend/src/main/java/io/metersphere/commons/constants/ProjectApplicationType.java @@ -56,6 +56,14 @@ public enum ProjectApplicationType { * 清理时间配置 (Y|M|D) */ CLEAN_API_REPORT_EXPR, + /** + * 是否开启定时清理接口测试报告 + */ + CLEAN_UI_REPORT, + /** + * 清理时间配置 (Y|M|D) + */ + CLEAN_UI_REPORT_EXPR, /** * 是否开启定时清理接口测试报告 */ diff --git a/backend/src/main/java/io/metersphere/controller/request/AddProjectRequest.java b/backend/src/main/java/io/metersphere/controller/request/AddProjectRequest.java index efc78969b0..78f65dcdec 100644 --- a/backend/src/main/java/io/metersphere/controller/request/AddProjectRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/AddProjectRequest.java @@ -19,6 +19,8 @@ public class AddProjectRequest extends Project { private String cleanTrackReportExpr; private Boolean cleanApiReport; private String cleanApiReportExpr; + private Boolean cleanUiReport; + private String cleanUiReportExpr; private Boolean cleanLoadReport; private String cleanLoadReportExpr; } diff --git a/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java b/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java index d0bd4b48f4..48e243368a 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectApplicationService.java @@ -62,6 +62,7 @@ public class ProjectApplicationService { this.doHandleMockTcpPort(projectId, value); } else if (StringUtils.equals(type, ProjectApplicationType.CLEAN_TRACK_REPORT.name()) || StringUtils.equals(type, ProjectApplicationType.CLEAN_API_REPORT.name()) + || StringUtils.equals(type, ProjectApplicationType.CLEAN_UI_REPORT.name()) || StringUtils.equals(type, ProjectApplicationType.CLEAN_LOAD_REPORT.name())) { this.doHandleCleanUp(projectId, type, value); } @@ -81,11 +82,14 @@ public class ProjectApplicationService { config.setCleanApiReport(cleanUp); } else if (StringUtils.equals(type, ProjectApplicationType.CLEAN_LOAD_REPORT.name())) { config.setCleanLoadReport(cleanUp); + } else if(StringUtils.equals(type, ProjectApplicationType.CLEAN_UI_REPORT.name())){ + config.setCleanUiReport(cleanUp); } // 根据这三个状态判断定时清理任务是否开启 request.setCleanTrackReport(config.getCleanTrackReport()); request.setCleanApiReport(config.getCleanApiReport()); request.setCleanLoadReport(config.getCleanLoadReport()); + request.setCleanUiReport(config.getCleanUiReport()); } projectService.addOrUpdateCleanUpSchedule(request); } diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 7a598fd797..c4d6b0810d 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -2,6 +2,7 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.collect.Lists; import io.metersphere.api.dto.DeleteAPITestRequest; import io.metersphere.api.dto.QueryAPITestRequest; import io.metersphere.api.dto.automation.ExecuteType; @@ -507,14 +508,16 @@ public class ProjectService { Boolean cleanTrackReport = project.getCleanTrackReport(); Boolean cleanApiReport = project.getCleanApiReport(); Boolean cleanLoadReport = project.getCleanLoadReport(); - LogUtil.info("clean track/api/performance report: " + cleanTrackReport + "/" + cleanApiReport + "/" + cleanLoadReport); + Boolean cleanUiReport = project.getCleanUiReport(); + LogUtil.info("clean track/api/performance report: " + cleanTrackReport + "/" + cleanApiReport + "/" + cleanLoadReport + "/" + cleanUiReport); // 未设置则不更新定时任务 - if (cleanTrackReport == null && cleanApiReport == null && cleanLoadReport == null) { + if (cleanTrackReport == null && cleanApiReport == null && cleanLoadReport == null && cleanUiReport == null) { return; } String projectId = project.getId(); Boolean enable = BooleanUtils.isTrue(cleanTrackReport) || BooleanUtils.isTrue(cleanApiReport) || + BooleanUtils.isTrue(cleanUiReport) || BooleanUtils.isTrue(cleanLoadReport); Schedule schedule = scheduleService.getScheduleByResource(projectId, ScheduleGroup.CLEAN_UP_REPORT.name()); if (schedule != null && StringUtils.isNotBlank(schedule.getId())) { @@ -1051,24 +1054,25 @@ public class ProjectService { ApiScenarioReportExample example = new ApiScenarioReportExample(); example.createCriteria() .andProjectIdEqualTo(projectId) - .andCreateTimeLessThan(backupTime).andReportTypeEqualTo(ReportTypeConstants.UI_INDEPENDENT.name()) - .andExecuteTypeEqualTo(ExecuteType.Debug.name()); + .andCreateTimeLessThan(backupTime).andReportTypeIn(Lists.newArrayList(ReportTypeConstants.UI_INDEPENDENT.name(), + ReportTypeConstants.UI_INTEGRATED.name())) + .andExecuteTypeIn(Lists.newArrayList(ExecuteType.Debug.name(), ExecuteType.Saved.name())); List apiScenarioReports = apiScenarioReportMapper.selectByExample(example); // 删除调试报告的截图 for (ApiScenarioReport apiScenarioReport : apiScenarioReports) { + // 删除调试报告 + ApiScenarioReportResultExample resultExample = new ApiScenarioReportResultExample(); + resultExample.createCriteria().andReportIdEqualTo(apiScenarioReport.getId()); + ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); + structureExample.createCriteria().andReportIdEqualTo(apiScenarioReport.getId()); + + apiScenarioReportDetailMapper.deleteByPrimaryKey(apiScenarioReport.getId()); + apiScenarioReportResultMapper.deleteByExample(resultExample); + apiScenarioReportStructureMapper.deleteByExample(structureExample); + apiScenarioReportMapper.deleteByPrimaryKey(apiScenarioReport.getId()); + //如果有截图数据则删除 if (FileUtil.deleteDir(new File(FileUtils.UI_IMAGE_DIR + "/" + apiScenarioReport.getId()))) { LogUtil.info("删除 UI 调试报告截图成功,报告 ID 为 :" + apiScenarioReport.getId()); - - // 删除调试报告 - ApiScenarioReportResultExample resultExample = new ApiScenarioReportResultExample(); - resultExample.createCriteria().andReportIdEqualTo(apiScenarioReport.getId()); - ApiScenarioReportStructureExample structureExample = new ApiScenarioReportStructureExample(); - structureExample.createCriteria().andReportIdEqualTo(apiScenarioReport.getId()); - - apiScenarioReportDetailMapper.deleteByPrimaryKey(apiScenarioReport.getId()); - apiScenarioReportResultMapper.deleteByExample(resultExample); - apiScenarioReportStructureMapper.deleteByExample(structureExample); - apiScenarioReportMapper.deleteByPrimaryKey(apiScenarioReport.getId()); } } } catch (Exception e) { diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 29d5973095..a7499a6363 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 29d59730956b073e36aeac3b957211959dc91427 +Subproject commit a7499a636342d4b58bb799c45468eb1245ce6e6b diff --git a/frontend/src/business/components/xpack b/frontend/src/business/components/xpack index 8fae61212e..90ebdc95e7 160000 --- a/frontend/src/business/components/xpack +++ b/frontend/src/business/components/xpack @@ -1 +1 @@ -Subproject commit 8fae61212eea4f7b2a3d22a8b78666185d43d24f +Subproject commit 90ebdc95e77e628581e2ac083568a3e543cb7c00