|
@@ -75,10 +75,12 @@ public class MessageService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
List<Long> ids = reqVO.getMsgIds();
|
|
List<Long> ids = reqVO.getMsgIds();
|
|
|
|
|
+ //msgIds不为空直接更新用户消息为已读
|
|
|
if (CollectionUtils.isNotEmpty(ids)) {
|
|
if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
List<Long> list = ids.stream().filter(msgIds::contains).toList();
|
|
List<Long> list = ids.stream().filter(msgIds::contains).toList();
|
|
|
kwmMessageUserService.readByUserAndMsgIds(1L, list);
|
|
kwmMessageUserService.readByUserAndMsgIds(1L, list);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ //msgIds为空根据category及type更新用户消息为已读
|
|
|
List<KwmMessage> messageList = kwmMessageService.getList(msgIds, reqVO.getCategory(), reqVO.getType(), 0);
|
|
List<KwmMessage> messageList = kwmMessageService.getList(msgIds, reqVO.getCategory(), reqVO.getType(), 0);
|
|
|
if (CollectionUtils.isEmpty(messageList)) {
|
|
if (CollectionUtils.isEmpty(messageList)) {
|
|
|
return;
|
|
return;
|
|
@@ -103,10 +105,12 @@ public class MessageService {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
List<Long> ids = reqVO.getMsgIds();
|
|
List<Long> ids = reqVO.getMsgIds();
|
|
|
|
|
+ //msgIds不为空直接删除用户消息
|
|
|
if (CollectionUtils.isNotEmpty(ids)) {
|
|
if (CollectionUtils.isNotEmpty(ids)) {
|
|
|
List<Long> list = ids.stream().filter(msgIds::contains).toList();
|
|
List<Long> list = ids.stream().filter(msgIds::contains).toList();
|
|
|
kwmMessageUserService.delByUserAndMsgIds(1L, list);
|
|
kwmMessageUserService.delByUserAndMsgIds(1L, list);
|
|
|
} else {
|
|
} else {
|
|
|
|
|
+ //msgIds为空,根据category及type查找删除用户消息
|
|
|
List<KwmMessage> messageList = kwmMessageService.getList(msgIds, reqVO.getCategory(), reqVO.getType(), null);
|
|
List<KwmMessage> messageList = kwmMessageService.getList(msgIds, reqVO.getCategory(), reqVO.getType(), null);
|
|
|
if (CollectionUtils.isEmpty(messageList)) {
|
|
if (CollectionUtils.isEmpty(messageList)) {
|
|
|
return;
|
|
return;
|
|
@@ -138,27 +142,34 @@ public class MessageService {
|
|
|
*/
|
|
*/
|
|
|
public List<MessagesStatisticsResVO> statistics(String category) {
|
|
public List<MessagesStatisticsResVO> statistics(String category) {
|
|
|
//TODO 当前线程获取用户id
|
|
//TODO 当前线程获取用户id
|
|
|
|
|
+ //获取用户未删除消息
|
|
|
List<KwmMessageUser> messageUserList = kwmMessageUserService.getByUserId(1L);
|
|
List<KwmMessageUser> messageUserList = kwmMessageUserService.getByUserId(1L);
|
|
|
Map<Long, KwmMessageUser> messageUserMap = messageUserList.stream().collect(Collectors.toMap(KwmMessageUser::getMsgId, e -> e, (k1, k2) -> k1));
|
|
Map<Long, KwmMessageUser> messageUserMap = messageUserList.stream().collect(Collectors.toMap(KwmMessageUser::getMsgId, e -> e, (k1, k2) -> k1));
|
|
|
if (CollectionUtils.isEmpty(messageUserMap)) {
|
|
if (CollectionUtils.isEmpty(messageUserMap)) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
List<Long> msgIds = messageUserMap.keySet().stream().toList();
|
|
List<Long> msgIds = messageUserMap.keySet().stream().toList();
|
|
|
|
|
+ //根据消息ids获取message详情
|
|
|
List<KwmMessage> messages = kwmMessageService.statistics(msgIds, category);
|
|
List<KwmMessage> messages = kwmMessageService.statistics(msgIds, category);
|
|
|
if (CollectionUtils.isEmpty(messages)) {
|
|
if (CollectionUtils.isEmpty(messages)) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
|
|
+ //设置用户消息状态及创建时间
|
|
|
messages.forEach(e->{
|
|
messages.forEach(e->{
|
|
|
KwmMessageUser kwmMessageUser = messageUserMap.get(e.getId());
|
|
KwmMessageUser kwmMessageUser = messageUserMap.get(e.getId());
|
|
|
e.setStatus(kwmMessageUser.getStatus());
|
|
e.setStatus(kwmMessageUser.getStatus());
|
|
|
e.setCreateTime(kwmMessageUser.getCreateTime());
|
|
e.setCreateTime(kwmMessageUser.getCreateTime());
|
|
|
});
|
|
});
|
|
|
|
|
+ //消息按状态升序、创建时间降序排序,无category按category分组,有category按type分组
|
|
|
Map<String, List<KwmMessage>> collect;
|
|
Map<String, List<KwmMessage>> collect;
|
|
|
if (StringUtils.isNotBlank(category)) {
|
|
if (StringUtils.isNotBlank(category)) {
|
|
|
- collect = messages.stream().sorted(Comparator.comparingInt(KwmMessage::getStatus).thenComparing(KwmMessage::getCreateTime, Comparator.reverseOrder())).collect(Collectors.groupingBy(KwmMessage::getType));
|
|
|
|
|
|
|
+ collect = messages.stream().sorted(Comparator.comparingInt(KwmMessage::getStatus)
|
|
|
|
|
+ .thenComparing(KwmMessage::getCreateTime, Comparator.reverseOrder())).collect(Collectors.groupingBy(KwmMessage::getType));
|
|
|
} else {
|
|
} else {
|
|
|
- collect = messages.stream().sorted(Comparator.comparingInt(KwmMessage::getStatus).thenComparing(KwmMessage::getCreateTime, Comparator.reverseOrder())).collect(Collectors.groupingBy(KwmMessage::getCategory));
|
|
|
|
|
|
|
+ collect = messages.stream().sorted(Comparator.comparingInt(KwmMessage::getStatus)
|
|
|
|
|
+ .thenComparing(KwmMessage::getCreateTime, Comparator.reverseOrder())).collect(Collectors.groupingBy(KwmMessage::getCategory));
|
|
|
}
|
|
}
|
|
|
|
|
+ //组装响应参数:消息分组第一条、统计未读数量
|
|
|
List<MessagesStatisticsResVO> list = new ArrayList<>(collect.size());
|
|
List<MessagesStatisticsResVO> list = new ArrayList<>(collect.size());
|
|
|
collect.values().forEach(e -> {
|
|
collect.values().forEach(e -> {
|
|
|
KwmMessage message = e.get(0);
|
|
KwmMessage message = e.get(0);
|
|
@@ -182,6 +193,7 @@ public class MessageService {
|
|
|
//TODO 当前线程获取用户id
|
|
//TODO 当前线程获取用户id
|
|
|
KwmMessage message = kwmMessageService.getById(id);
|
|
KwmMessage message = kwmMessageService.getById(id);
|
|
|
List<Long> ids = Collections.singletonList(id);
|
|
List<Long> ids = Collections.singletonList(id);
|
|
|
|
|
+ //更新用户消息为已读状态
|
|
|
kwmMessageUserService.readByUserAndMsgIds(1L, ids);
|
|
kwmMessageUserService.readByUserAndMsgIds(1L, ids);
|
|
|
return message;
|
|
return message;
|
|
|
}
|
|
}
|