diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ApiDefinitionCaseDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ApiDefinitionCaseDTO.java similarity index 98% rename from backend/services/project-management/src/main/java/io/metersphere/project/dto/ApiDefinitionCaseDTO.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ApiDefinitionCaseDTO.java index caedfad422..31e7ef2108 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ApiDefinitionCaseDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/ApiDefinitionCaseDTO.java @@ -1,4 +1,4 @@ -package io.metersphere.project.dto; +package io.metersphere.sdk.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/FunctionalCaseMessageDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FunctionalCaseMessageDTO.java similarity index 97% rename from backend/services/project-management/src/main/java/io/metersphere/project/dto/FunctionalCaseMessageDTO.java rename to backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FunctionalCaseMessageDTO.java index 3c4d6aa9e0..845db724ce 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/FunctionalCaseMessageDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/FunctionalCaseMessageDTO.java @@ -1,4 +1,4 @@ -package io.metersphere.project.dto; +package io.metersphere.sdk.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java index eba97452b9..bd7091371d 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java @@ -5,8 +5,8 @@ import io.metersphere.bug.domain.Bug; import io.metersphere.functional.domain.CaseReview; import io.metersphere.load.domain.LoadTest; import io.metersphere.plan.domain.TestPlan; -import io.metersphere.project.dto.ApiDefinitionCaseDTO; -import io.metersphere.project.dto.FunctionalCaseMessageDTO; +import io.metersphere.sdk.dto.ApiDefinitionCaseDTO; +import io.metersphere.sdk.dto.FunctionalCaseMessageDTO; import io.metersphere.project.dto.MessageTemplateFieldDTO; import io.metersphere.project.dto.MessageTemplateResultDTO; import io.metersphere.sdk.constants.TemplateScene; diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectRobotService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectRobotService.java index 38da44e9b6..f1cfd05c32 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectRobotService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectRobotService.java @@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Collections; import java.util.List; @Service @@ -105,12 +106,27 @@ public class ProjectRobotService { criteria.andProjectIdEqualTo(projectId); projectExample.setOrderByClause("create_time desc"); List projectRobots = robotMapper.selectByExample(projectExample); - for (ProjectRobot projectRobot : projectRobots) { + Integer inSiteIndex = 0; + Integer mailIndex = 0; + for (int i = 0; i < projectRobots.size(); i++) { + ProjectRobot projectRobot = projectRobots.get(i); + if (StringUtils.equalsIgnoreCase(projectRobot.getPlatform(), ProjectRobotPlatform.IN_SITE.toString())) { + inSiteIndex = i; + } + if (StringUtils.equalsIgnoreCase(projectRobot.getPlatform(), ProjectRobotPlatform.MAIL.toString())) { + mailIndex = i; + } if ((StringUtils.equalsIgnoreCase(projectRobot.getPlatform(), ProjectRobotPlatform.IN_SITE.toString()) || StringUtils.equalsIgnoreCase(projectRobot.getPlatform(), ProjectRobotPlatform.MAIL.toString())) && StringUtils.isNotBlank(projectRobot.getDescription())) { projectRobot.setDescription(Translator.get(projectRobot.getDescription())); projectRobot.setName(Translator.get(projectRobot.getName())); } } + if (projectRobots.size()>0 && inSiteIndex != 0) { + Collections.swap(projectRobots, inSiteIndex, 0); + } + if (projectRobots.size()>1 && mailIndex != 1) { + Collections.swap(projectRobots, mailIndex, 1); + } return projectRobots; } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java index 3adebcd6db..c928fa254e 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java @@ -75,6 +75,18 @@ public class ProjectRobotControllerTests extends BaseTest { @Test @Order(1) void addRobotSuccessWeCom() throws Exception { + ProjectRobotDTO projectRobotDTOInSite = new ProjectRobotDTO(); + projectRobotDTOInSite.setName("robot_in_site"); + projectRobotDTOInSite.setPlatform(ProjectRobotPlatform.IN_SITE.toString()); + projectRobotDTOInSite.setProjectId("test_project"); + projectRobotDTOInSite.setWebhook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2b67ccf4-e0da-4cd6-ae74-8d42657865f8"); + getPostResult(projectRobotDTOInSite, ROBOT_ADD, status().isOk()); + ProjectRobotDTO projectRobotDTOMail = new ProjectRobotDTO(); + projectRobotDTOMail.setName("robot_mail"); + projectRobotDTOMail.setPlatform(ProjectRobotPlatform.MAIL.toString()); + projectRobotDTOMail.setProjectId("test_project"); + projectRobotDTOMail.setWebhook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2b67ccf4-e0da-4cd6-ae74-8d42657865f8"); + getPostResult(projectRobotDTOMail, ROBOT_ADD, status().isOk()); ProjectRobotDTO projectRobotDTO = new ProjectRobotDTO(); projectRobotDTO.setName("企业微信机器人"); projectRobotDTO.setPlatform(ProjectRobotPlatform.WE_COM.toString()); @@ -107,6 +119,18 @@ public class ProjectRobotControllerTests extends BaseTest { @Test @Order(3) void addRobotSuccessDingCustom() throws Exception { + ProjectRobotDTO projectRobotDTOInSite = new ProjectRobotDTO(); + projectRobotDTOInSite.setName("robot_in_site"); + projectRobotDTOInSite.setPlatform(ProjectRobotPlatform.IN_SITE.toString()); + projectRobotDTOInSite.setProjectId("test_project3"); + projectRobotDTOInSite.setWebhook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2b67ccf4-e0da-4cd6-ae74-8d42657865f8"); + getPostResult(projectRobotDTOInSite, ROBOT_ADD, status().isOk()); + ProjectRobotDTO projectRobotDTOMail = new ProjectRobotDTO(); + projectRobotDTOMail.setName("robot_mail"); + projectRobotDTOMail.setPlatform(ProjectRobotPlatform.MAIL.toString()); + projectRobotDTOMail.setProjectId("test_project3"); + projectRobotDTOMail.setWebhook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2b67ccf4-e0da-4cd6-ae74-8d42657865f8"); + getPostResult(projectRobotDTOMail, ROBOT_ADD, status().isOk()); setDingCustom("test_project3","钉钉自定义机器人4"); checkName("test_project3", "钉钉自定义机器人4"); } @@ -314,6 +338,7 @@ public class ProjectRobotControllerTests extends BaseTest { @Order(20) void getListSuccessNoKeyword() throws Exception { List projectRobots = getList("test_project"); + System.out.println(projectRobots); Assertions.assertTrue(projectRobots.size() > 0); } @@ -417,6 +442,13 @@ public class ProjectRobotControllerTests extends BaseTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON)); } + @Test + @Order(25) + void getEmptyListSuccess() throws Exception { + List projectRobots = getList("test_project_x"); + Assertions.assertTrue(CollectionUtils.isEmpty(projectRobots)); + } + private static ProjectRobot getResult(MvcResult mvcResult) throws UnsupportedEncodingException { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); diff --git a/backend/services/project-management/src/test/resources/dml/init_project_robot.sql b/backend/services/project-management/src/test/resources/dml/init_project_robot.sql index c9c4db9c36..1f827658ae 100644 --- a/backend/services/project-management/src/test/resources/dml/init_project_robot.sql +++ b/backend/services/project-management/src/test/resources/dml/init_project_robot.sql @@ -1,7 +1,8 @@ # 插入测试数据 replace INTO project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES ('test_project_robot1', 'test', '测试机器人1', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null); -replace INTO project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES ('test_project_robot1', 'test', '测试机器人2', 'MAIL', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null); +replace INTO project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES ('test_project_robot2', 'test', '测试机器人1', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null); +replace INTO project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES ('test_project_robot3', 'test', '测试机器人2', 'MAIL', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java index a3554272e1..cd5fc253ea 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java @@ -1,12 +1,12 @@ package io.metersphere.system.notice.utils; -import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.domain.ApiScenario; import io.metersphere.bug.domain.Bug; import io.metersphere.functional.domain.CaseReview; -import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.load.domain.LoadTest; import io.metersphere.plan.domain.TestPlan; +import io.metersphere.sdk.dto.ApiDefinitionCaseDTO; +import io.metersphere.sdk.dto.FunctionalCaseMessageDTO; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.Schedule; import io.metersphere.system.notice.constants.NoticeConstants; @@ -137,22 +137,19 @@ public class MessageTemplateUtils { Field[] allFields; switch (taskType) { case NoticeConstants.TaskType.API_DEFINITION_TASK -> { - allFields = FieldUtils.getAllFields(ApiDefinition.class); - + allFields = FieldUtils.getAllFields(ApiDefinitionCaseDTO.class); } case NoticeConstants.TaskType.API_SCENARIO_TASK -> { allFields = FieldUtils.getAllFields(ApiScenario.class); - } case NoticeConstants.TaskType.TEST_PLAN_TASK -> { allFields = FieldUtils.getAllFields(TestPlan.class); - } case NoticeConstants.TaskType.CASE_REVIEW_TASK -> { allFields = FieldUtils.getAllFields(CaseReview.class); } case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> { - allFields = FieldUtils.getAllFields(FunctionalCase.class); + allFields = FieldUtils.getAllFields(FunctionalCaseMessageDTO.class); } case NoticeConstants.TaskType.BUG_TASK -> { allFields = FieldUtils.getAllFields(Bug.class);