fix(UI自动化): 修复定时删除UI报告失效问题

--bug=1017072 --user=刘瑶 【UI测试】定时删除报告失败 https://www.tapd.cn/55049933/s/1248763
This commit is contained in:
nathan.liu 2022-09-21 16:48:45 +08:00 committed by nathanliu2022
parent d425a43cd0
commit 1051ab591a
6 changed files with 35 additions and 17 deletions

View File

@ -56,6 +56,14 @@ public enum ProjectApplicationType {
* 清理时间配置 (Y|M|D)
*/
CLEAN_API_REPORT_EXPR,
/**
* 是否开启定时清理接口测试报告
*/
CLEAN_UI_REPORT,
/**
* 清理时间配置 (Y|M|D)
*/
CLEAN_UI_REPORT_EXPR,
/**
* 是否开启定时清理接口测试报告
*/

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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<ApiScenarioReport> 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) {

@ -1 +1 @@
Subproject commit 29d59730956b073e36aeac3b957211959dc91427
Subproject commit a7499a636342d4b58bb799c45468eb1245ce6e6b

@ -1 +1 @@
Subproject commit 8fae61212eea4f7b2a3d22a8b78666185d43d24f
Subproject commit 90ebdc95e77e628581e2ac083568a3e543cb7c00