From e00efb20b255568302203ddb329fc8c1fdffe759 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 17 Jun 2024 10:03:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/ApiReportSendNoticeService.java | 21 ++++++++++++------- .../controller/ApiReportSendNoticeTests.java | 13 ++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportSendNoticeService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportSendNoticeService.java index aba571764f..5d8a3228a9 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportSendNoticeService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportSendNoticeService.java @@ -14,6 +14,7 @@ import io.metersphere.api.mapper.ApiScenarioReportMapper; import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ProjectMapper; +import io.metersphere.sdk.constants.ApiExecuteResourceType; import io.metersphere.sdk.constants.ReportStatus; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; @@ -57,15 +58,17 @@ public class ApiReportSendNoticeService { private EnvironmentMapper environmentMapper; @Resource private ProjectMapper projectMapper; - private static final String API_SCENARIO = "API_SCENARIO"; - private static final String API_CASE = "API_CASE"; public void sendNotice(ApiNoticeDTO noticeDTO) { - String noticeType; + String noticeType = null; + if (StringUtils.equalsAnyIgnoreCase(noticeDTO.getResourceType(), + ApiExecuteResourceType.PLAN_RUN_API_CASE.name(), ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name())) { + return; + } SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); assert systemParameterService != null; BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); - BeanMap beanMap; + BeanMap beanMap = null; String event = null; ApiReportShareService shareService = CommonBeanFactory.getBean(ApiReportShareService.class); ApiReportShareRequest shareRequest = new ApiReportShareRequest(); @@ -77,12 +80,13 @@ public class ApiReportSendNoticeService { String reportUrl = baseSystemConfigDTO.getUrl() + "/#/api-test/report?orgId=%s&pId=%s&type=%s&reportId=%s"; String shareUrl = baseSystemConfigDTO.getUrl() + "/#/share/%s?shareId=" + url.getId(); ApiScenarioReport report = new ApiScenarioReport(); - if (API_SCENARIO.equals(noticeDTO.getResourceType())) { + if (StringUtils.equalsAnyIgnoreCase(noticeDTO.getResourceType(), + ApiExecuteResourceType.API_SCENARIO.name(), ApiExecuteResourceType.TEST_PLAN_API_SCENARIO.name())) { ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(noticeDTO.getResourceId()); beanMap = new BeanMap(scenario); noticeType = NoticeConstants.TaskType.API_SCENARIO_TASK; report = apiScenarioReportMapper.selectByPrimaryKey(noticeDTO.getReportId()); - reportUrl = String.format(reportUrl, project.getOrganizationId(), project.getId(), API_SCENARIO, report.getId()); + reportUrl = String.format(reportUrl, project.getOrganizationId(), project.getId(), ApiExecuteResourceType.API_SCENARIO.name(), report.getId()); if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ReportStatus.SUCCESS.name())) { event = NoticeConstants.Event.SCENARIO_EXECUTE_SUCCESSFUL; } else if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ReportStatus.FAKE_ERROR.name())) { @@ -91,14 +95,15 @@ public class ApiReportSendNoticeService { event = NoticeConstants.Event.SCENARIO_EXECUTE_FAILED; } shareUrl = String.format(shareUrl, "shareReportScenario"); - } else { + } else if (StringUtils.equalsAnyIgnoreCase(noticeDTO.getResourceType(), + ApiExecuteResourceType.API_CASE.name(), ApiExecuteResourceType.TEST_PLAN_API_CASE.name())) { ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(noticeDTO.getResourceId()); beanMap = new BeanMap(testCase); // TODO 是否需要区分场景和用例 noticeType = NoticeConstants.TaskType.API_DEFINITION_TASK; ApiReport apiReport = apiReportMapper.selectByPrimaryKey(noticeDTO.getReportId()); - reportUrl = String.format(reportUrl, project.getOrganizationId(), project.getId(), API_CASE, apiReport.getId()); + reportUrl = String.format(reportUrl, project.getOrganizationId(), project.getId(), ApiExecuteResourceType.API_CASE.name(), apiReport.getId()); BeanUtils.copyBean(report, apiReport); if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ReportStatus.SUCCESS.name())) { event = NoticeConstants.Event.CASE_EXECUTE_SUCCESSFUL; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java index 140785e2b7..926facdb0a 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportSendNoticeTests.java @@ -6,6 +6,7 @@ import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.service.ApiReportSendNoticeService; import io.metersphere.api.service.definition.ApiReportService; import io.metersphere.api.service.scenario.ApiScenarioReportService; +import io.metersphere.sdk.constants.ApiExecuteResourceType; import io.metersphere.sdk.constants.ReportStatus; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; @@ -123,6 +124,12 @@ public class ApiReportSendNoticeTests extends BaseTest { noticeDTO.setReportId("send-api-case-report-id2"); apiReportSendNoticeService.sendNotice(noticeDTO); + noticeDTO.setResourceType(ApiExecuteResourceType.PLAN_RUN_API_CASE.name()); + apiReportSendNoticeService.sendNotice(noticeDTO); + + noticeDTO.setResourceType(ApiExecuteResourceType.TEST_PLAN_API_CASE.name()); + apiReportSendNoticeService.sendNotice(noticeDTO); + ApiScenario apiScenario = new ApiScenario(); apiScenario.setId("send-scenario-id"); @@ -190,5 +197,11 @@ public class ApiReportSendNoticeTests extends BaseTest { noticeDTO.setReportStatus(ReportStatus.FAKE_ERROR.name()); noticeDTO.setReportId("send-scenario-report-id2"); apiReportSendNoticeService.sendNotice(noticeDTO); + + noticeDTO.setResourceType(ApiExecuteResourceType.PLAN_RUN_API_SCENARIO.name()); + apiReportSendNoticeService.sendNotice(noticeDTO); + + noticeDTO.setResourceType(ApiExecuteResourceType.TEST_PLAN_API_SCENARIO.name()); + apiReportSendNoticeService.sendNotice(noticeDTO); } }