From b29fa733e82d5ae4167280ce79af38698f22fbf0 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 18 Jan 2024 10:36:47 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E6=89=A7=E8=A1=8C=E9=80=9A=E7=9F=A5=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E9=9B=86=E5=90=88=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sdk/dto/api/notice/ApiNoticeDTO.java | 32 +++++++++++++++++-- .../api/listener/MessageListener.java | 13 +++++--- .../service/ApiReportSendNoticeService.java | 5 ++- .../api/listener/MessageListenerTest.java | 6 ++-- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java index a080678122..b736ccfaaa 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java @@ -1,6 +1,5 @@ package io.metersphere.sdk.dto.api.notice; -import io.metersphere.sdk.constants.ApiExecuteResourceType; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -13,13 +12,40 @@ import java.io.Serial; public class ApiNoticeDTO implements java.io.Serializable { @Serial private static final long serialVersionUID = 1L; - - private ApiExecuteResourceType resourceType; + /** + * 资源类型 + */ + private String resourceType; + /** + * 资源ID + */ private String resourceId; + /** + * 报告状态 + */ private String reportStatus; + /** + * 用户ID + */ private String userId; + /** + * 项目ID + */ private String projectId; + /** + * 环境ID + */ private String environmentId; + /** + * 报告ID + */ private String reportId; + /** + * 队列ID + */ private String queueId; + /** + * 报告类型 + */ + private String reportType; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java index aad8d6628a..04790c3480 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java @@ -3,6 +3,7 @@ package io.metersphere.api.listener; import io.metersphere.api.event.ApiEventSource; import io.metersphere.api.service.ApiReportSendNoticeService; import io.metersphere.api.service.queue.ApiExecutionQueueService; +import io.metersphere.sdk.constants.ApiReportType; import io.metersphere.sdk.constants.ApplicationScope; import io.metersphere.sdk.constants.KafkaTopicConstants; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; @@ -11,6 +12,7 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; import jakarta.annotation.Resource; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.springframework.context.annotation.Configuration; import org.springframework.kafka.annotation.KafkaListener; @@ -33,12 +35,15 @@ public class MessageListener { LogUtils.info("接收到发送通知信息:", record.key()); if (ObjectUtils.isNotEmpty(record.value())) { ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class); - apiReportSendNoticeService.sendNotice(dto); - // TODO 通知测试计划处理后续 - LogUtils.info("发送通知给测试计划:", record.key()); - apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value()); + // 集合报告不发送通知 + if (!StringUtils.equalsIgnoreCase(dto.getReportType(), ApiReportType.INTEGRATED.name())) { + apiReportSendNoticeService.sendNotice(dto); + // TODO 通知测试计划处理后续 + LogUtils.info("发送通知给测试计划:", record.key()); + apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value()); + } // TODO 串行触发下次执行 ExecutionQueueDetail detail = apiExecutionQueueService.getNextDetail(dto.getQueueId()); // TODO 调用执行方法 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 d03863ae4b..e11699b4fe 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 @@ -8,7 +8,6 @@ import io.metersphere.api.mapper.ApiScenarioMapper; 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.ApiReportStatus; import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; @@ -55,13 +54,13 @@ public class ApiReportSendNoticeService { BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); BeanMap beanMap; switch (noticeDTO.getResourceType()) { - case ApiExecuteResourceType.API_SCENARIO: + case "API_SCENARIO": ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(noticeDTO.getResourceId()); beanMap = new BeanMap(scenario); noticeType = NoticeConstants.TaskType.API_SCENARIO_TASK; reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report/view/" + noticeDTO.getReportId(); break; - case ApiExecuteResourceType.API: + case "API": ApiDefinition definition = apiDefinitionMapper.selectByPrimaryKey(noticeDTO.getResourceId()); beanMap = new BeanMap(definition); noticeType = NoticeConstants.TaskType.API_DEFINITION_TASK; diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java index c586a171c4..fb8ac90e4a 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java @@ -26,7 +26,7 @@ public class MessageListenerTest { ApiNoticeDTO api = new ApiNoticeDTO(); // Set values for the fields - api.setResourceType(ApiExecuteResourceType.API); + api.setResourceType(ApiExecuteResourceType.API.name()); api.setResourceId("exampleResourceId"); api.setReportStatus("exampleReportStatus"); api.setUserId("exampleUserId"); @@ -42,7 +42,7 @@ public class MessageListenerTest { ApiNoticeDTO scenario = new ApiNoticeDTO(); // Set values for the fields - scenario.setResourceType(ApiExecuteResourceType.API); + scenario.setResourceType(ApiExecuteResourceType.API.name()); scenario.setResourceId("exampleResourceId"); scenario.setReportStatus("exampleReportStatus"); scenario.setUserId("exampleUserId"); @@ -58,7 +58,7 @@ public class MessageListenerTest { ApiNoticeDTO testCase = new ApiNoticeDTO(); // Set values for the fields - testCase.setResourceType(ApiExecuteResourceType.API); + testCase.setResourceType(ApiExecuteResourceType.API.name()); testCase.setResourceId("exampleResourceId"); testCase.setReportStatus("exampleReportStatus"); testCase.setUserId("exampleUserId");