|
|
@@ -1174,6 +1174,102 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Object getCommentDetail(Integer commentId) {
|
|
|
+ QueryWrapper<StoreComment> commentDetail = new QueryWrapper<>();
|
|
|
+ commentDetail.eq("delete_flag", 0)
|
|
|
+ .eq("id", commentId)
|
|
|
+ .orderByAsc("created_time");
|
|
|
+ StoreComment storeComment = storeCommentMapper.selectOne(commentDetail);
|
|
|
+ StoreCommentVo storeCommentVo = new StoreCommentVo();
|
|
|
+ BeanUtils.copyProperties(storeComment, storeCommentVo);
|
|
|
+ // 一级评论:直接回复当前评论的所有记录
|
|
|
+ QueryWrapper<StoreCommentVo> firstLevelWrapper = new QueryWrapper<>();
|
|
|
+ firstLevelWrapper.eq("a.delete_flag", 0)
|
|
|
+ .eq("a.reply_id", commentId)
|
|
|
+ .orderByAsc("a.created_time");
|
|
|
+ List<StoreCommentVo> firstLevelComments = storeCommentMapper.getCommentList(firstLevelWrapper);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(firstLevelComments)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理每条一级评论,递归补充其下所有子评论
|
|
|
+ for (StoreCommentVo first : firstLevelComments) {
|
|
|
+ // 递归获取所有子评论(扁平化)
|
|
|
+ List<StoreCommentVo> allChildComments = getChildCommentsRecursively(first.getId());
|
|
|
+
|
|
|
+ // 一级评论本身的商家/用户标识和商家信息
|
|
|
+// setStoreUserInfo(first);
|
|
|
+
|
|
|
+ // 按时间排序后绑定子评论列表
|
|
|
+ allChildComments.sort(Comparator.comparing(StoreCommentVo::getCreatedTime));
|
|
|
+ first.setStoreComment(allChildComments);
|
|
|
+ }
|
|
|
+ storeCommentVo.setStoreComment(firstLevelComments);
|
|
|
+ // 返回该评价下的多级评论结构
|
|
|
+ return storeCommentVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 递归获取评论的所有子评论(扁平化处理)
|
|
|
+ *
|
|
|
+ * @param parentId 父评论ID
|
|
|
+ * @return 所有子评论列表(扁平化)
|
|
|
+ */
|
|
|
+ private List<StoreCommentVo> getChildCommentsRecursively(Integer parentId) {
|
|
|
+ List<StoreCommentVo> allChildComments = new ArrayList<>();
|
|
|
+
|
|
|
+ // 查询直接回复当前评论的所有记录
|
|
|
+ QueryWrapper<StoreCommentVo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("a.delete_flag", 0)
|
|
|
+ .eq("a.reply_id", parentId)
|
|
|
+ .orderByAsc("a.created_time");
|
|
|
+ List<StoreCommentVo> directChildren = storeCommentMapper.getCommentList(wrapper);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(directChildren)) {
|
|
|
+ return allChildComments;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理每个直接子评论
|
|
|
+ for (StoreCommentVo child : directChildren) {
|
|
|
+ // 设置商家/用户标识
|
|
|
+// setStoreUserInfo(child);
|
|
|
+
|
|
|
+ // 递归获取该子评论的所有子评论
|
|
|
+ List<StoreCommentVo> grandChildren = getChildCommentsRecursively(child.getId());
|
|
|
+
|
|
|
+ // 将当前子评论添加到结果列表
|
|
|
+ allChildComments.add(child);
|
|
|
+
|
|
|
+ // 将该子评论的所有子评论也添加到结果列表(扁平化)
|
|
|
+ allChildComments.addAll(grandChildren);
|
|
|
+ }
|
|
|
+
|
|
|
+ return allChildComments;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置评论的商家/用户标识和商家信息
|
|
|
+ *
|
|
|
+ * @param comment 评论对象
|
|
|
+ */
|
|
|
+ private void setStoreUserInfo(StoreCommentVo comment) {
|
|
|
+ if (StringUtils.isNotEmpty(comment.getPhoneId())) {
|
|
|
+ if (comment.getPhoneId().contains("store_")) {
|
|
|
+ comment.setStoreUserFlag(0);
|
|
|
+ StoreUser storeUser = storeUserMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, comment.getStoreId()));
|
|
|
+ if (storeUser != null) {
|
|
|
+ comment.setStoreUserName(storeUser.getName());
|
|
|
+ comment.setStoreUserImg(storeUser.getHeadImg());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ comment.setStoreUserFlag(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 转换商户订单为统一VO
|
|
|
*/
|