refactor(消息管理): 修改机器人列表的显示

This commit is contained in:
guoyuqi 2023-10-17 19:06:26 +08:00 committed by Craftsman
parent 4030e11d64
commit 7cfc18a007
7 changed files with 59 additions and 13 deletions

View File

@ -1,4 +1,4 @@
package io.metersphere.project.dto; package io.metersphere.sdk.dto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;

View File

@ -1,4 +1,4 @@
package io.metersphere.project.dto; package io.metersphere.sdk.dto;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;

View File

@ -5,8 +5,8 @@ import io.metersphere.bug.domain.Bug;
import io.metersphere.functional.domain.CaseReview; import io.metersphere.functional.domain.CaseReview;
import io.metersphere.load.domain.LoadTest; import io.metersphere.load.domain.LoadTest;
import io.metersphere.plan.domain.TestPlan; import io.metersphere.plan.domain.TestPlan;
import io.metersphere.project.dto.ApiDefinitionCaseDTO; import io.metersphere.sdk.dto.ApiDefinitionCaseDTO;
import io.metersphere.project.dto.FunctionalCaseMessageDTO; import io.metersphere.sdk.dto.FunctionalCaseMessageDTO;
import io.metersphere.project.dto.MessageTemplateFieldDTO; import io.metersphere.project.dto.MessageTemplateFieldDTO;
import io.metersphere.project.dto.MessageTemplateResultDTO; import io.metersphere.project.dto.MessageTemplateResultDTO;
import io.metersphere.sdk.constants.TemplateScene; import io.metersphere.sdk.constants.TemplateScene;

View File

@ -17,6 +17,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List; import java.util.List;
@Service @Service
@ -105,12 +106,27 @@ public class ProjectRobotService {
criteria.andProjectIdEqualTo(projectId); criteria.andProjectIdEqualTo(projectId);
projectExample.setOrderByClause("create_time desc"); projectExample.setOrderByClause("create_time desc");
List<ProjectRobot> projectRobots = robotMapper.selectByExample(projectExample); List<ProjectRobot> 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())) { 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.setDescription(Translator.get(projectRobot.getDescription()));
projectRobot.setName(Translator.get(projectRobot.getName())); 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; return projectRobots;
} }

View File

@ -75,6 +75,18 @@ public class ProjectRobotControllerTests extends BaseTest {
@Test @Test
@Order(1) @Order(1)
void addRobotSuccessWeCom() throws Exception { 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 projectRobotDTO = new ProjectRobotDTO();
projectRobotDTO.setName("企业微信机器人"); projectRobotDTO.setName("企业微信机器人");
projectRobotDTO.setPlatform(ProjectRobotPlatform.WE_COM.toString()); projectRobotDTO.setPlatform(ProjectRobotPlatform.WE_COM.toString());
@ -107,6 +119,18 @@ public class ProjectRobotControllerTests extends BaseTest {
@Test @Test
@Order(3) @Order(3)
void addRobotSuccessDingCustom() throws Exception { 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"); setDingCustom("test_project3","钉钉自定义机器人4");
checkName("test_project3", "钉钉自定义机器人4"); checkName("test_project3", "钉钉自定义机器人4");
} }
@ -314,6 +338,7 @@ public class ProjectRobotControllerTests extends BaseTest {
@Order(20) @Order(20)
void getListSuccessNoKeyword() throws Exception { void getListSuccessNoKeyword() throws Exception {
List<ProjectRobot> projectRobots = getList("test_project"); List<ProjectRobot> projectRobots = getList("test_project");
System.out.println(projectRobots);
Assertions.assertTrue(projectRobots.size() > 0); Assertions.assertTrue(projectRobots.size() > 0);
} }
@ -417,6 +442,13 @@ public class ProjectRobotControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(MediaType.APPLICATION_JSON));
} }
@Test
@Order(25)
void getEmptyListSuccess() throws Exception {
List<ProjectRobot> projectRobots = getList("test_project_x");
Assertions.assertTrue(CollectionUtils.isEmpty(projectRobots));
}
private static ProjectRobot getResult(MvcResult mvcResult) throws UnsupportedEncodingException { private static ProjectRobot getResult(MvcResult mvcResult) throws UnsupportedEncodingException {
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);

View File

@ -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', '测试机器人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);

View File

@ -1,12 +1,12 @@
package io.metersphere.system.notice.utils; package io.metersphere.system.notice.utils;
import io.metersphere.api.domain.ApiDefinition;
import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenario;
import io.metersphere.bug.domain.Bug; import io.metersphere.bug.domain.Bug;
import io.metersphere.functional.domain.CaseReview; import io.metersphere.functional.domain.CaseReview;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.load.domain.LoadTest; import io.metersphere.load.domain.LoadTest;
import io.metersphere.plan.domain.TestPlan; 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.sdk.util.Translator;
import io.metersphere.system.domain.Schedule; import io.metersphere.system.domain.Schedule;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
@ -137,22 +137,19 @@ public class MessageTemplateUtils {
Field[] allFields; Field[] allFields;
switch (taskType) { switch (taskType) {
case NoticeConstants.TaskType.API_DEFINITION_TASK -> { case NoticeConstants.TaskType.API_DEFINITION_TASK -> {
allFields = FieldUtils.getAllFields(ApiDefinition.class); allFields = FieldUtils.getAllFields(ApiDefinitionCaseDTO.class);
} }
case NoticeConstants.TaskType.API_SCENARIO_TASK -> { case NoticeConstants.TaskType.API_SCENARIO_TASK -> {
allFields = FieldUtils.getAllFields(ApiScenario.class); allFields = FieldUtils.getAllFields(ApiScenario.class);
} }
case NoticeConstants.TaskType.TEST_PLAN_TASK -> { case NoticeConstants.TaskType.TEST_PLAN_TASK -> {
allFields = FieldUtils.getAllFields(TestPlan.class); allFields = FieldUtils.getAllFields(TestPlan.class);
} }
case NoticeConstants.TaskType.CASE_REVIEW_TASK -> { case NoticeConstants.TaskType.CASE_REVIEW_TASK -> {
allFields = FieldUtils.getAllFields(CaseReview.class); allFields = FieldUtils.getAllFields(CaseReview.class);
} }
case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> { case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> {
allFields = FieldUtils.getAllFields(FunctionalCase.class); allFields = FieldUtils.getAllFields(FunctionalCaseMessageDTO.class);
} }
case NoticeConstants.TaskType.BUG_TASK -> { case NoticeConstants.TaskType.BUG_TASK -> {
allFields = FieldUtils.getAllFields(Bug.class); allFields = FieldUtils.getAllFields(Bug.class);