Преглед на файлове

bugfix:动态评价修改

刘云鑫 преди 2 месеца
родител
ревизия
7d88874909

+ 1 - 1
alien-entity/src/main/java/shop/alien/entity/store/CommonComment.java

@@ -28,7 +28,7 @@ public class CommonComment implements Serializable {
     @TableId(value = "id", type = IdType.AUTO)
     private Long id;
 
-    @ApiModelProperty(value = "评论来源类型:1-评价的评论 2-社区动态 3-活动留言")
+    @ApiModelProperty(value = "评论来源类型:1-评价的评论 2-动态评论")
     @TableField("source_type")
     private Integer sourceType;
 

+ 5 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/CommonCommentVo.java

@@ -18,4 +18,9 @@ public class CommonCommentVo extends CommonComment {
     private String headName;
     @ApiModelProperty(value = "是否点赞")
     private String isLike;
+    @ApiModelProperty(value = "来源关联id")
+    private Long sourceId;
+    @ApiModelProperty(value = "数量")
+    private Integer commentCount;
+
 }

+ 10 - 1
alien-entity/src/main/java/shop/alien/mapper/CommonCommentMapper.java

@@ -3,6 +3,7 @@ package shop.alien.mapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -33,8 +34,16 @@ public interface CommonCommentMapper extends BaseMapper<CommonComment> {
             "and llr.dianzan_id = #{dianzanId}\n" +
             "and llr.delete_flag = 0\n" +
             "${ew.customSqlSegment}")
-    List<CommonCommentVo> selectALlComment(@Param(Constants.WRAPPER)QueryWrapper<CommonCommentVo> wrapper,
+    List<CommonCommentVo> selectALlComment(@Param("page") Page<CommonCommentVo> page,
+                                           @Param(Constants.WRAPPER)QueryWrapper<CommonCommentVo> wrapper,
                                            @Param("type") String type,
                                            @Param("dianzanId") Long dianzanId);
+
+    @Select("select cc.source_id sourceId,count(*) commentCount\n" +
+            "from common_comment cc\n" +
+            "where \n" +
+            "cc.source_type = #{businessType}\n" +
+            "group by source_id")
+    List<CommonCommentVo> getCommentCount(Integer type);
 }
 

+ 4 - 0
alien-store/pom.xml

@@ -297,6 +297,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-security</artifactId>
         </dependency>
+        <dependency>
+            <groupId>jakarta.validation</groupId>
+            <artifactId>jakarta.validation-api</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 48 - 3
alien-store/src/main/java/shop/alien/store/controller/CommonCommentController.java

@@ -1,8 +1,6 @@
 package shop.alien.store.controller;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiSort;
+import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
@@ -103,5 +101,52 @@ public class CommonCommentController {
         return R.fail("删除评论失败");
     }
 
+
+    /**
+     * 根据动态类型和动态id查询评论列表
+     * @param sourceType
+     * @param sourceId
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    @ApiOperation(value = "动态评论")
+    @GetMapping("/getListBySourceType")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "sourceType", value = "类型", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "sourceId", value = "id", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "pageNum", value = "页码", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "pageSize", value = "每页数量", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "userId", value = "用户id", required = false, dataType = "Long")
+    })
+    public R getListBySourceType(@RequestParam Integer sourceType,
+                                 @RequestParam Integer sourceId,
+                                 @RequestParam(defaultValue = "1") Integer pageNum,
+                                 @RequestParam(defaultValue = "10") Integer pageSize,
+                                 @RequestParam(required = false) Long userId) {
+        return R.data(commonCommentService.getListBySourceType(sourceType, sourceId, pageNum, pageSize, userId));
+    }
+
+    /**
+     * 获取评论数量
+     * @param sourceId
+     * @param sourceType
+     * @param userId
+     * @return
+     */
+    @ApiOperation(value = "获取评论数量")
+    @GetMapping("/getCommitCount")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(name = "sourceId", value = "id", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "sourceType", value = "类型", required = true, dataType = "Integer"),
+            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "userType", value = "用户类型,user,store", required = true, dataType = "String")
+    })
+    public R getCommitCount(@RequestParam Integer sourceId,
+                            @RequestParam Integer sourceType,
+                            @RequestParam String userId,
+                            @RequestParam String userType){
+        return R.data(commonCommentService.getCommitCount(sourceId, sourceType, userId, userType));
+    }
 }
 

+ 38 - 1
alien-store/src/main/java/shop/alien/store/service/CommonCommentService.java

@@ -2,6 +2,11 @@ package shop.alien.store.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import shop.alien.entity.store.CommonComment;
+import shop.alien.entity.store.vo.CommonCommentVo;
+import shop.alien.entity.store.vo.CommonRatingVo;
+
+import java.util.List;
+import java.util.Map;
 
 /**
  * 评论表 服务类
@@ -10,7 +15,39 @@ import shop.alien.entity.store.CommonComment;
  * @since 2025-01-XX
  */
 public interface CommonCommentService extends IService<CommonComment> {
-
+    /**
+     * 新增评论
+     * @param commonComment
+     * @return
+     */
     Integer addComment(CommonComment commonComment);
+
+    /**
+     * 根据动态类型和动态id查询评论列表
+     * @param sourceType
+     * @param sourceId
+     * @param pageNum
+     * @param pageSize
+     * @param userId
+     * @return
+     */
+    List<CommonCommentVo> getListBySourceType(Integer sourceType, Integer sourceId, Integer pageNum, Integer pageSize, Long userId);
+
+
+    /**
+     *
+     * @param sourceType
+     * @param sourceId
+     * @param pageNum
+     * @param pageSize
+     * @param userId
+     * @param likeType
+     * @return
+     */
+    List<CommonCommentVo> getFirstLevelComment(Integer sourceType, Integer sourceId, Integer pageNum, Integer pageSize, Long userId, String likeType);
+
+    void getAllChildComment(Long userId, CommonRatingVo commonRatingVo, List<CommonCommentVo> commonComments, String likeType);
+
+    Map<String,Object> getCommitCount(Integer sourceId, Integer sourceType, String userId, String userType);
 }
 

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/LifeCommentService.java

