refactor(消息管理): 模板国际化显示处理
This commit is contained in:
parent
c40ad1fd3c
commit
efc7991568
|
@ -14,6 +14,7 @@ import io.metersphere.sdk.util.JSON;
|
|||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -54,7 +55,9 @@ public class MessageTaskLogService {
|
|||
|
||||
dto.setPath("/notice/message/task/save");
|
||||
dto.setMethod(HttpMethodConstants.POST.name());
|
||||
dto.setOriginalValue(JSON.toJSONBytes(messageTasks.get(0)));
|
||||
if (CollectionUtils.isNotEmpty(messageTasks)) {
|
||||
dto.setOriginalValue(JSON.toJSONBytes(messageTasks.get(0)));
|
||||
}
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
|
|
@ -390,7 +390,11 @@ public class NoticeMessageTaskService {
|
|||
|
||||
private ProjectRobotConfigDTO getProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, MessageTask messageTask, MessageTaskBlob messageTaskBlob) {
|
||||
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
|
||||
projectRobotConfigDTO.setRobotName(projectRobot.getName());
|
||||
if (StringUtils.equalsIgnoreCase(projectRobot.getName(),"robot_in_site") || StringUtils.equalsIgnoreCase(projectRobot.getName(),"robot_mail")) {
|
||||
projectRobotConfigDTO.setRobotName(Translator.get(projectRobot.getName()));
|
||||
} else {
|
||||
projectRobotConfigDTO.setRobotName(projectRobot.getName());
|
||||
}
|
||||
projectRobotConfigDTO.setRobotId(projectRobot.getId());
|
||||
projectRobotConfigDTO.setPlatform(projectRobot.getPlatform());
|
||||
projectRobotConfigDTO.setDingType(projectRobot.getType());
|
||||
|
@ -406,7 +410,7 @@ public class NoticeMessageTaskService {
|
|||
projectRobotConfigDTO.setTemplate(messageTaskBlob.getTemplate());
|
||||
}
|
||||
String translateTemplate = MessageTemplateUtils.getTranslateTemplate(messageTask.getTaskType(), projectRobotConfigDTO.getTemplate());
|
||||
String translateSubject = MessageTemplateUtils.getTranslateTemplate(messageTask.getTaskType(), projectRobotConfigDTO.getSubject());
|
||||
String translateSubject = MessageTemplateUtils.getTranslateSubject(messageTask.getTaskType(), projectRobotConfigDTO.getSubject());
|
||||
projectRobotConfigDTO.setPreviewTemplate(translateTemplate);
|
||||
projectRobotConfigDTO.setPreviewSubject(translateSubject);
|
||||
projectRobotConfigDTO.setDefaultTemplate(defaultTemplate);
|
||||
|
@ -419,7 +423,7 @@ public class NoticeMessageTaskService {
|
|||
private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String taskType, String defaultTemplate, String defaultSubject, ProjectRobot projectRobot) {
|
||||
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
|
||||
projectRobotConfigDTO.setRobotId(projectRobot.getId());
|
||||
projectRobotConfigDTO.setRobotName(projectRobot.getName());
|
||||
projectRobotConfigDTO.setRobotName(Translator.get(projectRobot.getName()));
|
||||
projectRobotConfigDTO.setPlatform(ProjectRobotPlatform.IN_SITE.toString());
|
||||
projectRobotConfigDTO.setDingType(projectRobot.getType());
|
||||
projectRobotConfigDTO.setEnable(false);
|
||||
|
@ -430,7 +434,7 @@ public class NoticeMessageTaskService {
|
|||
projectRobotConfigDTO.setUseDefaultSubject(true);
|
||||
projectRobotConfigDTO.setUseDefaultTemplate(true);
|
||||
String translateTemplate = MessageTemplateUtils.getTranslateTemplate(taskType, defaultTemplate);
|
||||
String translateSubject = MessageTemplateUtils.getTranslateTemplate(taskType, defaultSubject);
|
||||
String translateSubject = MessageTemplateUtils.getTranslateSubject(taskType, defaultSubject);
|
||||
projectRobotConfigDTO.setPreviewTemplate(translateTemplate);
|
||||
projectRobotConfigDTO.setPreviewSubject(translateSubject);
|
||||
return projectRobotConfigDTO;
|
||||
|
|
|
@ -14,10 +14,6 @@ import io.metersphere.system.uid.UUID;
|
|||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -36,9 +32,6 @@ public class ProjectRobotService {
|
|||
@Resource
|
||||
private MessageTaskBlobMapper messageTaskBlobMapper;
|
||||
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public void add(ProjectRobot projectRobot) {
|
||||
projectRobot.setId(UUID.randomUUID().toString());
|
||||
projectRobot.setEnable(projectRobot.getEnable());
|
||||
|
@ -102,17 +95,6 @@ public class ProjectRobotService {
|
|||
projectRobot.setCreateTime(null);
|
||||
projectRobot.setUpdateUser(updateUser);
|
||||
projectRobot.setUpdateTime(updateTime);
|
||||
MessageTaskExample messageTaskExample = new MessageTaskExample();
|
||||
messageTaskExample.createCriteria().andProjectRobotIdEqualTo(id);
|
||||
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
MessageTaskMapper mapper = sqlSession.getMapper(MessageTaskMapper.class);
|
||||
for (MessageTask messageTask : messageTasks) {
|
||||
messageTask.setEnable(projectRobot.getEnable());
|
||||
mapper.updateByPrimaryKeySelective(messageTask);
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
robotMapper.updateByPrimaryKeySelective(projectRobot);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.metersphere.project.mapper.ProjectMapper;
|
|||
import io.metersphere.project.mapper.ProjectRobotMapper;
|
||||
import io.metersphere.sdk.constants.SessionConstants;
|
||||
import io.metersphere.sdk.dto.OptionDTO;
|
||||
import io.metersphere.sdk.dto.request.MessageTaskRequest;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
|
@ -30,12 +31,15 @@ import org.mybatis.spring.SqlSessionUtils;
|
|||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.jdbc.SqlConfig;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultMatcher;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
|
@ -186,7 +190,7 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(8)
|
||||
void updateRobotSuccessCusTom() throws Exception {
|
||||
setCustomRobot("用于更新自定义机器人");
|
||||
setCustomRobot("用于更新自定义机器人","test_project");
|
||||
ProjectRobot projectRobot = getRobot("test_project", "用于更新自定义机器人");
|
||||
checkUpdate(projectRobot, "更新自定义机器人", status().isOk());
|
||||
}
|
||||
|
@ -210,7 +214,7 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(11)
|
||||
void updateRobotFileIdNotExist() throws Exception {
|
||||
setCustomRobot("测试没有ID失败");
|
||||
setCustomRobot("测试没有ID失败","test_project");
|
||||
ProjectRobot projectRobot = getRobot("test_project", "测试没有ID失败");
|
||||
projectRobot.setId("noId");
|
||||
checkUpdate(projectRobot, "测试没有ID失败", status().is5xxServerError());
|
||||
|
@ -219,7 +223,7 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(12)
|
||||
void updateRobotFileIdNoId() throws Exception {
|
||||
setCustomRobot("测试ID空失败");
|
||||
setCustomRobot("测试ID空失败","test_project");
|
||||
ProjectRobot projectRobot = getRobot("test_project", "测试ID空失败");
|
||||
projectRobot.setId(null);
|
||||
checkUpdate(projectRobot, "测试ID空失败", status().isBadRequest());
|
||||
|
@ -255,7 +259,7 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
@Test
|
||||
@Order(16)
|
||||
void deleteRobotSuccess() throws Exception {
|
||||
setCustomRobot("测试删除");
|
||||
setCustomRobot("测试删除","test_project");
|
||||
ProjectRobot projectRobot = getRobot("test_project", "测试删除");
|
||||
String projectRobotId = projectRobot.getId();
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_DELETE + "/" + projectRobotId)
|
||||
|
@ -292,9 +296,9 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
@Order(19)
|
||||
void getDetailSuccess() throws Exception {
|
||||
setCustomRobot("测试获取详情");
|
||||
setCustomRobot("测试获取详情","test_project");
|
||||
ProjectRobot projectRobot = getRobot("test_project", "测试获取详情");
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_DETAIL + "/" + projectRobot.getId())
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
@ -307,43 +311,78 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
@Order(20)
|
||||
void getListSuccessNoKeyword() throws Exception {
|
||||
List<ProjectRobot> projectRobots = getList("test_project");
|
||||
Assertions.assertTrue(projectRobots.size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
@Order(21)
|
||||
@Sql(scripts = {"/dml/init_project_robot_message.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED))
|
||||
void setEnableSuccess() throws Exception {
|
||||
setCustomRobot("测试Enable");
|
||||
ProjectRobot projectRobot = getRobot("test_project","测试Enable");
|
||||
setCustomRobot("测试Enable","project-robot-message-test-1");
|
||||
ProjectRobot projectRobot = getRobot("project-robot-message-test-1","测试Enable");
|
||||
String projectRobotId = projectRobot.getId();
|
||||
MessageTaskRequest messageTaskRequest = new MessageTaskRequest();
|
||||
messageTaskRequest.setProjectId("project-robot-message-test-1");
|
||||
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
|
||||
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
|
||||
List<String> userIds = new ArrayList<>();
|
||||
userIds.add("project-robot-message-user-3");
|
||||
userIds.add("project-robot-message-user-4");
|
||||
userIds.add("project-robot-message-user-del");
|
||||
messageTaskRequest.setReceiverIds(userIds);
|
||||
messageTaskRequest.setRobotId(projectRobotId);
|
||||
messageTaskRequest.setEnable(true);
|
||||
mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.content(JSON.toJSONString(messageTaskRequest))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_ENABLE + "/" + projectRobotId)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||
ProjectRobot projectRobotEnable = getRobot("test_project","测试Enable");
|
||||
ProjectRobot projectRobotEnable = getRobot("project-robot-message-test-1","测试Enable");
|
||||
Assertions.assertFalse(projectRobotEnable.getEnable());
|
||||
MvcResult mvcResult1 = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-robot-message-test-1")
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
String contentAsString = mvcResult1.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||
List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
|
||||
for (MessageTaskDTO messageTaskDTO : messageTaskDetailDTOList) {
|
||||
for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskDTO.getMessageTaskTypeDTOList()) {
|
||||
if (StringUtils.equalsIgnoreCase(messageTaskTypeDTO.getTaskType(),NoticeConstants.TaskType.API_DEFINITION_TASK)) {
|
||||
Boolean testRobotMessageRobot1 = messageTaskTypeDTO.getMessageTaskDetailDTOList().get(0).getProjectRobotConfigMap().get(projectRobotId).getEnable();
|
||||
Assertions.assertTrue(testRobotMessageRobot1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
@Order(22)
|
||||
void setEnableFalseSuccess() throws Exception {
|
||||
ProjectRobot projectRobot = getRobot("test_project","测试Enable");
|
||||
ProjectRobot projectRobot = getRobot("project-robot-message-test-1","测试Enable");
|
||||
String projectRobotId = projectRobot.getId();
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_ENABLE + "/" + projectRobotId)
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||
ProjectRobot projectRobotEnable = getRobot("test_project","测试Enable");
|
||||
ProjectRobot projectRobotEnable = getRobot("project-robot-message-test-1","测试Enable");
|
||||
Assertions.assertTrue(projectRobotEnable.getEnable());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
@Order(23)
|
||||
void setEnableFail() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ROBOT_ENABLE + "/no_id")
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
|
@ -354,7 +393,7 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
@Order(24)
|
||||
void deleteRobotWithMessage() throws Exception {
|
||||
Project project = new Project();
|
||||
project.setId("test_project1");
|
||||
|
@ -396,11 +435,11 @@ public class ProjectRobotControllerTests extends BaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
private void setCustomRobot(String name) throws Exception {
|
||||
private void setCustomRobot(String name, String projectId) throws Exception {
|
||||
ProjectRobotDTO projectRobotDTO = new ProjectRobotDTO();
|
||||
projectRobotDTO.setName(name);
|
||||
projectRobotDTO.setPlatform(ProjectRobotPlatform.CUSTOM.toString());
|
||||
projectRobotDTO.setProjectId("test_project");
|
||||
projectRobotDTO.setProjectId(projectId);
|
||||
projectRobotDTO.setEnable(true);
|
||||
projectRobotDTO.setWebhook("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=2b67ccf4-e0da-4cd6-ae74-8d42657865f8");
|
||||
getPostResult(projectRobotDTO, ROBOT_ADD, status().isOk());
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# 插入测试数据
|
||||
INSERT INTO organization(id, num, name, description, create_time, update_time, create_user, update_user, deleted, delete_user, delete_time) VALUE
|
||||
('organization-robot-message-test', null, 'organization-robot-message-test', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, 'admin', 'admin', 0, null, null);
|
||||
INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES
|
||||
('project-robot-message-test', null, 'organization-robot-message-test', '默认项目', '系统默认创建的项目', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000),
|
||||
('project-robot-message-test-1', null, 'organization-robot-message-test', '默认项目1', '系统默认创建的项目1', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000),
|
||||
('project-robot-message-test-2', null, 'organization-robot-message-test', '默认项目2', '系统默认创建的项目2', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000),
|
||||
('project-robot-message-test-3', null, 'organization-robot-message-test', '默认项目3', '系统默认创建的项目3', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000);
|
||||
|
||||
|
||||
INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user, deleted) VALUES
|
||||
('project-robot-message-user-1', 'project-robot-message-user-1', 'project-robot-message-member1@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-2', 'project-robot-message-user-2', 'project-robot-message-member2@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-3', 'project-robot-message-user-3', 'project-robot-message-member3@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-4', 'project-robot-message-user-4', 'project-robot-message-member4@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-5', 'project-robot-message-user-5', 'project-robot-message-member5@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-6', 'project-robot-message-user-6', 'project-robot-message-member6@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-7', 'project-robot-message-user-7', 'project-robot-message-member7@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-8', 'project-robot-message-user-8', 'project-robot-message-member8@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-9', 'project-robot-message-user-9', 'project-robot-message-member9@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-10', 'project-robot-message-user-10', 'project-robot-message-member10@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 0),
|
||||
('project-robot-message-user-del', 'project-robot-message-user-del', 'project-robot-message-member-del@metersphere.io', MD5('metersphere'), UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000, NULL, NUll, '', 'LOCAL', NULL, 'admin', 'admin', 1);
|
||||
|
||||
INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id, create_time, create_user) VALUES
|
||||
(UUID(), 'project-robot-message-user-1', 'project_member', 'project-robot-message-test', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-2', 'project_member', 'project-robot-message-test', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-3', 'project_member', 'project-robot-message-test-1', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-4', 'project_member', 'project-robot-message-test-1', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-5', 'project_member', 'project-robot-message-test', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-6', 'project_member', 'project-robot-message-test', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-7', 'project_member', 'project-robot-message-test-1', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-8', 'project_member', 'project-robot-message-test-1', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-9', 'project_member', 'project-robot-message-test-1', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin'),
|
||||
(UUID(), 'project-robot-message-user-10', 'project_member', 'project-robot-message-test-1', 'organization-robot-message-test', UNIX_TIMESTAMP() * 1000, 'admin');
|
||||
|
||||
|
||||
|
||||
|
||||
INSERT 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_robot_message_robot1', 'project-robot-message-test-1', '测试机器人1', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null),
|
||||
('test_robot_message_robot2', 'project-robot-message-test-1', '测试机器人2', 'MAIL', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -220,6 +220,8 @@ public class MessageTemplateUtils {
|
|||
String description = annotation.description();
|
||||
if (StringUtils.equals(allField.getName(), "name") || StringUtils.equals(allField.getName(), "title")) {
|
||||
description = "{{" + description + "}}";
|
||||
} else {
|
||||
description = "<" + description + ">";
|
||||
}
|
||||
map.put(allField.getName(), description);
|
||||
}
|
||||
|
@ -227,4 +229,33 @@ public class MessageTemplateUtils {
|
|||
return getContent(template, map);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getTranslateSubject(String taskType, String subject) {
|
||||
if (StringUtils.equalsIgnoreCase(taskType, NoticeConstants.TaskType.JENKINS_TASK)) {
|
||||
if (StringUtils.isNotBlank(subject) && subject.contains("${name}")) {
|
||||
subject = subject.replace("${name}", Translator.get("message.jenkins_name"));
|
||||
}
|
||||
return subject;
|
||||
} else {
|
||||
Field[] domainTemplateFields = getDomainTemplateFields(taskType);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StringUtils.isNotBlank(subject) && subject.contains("${OPERATOR}")) {
|
||||
subject = subject.replace("${OPERATOR}", Translator.get("message.operator"));
|
||||
}
|
||||
if (StringUtils.isNotBlank(subject) && subject.contains("${total}")) {
|
||||
subject = subject.replace("${total}", "n");
|
||||
}
|
||||
for (Field allField : domainTemplateFields) {
|
||||
Schema annotation = allField.getAnnotation(Schema.class);
|
||||
if (annotation != null) {
|
||||
String description = annotation.description();
|
||||
if (StringUtils.equals(allField.getName(), "name") || StringUtils.equals(allField.getName(), "title")) {
|
||||
description = "{{" + description + "}}";
|
||||
}
|
||||
map.put(allField.getName(), description);
|
||||
}
|
||||
}
|
||||
return getContent(subject, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ public class MessageTemplateUtilsTests {
|
|||
if (StringUtils.isNotBlank(template)) {
|
||||
String translateTemplate = MessageTemplateUtils.getTranslateTemplate(type, template);
|
||||
Assertions.assertTrue(StringUtils.isNotBlank(translateTemplate));
|
||||
String translateSubject= MessageTemplateUtils.getTranslateSubject(type, template);
|
||||
Assertions.assertTrue(StringUtils.isNotBlank(translateSubject));
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue