From 7ee21f06ff0fc1ecd9d9f080e1963e2984c13e2f Mon Sep 17 00:00:00 2001 From: John Bro <42930107+john1298308460@users.noreply.github.com> Date: Tue, 21 Jun 2022 15:30:50 +0800 Subject: [PATCH] Update ProjectService.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代码格式化 --- .../metersphere/service/ProjectService.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index cea038135a..f8e86529ae 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -1028,31 +1028,36 @@ public class ProjectService { } // 删除 UI 报告产生的截图 - public void cleanUpUiReportImg(){ - // 属于定时任务删除调试报告情况 - // 获取昨天的当前时间 - Date backupTime = org.apache.commons.lang3.time.DateUtils.addDays(new Date(), -1); - // 清理类型为 UI 报告类型,且时间为昨天之前的 UI 调试类型报告截图 - ApiScenarioReportExample example = new ApiScenarioReportExample(); - example.createCriteria().andCreateTimeLessThan(backupTime.getTime()).andReportTypeEqualTo(ReportTypeConstants.UI_INDEPENDENT.name()) - .andExecuteTypeEqualTo(ExecuteType.Debug.name()); - List apiScenarioReports = apiScenarioReportMapper.selectByExample(example); - // 删除调试报告的截图 - for(ApiScenarioReport apiScenarioReport : apiScenarioReports){ - if(FileUtil.deleteDir(new File(FileUtils.UI_IMAGE_DIR + "/" + apiScenarioReport.getId()))){ - LogUtil.info("删除 UI 调试报告截图成功,报告 ID 为 :" + apiScenarioReport.getId()); + public void cleanUpUiReportImg() { + try { + // 属于定时任务删除调试报告情况 + // 获取昨天的当前时间 + Date backupTime = org.apache.commons.lang3.time.DateUtils.addDays(new Date(), -1); + // 清理类型为 UI 报告类型,且时间为昨天之前的 UI 调试类型报告截图 + ApiScenarioReportExample example = new ApiScenarioReportExample(); + example.createCriteria().andCreateTimeLessThan(backupTime.getTime()).andReportTypeEqualTo(ReportTypeConstants.UI_INDEPENDENT.name()) + .andExecuteTypeEqualTo(ExecuteType.Debug.name()); + List apiScenarioReports = apiScenarioReportMapper.selectByExample(example); + // 删除调试报告的截图 + for (ApiScenarioReport apiScenarioReport : apiScenarioReports) { + 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()); + // 删除调试报告 + 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()); + apiScenarioReportDetailMapper.deleteByPrimaryKey(apiScenarioReport.getId()); + apiScenarioReportResultMapper.deleteByExample(resultExample); + apiScenarioReportStructureMapper.deleteByExample(structureExample); + apiScenarioReportMapper.deleteByPrimaryKey(apiScenarioReport.getId()); + } } + } catch (Exception e) { + LogUtil.error(e.getMessage(), e); + MSException.throwException(e.getMessage()); } }