Przeglądaj źródła

bugfix:评论详情修改

lyx 3 miesięcy temu
rodzic
commit
5fe7005738

+ 3 - 3
alien-entity/src/main/java/shop/alien/entity/store/StoreInfo.java

@@ -341,13 +341,13 @@ public class StoreInfo {
     @TableField("business_category_name")
     private String businessCategoryName;
 
-    @ApiModelProperty(value = "评1")
+    @ApiModelProperty(value = "评1")
     @TableField("score_one")
     private Double scoreOne;
-     @ApiModelProperty(value = "评2")
+     @ApiModelProperty(value = "评2")
     @TableField("score_two")
     private Double scoreTwo;
-     @ApiModelProperty(value = "评3")
+     @ApiModelProperty(value = "评3")
     @TableField("score_three")
     private Double scoreThree;
 

+ 13 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreCommentController.java

@@ -251,5 +251,18 @@ public class StoreCommentController {
     }
 
 
+    @ApiOperation("获取评论详情")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "评论主键", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getCommentDetail")
+    public R getCommentDetail(Integer commentId) {
+        log.info("StoreCommentController.getCommentDetail?id={}", commentId);
+        if (commentId == null) {
+            throw new IllegalArgumentException("参数[commentId]不能为空");
+        }
+        return R.data(storeCommentService.getCommentDetail(commentId));
+    }
+
 
 }

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/StoreCommentService.java

@@ -141,4 +141,12 @@ public interface StoreCommentService extends IService<StoreComment> {
      * @return 0:成功, 1:失败, 2:文本内容异常, 3:图片内容异常
      */
     Integer saveCommentOnlyStore(String imageUrls, Integer id, Integer businessType, Integer storeId, Integer userId, Integer replyId, String commentContent, Double score, String otherScore, Integer isAnonymous);
+
+    /**
+     * 获取评论详情
+     *
+     * @param commentId 主键
+     * @return StoreCommentVo
+     */
+    Object getCommentDetail(Integer commentId);
 }

+ 96 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreCommentServiceImpl.java

@@ -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
      */