@@ -196,7 +196,7 @@ public class LifeCommentService {
                 return commonRatingMapper.update(null, new UpdateWrapper<CommonRating>()
                         .setSql("like_count = like_count + 1")
                         .eq("id", huifuId));
-            } else if (CommonConstant.COMMENT_LIKE.equals(type)) {
+            } else if (CommonConstant.COMMENT_LIKE.equals(type) || CommonConstant.DYNAMIC_LIKE.equals(type)) {
                 // 12-评论点赞:更新评论表点赞数
                 return commonCommentMapper.update(null, new UpdateWrapper<CommonComment>()
                         .setSql("like_count = like_count + 1")
@@ -364,7 +364,7 @@ public class LifeCommentService {
                 return commonRatingMapper.update(null, new UpdateWrapper<CommonRating>()
                         .setSql("like_count = like_count - 1")
                         .eq("id", huifuId));
-            } else if (CommonConstant.COMMENT_LIKE.equals(type)) {
+            } else if (CommonConstant.COMMENT_LIKE.equals(type) || CommonConstant.DYNAMIC_LIKE.equals(type)) {
                 // 12-评论点赞:更新评论表点赞数
                 return commonCommentMapper.update(null, new UpdateWrapper<CommonComment>()
                         .setSql("like_count = like_count - 1")

+ 21 - 14
alien-store/src/main/java/shop/alien/store/service/LifeUserDynamicsService.java

@@ -13,11 +13,9 @@ import org.springframework.util.CollectionUtils;
 import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
 import shop.alien.entity.store.*;
-import shop.alien.entity.store.vo.LifePinglunVo;
-import shop.alien.entity.store.vo.LifeUserDynamicsVo;
-import shop.alien.entity.store.vo.StoreCommentVo;
-import shop.alien.entity.store.vo.StoreUserVo;
+import shop.alien.entity.store.vo.*;
 import shop.alien.mapper.*;
+import shop.alien.util.common.constant.CommentSourceTypeEnum;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -54,6 +52,8 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
 
     private final StoreInfoMapper storeInfoMapper;
 
+    private final CommonCommentMapper commonCommentMapper;
+
     public int addLiulanCount(String id) {
         LambdaUpdateWrapper<LifeUserDynamics> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
         lambdaUpdateWrapper.eq(LifeUserDynamics::getId, id);
@@ -199,8 +199,10 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
             lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(item -> followList.contains(item.getPhoneId())).collect(Collectors.toList());
         }
 
-        List<StoreCommentVo> rootCommitCount = storeCommentMapper.getRootCommitCount(2, null);
-        List<StoreCommentVo> sonCommitCount = storeCommentMapper.getSonCommitCount(2, null);
+//        List<StoreCommentVo> rootCommitCount = storeCommentMapper.getRootCommitCount(2, null);
+//        List<StoreCommentVo> sonCommitCount = storeCommentMapper.getSonCommitCount(2, null);
+
+        List<CommonCommentVo> commonCommentVo= commonCommentMapper.getCommentCount(CommentSourceTypeEnum.DYNAMIC_COMMENT.getType());
 
         // 设置动态对象的状态信息:是否关注对方、是否被关注、是否点赞及评论数量
         // 设置.imagePath。视频为mp4+jpg格式,图片为jpg/png格式。
@@ -220,17 +222,21 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
             } else {
                 vo.setIsLike("0");
             }
-            List<StoreCommentVo> rootList = rootCommitCount.stream().filter(item -> Objects.equals(item.getBusinessId(), vo.getId())).collect(Collectors.toList());
-            if (rootList.isEmpty()) {
+            List<CommonCommentVo> collect = commonCommentVo.stream().filter(x -> x.getSourceId().equals(Long.parseLong(vo.getId().toString()))).collect(Collectors.toList());
+//            List<StoreCommentVo> rootList = rootCommitCount.stream().filter(item -> Objects.equals(item.getBusinessId(), vo.getId())).collect(Collectors.toList());
+            if (collect.isEmpty()) {
                 vo.setCommentCount(0);
             } else {
-                Integer count = rootList.size();
-                for (StoreCommentVo storeCommentVo : rootList) {
-                    List<StoreCommentVo> sonList = sonCommitCount.stream().filter(item -> Objects.equals(item.getReplyId(), storeCommentVo.getId())).collect(Collectors.toList());
-                    if (!sonList.isEmpty()) {
-                        count += sonList.get(0).getCommitCount();
-                    }
+                Integer count = collect.size();
+                for (CommonCommentVo commentVo : collect) {
+                    count += commentVo.getCommentCount();
                 }
+//                for (CommonCommentVo storeCommentVo : collect) {
+//                    List<StoreCommentVo> sonList = sonCommitCount.stream().filter(item -> Objects.equals(item.getReplyId(), storeCommentVo.getId())).collect(Collectors.toList());
+//                    if (!sonList.isEmpty()) {
+//                        count += sonList.get(0).getCommitCount();
+//                    }
+//                }
                 vo.setCommentCount(count);
             }
         }
@@ -440,6 +446,7 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
             if (storeUser != null) {
                 if (storeUser.getStoreId() != null) {
                     StoreInfo storeInfo = storeInfoMapper.selectById(storeUser.getStoreId());
+                    resultMap.put("businessSection",storeInfo.getBusinessSection());
                     if (storeInfo != null && storeInfo.getStoreName() != null) {
                         // 使用店铺名称作为昵称
                         storeUser.setUserName(storeInfo.getStoreName());

+ 195 - 4
alien-store/src/main/java/shop/alien/store/service/impl/CommonCommentServiceImpl.java

@@ -1,17 +1,29 @@
 package shop.alien.store.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import shop.alien.entity.store.CommonComment;
-import shop.alien.mapper.CommonCommentMapper;
+import shop.alien.entity.store.*;
+import shop.alien.entity.store.vo.CommonCommentVo;
+import shop.alien.entity.store.vo.CommonRatingVo;
+import shop.alien.mapper.*;
 import shop.alien.store.service.CommonCommentService;
+import shop.alien.store.util.CommonConstant;
+import shop.alien.util.common.constant.CommentSourceTypeEnum;
 import shop.alien.util.common.safe.TextModerationResultVO;
 import shop.alien.util.common.safe.TextModerationUtil;
 
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+
 /**
  * 评论表 服务实现类
  *
@@ -27,9 +39,17 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
     @Autowired
     private TextModerationUtil textModerationUtil;
 
+    private final CommonCommentMapper commonCommentMapper;
+    private final LifeUserDynamicsMapper lifeUserDynamicsMapper;
+    private final LifeLikeRecordMapper lifeLikeRecordMapper;
+    private final StoreUserMapper storeUserMapper;
+    private final LifeUserViolationMapper lifeUserViolationMapper;
+    private final LifeUserMapper lifeUserMapper;
+
+
     /**
      * 新增评论
-     * 
+     *
      * @param commonComment 评论对象
      * @return 0:成功, 1:失败, 2:文本内容异常, 4:字数超限(超过300字)
      */
@@ -40,7 +60,7 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
             log.warn("评论内容超过300字限制,content length={}", commonComment.getContent().length());
             return 4; // 字数超限
         }
-        
+
         // 文本内容审核
         TextModerationResultVO textCheckResult = null;
         try {
@@ -54,6 +74,177 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
             return 1;
         }
     }
+
+    @Override
+    public List<CommonCommentVo> getListBySourceType(Integer sourceType, Integer sourceId, Integer pageNum, Integer pageSize, Long userId) {
+        String likeType = null;
+        if(sourceType == CommentSourceTypeEnum.STORE_COMMENT.getType()){
+            likeType = CommonConstant.COMMENT_LIKE;
+        } else if (sourceType == CommentSourceTypeEnum.DYNAMIC_COMMENT.getType()) {
+            likeType = CommonConstant.DYNAMIC_LIKE;
+        }
+        List<CommonCommentVo> firstLevelComment = getFirstLevelComment(sourceType, sourceId, pageNum, pageSize, userId,likeType);
+        CommonRatingVo commonRatingVo = new CommonRatingVo();
+        getAllChildComment(userId, commonRatingVo, firstLevelComment,likeType);
+        return commonRatingVo.getChildCommonComments();
+    }
+
+    @Override
+    public List<CommonCommentVo> getFirstLevelComment(Integer sourceType, Integer sourceId, Integer pageNum, Integer pageSize, Long userId, String likeType){
+        List<CommonCommentVo> commonComments = null;
+        QueryWrapper<CommonCommentVo> commentWrapper = new QueryWrapper<CommonCommentVo>();
+        if(sourceType == CommentSourceTypeEnum.STORE_COMMENT.getType()){
+            // 1查询店铺评价
+            commentWrapper.eq("cc.source_type", CommentSourceTypeEnum.STORE_COMMENT.getType());
+
+        } else if (sourceType == CommentSourceTypeEnum.DYNAMIC_COMMENT.getType()) {
+            // 2查询动态评论
+            commentWrapper.eq("cc.source_type", CommentSourceTypeEnum.DYNAMIC_COMMENT.getType());
+        }
+        commentWrapper.eq("cc.source_id", sourceId)
+                .eq("cc.parent_id", 0);
+        Page<CommonCommentVo> page = null;
+        if( null != pageNum && null != pageSize){
+            page = new Page<>(pageNum, pageSize);
+        }
+        commonComments = commonCommentMapper.selectALlComment(page, commentWrapper, likeType, userId);
+        return commonComments;
+    }
+
+    @Override
+    public void getAllChildComment(Long userId, CommonRatingVo commonRatingVo, List<CommonCommentVo> commonComments, String likeType) {
+        // 定义评论总数
+        AtomicReference<Long> count = new AtomicReference<>(0L);
+        count.updateAndGet(v -> v + commonComments.size());
+        List<CommonCommentVo> commonCommentVos = new ArrayList<>();
+        for (CommonCommentVo commonComment : commonComments) {
+//                CommonCommentVo commonCommentVo = new CommonCommentVo();
+//                BeanUtils.copyProperties(commonComment, commonCommentVo);
+            // 递归获取所有子评论(扁平化)
+            List<CommonCommentVo> allChildComments = getChildCommentsRecursively(commonComment.getId(), userId,likeType);
+            count.updateAndGet(v -> v + allChildComments.size());
+            // 一级评论本身的商家/用户标识和商家信息
+            // setStoreUserInfo(first);
+
+            // 按时间排序后绑定子评论列表
+            allChildComments.sort(Comparator.comparing(CommonCommentVo::getCreatedTime));
+
+            commonComment.setChildCommonComments(allChildComments);
+            commonCommentVos.add(commonComment);
+        }
+        commonRatingVo.setCommentCount(count.get());
+        commonRatingVo.setChildCommonComments(commonCommentVos);
+    }
+
+    /**
+     * 动态评论数量 目前给的是动态用的接口,可以根据sorceType返回不同数据
+     * @param sourceId
+     * @param sourceType
+     * @param userId
+     * @return
+     */
+    @Override
+    public Map<String, Object> getCommitCount(Integer sourceId, Integer sourceType, String userId, String userType) {
+        // 返回分享数,喜欢数,评论数
+        Map<String, Object> map = new HashMap<>();
+        // 计算评论数
+        QueryWrapper<CommonComment> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq(null != sourceId, "source_id", sourceId);
+        queryWrapper.eq(null != sourceType, "source_type", sourceType);
+        //通过当前登录人id和类型 查询举报业务id 不包含已举报的
+        List<LifeUserViolation> lifeUserViolations = new ArrayList<>();
+        if(sourceType == CommentSourceTypeEnum.DYNAMIC_COMMENT.getType() ){
+            if("user".equals(userType)){
+                LifeUser lifeUser = lifeUserMapper.selectOne(new LambdaQueryWrapper<LifeUser>().eq(LifeUser::getId,userId));
+                if(lifeUser!=null){
+                    LambdaQueryWrapper<LifeUserViolation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    lambdaQueryWrapper.eq(LifeUserViolation::getReportingUserId,lifeUser.getId());
+                    lambdaQueryWrapper.eq(LifeUserViolation::getReportingUserType,2);
+                    lambdaQueryWrapper.ne(LifeUserViolation::getProcessingStatus,2);
+                    lifeUserViolations = lifeUserViolationMapper.selectList(lambdaQueryWrapper);
+                }
+            } else {
+                StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getId,userId));
+                if(storeUser!=null){
+                    LambdaQueryWrapper<LifeUserViolation> lambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    lambdaQueryWrapper.eq(LifeUserViolation::getReportingUserId,storeUser.getId());
+                    lambdaQueryWrapper.eq(LifeUserViolation::getReportingUserType,1);
+                    lambdaQueryWrapper.ne(LifeUserViolation::getProcessingStatus,2);
+                    lifeUserViolations = lifeUserViolationMapper.selectList(lambdaQueryWrapper);
+                }
+            }
+        }
+        List<Integer> businessIds = lifeUserViolations.stream()
+                .filter(Objects::nonNull)
+                .map(LifeUserViolation::getBusinessId)
+                .filter(id -> id != null && !id.toString().isEmpty())
+                .collect(Collectors.toList());
+        if(businessIds!=null && businessIds.size()>0){
+            queryWrapper.notIn("id",businessIds);
+        }
+
+        Integer i = commonCommentMapper.selectCount(queryWrapper);
+        map.put("commentCount", i);
+        getOtherDataWithSourceType(sourceId, sourceType, userId, map);
+        return map;
+    }
+
+    private void getOtherDataWithSourceType(Integer sourceId, Integer sourceType, String userId, Map<String, Object> map) {
+        if ( sourceType == CommentSourceTypeEnum.DYNAMIC_COMMENT.getType() ) {
+            // 计算分析数和喜欢数
+            LifeUserDynamics lifeUserDynamics = lifeUserDynamicsMapper.selectOne(new QueryWrapper<LifeUserDynamics>().eq("id", sourceId));
+            if(null != lifeUserDynamics){
+                map.put("likeCount",lifeUserDynamics.getDianzanCount());
+                map.put("transferCount",lifeUserDynamics.getTransferCount());
+            } else {
+                map.put("likeCount",0);
+                map.put("transferCount",0);
+            }
+            // 查询商家头像 TODO -> 动态发布的时候id不应该用Store_phone的格式,来不及重构动态的位置,后续等有缘人吧
+            StoreUser storeUser = storeUserMapper.selectOne(new QueryWrapper<StoreUser>().eq("phone", lifeUserDynamics.getPhoneId().split("_")[1]));
+            map.put("userImage",storeUser.getHeadImg()!= null?storeUser.getHeadImg():"");
+            // 查询当前用户是否喜欢
+            LifeLikeRecord lifeLikeRecord = lifeLikeRecordMapper.selectOne(new QueryWrapper<LifeLikeRecord>()
+                    .eq("type", CommonConstant.LIKE_TYPE_DYNAMICS)
+                    .eq("dianzan_id", userId)
+                    .eq("huifu_id", sourceId)
+                    .eq("delete_flag", 0));
+            if(null != lifeLikeRecord){
+                map.put("isLike",1);
+            } else {
+                map.put("isLike",0);
+            }
+        }
+    }
+
+    private List<CommonCommentVo> getChildCommentsRecursively(Long id, Long userId, String likeType) {
+        List<CommonCommentVo> allChildComments = new ArrayList<>();
+
+        // 查询直接回复当前评论的所有记录
+        QueryWrapper<CommonCommentVo> wrapper = new QueryWrapper<>();
+        wrapper.eq("cc.delete_flag", 0)
+                .eq("cc.parent_id", id)
+                .orderByAsc("cc.created_time");
+        List<CommonCommentVo> directChildren = commonCommentMapper.selectALlComment(null,wrapper,likeType, userId);
+
+        if (CollectionUtils.isEmpty(directChildren)) {
+            return allChildComments;
+        }
+        // 处理每个直接子评论
+        for (CommonCommentVo child : directChildren) {
+            // 设置商家/用户标识
+//            setStoreUserInfo(child);
+            // 递归获取该子评论的所有子评论
+            List<CommonCommentVo> grandChildren = getChildCommentsRecursively(child.getId(), userId,likeType);
+            // 将当前子评论添加到结果列表
+            allChildComments.add(child);
+            // 将该子评论的所有子评论也添加到结果列表(扁平化)
+            allChildComments.addAll(grandChildren);
+        }
+
+        return allChildComments;
+    }
+
 //
 //    @Override
 //    public IPage<CommonComment> getCommentList(Integer pageNum, Integer pageSize, Integer sourceType, Long sourceId, Long parentId, Integer commentType, Integer auditStatus) {

+ 51 - 100
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -27,6 +27,7 @@ import shop.alien.entity.store.vo.WebSocketVo;
 import shop.alien.mapper.*;
 import shop.alien.entity.store.TagsSynonym;
 import shop.alien.store.config.WebSocketProcess;
+import shop.alien.store.service.CommonCommentService;
 import shop.alien.store.service.CommonRatingService;
 import shop.alien.store.util.CommonConstant;
 import shop.alien.util.common.constant.CommentSourceTypeEnum;
@@ -70,6 +71,8 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
     private final LifeCollectMapper lifeCollectMapper;
     private final LifeFansMapper lifeFansMapper;
     private final TagsSynonymMapper tagsSynonymMapper;
+    private final CommonCommentService commonCommentService;
+
 
 
     public static final List<String> SERVICES_LIST = ImmutableList.of(
@@ -220,7 +223,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                      .eq(TagsSynonym::getDeleteFlag, 0)
                      .isNotNull(TagsSynonym::getCommentId);  // 确保comment_id不为空
             List<TagsSynonym> tagsSynonymList = tagsSynonymMapper.selectList(tagWrapper);
-            
+
             if (CollectionUtils.isNotEmpty(tagsSynonymList)) {
                 // 2. 提取评论ID列表(common_comment.id)
                 List<Long> commentIdList = tagsSynonymList.stream()
@@ -228,7 +231,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                         .map(synonym -> synonym.getCommentId().longValue())
                         .distinct()
                         .collect(Collectors.toList());
-                
+
                 if (CollectionUtils.isNotEmpty(commentIdList)) {
                     // 3. 通过评论ID查询common_comment表,获取source_id(评价ID)
                     LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<>();
@@ -237,7 +240,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                                  .eq(CommonComment::getIsShow, 1)
                                  .eq(CommonComment::getAuditStatus, 1);
                     List<CommonComment> comments = commonCommentMapper.selectList(commentWrapper);
-                    
+
                     if (CollectionUtils.isNotEmpty(comments)) {
                         // 4. 提取评价ID列表(common_comment.source_id = common_rating.id)
                         List<Long> ratingIdList = comments.stream()
@@ -245,7 +248,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                                 .map(CommonComment::getSourceId)
                                 .distinct()
                                 .collect(Collectors.toList());
-                        
+
                         if (CollectionUtils.isNotEmpty(ratingIdList)) {
                             wrapper.in(CommonRating::getId, ratingIdList);
                         } else {
@@ -265,11 +268,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 wrapper.eq(CommonRating::getId, -1);
             }
         }
-        
+
         wrapper.eq(CommonRating::getIsShow, 1);
         wrapper.orderByDesc(CommonRating::getId);
         IPage<CommonRating> page1 = this.page(page, wrapper);
-        
+
         // 处理回复状态筛选
         return doListBusinessWithType(page1, businessType, userId, replyStatus);
     }
@@ -290,20 +293,20 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
         }
         // 获取评价统计信息(总评论数、有图评论数、好评数、中评数、差评数)
         ratingCount = commonRatingMapper.getRatingCount(new QueryWrapper<CommonRating>().in("id", collect));
-        
+
         // 计算好评、中评、差评占比
         // 注意:数据库返回的 count 可能是 BigDecimal、Long 或 Integer 类型,需要安全转换
         int goodCount = getIntValue(ratingCount.get("goodCount"));
         int midCount = getIntValue(ratingCount.get("midCount"));
         int badCount = getIntValue(ratingCount.get("badCount"));
         int totalCount = goodCount + midCount + badCount;
-        
+
         if (totalCount > 0) {
             // 计算占比(保留2位小数)
             Double goodPercent = Math.round((goodCount * 100.0 / totalCount) * 100.0) / 100.0;
             Double midPercent = Math.round((midCount * 100.0 / totalCount) * 100.0) / 100.0;
             Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
-            
+
             ratingCount.put("goodPercent", goodPercent);
             ratingCount.put("midPercent", midPercent);
             ratingCount.put("badPercent", badPercent);
@@ -312,7 +315,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             ratingCount.put("midPercent", 0.0);
             ratingCount.put("badPercent", 0.0);
         }
-        
+
         if(RatingBusinessTypeEnum.STORE_RATING.getBusinessType() == businessType){
             // 1店铺评分
             StoreInfo storeInfo = storeInfoMapper.selectById(businessId);
@@ -338,7 +341,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             List<Long> collect2 = commonRatings.stream().filter(i -> i.getScore() >= 4.5).map(CommonRating::getUserId).distinct().limit(6).collect(Collectors.toList());
             if(!collect2.isEmpty()) {
                 List<LifeUser> lifeUsers = lifeUserMapper.selectList(new QueryWrapper<LifeUser>().lambda().in(LifeUser::getId, collect2));
-                ratingCount.put("img", lifeUsers.stream().filter(x -> x.getUserImage() != null).map(LifeUser::getUserImage).collect(Collectors.toList()));
+                ratingCount.put("img", lifeUsers.stream().map(LifeUser::getUserImage).collect(Collectors.toList()));
             } else {
                 ratingCount.put("img", new ArrayList<>());
             }
@@ -435,64 +438,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 commonRatingVo.setIsCollect(0);
             }
             // 2查询一级评价
-            QueryWrapper<CommonCommentVo> commentWrapper = new QueryWrapper<CommonCommentVo>()
-                    .eq("cc.source_type", CommentSourceTypeEnum.STORE_COMMENT.getType())
-                    .eq("cc.source_id", ratingId)
-                    .eq("cc.parent_id", 0);
-            List<CommonCommentVo> commonComments = commonCommentMapper.selectALlComment(commentWrapper,CommonConstant.COMMENT_LIKE, userId);
-
-            // 定义评论总数
-            AtomicReference<Long> count = new AtomicReference<>(0L);
-            count.updateAndGet(v -> v + commonComments.size());
-            List<CommonCommentVo> commonCommentVos = new ArrayList<>();
-            for (CommonCommentVo commonComment : commonComments) {
-//                CommonCommentVo commonCommentVo = new CommonCommentVo();
-//                BeanUtils.copyProperties(commonComment, commonCommentVo);
-                // 递归获取所有子评论(扁平化)
-                List<CommonCommentVo> allChildComments = getChildCommentsRecursively(commonComment.getId(), userId);
-                count.updateAndGet(v -> v + allChildComments.size());
-                // 一级评论本身的商家/用户标识和商家信息
-                // setStoreUserInfo(first);
-
-                // 按时间排序后绑定子评论列表
-                allChildComments.sort(Comparator.comparing(CommonCommentVo::getCreatedTime));
-
-                commonComment.setChildCommonComments(allChildComments);
-                commonCommentVos.add(commonComment);
-            }
-            commonRatingVo.setCommentCount(count.get());
-            commonRatingVo.setChildCommonComments(commonCommentVos);
+            List<CommonCommentVo> commonComments = commonCommentService.getFirstLevelComment(CommentSourceTypeEnum.STORE_COMMENT.getType(), ratingId,null,null, userId,CommonConstant.COMMENT_LIKE);
+            commonCommentService.getAllChildComment(userId, commonRatingVo, commonComments,CommonConstant.COMMENT_LIKE);
         }
     }
 
-    private List<CommonCommentVo> getChildCommentsRecursively(Long id, Long userId) {
-        List<CommonCommentVo> allChildComments = new ArrayList<>();
-
-        // 查询直接回复当前评论的所有记录
-        QueryWrapper<CommonCommentVo> wrapper = new QueryWrapper<>();
-        wrapper.eq("cc.delete_flag", 0)
-                .eq("cc.parent_id", id)
-                .orderByAsc("cc.created_time");
-        List<CommonCommentVo> directChildren = commonCommentMapper.selectALlComment(wrapper,CommonConstant.COMMENT_LIKE, userId);
-
-        if (CollectionUtils.isEmpty(directChildren)) {
-            return allChildComments;
-        }
-        // 处理每个直接子评论
-        for (CommonCommentVo child : directChildren) {
-            // 设置商家/用户标识
-//            setStoreUserInfo(child);
-            // 递归获取该子评论的所有子评论
-            List<CommonCommentVo> grandChildren = getChildCommentsRecursively(child.getId(), userId);
-            // 将当前子评论添加到结果列表
-            allChildComments.add(child);
-            // 将该子评论的所有子评论也添加到结果列表(扁平化)
-            allChildComments.addAll(grandChildren);
-        }
-
-        return allChildComments;
-    }
-
     @NotNull
     private Integer getAllCommentsOnCommentsNum(List<Long> collect1) {
         LambdaQueryWrapper<CommonComment> commentReplyWrapper = new LambdaQueryWrapper<CommonComment>()
@@ -522,7 +472,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 result.setRecords(resultList);
                 return R.data(result);
             }
-            
+
             // 1. 查询评价用户信息
             Set<Long> userIdSet = page1.getRecords().stream()
                     .map(CommonRating::getUserId)
@@ -536,7 +486,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 lifeUserMap = lifeUsers.stream()
                         .collect(Collectors.toMap(LifeUser::getId, Function.identity()));
             }
-            
+
             // 2. 查询当前用户点赞列表(仅评价)
             List<LifeLikeRecord> lifeLikeRecords = new ArrayList<>();
             Map<String, LifeLikeRecord> likeRecordMap = new HashMap<>();
@@ -553,7 +503,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             Set<Long> ratingIdSet = page1.getRecords().stream()
                     .map(CommonRating::getId)
                     .collect(Collectors.toSet());
-            
+
             // 查询所有评论(用于统计评论数)
             LambdaQueryWrapper<CommonComment> commentWrapper = new LambdaQueryWrapper<>();
             commentWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
@@ -561,7 +511,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                          .eq(CommonComment::getIsShow, 1)
                          .eq(CommonComment::getAuditStatus, 1);
             List<CommonComment> allComments = commonCommentMapper.selectList(commentWrapper);
-            
+
             // 评价ID -> 该评价下的总评论数
             Map<Long, Long> ratingCommentCountMap = allComments.stream()
                     .collect(Collectors.groupingBy(CommonComment::getSourceId, Collectors.counting()));
@@ -578,14 +528,15 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                                    .eq("cc.audit_status", 1)
                                    .eq("cc.delete_flag", 0)
                                    .orderByDesc("cc.created_time");
-                
+
                 // 查询所有商户回复(包含用户信息)
                 List<CommonCommentVo> merchantReplies = commonCommentMapper.selectALlComment(
-                    merchantReplyWrapper, 
-                    CommonConstant.COMMENT_LIKE, 
+                        null,
+                    merchantReplyWrapper,
+                    CommonConstant.COMMENT_LIKE,
                     userId != null ? userId : 0L
                 );
-                
+
                 // 按评价ID分组,每组只取最新的一条(已按时间倒序排序)
                 if (CollectionUtils.isNotEmpty(merchantReplies)) {
                     for (CommonCommentVo reply : merchantReplies) {
@@ -602,23 +553,23 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             for (CommonRating record : page1.getRecords()) {
                 CommonRatingVo commonRatingVo = new CommonRatingVo();
                 BeanUtil.copyProperties(record, commonRatingVo);
-                
+
                 // 设置用户信息
                 if(lifeUserMap.containsKey(Integer.parseInt(record.getUserId().toString()))){
                     LifeUser lifeUser = lifeUserMap.get(Integer.parseInt(record.getUserId().toString()));
                     commonRatingVo.setUserImage(lifeUser.getUserImage());
                     commonRatingVo.setUserName(lifeUser.getUserName());
                 }
-                
+
                 // 设置点赞状态
                 commonRatingVo.setIsLike(0);
                 if(likeRecordMap.containsKey(record.getId().toString())){
                     commonRatingVo.setIsLike(1);
                 }
-                
+
                 // 设置评论数
                 commonRatingVo.setCommentCount(ratingCommentCountMap.getOrDefault(record.getId(), 0L));
-                
+
                 // 设置商户最新回复(同一评价下,商家只显示最新的一条回复)
                 CommonCommentVo latestMerchantReply = latestMerchantReplyMap.get(record.getId());
                 if (latestMerchantReply != null) {
@@ -628,10 +579,10 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                     // 没有商户回复,设置为空列表
                     commonRatingVo.setChildCommonComments(new ArrayList<>());
                 }
-                
+
                 resultList.add(commonRatingVo);
             }
-            
+
             result.setRecords(resultList);
             return R.data(result);
         }
@@ -666,11 +617,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
         
         return (long) this.count(wrapper);
     }*/
-    
+
     /**
      * 安全地将数据库返回的数值类型转换为 int
      * 支持 BigDecimal、Long、Integer、Number 等类型
-     * 
+     *
      * @param value 数据库返回的数值对象
      * @return int 值,如果为 null 或无法转换则返回 0
      */
@@ -678,11 +629,11 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
         if (value == null) {
             return 0;
         }
-        
+
         if (value instanceof Number) {
             return ((Number) value).intValue();
         }
-        
+
         // 尝试字符串转换
         try {
             if (value instanceof String) {
@@ -691,7 +642,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
         } catch (NumberFormatException e) {
             log.warn("无法将值转换为 int: {}", value, e);
         }
-        
+
         return 0;
     }
 
@@ -705,9 +656,9 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
     @Override
     public RatingPercentVo getRatingPercent(Integer businessId, Integer businessType) {
         log.info("CommonRatingServiceImpl.getRatingPercent?businessId={}&businessType={}", businessId, businessType);
-        
+
         RatingPercentVo vo = new RatingPercentVo();
-        
+
         // 1. 查询全部评价记录(仅展示的、审核通过的)
         LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(CommonRating::getBusinessId, businessId);
@@ -715,7 +666,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
         wrapper.eq(CommonRating::getIsShow, 1);
         wrapper.eq(CommonRating::getAuditStatus, 1);  // 仅统计审核通过的
         List<CommonRating> commonRatings = commonRatingMapper.selectList(wrapper);
-        
+
         // 如果为空,返回默认值
         if (CollectionUtils.isEmpty(commonRatings)) {
             vo.setTotalRatingCount(0);
@@ -729,32 +680,32 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             vo.setReplyRate(0.0);
             return vo;
         }
-        
+
         List<Long> ratingIdList = commonRatings.stream()
                 .map(CommonRating::getId)
                 .collect(Collectors.toList());
-        
+
         // 2. 获取评价统计信息(好评、中评、差评数量)
         Map<String, Object> ratingCount = commonRatingMapper.getRatingCount(
                 new QueryWrapper<CommonRating>().in("id", ratingIdList));
-        
+
         // 3. 计算好评、中评、差评数量和占比
         int goodCount = getIntValue(ratingCount.get("goodCount"));
         int midCount = getIntValue(ratingCount.get("midCount"));
         int badCount = getIntValue(ratingCount.get("badCount"));
         int totalCount = goodCount + midCount + badCount;
-        
+
         vo.setTotalRatingCount(totalCount);
         vo.setGoodCount(goodCount);
         vo.setMidCount(midCount);
         vo.setBadCount(badCount);
-        
+
         // 计算占比(保留2位小数)
         if (totalCount > 0) {
             Double goodPercent = Math.round((goodCount * 100.0 / totalCount) * 100.0) / 100.0;
             Double midPercent = Math.round((midCount * 100.0 / totalCount) * 100.0) / 100.0;
             Double badPercent = Math.round((badCount * 100.0 / totalCount) * 100.0) / 100.0;
-            
+
             vo.setGoodPercent(goodPercent);
             vo.setMidPercent(midPercent);
             vo.setBadPercent(badPercent);
@@ -763,7 +714,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             vo.setMidPercent(0.0);
             vo.setBadPercent(0.0);
         }
-        
+
         // 4. 计算回复率
         // 查询已回复的评价数(存在商户评论 comment_type=2, parent_id=0)
         LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
@@ -773,26 +724,26 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                      .eq(CommonComment::getParentId, 0)     // 根评论(直接回复评价)
                      .eq(CommonComment::getIsShow, 1)
                      .eq(CommonComment::getAuditStatus, 1);
-        
+
         // 获取已回复的评价ID列表(去重)
         Set<Long> repliedRatingIds = commonCommentMapper.selectList(repliedWrapper).stream()
                 .map(CommonComment::getSourceId)
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
-        
+
         int repliedCount = repliedRatingIds.size();
         vo.setRepliedCount(repliedCount);
-        
+
         // 计算回复率(保留2位小数)
         Double replyRate = 0.0;
         if (totalCount > 0) {
             replyRate = Math.round((repliedCount * 100.0 / totalCount) * 100.0) / 100.0;
         }
         vo.setReplyRate(replyRate);
-        
+
         log.info("CommonRatingServiceImpl.getRatingPercent result: totalCount={}, goodCount={}, midCount={}, badCount={}, repliedCount={}, replyRate={}%",
                 totalCount, goodCount, midCount, badCount, repliedCount, replyRate);
-        
+
         return vo;
     }
 }

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

@@ -82,6 +82,8 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
 
     @Autowired
     private TextModerationUtil textModerationUtil;
+    @Autowired
+    private CommonCommentMapper commonCommentMapper;
 
     /**
      * 评论列表

+ 1 - 0
alien-store/src/main/java/shop/alien/store/util/CommonConstant.java

@@ -111,4 +111,5 @@ public class CommonConstant {
     public static final String LIKE_TYPE_STORE = "9";
     public static final String RATING_LIKE = "11";
     public static final String COMMENT_LIKE = "12";
+    public static final String DYNAMIC_LIKE = "13";
 }

+ 2 - 2
alien-util/src/main/java/shop/alien/util/common/constant/CommentSourceTypeEnum.java

@@ -2,8 +2,8 @@ package shop.alien.util.common.constant;
 
 
 public enum CommentSourceTypeEnum {
-    STORE_COMMENT(1, "店铺评价");
-
+    STORE_COMMENT(1, "店铺评价"),
+    DYNAMIC_COMMENT(2, "动态评论");
     private final Integer type;
     private final String info;