fix(项目管理): 修复消息通知新保存机器人类型失败问题
This commit is contained in:
parent
e852795027
commit
01a375210e
|
@ -54,8 +54,6 @@ public class NoticeMessageTaskService {
|
||||||
@Resource
|
@Resource
|
||||||
private MessageTaskBlobMapper messageTaskBlobMapper;
|
private MessageTaskBlobMapper messageTaskBlobMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private ProjectMapper projectMapper;
|
|
||||||
@Resource
|
|
||||||
private ExtProjectUserRoleMapper extProjectUserRoleMapper;
|
private ExtProjectUserRoleMapper extProjectUserRoleMapper;
|
||||||
@Resource
|
@Resource
|
||||||
protected CustomFieldMapper customFieldMapper;
|
protected CustomFieldMapper customFieldMapper;
|
||||||
|
@ -79,12 +77,12 @@ 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();
|
Map<String, List<MessageTask>> robotMap = messageTasks.stream().collect(Collectors.groupingBy(MessageTask::getProjectRobotId));
|
||||||
//如果新增时只选了用户,没有选机器人,默认机器人为站内信
|
//如果新增时只选了用户,没有选机器人,默认机器人为站内信
|
||||||
ProjectRobot projectRobot = getDefaultRobot(messageTaskRequest.getProjectId(), messageTaskRequest.getRobotId());
|
ProjectRobot projectRobot = getDefaultRobot(messageTaskRequest.getProjectId(), messageTaskRequest.getRobotId());
|
||||||
String robotId = projectRobot.getId();
|
String robotId = projectRobot.getId();
|
||||||
messageTaskRequest.setRobotId(robotId);
|
messageTaskRequest.setRobotId(robotId);
|
||||||
insertMessageTask(messageTaskRequest, userId, mapper, blobMapper, existUserIds, messageTaskReceivers);
|
insertMessageTask(messageTaskRequest, userId, mapper, blobMapper, existUserIds, robotMap);
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
if (CollectionUtils.isNotEmpty(stringListMap.get(NO_USER_NAMES))) {
|
if (CollectionUtils.isNotEmpty(stringListMap.get(NO_USER_NAMES))) {
|
||||||
|
@ -118,13 +116,19 @@ public class NoticeMessageTaskService {
|
||||||
* @param mapper MessageTaskMapper
|
* @param mapper MessageTaskMapper
|
||||||
* @param blobMapper MessageTaskBlobMapper
|
* @param blobMapper MessageTaskBlobMapper
|
||||||
* @param existUserIds 系统中还存在的入参传过来的接收人
|
* @param existUserIds 系统中还存在的入参传过来的接收人
|
||||||
* @param messageTaskReceivers 更新过后还有多少接收人需要保存
|
* @param robotMap 更新过后机器人消息通知map
|
||||||
*/
|
*/
|
||||||
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, Map<String, List<MessageTask>> robotMap) {
|
||||||
|
//判断是否需要完整的新增机器人数据
|
||||||
|
List<MessageTask> messageTasks = robotMap.get(messageTaskRequest.getRobotId());
|
||||||
for (String receiverId : existUserIds) {
|
for (String receiverId : existUserIds) {
|
||||||
if (CollectionUtils.isNotEmpty(messageTaskReceivers) && messageTaskReceivers.contains(receiverId)) {
|
//如果为空则需要完整新增,新增人,则需要过滤数据里是否有这个人,有则过滤
|
||||||
|
if (!CollectionUtils.isEmpty(messageTasks)) {
|
||||||
|
List<String> receivers = messageTasks.stream().map(MessageTask::getReceiver).toList();
|
||||||
|
if (CollectionUtils.isNotEmpty(receivers) && receivers.contains(receiverId)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
MessageTask messageTask = new MessageTask();
|
MessageTask messageTask = new MessageTask();
|
||||||
buildMessageTask(messageTaskRequest, userId, receiverId, messageTask);
|
buildMessageTask(messageTaskRequest, userId, receiverId, messageTask);
|
||||||
mapper.insert(messageTask);
|
mapper.insert(messageTask);
|
||||||
|
@ -171,6 +175,7 @@ public class NoticeMessageTaskService {
|
||||||
boolean useDefaultSubject = messageTaskRequest.getUseDefaultSubject() == null || messageTaskRequest.getUseDefaultSubject();
|
boolean useDefaultSubject = messageTaskRequest.getUseDefaultSubject() == null || messageTaskRequest.getUseDefaultSubject();
|
||||||
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()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent());
|
messageTaskExample.createCriteria().andReceiverIn(existUserIds).andProjectIdEqualTo(messageTaskRequest.getProjectId()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent());
|
||||||
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||||
|
@ -181,7 +186,8 @@ 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);
|
||||||
if (StringUtils.isNotBlank(messageTaskRequest.getRobotId())) {
|
//如果有机器人id,则是修改机器人开关和消息配置
|
||||||
|
if (StringUtils.isNotBlank(messageTaskRequest.getRobotId()) && StringUtils.equalsIgnoreCase(messageTask.getProjectRobotId(), messageTaskRequest.getRobotId())) {
|
||||||
messageTask.setEnable(enable);
|
messageTask.setEnable(enable);
|
||||||
messageTask.setUseDefaultSubject(useDefaultSubject);
|
messageTask.setUseDefaultSubject(useDefaultSubject);
|
||||||
messageTask.setUseDefaultTemplate(useDefaultTemplate);
|
messageTask.setUseDefaultTemplate(useDefaultTemplate);
|
||||||
|
@ -189,6 +195,7 @@ public class NoticeMessageTaskService {
|
||||||
messageTask.setSubject(messageTaskRequest.getSubject());
|
messageTask.setSubject(messageTaskRequest.getSubject());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//如果没有机器人id,则只是修改人其余配置不变
|
||||||
useDefaultTemplate = messageTask.getUseDefaultTemplate();
|
useDefaultTemplate = messageTask.getUseDefaultTemplate();
|
||||||
}
|
}
|
||||||
mapper.updateByPrimaryKeySelective(messageTask);
|
mapper.updateByPrimaryKeySelective(messageTask);
|
||||||
|
|
|
@ -147,11 +147,29 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
messageTaskExample = new MessageTaskExample();
|
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(2, messageTasks.size());
|
||||||
messageTaskExample = new MessageTaskExample();
|
messageTaskExample = new MessageTaskExample();
|
||||||
messageTaskExample.createCriteria().andProjectIdEqualTo("project-message-test").andTaskTypeEqualTo(NoticeConstants.TaskType.API_DEFINITION_TASK).andEventEqualTo(NoticeConstants.Event.CREATE).andReceiverEqualTo("project-message-user-3");
|
messageTaskExample.createCriteria().andProjectIdEqualTo("project-message-test").andTaskTypeEqualTo(NoticeConstants.TaskType.API_DEFINITION_TASK).andEventEqualTo(NoticeConstants.Event.CREATE).andReceiverEqualTo("project-message-user-3");
|
||||||
messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||||
Assertions.assertEquals(0, messageTasks.size());
|
Assertions.assertEquals(0, messageTasks.size());
|
||||||
|
|
||||||
|
//projectId 存在 用户有部分被删除的测试
|
||||||
|
messageTaskRequest = new MessageTaskRequest();
|
||||||
|
messageTaskRequest.setProjectId("project-message-test");
|
||||||
|
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
|
||||||
|
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
|
||||||
|
userIds = new ArrayList<>();
|
||||||
|
userIds.add("project-message-user-1");
|
||||||
|
messageTaskRequest.setReceiverIds(userIds);
|
||||||
|
messageTaskRequest.setRobotId("test_message_robot5");
|
||||||
|
messageTaskRequest.setEnable(true);
|
||||||
|
messageTaskRequest.setSubject("看看改不改");
|
||||||
|
messageTaskRequest.setUseDefaultSubject(false);
|
||||||
|
this.requestPostWithOk("/notice/message/task/save",messageTaskRequest);
|
||||||
|
messageTaskExample = new MessageTaskExample();
|
||||||
|
messageTaskExample.createCriteria().andProjectIdEqualTo("project-message-test").andTaskTypeEqualTo(NoticeConstants.TaskType.API_DEFINITION_TASK).andEventEqualTo(NoticeConstants.Event.CREATE).andProjectRobotIdEqualTo("test_message_robot5");
|
||||||
|
messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||||
|
Assertions.assertEquals(1, messageTasks.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue