fix(项目管理): 修复保存通知人时消息通知会关闭以及模版会更改问题
--bug=1035461 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001035461&from=wxnotification&corpid=ww918354e3468dc0cc&agentid=1000014&jump_count=1&qy_private_corpid=
This commit is contained in:
parent
01d8747468
commit
08df0f8e1f
|
@ -11,6 +11,7 @@ import io.metersphere.system.dto.sdk.request.MessageTaskRequest;
|
||||||
import io.metersphere.system.controller.handler.ResultHolder;
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
import io.metersphere.system.log.annotation.Log;
|
import io.metersphere.system.log.annotation.Log;
|
||||||
import io.metersphere.system.log.constants.OperationLogType;
|
import io.metersphere.system.log.constants.OperationLogType;
|
||||||
|
import io.metersphere.system.security.CheckOwner;
|
||||||
import io.metersphere.system.utils.SessionUtils;
|
import io.metersphere.system.utils.SessionUtils;
|
||||||
import io.metersphere.validation.groups.Created;
|
import io.metersphere.validation.groups.Created;
|
||||||
import io.metersphere.validation.groups.Updated;
|
import io.metersphere.validation.groups.Updated;
|
||||||
|
@ -38,6 +39,7 @@ public class NoticeMessageTaskController {
|
||||||
@Operation(summary = "项目管理-消息管理-消息设置-保存消息设置")
|
@Operation(summary = "项目管理-消息管理-消息设置-保存消息设置")
|
||||||
@RequiresPermissions(value = {PermissionConstants.PROJECT_MESSAGE_READ_ADD, PermissionConstants.PROJECT_MESSAGE_READ_UPDATE}, logical = Logical.OR)
|
@RequiresPermissions(value = {PermissionConstants.PROJECT_MESSAGE_READ_ADD, PermissionConstants.PROJECT_MESSAGE_READ_UPDATE}, logical = Logical.OR)
|
||||||
@Log(type = OperationLogType.UPDATE, expression = "#msClass.addLog(#messageTaskRequest)", msClass = MessageTaskLogService.class)
|
@Log(type = OperationLogType.UPDATE, expression = "#msClass.addLog(#messageTaskRequest)", msClass = MessageTaskLogService.class)
|
||||||
|
@CheckOwner(resourceId = "#request.projectId", resourceType = "project")
|
||||||
public ResultHolder saveMessage(@Validated({Created.class, Updated.class}) @RequestBody MessageTaskRequest messageTaskRequest) {
|
public ResultHolder saveMessage(@Validated({Created.class, Updated.class}) @RequestBody MessageTaskRequest messageTaskRequest) {
|
||||||
return noticeMessageTaskService.saveMessageTask(messageTaskRequest, SessionUtils.getUserId());
|
return noticeMessageTaskService.saveMessageTask(messageTaskRequest, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
@ -45,6 +47,7 @@ public class NoticeMessageTaskController {
|
||||||
@GetMapping("message/task/get/{projectId}")
|
@GetMapping("message/task/get/{projectId}")
|
||||||
@Operation(summary = "项目管理-消息管理-消息设置-获取消息设置")
|
@Operation(summary = "项目管理-消息管理-消息设置-获取消息设置")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_ADD)
|
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ_ADD)
|
||||||
|
@CheckOwner(resourceId = "#projectId", resourceType = "project")
|
||||||
public List<MessageTaskDTO> getMessageList(@PathVariable String projectId) throws IOException {
|
public List<MessageTaskDTO> getMessageList(@PathVariable String projectId) throws IOException {
|
||||||
return noticeMessageTaskService.getMessageList(projectId);
|
return noticeMessageTaskService.getMessageList(projectId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,11 +68,6 @@ public class NoticeMessageTaskService {
|
||||||
|
|
||||||
public ResultHolder saveMessageTask(MessageTaskRequest messageTaskRequest, String userId) {
|
public ResultHolder saveMessageTask(MessageTaskRequest messageTaskRequest, String userId) {
|
||||||
String projectId = messageTaskRequest.getProjectId();
|
String projectId = messageTaskRequest.getProjectId();
|
||||||
checkProjectExist(projectId);
|
|
||||||
//如果只选了用户,没有选机器人,默认机器人为站内信
|
|
||||||
ProjectRobot projectRobot = getDefaultRobot(messageTaskRequest.getProjectId(), messageTaskRequest.getRobotId());
|
|
||||||
String robotId = projectRobot.getId();
|
|
||||||
messageTaskRequest.setRobotId(robotId);
|
|
||||||
//删除用户数据不在当前传送用户内的数据
|
//删除用户数据不在当前传送用户内的数据
|
||||||
deleteUserData(messageTaskRequest, projectId);
|
deleteUserData(messageTaskRequest, projectId);
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
|
@ -85,6 +80,10 @@ public class NoticeMessageTaskService {
|
||||||
List<MessageTask> messageTasks = updateMessageTasks(messageTaskRequest, userId, mapper, blobMapper, existUserIds);
|
List<MessageTask> messageTasks = updateMessageTasks(messageTaskRequest, userId, mapper, blobMapper, existUserIds);
|
||||||
//保存消息任务
|
//保存消息任务
|
||||||
List<String> messageTaskReceivers = CollectionUtils.isEmpty(messageTasks) ? new ArrayList<>() : messageTasks.stream().map(MessageTask::getReceiver).toList();
|
List<String> messageTaskReceivers = CollectionUtils.isEmpty(messageTasks) ? new ArrayList<>() : messageTasks.stream().map(MessageTask::getReceiver).toList();
|
||||||
|
//如果新增时只选了用户,没有选机器人,默认机器人为站内信
|
||||||
|
ProjectRobot projectRobot = getDefaultRobot(messageTaskRequest.getProjectId(), messageTaskRequest.getRobotId());
|
||||||
|
String robotId = projectRobot.getId();
|
||||||
|
messageTaskRequest.setRobotId(robotId);
|
||||||
insertMessageTask(messageTaskRequest, userId, mapper, blobMapper, existUserIds, messageTaskReceivers);
|
insertMessageTask(messageTaskRequest, userId, mapper, blobMapper, existUserIds, messageTaskReceivers);
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
@ -111,13 +110,6 @@ public class NoticeMessageTaskService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkProjectExist(String projectId) {
|
|
||||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
|
||||||
if (project == null) {
|
|
||||||
throw new MSException(Translator.get("project_is_not_exist"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增MessageTask
|
* 新增MessageTask
|
||||||
*
|
*
|
||||||
|
@ -129,7 +121,6 @@ public class NoticeMessageTaskService {
|
||||||
* @param messageTaskReceivers 更新过后还有多少接收人需要保存
|
* @param messageTaskReceivers 更新过后还有多少接收人需要保存
|
||||||
*/
|
*/
|
||||||
private void insertMessageTask(MessageTaskRequest messageTaskRequest, String userId, MessageTaskMapper mapper, MessageTaskBlobMapper blobMapper, List<String> existUserIds, List<String> messageTaskReceivers) {
|
private void insertMessageTask(MessageTaskRequest messageTaskRequest, String userId, MessageTaskMapper mapper, MessageTaskBlobMapper blobMapper, List<String> existUserIds, List<String> messageTaskReceivers) {
|
||||||
List<MessageTask> messageTasks = new ArrayList<>();
|
|
||||||
for (String receiverId : existUserIds) {
|
for (String receiverId : existUserIds) {
|
||||||
if (CollectionUtils.isNotEmpty(messageTaskReceivers) && messageTaskReceivers.contains(receiverId)) {
|
if (CollectionUtils.isNotEmpty(messageTaskReceivers) && messageTaskReceivers.contains(receiverId)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -143,7 +134,6 @@ public class NoticeMessageTaskService {
|
||||||
messageTaskBlob.setTemplate(messageTaskRequest.getTemplate());
|
messageTaskBlob.setTemplate(messageTaskRequest.getTemplate());
|
||||||
}
|
}
|
||||||
messageTaskBlob.setTemplate(messageTaskRequest.getTemplate());
|
messageTaskBlob.setTemplate(messageTaskRequest.getTemplate());
|
||||||
messageTasks.add(messageTask);
|
|
||||||
blobMapper.insert(messageTaskBlob);
|
blobMapper.insert(messageTaskBlob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,8 +172,7 @@ public class NoticeMessageTaskService {
|
||||||
boolean useDefaultTemplate = messageTaskRequest.getUseDefaultTemplate() == null || messageTaskRequest.getUseDefaultTemplate();
|
boolean useDefaultTemplate = messageTaskRequest.getUseDefaultTemplate() == null || messageTaskRequest.getUseDefaultTemplate();
|
||||||
|
|
||||||
MessageTaskExample messageTaskExample = new MessageTaskExample();
|
MessageTaskExample messageTaskExample = new MessageTaskExample();
|
||||||
messageTaskExample.createCriteria().andReceiverIn(existUserIds).andProjectIdEqualTo(messageTaskRequest.getProjectId())
|
messageTaskExample.createCriteria().andReceiverIn(existUserIds).andProjectIdEqualTo(messageTaskRequest.getProjectId()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent());
|
||||||
.andProjectRobotIdEqualTo(messageTaskRequest.getRobotId()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent());
|
|
||||||
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||||
List<String> messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList();
|
List<String> messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList();
|
||||||
if (CollectionUtils.isEmpty(messageTasks)) {
|
if (CollectionUtils.isEmpty(messageTasks)) {
|
||||||
|
@ -192,11 +181,15 @@ public class NoticeMessageTaskService {
|
||||||
for (MessageTask messageTask : messageTasks) {
|
for (MessageTask messageTask : messageTasks) {
|
||||||
messageTask.setUpdateTime(System.currentTimeMillis());
|
messageTask.setUpdateTime(System.currentTimeMillis());
|
||||||
messageTask.setUpdateUser(userId);
|
messageTask.setUpdateUser(userId);
|
||||||
messageTask.setEnable(enable);
|
if (StringUtils.isNotBlank(messageTaskRequest.getRobotId())) {
|
||||||
messageTask.setUseDefaultSubject(useDefaultSubject);
|
messageTask.setEnable(enable);
|
||||||
messageTask.setUseDefaultTemplate(useDefaultTemplate);
|
messageTask.setUseDefaultSubject(useDefaultSubject);
|
||||||
if (!useDefaultSubject) {
|
messageTask.setUseDefaultTemplate(useDefaultTemplate);
|
||||||
messageTask.setSubject(messageTaskRequest.getSubject());
|
if (!messageTask.getUseDefaultSubject()) {
|
||||||
|
messageTask.setSubject(messageTaskRequest.getSubject());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
useDefaultTemplate = messageTask.getUseDefaultTemplate();
|
||||||
}
|
}
|
||||||
mapper.updateByPrimaryKeySelective(messageTask);
|
mapper.updateByPrimaryKeySelective(messageTask);
|
||||||
}
|
}
|
||||||
|
@ -204,9 +197,11 @@ public class NoticeMessageTaskService {
|
||||||
messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds);
|
messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds);
|
||||||
List<MessageTaskBlob> messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample);
|
List<MessageTaskBlob> messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample);
|
||||||
for (MessageTaskBlob messageTaskBlob : messageTaskBlobs) {
|
for (MessageTaskBlob messageTaskBlob : messageTaskBlobs) {
|
||||||
if (!useDefaultTemplate) {
|
if (StringUtils.isNotBlank(messageTaskRequest.getRobotId())) {
|
||||||
messageTaskBlob.setTemplate(messageTaskRequest.getTemplate());
|
if (!useDefaultTemplate) {
|
||||||
blobMapper.updateByPrimaryKeySelective(messageTaskBlob);
|
messageTaskBlob.setTemplate(messageTaskRequest.getTemplate());
|
||||||
|
blobMapper.updateByPrimaryKeySelective(messageTaskBlob);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messageTasks;
|
return messageTasks;
|
||||||
|
@ -318,7 +313,6 @@ public class NoticeMessageTaskService {
|
||||||
* @return List<MessageTaskDTO>
|
* @return List<MessageTaskDTO>
|
||||||
*/
|
*/
|
||||||
public List<MessageTaskDTO> getMessageList(String projectId) throws IOException {
|
public List<MessageTaskDTO> getMessageList(String projectId) throws IOException {
|
||||||
checkProjectExist(projectId);
|
|
||||||
//获取返回数据结构
|
//获取返回数据结构
|
||||||
StringBuilder jsonStr = new StringBuilder();
|
StringBuilder jsonStr = new StringBuilder();
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -75,6 +75,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
messageTaskRequest.setReceiverIds(userIds);
|
messageTaskRequest.setReceiverIds(userIds);
|
||||||
messageTaskRequest.setRobotId("test_message_robot2");
|
messageTaskRequest.setRobotId("test_message_robot2");
|
||||||
messageTaskRequest.setEnable(true);
|
messageTaskRequest.setEnable(true);
|
||||||
|
messageTaskRequest.setSubject("看看改不改");
|
||||||
|
messageTaskRequest.setUseDefaultSubject(false);
|
||||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
|
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
|
||||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
@ -116,6 +118,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
Assertions.assertEquals(100200, resultHolder.getCode());
|
Assertions.assertEquals(100200, resultHolder.getCode());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
messageTaskRequest = new MessageTaskRequest();
|
messageTaskRequest = new MessageTaskRequest();
|
||||||
messageTaskRequest.setProjectId("project-message-test");
|
messageTaskRequest.setProjectId("project-message-test");
|
||||||
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
|
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
|
||||||
|
@ -123,8 +127,6 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
userIds = new ArrayList<>();
|
userIds = new ArrayList<>();
|
||||||
userIds.add("project-message-user-1");
|
userIds.add("project-message-user-1");
|
||||||
messageTaskRequest.setReceiverIds(userIds);
|
messageTaskRequest.setReceiverIds(userIds);
|
||||||
messageTaskRequest.setRobotId("test_message_robot2");
|
|
||||||
messageTaskRequest.setEnable(true);
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
|
mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save")
|
||||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||||
|
@ -132,10 +134,17 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
.contentType(MediaType.APPLICATION_JSON))
|
.contentType(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||||
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
Assertions.assertEquals(100200, resultHolder.getCode());
|
Assertions.assertEquals(100200, resultHolder.getCode());
|
||||||
|
|
||||||
MessageTaskExample messageTaskExample = new MessageTaskExample();
|
MessageTaskExample messageTaskExample = new MessageTaskExample();
|
||||||
|
messageTaskExample.createCriteria().andReceiverEqualTo("project-message-user-1")
|
||||||
|
.andProjectIdEqualTo("project-message-test").andProjectRobotIdEqualTo("test_message_robot2").andTaskTypeEqualTo(NoticeConstants.TaskType.API_DEFINITION_TASK).andEventEqualTo(NoticeConstants.Event.CREATE);
|
||||||
|
List<MessageTask> messageTasks1 = messageTaskMapper.selectByExample(messageTaskExample);
|
||||||
|
Assertions.assertTrue(messageTasks1.get(0).getEnable());
|
||||||
|
Assertions.assertTrue(StringUtils.equalsIgnoreCase(messageTasks1.get(0).getSubject(), "看看改不改"));
|
||||||
|
|
||||||
|
messageTaskExample = new MessageTaskExample();
|
||||||
messageTaskExample.createCriteria().andProjectIdEqualTo("project-message-test").andTaskTypeEqualTo(NoticeConstants.TaskType.API_DEFINITION_TASK).andEventEqualTo(NoticeConstants.Event.CREATE);
|
messageTaskExample.createCriteria().andProjectIdEqualTo("project-message-test").andTaskTypeEqualTo(NoticeConstants.TaskType.API_DEFINITION_TASK).andEventEqualTo(NoticeConstants.Event.CREATE);
|
||||||
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||||
Assertions.assertEquals(1, messageTasks.size());
|
Assertions.assertEquals(1, messageTasks.size());
|
||||||
|
@ -314,16 +323,6 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
System.out.println(messageTaskDetailDTOList);
|
System.out.println(messageTaskDetailDTOList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Order(9)
|
|
||||||
public void getMessageListProjectFail() throws Exception {
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-message-test-x")
|
|
||||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
|
||||||
.header(SessionConstants.CSRF_TOKEN, csrfToken))
|
|
||||||
.andExpect(status().is5xxServerError())
|
|
||||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(10)
|
@Order(10)
|
||||||
public void getMessageListEmpty() throws Exception {
|
public void getMessageListEmpty() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue