消息列表rootCommentId 修复

This commit is contained in:
tianfeng 2026-02-03 10:28:47 +08:00
parent 0c2bd92fb4
commit 94e293a253
3 changed files with 51 additions and 2 deletions

View File

@ -1,8 +1,8 @@
package com.red.circle.other.app.command.dynamic.query;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.google.common.collect.Maps;
import com.red.circle.common.business.enums.DynamicMessageEnum;
import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicMessageListCO;
@ -10,8 +10,10 @@ import com.red.circle.other.app.dto.clientobject.dynamic.MessageItemCO;
import com.red.circle.other.app.dto.cmd.dynamic.DynamicLimitCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicComment;
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicContent;
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicMessage;
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicCommentService;
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicContentService;
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicMessageService;
import com.red.circle.tool.core.collection.CollectionUtils;
@ -38,6 +40,7 @@ public class DynamicMessageQryExe {
private final UserProfileGateway userProfileGateway;
private final DynamicContentService dynamicContentService;
private final DynamicMessageService dynamicMessageService;
private final DynamicCommentService dynamicCommentService;
public PageResult<DynamicMessageListCO> execute(DynamicLimitCmd cmd) {
@ -49,6 +52,7 @@ public class DynamicMessageQryExe {
Map<Long, UserProfile> userMap = userProfileGateway.mapByUserIds(getUserIds(messages));
Map<Long, DynamicContent> contentMap = getContentMap(messages);
Map<Long, DynamicComment> commentMap = getCommentMap(messages);
return messages.convert(message -> {
@ -64,7 +68,13 @@ public class DynamicMessageQryExe {
messageCO.setCreateTime(message.getCreateTime());
messageCO.setDynamicId(message.getDynamicContentId());
messageCO.setDynamicContent(dynamicContent.getContent());
messageCO.setRootCommentId(message.getDynamicCommentId());
// 批量查询评论ID对应的 rootCommentId
DynamicComment comment = commentMap.get(message.getDynamicCommentId());
if (comment != null) {
messageCO.setRootCommentId(comment.getRootCommentId());
}
// 处理messageContent giftCount
parseMessageContent(messageCO, message);
@ -112,6 +122,19 @@ public class DynamicMessageQryExe {
Collectors.toSet()));
}
private Map<Long, DynamicComment> getCommentMap(PageResult<DynamicMessage> messages) {
Set<Long> commentIds = messages.getRecords().stream()
.map(DynamicMessage::getDynamicCommentId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
if (CollectionUtils.isEmpty(commentIds)) {
return Maps.newHashMap();
}
return dynamicCommentService.mapByIds(commentIds);
}
private PageResult<DynamicMessage> getMessages(DynamicLimitCmd cmd) {
return dynamicMessageService.pageByTimeDesc(cmd.getPageReq(), cmd.getReqUserId(), cmd.getDynamicMessageEnums());
}

View File

@ -107,4 +107,12 @@ public interface DynamicCommentService extends BaseService<DynamicComment> {
*/
Map<Long, Integer> mapChildCommentCount(Collection<Long> rootCommentIds);
/**
* 根据评论ID集合批量查询评论
*
* @param commentIds 评论ID集合
* @return Map<评论ID, 评论对象>
*/
Map<Long, DynamicComment> mapByIds(Collection<Long> commentIds);
}

View File

@ -195,4 +195,22 @@ public class DynamicCommentServiceImpl extends
return result;
}
@Override
public Map<Long, DynamicComment> mapByIds(Collection<Long> commentIds) {
if (CollectionUtils.isEmpty(commentIds)) {
return Maps.newHashMap();
}
List<DynamicComment> comments = query()
.in(DynamicComment::getId, commentIds)
.list();
Map<Long, DynamicComment> result = Maps.newHashMap();
for (DynamicComment comment : comments) {
result.put(comment.getId(), comment);
}
return result;
}
}