refactor(消息管理): 优化内置机器人的描述

This commit is contained in:
guoyuqi 2023-10-13 18:06:30 +08:00 committed by Yuki Guo
parent a2622f45c8
commit 3cf24058f7
3 changed files with 12 additions and 8 deletions

View File

@ -12,7 +12,6 @@ import io.metersphere.project.mapper.MessageTaskMapper;
import io.metersphere.project.mapper.ProjectRobotMapper; import io.metersphere.project.mapper.ProjectRobotMapper;
import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.service.CreateProjectResourceService; import io.metersphere.system.service.CreateProjectResourceService;
import io.metersphere.system.uid.UUID; import io.metersphere.system.uid.UUID;
@ -48,7 +47,7 @@ public class CreateRobotResourceService implements CreateProjectResourceService
String inSiteId = UUID.randomUUID().toString(); String inSiteId = UUID.randomUUID().toString();
projectRobot.setId(inSiteId); projectRobot.setId(inSiteId);
projectRobot.setProjectId(projectId); projectRobot.setProjectId(projectId);
projectRobot.setName(Translator.get("robot_in_site")); projectRobot.setName("robot_in_site");
projectRobot.setPlatform(ProjectRobotPlatform.IN_SITE.toString()); projectRobot.setPlatform(ProjectRobotPlatform.IN_SITE.toString());
projectRobot.setWebhook("NONE"); projectRobot.setWebhook("NONE");
projectRobot.setCreateUser("admin"); projectRobot.setCreateUser("admin");
@ -56,17 +55,17 @@ public class CreateRobotResourceService implements CreateProjectResourceService
projectRobot.setUpdateUser("admin"); projectRobot.setUpdateUser("admin");
projectRobot.setUpdateTime(System.currentTimeMillis()); projectRobot.setUpdateTime(System.currentTimeMillis());
projectRobot.setEnable(true); projectRobot.setEnable(true);
projectRobot.setDescription(Translator.get("robot_in_site_description")); projectRobot.setDescription("robot_in_site_description");
list.add(projectRobot); list.add(projectRobot);
ProjectRobot projectRobotMail = new ProjectRobot(); ProjectRobot projectRobotMail = new ProjectRobot();
projectRobotMail.setId(UUID.randomUUID().toString()); projectRobotMail.setId(UUID.randomUUID().toString());
projectRobotMail.setProjectId(projectId); projectRobotMail.setProjectId(projectId);
projectRobotMail.setName(Translator.get("robot_mail")); projectRobotMail.setName("robot_mail");
projectRobotMail.setPlatform(ProjectRobotPlatform.MAIL.toString()); projectRobotMail.setPlatform(ProjectRobotPlatform.MAIL.toString());
projectRobotMail.setWebhook("NONE"); projectRobotMail.setWebhook("NONE");
projectRobotMail.setCreateUser("admin"); projectRobotMail.setCreateUser("admin");
projectRobotMail.setEnable(true); projectRobotMail.setEnable(true);
projectRobotMail.setDescription(Translator.get("robot_mail_description")); projectRobotMail.setDescription("robot_mail_description");
projectRobotMail.setCreateTime(System.currentTimeMillis()); projectRobotMail.setCreateTime(System.currentTimeMillis());
projectRobotMail.setUpdateUser("admin"); projectRobotMail.setUpdateUser("admin");
projectRobotMail.setUpdateTime(System.currentTimeMillis()); projectRobotMail.setUpdateTime(System.currentTimeMillis());

View File

@ -122,8 +122,14 @@ public class ProjectRobotService {
ProjectRobotExample.Criteria criteria = projectExample.createCriteria(); ProjectRobotExample.Criteria criteria = projectExample.createCriteria();
criteria.andProjectIdEqualTo(projectId); criteria.andProjectIdEqualTo(projectId);
projectExample.setOrderByClause("create_time desc"); projectExample.setOrderByClause("create_time desc");
List<ProjectRobot> projectRobots = robotMapper.selectByExample(projectExample);
return robotMapper.selectByExample(projectExample); for (ProjectRobot projectRobot : projectRobots) {
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()));
}
}
return projectRobots;
} }
public ProjectRobotDTO getDetail(String robotId) { public ProjectRobotDTO getDetail(String robotId) {

View File

@ -61,7 +61,6 @@ public class CreateRobotResourceTests extends BaseTest {
Assertions.assertEquals(2, projectRobotAfters.size()); Assertions.assertEquals(2, projectRobotAfters.size());
List<MessageTaskDTO> messageList = getMessageList(id); List<MessageTaskDTO> messageList = getMessageList(id);
Assertions.assertTrue(messageList.size() > 0); Assertions.assertTrue(messageList.size() > 0);
System.out.println(messageList);
} }
private List<ProjectRobot> getList(String id) throws Exception { private List<ProjectRobot> getList(String id) throws Exception {