|
@@ -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;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -67,7 +78,6 @@ public class MessageService {
|
|
|
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 {
|
|
|
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)) {
|
|
@@ -75,7 +85,6 @@ public class MessageService {
|
|
|
}
|
|
}
|
|
|
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);
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -97,7 +106,6 @@ public class MessageService {
|
|
|
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 {
|
|
|
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)) {
|
|
@@ -105,7 +113,6 @@ public class MessageService {
|
|
|
}
|
|
}
|
|
|
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,19 +138,26 @@ 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();
|
|
|
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());
|
|
|
|
|
+ });
|
|
|
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 -> {
|
|
@@ -167,11 +181,8 @@ 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;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|