diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/DynamicCommentCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/DynamicCommentCmdExe.java index 8f1d90e6..478aa3b4 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/DynamicCommentCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/dynamic/DynamicCommentCmdExe.java @@ -25,7 +25,14 @@ import com.red.circle.other.inner.model.cmd.user.account.PunishmentAccountCmd; import com.red.circle.tool.core.date.TimestampUtils; import com.red.circle.tool.core.num.NumUtils; import com.red.circle.tool.core.sequence.IdWorkerUtils; + +import java.util.Arrays; +import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; @@ -63,9 +70,10 @@ public class DynamicCommentCmdExe { incrCommentQuantity(cmd); //评论自己创建的动态或者自己回复自己不发送消息 - UserProfile userProfile = userProfileGateway.getByUserId(cmd.getReqUserId()); + Set userIdSet = Stream.of(cmd.getReqUserId(), cmd.getToUserId()).filter(Objects::nonNull).collect(Collectors.toSet()); + Map userProfileMap = userProfileGateway.mapByUserIds(userIdSet); if (isOwnDynamic(cmd, dynamicContent)) { - return convert(dynamicComment, userProfile); + return convert(dynamicComment, userProfileMap); } dynamicPopularService.updateScore(dynamicContent.getId(), dynamicCacheService.getCommentScore(), @@ -78,10 +86,10 @@ public class DynamicCommentCmdExe { //发送消息给动态被回复人 saveDynamicMessage(cmd, DynamicMessageEnum.REPLY_COMMENT); - return convert(dynamicComment, userProfile); + return convert(dynamicComment, userProfileMap); } - private DynamicCommentListCO convert(DynamicComment dynamicComment, UserProfile userProfile) { + private DynamicCommentListCO convert(DynamicComment dynamicComment, Map userProfileMap) { DynamicCommentListCO commentListCO = new DynamicCommentListCO(); commentListCO.setId(dynamicComment.getId()); commentListCO.setDynamicId(dynamicComment.getDynamicContentId()); @@ -89,10 +97,19 @@ public class DynamicCommentCmdExe { commentListCO.setContent(dynamicComment.getContent()); commentListCO.setCreateTime(dynamicComment.getCreateTime()); commentListCO.setRootCommentId(dynamicComment.getRootCommentId()); - commentListCO.setUserId(userProfile.getId()); - commentListCO.setUserAvatar(userProfile.getUserAvatar()); - commentListCO.setUserNickname(userProfile.getUserNickname()); - commentListCO.setUserSex(userProfile.getUserSex()); + + UserProfile userProfile = userProfileMap.get(dynamicComment.getCreateUser()); + if (userProfile != null) { + commentListCO.setUserId(userProfile.getId()); + commentListCO.setUserAvatar(userProfile.getUserAvatar()); + commentListCO.setUserNickname(userProfile.getUserNickname()); + commentListCO.setUserSex(userProfile.getUserSex()); + } + + UserProfile toUser = userProfileMap.get(dynamicComment.getToUserId()); + if (toUser != null) { + commentListCO.setToUserNickname(toUser.getUserNickname()); + } return commentListCO; }