|
|
|
@ -125,10 +125,10 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public PageDTO<SysMessageVO> querySendMessages(MessagesQuery messagesQuery) { |
|
|
|
|
// 初始化一个按发送时间降序排序的Page对象
|
|
|
|
|
// 1. 初始化一个按发送时间降序排序的Page对象
|
|
|
|
|
Page<SysMessages> page = messagesQuery.toMpPage("send_time", false); |
|
|
|
|
|
|
|
|
|
// 根据条件查询SysMessages表
|
|
|
|
|
// 2. 根据条件查询SysMessages表
|
|
|
|
|
Page<SysMessages> p = messagesService.page(page, |
|
|
|
|
new LambdaQueryWrapper<SysMessages>() |
|
|
|
|
.eq(SysMessages::getSenderId, messagesQuery.getUserId()) |
|
|
|
@ -137,7 +137,7 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox |
|
|
|
|
.select(SysMessages::getId, SysMessages::getCourseId, SysMessages::getTitle, SysMessages::getSendTime) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 将Page<SysMessages>转换为PageDTO<SysMessageVO>
|
|
|
|
|
// 3. 将Page<SysMessages>转换为PageDTO<SysMessageVO>
|
|
|
|
|
PageDTO<SysMessageVO> messages = PageDTO.of(p, SysMessageVO.class); |
|
|
|
|
List<SysMessageVO> messagesList = messages.getList(); |
|
|
|
|
|
|
|
|
@ -145,31 +145,33 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox |
|
|
|
|
throw new BusinessException(ErrorCode.MESSAGE_NO_EXIT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 批量查询课程名称
|
|
|
|
|
// 4. 批量查询课程ID
|
|
|
|
|
Set<String> courseIds = messagesList.stream() |
|
|
|
|
.map(SysMessageVO::getCourseId) |
|
|
|
|
.filter(Objects::nonNull) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 5. 批量查询课程ID对应的课程名称 并把ID:name 对应到一起
|
|
|
|
|
Map<String, String> courseNames = coursesMapper.selectBatchIds(courseIds).stream() |
|
|
|
|
.collect(Collectors.toMap(Courses::getId, Courses::getName)); |
|
|
|
|
|
|
|
|
|
// 批量查询所有用户收件箱数据
|
|
|
|
|
// 6. 批量查询当前用户对应的消息集合messageIds
|
|
|
|
|
Set<Long> messageIds = messagesList.stream() |
|
|
|
|
.map(SysMessageVO::getId) |
|
|
|
|
.collect(Collectors.toSet()); |
|
|
|
|
|
|
|
|
|
// 在用户邮箱中批量查询 对应消息的 信息(消息id,接受者id,是否已读)
|
|
|
|
|
List<UserInbox> allUserInboxes = userInboxMapper.selectList( |
|
|
|
|
new LambdaQueryWrapper<UserInbox>() |
|
|
|
|
.in(UserInbox::getMessageId, messageIds) |
|
|
|
|
.select(UserInbox::getMessageId, UserInbox::getReceiverId, UserInbox::getIsRead) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 将UserInbox数据按消息ID进行分组
|
|
|
|
|
// 7. 将UserInbox数据按消息ID进行分组(已经初步得到了消息的详情)
|
|
|
|
|
Map<Long, List<UserInbox>> userInboxesByMessageId = allUserInboxes.stream() |
|
|
|
|
.collect(Collectors.groupingBy(UserInbox::getMessageId)); |
|
|
|
|
|
|
|
|
|
// 缓存用户名称以避免重复查询
|
|
|
|
|
// 8. 缓存用户名称以避免重复查询
|
|
|
|
|
Map<Long, String> userNamesCache = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
for (SysMessageVO sysMessageVO : messagesList) { |
|
|
|
@ -200,7 +202,7 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox |
|
|
|
|
UmsTeacher umsTeacher = umsTeacherMapper.selectOne( |
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>().eq(UmsTeacher::getUserId, id) |
|
|
|
|
); |
|
|
|
|
return umsTeacher != null ? umsTeacher.getName() : null; |
|
|
|
|
return umsTeacher != null ? umsTeacher.getName() : "教师不存在"; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -212,20 +214,27 @@ public class UserInboxServiceImpl extends ServiceImpl<UserInboxMapper, UserInbox |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新PageDTO中的消息列表并返回
|
|
|
|
|
// 9. 更新PageDTO中的消息列表并返回
|
|
|
|
|
messages.setList(messagesList); |
|
|
|
|
return messages; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public SysMessageVO getMessageDetail(MessagesQuery messagesQuery) { |
|
|
|
|
Long count = userInboxMapper.selectCount(new LambdaQueryWrapper<>(UserInbox.class) |
|
|
|
|
.eq(UserInbox::getMessageId, messagesQuery.getMessageId()) |
|
|
|
|
.eq(UserInbox::getReceiverId, messagesQuery.getUserId())); |
|
|
|
|
if (!(count > 0)){ |
|
|
|
|
throw new BusinessException(ErrorCode.MESSAGE_NO_EXIT); |
|
|
|
|
} |
|
|
|
|
SysMessages sysMessage = messagesService.getById(messagesQuery.getMessageId()); |
|
|
|
|
SysMessageVO sysMessageVO = new SysMessageVO(); |
|
|
|
|
sysMessageVO.setId(messagesQuery.getMessageId()); |
|
|
|
|
sysMessageVO.setContent(sysMessage.getContent()); |
|
|
|
|
sysMessageVO.setSenderId(messagesQuery.getUserId()); |
|
|
|
|
// 获取发件人信息
|
|
|
|
|
//获取发件人信息
|
|
|
|
|
UmsTeacher umsTeacher = umsTeacherMapper.selectOne( |
|
|
|
|
new LambdaQueryWrapper<UmsTeacher>() |
|
|
|
|
.eq(UmsTeacher::getUserId, sysMessage.getSenderId())); |
|
|
|
|