|
@@ -6,6 +6,7 @@ import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
import com.sckw.core.utils.StringUtils;
|
|
|
import com.sckw.message.model.FindMessagePageParam;
|
|
import com.sckw.message.model.FindMessagePageParam;
|
|
|
import com.sckw.message.model.KwmMessage;
|
|
import com.sckw.message.model.KwmMessage;
|
|
|
|
|
+import com.sckw.message.model.KwmMessageUser;
|
|
|
import com.sckw.message.model.vo.req.DeleteMessagesReqVO;
|
|
import com.sckw.message.model.vo.req.DeleteMessagesReqVO;
|
|
|
import com.sckw.message.model.vo.req.FindMessagesReqVO;
|
|
import com.sckw.message.model.vo.req.FindMessagesReqVO;
|
|
|
import com.sckw.message.model.vo.req.ReadMessagesReqVO;
|
|
import com.sckw.message.model.vo.req.ReadMessagesReqVO;
|
|
@@ -42,11 +43,21 @@ public class MessageService {
|
|
|
*/
|
|
*/
|
|
|
public List<KwmMessage> selectMessages(FindMessagesReqVO params) {
|
|
public List<KwmMessage> selectMessages(FindMessagesReqVO params) {
|
|
|
//TODO 当前线程获取用户id
|
|
//TODO 当前线程获取用户id
|
|
|
- List<Long> msgIds = kwmMessageUserService.getMsgIdsByUserId(1L);
|
|
|
|
|
- if (CollectionUtils.isEmpty(msgIds)) {
|
|
|
|
|
|
|
+ List<KwmMessageUser> messageUsers = kwmMessageUserService.getByUserId(1L);
|
|
|
|
|
+ Map<Long, KwmMessageUser> map = messageUsers.stream().collect(Collectors.toMap(KwmMessageUser::getMsgId, e -> e, (k1, k2) -> k1));
|
|
|
|
|
+ if (CollectionUtils.isEmpty(map)) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
- return kwmMessageService.getList(msgIds, params.getCategory(), params.getType(), null);
|
|
|
|
|
|
|
+ List<Long> msgIds = map.keySet().stream().toList();
|
|
|
|
|
+ List<KwmMessage> list = kwmMessageService.getList(msgIds, params.getCategory(), params.getType(), null);
|
|
|
|
|
+ list.forEach(e->{
|
|
|
|
|
+ KwmMessageUser messageUser = map.get(e.getId());
|
|
|
|
|
+ e.setStatus(messageUser.getStatus());
|
|
|
|
|
+ e.setCreateTime(messageUser.getCreateTime());
|
|
|
|
|
+ e.setUpdateTime(messageUser.getUpdateTime());
|
|
|
|
|
+ e.setUpdateBy(messageUser.getUpdateBy());
|
|
|
|
|
+ });
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -64,18 +75,18 @@ 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);
|
|
|
- kwmMessageService.readByMsgIds(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;
|
|
|
}
|
|
}
|
|
|
List<Long> updateMsgIds = messageList.stream().map(KwmMessage::getId).toList();
|
|
List<Long> updateMsgIds = messageList.stream().map(KwmMessage::getId).toList();
|
|
|
kwmMessageUserService.readByUserAndMsgIds(1L, updateMsgIds);
|
|
kwmMessageUserService.readByUserAndMsgIds(1L, updateMsgIds);
|
|
|
- kwmMessageService.readByMsgIds(updateMsgIds);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -94,18 +105,18 @@ 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);
|
|
|
- kwmMessageService.delByMsgIds(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;
|
|
|
}
|
|
}
|
|
|
List<Long> delMsgIds = messageList.stream().map(KwmMessage::getId).toList();
|
|
List<Long> delMsgIds = messageList.stream().map(KwmMessage::getId).toList();
|
|
|
kwmMessageUserService.delByUserAndMsgIds(1L, delMsgIds);
|
|
kwmMessageUserService.delByUserAndMsgIds(1L, delMsgIds);
|
|
|
- kwmMessageService.delByMsgIds(delMsgIds);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -131,20 +142,34 @@ public class MessageService {
|
|
|
*/
|
|
*/
|
|
|
public List<MessagesStatisticsResVO> statistics(String category) {
|
|
public List<MessagesStatisticsResVO> statistics(String category) {
|
|
|
//TODO 当前线程获取用户id
|
|
//TODO 当前线程获取用户id
|
|
|
- List<Long> msgIds = kwmMessageUserService.getMsgIdsByUserId(1L);
|
|
|
|
|
- if (CollectionUtils.isEmpty(msgIds)) {
|
|
|
|
|
|
|
+ //获取用户未删除消息
|
|
|
|
|
+ List<KwmMessageUser> messageUserList = kwmMessageUserService.getByUserId(1L);
|
|
|
|
|
+ Map<Long, KwmMessageUser> messageUserMap = messageUserList.stream().collect(Collectors.toMap(KwmMessageUser::getMsgId, e -> e, (k1, k2) -> k1));
|
|
|
|
|
+ if (CollectionUtils.isEmpty(messageUserMap)) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
|
|
+ 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->{
|
|
|
|
|
+ KwmMessageUser kwmMessageUser = messageUserMap.get(e.getId());
|
|
|
|
|
+ e.setStatus(kwmMessageUser.getStatus());
|
|
|
|
|
+ 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);
|
|
@@ -167,11 +192,9 @@ public class MessageService {
|
|
|
public KwmMessage detail(Long id) {
|
|
public KwmMessage detail(Long id) {
|
|
|
//TODO 当前线程获取用户id
|
|
//TODO 当前线程获取用户id
|
|
|
KwmMessage message = kwmMessageService.getById(id);
|
|
KwmMessage message = kwmMessageService.getById(id);
|
|
|
- if (Global.UN_READ.equals(message.getStatus())) {
|
|
|
|
|
- List<Long> ids = Collections.singletonList(id);
|
|
|
|
|
- kwmMessageService.readByMsgIds(ids);
|
|
|
|
|
- kwmMessageUserService.readByUserAndMsgIds(1L, ids);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ List<Long> ids = Collections.singletonList(id);
|
|
|
|
|
+ //更新用户消息为已读状态
|
|
|
|
|
+ kwmMessageUserService.readByUserAndMsgIds(1L, ids);
|
|
|
return message;
|
|
return message;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|