Pārlūkot izejas kodu

Merge branch 'fix-panzhilin' into sit

# Conflicts:
#	alien-store/src/main/java/shop/alien/store/service/impl/CommonCommentServiceImpl.java
panzhilin 2 mēneši atpakaļ
vecāks
revīzija
1e82ce9adb

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/CommonRatingVo.java

@@ -38,4 +38,8 @@ public class CommonRatingVo extends CommonRating {
     private Long commentCount;
     @ApiModelProperty(name = "isFollow", value = "是否关注")
     private Integer isFollow;
+    @ApiModelProperty(name = "appealStatus", value = "申诉状态:null-未申诉, 0-待处理, 1-已驳回, 2-已同意, 3-处理中")
+    private Integer appealStatus;
+    @ApiModelProperty(name = "appealFlag", value = "是否已申诉:0-未申诉, 1-已申诉")
+    private Integer appealFlag;
 }

+ 2 - 2
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreCommentAppealVo.java

@@ -35,10 +35,10 @@ public class StoreCommentAppealVo extends StoreCommentAppeal {
     private String commentContent;
 
     @ApiModelProperty(value = "顾客评论星级")
-    private Integer commentStar;
+    private Double commentStar;
 
     @ApiModelProperty(value = "评分")
-    private String score;
+    private Double score;
 
     @ApiModelProperty(value = "其他评分")
     private String otherScore;

+ 32 - 11
alien-entity/src/main/java/shop/alien/mapper/CommonCommentMapper.java

@@ -7,6 +7,7 @@ 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;
+import org.apache.ibatis.annotations.Update;
 import shop.alien.entity.store.CommonComment;
 import shop.alien.entity.store.vo.CommonCommentVo;
 
@@ -22,17 +23,26 @@ import java.util.List;
 public interface CommonCommentMapper extends BaseMapper<CommonComment> {
 
 
-    @Select("select *,if(comment_type = 1,lu.user_image,su.head_img) headImg,\n" +
-            "if(comment_type = 1,lu.user_name ,su.nick_name ) headName," +
-            "if(llr.dianzan_id is null,'0','1') isLike\n" +
-            "from common_comment cc\n" +
-            "left join life_user lu on cc.user_id = lu.id and lu.delete_flag = 0\n" +
-            "left join store_user su on cc.merchant_id = su.store_id and su.delete_flag = 0\n" +
-            "left join life_like_record llr on\n" +
-            "llr.huifu_id = cc.id\n" +
-            "and llr.`type` = #{type}\n" +
-            "and llr.dianzan_id = #{dianzanId}\n" +
-            "and llr.delete_flag = 0\n" +
+    /**
+     * 查询评论列表(含用户/商户信息)
+     * 
+     * 关联说明:
+     * - 用户评论(comment_type=1):关联 life_user 表获取用户头像和昵称
+     * - 商户评论(comment_type=2):关联 store_user 表获取商户头像和昵称
+     *   (通过子查询取每个店铺的主账号记录,即 id 最小的记录)
+     */
+    @Select("SELECT cc.*, " +
+            "IF(cc.comment_type = 1, lu.user_image, su.head_img) AS headImg, " +
+            "IF(cc.comment_type = 1, lu.user_name, su.nick_name) AS headName, " +
+            "IF(llr.dianzan_id IS NULL, '0', '1') AS isLike " +
+            "FROM common_comment cc " +
+            "LEFT JOIN life_user lu ON cc.user_id = lu.id AND lu.delete_flag = 0 " +
+            "LEFT JOIN store_user su ON cc.merchant_id = su.store_id AND su.delete_flag = 0 " +
+            "AND su.id = (SELECT MIN(su2.id) FROM store_user su2 WHERE su2.store_id = cc.merchant_id AND su2.delete_flag = 0) " +
+            "LEFT JOIN life_like_record llr ON llr.huifu_id = cc.id " +
+            "AND llr.`type` = #{type} " +
+            "AND llr.dianzan_id = #{dianzanId} " +
+            "AND llr.delete_flag = 0 " +
             "${ew.customSqlSegment}")
     List<CommonCommentVo> selectALlComment(@Param("page") Page<CommonCommentVo> page,
                                            @Param(Constants.WRAPPER)QueryWrapper<CommonCommentVo> wrapper,
@@ -46,5 +56,16 @@ public interface CommonCommentMapper extends BaseMapper<CommonComment> {
             "and cc.delete_flag = 0\n" +
             "group by source_id")
     List<CommonCommentVo> getCommentCount(Integer type);
+
+    /**
+     * 批量逻辑删除评论(使用原生 SQL 绕过 @TableLogic 注解限制)
+     *
+     * @param sourceType 来源类型
+     * @param sourceId   来源ID(评价ID)
+     * @return 影响行数
+     */
+    @Update("UPDATE common_comment SET delete_flag = 1, updated_time = NOW() " +
+            "WHERE source_type = #{sourceType} AND source_id = #{sourceId} AND delete_flag = 0")
+    int logicDeleteBySourceId(@Param("sourceType") Integer sourceType, @Param("sourceId") Integer sourceId);
 }
 

+ 10 - 0
alien-entity/src/main/java/shop/alien/mapper/CommonRatingMapper.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 import shop.alien.entity.store.CommonRating;
 import shop.alien.entity.store.vo.StoreInfoScoreVo;
 
@@ -57,5 +58,14 @@ public interface CommonRatingMapper extends BaseMapper<CommonRating> {
             "    common_rating\n" +
             "   ${ew.customSqlSegment}\n")
     Map<String, Object> getRatingCount(@Param(Constants.WRAPPER) QueryWrapper<CommonRating> wrapper);
+
+    /**
+     * 逻辑删除评价(使用原生 SQL 绕过 @TableLogic 注解限制)
+     *
+     * @param id 评价ID
+     * @return 影响行数
+     */
+    @Update("UPDATE common_rating SET delete_flag = 1, updated_time = NOW() WHERE id = #{id}")
+    int logicDeleteById(@Param("id") Integer id);
 }
 

+ 17 - 14
alien-entity/src/main/java/shop/alien/mapper/StoreCommentAppealMapper.java

@@ -23,15 +23,16 @@ public interface StoreCommentAppealMapper extends BaseMapper<StoreCommentAppeal>
 
     /**
      * 申诉历史-分页查询
+     * 注意:comment_id 关联的是 common_rating.id(评价ID),不是 store_comment.id
      *
      * @param page         分页参数
      * @param queryWrapper 查询条件
      * @return IPage<StoreCommentAppealVo>
      */
-    @Select("select a.*, b.dict_detail appeal_status_str, c.comment_content, c.comment_star, c.score score, c.other_score,c.is_anonymous,c.img_id commentImgId, d.user_name, d.user_image, e.store_name, f.phone store_phone, f.name store_contact, e.store_type " +
+    @Select("select a.*, b.dict_detail appeal_status_str, c.content comment_content, c.score comment_star, c.score score, c.other_score, c.is_anonymous, c.image_urls commentImgId, d.user_name, d.user_image, e.store_name, f.phone store_phone, f.name store_contact, e.store_type " +
             "from store_comment_appeal a " +
             "left join store_dictionary b on a.appeal_status = b.dict_id and b.type_name = 'appealStatus' and b.delete_flag = 0 " +
-            "left join store_comment c on a.comment_id = c.id " +
+            "left join common_rating c on a.comment_id = c.id and c.delete_flag = 0 " +
             "left join life_user d on c.user_id = d.id and d.delete_flag = 0 " +
             "left join store_info e on a.store_id = e.id and e.delete_flag = 0 " +
             "Left join store_user f on e.id = f.store_id and f.delete_flag = 0 ${ew.customSqlSegment}")
@@ -39,43 +40,45 @@ public interface StoreCommentAppealMapper extends BaseMapper<StoreCommentAppeal>
 
     /**
      * 申诉历史-全部查询
+     * 注意:comment_id 关联的是 common_rating.id(评价ID),不是 store_comment.id
      *
      * @param queryWrapper 查询条件
-     * @return IPage<StoreCommentAppealVo>
+     * @return List<StoreCommentAppealVo>
      */
-    @Select("select a.*, b.dict_detail appeal_status_str, c.comment_content, c.comment_star, d.user_name, d.user_image, e.store_name, f.phone store_phone, f.name store_contact, e.store_type from store_comment_appeal a " +
-            "left join store_dictionary b on a.appeal_status = b.dict_id and b.type_name = 'appealStatus' " +
-            "left join store_comment c on a.comment_id = c.id " +
+    @Select("select a.*, b.dict_detail appeal_status_str, c.content comment_content, c.score comment_star, d.user_name, d.user_image, e.store_name, f.phone store_phone, f.name store_contact, e.store_type from store_comment_appeal a " +
+            "left join store_dictionary b on a.appeal_status = b.dict_id and b.type_name = 'appealStatus' and b.delete_flag = 0 " +
+            "left join common_rating c on a.comment_id = c.id and c.delete_flag = 0 " +
             "left join life_user d on c.user_id = d.id  and d.delete_flag = 0 " +
-            "left join store_info e on a.store_id = e.id " +
+            "left join store_info e on a.store_id = e.id and e.delete_flag = 0 " +
             "Left join store_user f on e.id = f.store_id and f.delete_flag = 0 ${ew.customSqlSegment}")
     List<StoreCommentAppealVo> getStoreCommentAppealPage(@Param(Constants.WRAPPER) QueryWrapper<StoreCommentAppealVo> queryWrapper);
 
     /**
      * 申诉详情
+     * 注意:comment_id 关联的是 common_rating.id(评价ID),不是 store_comment.id
      *
      * @param queryWrapper 查询条件
      * @return StoreCommentAppealVo
      */
-    @Select("select a.*, b.dict_detail appeal_status_str, c.comment_content, c.score, c.other_score, a.created_time comment_time, c.comment_star,c.is_anonymous,c.img_id commentImgId, d.user_name, e.phone store_phone, d.user_name userName, d.user_image userImage " +
+    @Select("select a.*, b.dict_detail appeal_status_str, c.content comment_content, c.score, c.other_score, a.created_time comment_time, c.score comment_star, c.is_anonymous, c.image_urls commentImgId, d.user_name, e.phone store_phone, d.user_name userName, d.user_image userImage " +
             "from store_comment_appeal a " +
-            "left join store_dictionary b on a.appeal_status = b.dict_id and b.type_name = 'appealStatus' " +
-            "left join store_comment c on a.comment_id = c.id  " +
+            "left join store_dictionary b on a.appeal_status = b.dict_id and b.type_name = 'appealStatus' and b.delete_flag = 0 " +
+            "left join common_rating c on a.comment_id = c.id and c.delete_flag = 0 " +
             "left join life_user d on c.user_id = d.id and d.delete_flag = 0 " +
             "left join store_user e on a.store_id = e.store_id and e.delete_flag = 0  ${ew.customSqlSegment}")
     StoreCommentAppealVo getCommentDetail(@Param(Constants.WRAPPER) QueryWrapper<StoreCommentAppealVo> queryWrapper);
 
 
     /**
-     * 申诉列表
+     * 申诉列表(平台端使用)
+     * 注意:comment_id 关联的是 common_rating.id(评价ID),不是 store_comment.id
      *
      * @return List<Map < String, Object>>
      */
-    @Select("SELECT sca.id, sca.appeal_reason, sca.appeal_status, sc.comment_content, si.img_url, sci.user_img_url, sc.id comment_id, sc.business_id " +
+    @Select("SELECT sca.id, sca.appeal_reason, sca.appeal_status, cr.content comment_content, si.img_url, cr.image_urls user_img_url, cr.id comment_id, cr.business_id " +
             "FROM store_comment_appeal sca " +
-            "LEFT JOIN store_comment sc ON sca.comment_id = sc.id " +
+            "LEFT JOIN common_rating cr ON sca.comment_id = cr.id AND cr.delete_flag = 0 " +
             "LEFT JOIN store_img si ON sca.img_id = si.id " +
-            "LEFT JOIN (SELECT sc.id id, si.img_url user_img_url FROM store_comment sc LEFT JOIN store_img si ON sc.img_id = si.id AND sc.delete_flag = 0) sci ON sci.id = sca.comment_id " +
             "WHERE sca.appeal_status = 0 and record_id is null AND sca.delete_flag = 0")
     List<Map<String, Object>> getAppealList();
 

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

@@ -68,19 +68,6 @@ public class CommonRatingController {
         return R.data(commonRatingService.getRatingCount(businessId, businessType));
     }
 
-    @ApiOperation("获取回复率和评价比例(商户端)")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name = "businessId", value = "业务ID(店铺ID)", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "businessType", value = "业务类型:1-店铺评价", dataType = "Integer", paramType = "query", required = true)
-    })
-    @GetMapping("/getRatingPercent")
-    public R<shop.alien.entity.store.vo.RatingPercentVo> getRatingPercent(
-            @RequestParam Integer businessId,
-            @RequestParam Integer businessType) {
-        log.info("CommonRatingController.getRatingPercent?businessId={}&businessType={}", businessId, businessType);
-        return R.data(commonRatingService.getRatingPercent(businessId, businessType));
-    }
-
 //
 //    @ApiOperation("根据ID获取评价详情")
 //    @ApiImplicitParam(name = "id", value = "评价ID", dataType = "Long", paramType = "path", required = true)

+ 0 - 9
alien-store/src/main/java/shop/alien/store/service/CommonRatingService.java

@@ -54,15 +54,6 @@ public interface CommonRatingService extends IService<CommonRating> {
      */
     Object getRatingDetail(Integer ratingId, Long userId);
 
-    /**
-     * 获取回复率和评价比例
-     *
-     * @param businessId   业务ID(店铺ID)
-     * @param businessType 业务类型:1-店铺评价
-     * @return 回复率和评价比例信息
-     */
-    shop.alien.entity.store.vo.RatingPercentVo getRatingPercent(Integer businessId, Integer businessType);
-
 
   /*  /**
      * 根据业务类型和业务ID获取平均评分

+ 75 - 103
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -21,7 +21,6 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.*;
 import shop.alien.entity.store.vo.CommonCommentVo;
 import shop.alien.entity.store.vo.CommonRatingVo;
-import shop.alien.entity.store.vo.RatingPercentVo;
 import shop.alien.entity.store.vo.StoreInfoScoreVo;
 import shop.alien.entity.store.vo.WebSocketVo;
 import shop.alien.mapper.*;
@@ -72,6 +71,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
     private final LifeFansMapper lifeFansMapper;
     private final TagsSynonymMapper tagsSynonymMapper;
     private final CommonCommentService commonCommentService;
+    private final StoreCommentAppealMapper storeCommentAppealMapper;
 
 
 
@@ -348,6 +348,30 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 ratingCount.put("img", new ArrayList<>());
             }
 
+            // 4. 计算回复率(已回复的评价数 / 总评价数)
+            LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
+            repliedWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
+                         .in(CommonComment::getSourceId, collect)
+                         .eq(CommonComment::getCommentType, 2)  // 商户评论
+                         .eq(CommonComment::getParentId, 0)     // 根评论(直接回复评价)
+                         .eq(CommonComment::getDeleteFlag, 0);  // 未删除
+
+            // 获取已回复的评价ID列表(去重)
+            Set<Long> repliedRatingIds = commonCommentMapper.selectList(repliedWrapper).stream()
+                    .map(CommonComment::getSourceId)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toSet());
+
+            int repliedCount = repliedRatingIds.size();
+            ratingCount.put("repliedCount", repliedCount);
+
+            // 计算回复率(保留2位小数)
+            Double replyRate = 0.0;
+            int ratingTotalCount = collect.size();
+            if (ratingTotalCount > 0) {
+                replyRate = Math.round((repliedCount * 100.0 / ratingTotalCount) * 100.0) / 100.0;
+            }
+            ratingCount.put("replyRate", replyRate);
 
         }
         return ratingCount;
@@ -551,7 +575,44 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 }
             }
 
-            // 4. 组装评价列表数据
+            // 4. 查询申诉信息(关联 store_comment_appeal 表)
+            Map<Long, StoreCommentAppeal> appealMap = new HashMap<>();
+            if (!ratingIdSet.isEmpty()) {
+                // 将 Long 类型的评价ID转换为 Integer 类型(因为 comment_id 是 Integer)
+                List<Integer> ratingIdList = ratingIdSet.stream()
+                        .map(Long::intValue)
+                        .collect(Collectors.toList());
+                
+                // 查询申诉记录(comment_id 关联 common_rating.id)
+                LambdaQueryWrapper<StoreCommentAppeal> appealWrapper = new LambdaQueryWrapper<>();
+                appealWrapper.in(StoreCommentAppeal::getCommentId, ratingIdList)
+                            .eq(StoreCommentAppeal::getDeleteFlag, 0);
+                List<StoreCommentAppeal> appeals = storeCommentAppealMapper.selectList(appealWrapper);
+                
+                // 构建评价ID -> 申诉记录的映射(一个评价可能有多条申诉,取最新的一条)
+                if (CollectionUtils.isNotEmpty(appeals)) {
+                    // 按评价ID分组,每组只取最新的一条申诉记录
+                    Map<Integer, StoreCommentAppeal> tempAppealMap = new HashMap<>();
+                    for (StoreCommentAppeal appeal : appeals) {
+                        Integer commentId = appeal.getCommentId();
+                        if (commentId != null) {
+                            // 如果该评价还没有申诉记录,或者当前申诉记录更新,则更新
+                            if (!tempAppealMap.containsKey(commentId) || 
+                                (appeal.getUpdatedTime() != null && 
+                                 tempAppealMap.get(commentId).getUpdatedTime() != null &&
+                                 appeal.getUpdatedTime().after(tempAppealMap.get(commentId).getUpdatedTime()))) {
+                                tempAppealMap.put(commentId, appeal);
+                            }
+                        }
+                    }
+                    // 转换为 Long 类型的 key
+                    for (Map.Entry<Integer, StoreCommentAppeal> entry : tempAppealMap.entrySet()) {
+                        appealMap.put(entry.getKey().longValue(), entry.getValue());
+                    }
+                }
+            }
+
+            // 5. 组装评价列表数据
             for (CommonRating record : page1.getRecords()) {
                 CommonRatingVo commonRatingVo = new CommonRatingVo();
                 BeanUtil.copyProperties(record, commonRatingVo);
@@ -582,6 +643,18 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                     commonRatingVo.setChildCommonComments(new ArrayList<>());
                 }
 
+                // 设置申诉状态和申诉标识
+                StoreCommentAppeal appeal = appealMap.get(record.getId());
+                if (appeal != null) {
+                    // 已申诉,设置申诉状态
+                    commonRatingVo.setAppealStatus(appeal.getAppealStatus());
+                    commonRatingVo.setAppealFlag(1);
+                } else {
+                    // 未申诉
+                    commonRatingVo.setAppealStatus(null);
+                    commonRatingVo.setAppealFlag(0);
+                }
+
                 resultList.add(commonRatingVo);
             }
 
@@ -647,106 +720,5 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
 
         return 0;
     }
-
-    /**
-     * 获取回复率和评价比例
-     *
-     * @param businessId   业务ID(店铺ID)
-     * @param businessType 业务类型:1-店铺评价
-     * @return 回复率和评价比例信息
-     */
-    @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);
-        wrapper.eq(CommonRating::getBusinessType, businessType);
-        wrapper.eq(CommonRating::getIsShow, 1);
-        wrapper.eq(CommonRating::getAuditStatus, 1);  // 仅统计审核通过的
-        List<CommonRating> commonRatings = commonRatingMapper.selectList(wrapper);
-
-        // 如果为空,返回默认值
-        if (CollectionUtils.isEmpty(commonRatings)) {
-            vo.setTotalRatingCount(0);
-            vo.setGoodCount(0);
-            vo.setMidCount(0);
-            vo.setBadCount(0);
-            vo.setGoodPercent(0.0);
-            vo.setMidPercent(0.0);
-            vo.setBadPercent(0.0);
-            vo.setRepliedCount(0);
-            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);
-        } else {
-            vo.setGoodPercent(0.0);
-            vo.setMidPercent(0.0);
-            vo.setBadPercent(0.0);
-        }
-
-        // 4. 计算回复率
-        // 查询已回复的评价数(存在商户评论 comment_type=2, parent_id=0)
-        LambdaQueryWrapper<CommonComment> repliedWrapper = new LambdaQueryWrapper<>();
-        repliedWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
-                     .in(CommonComment::getSourceId, ratingIdList)
-                     .eq(CommonComment::getCommentType, 2)  // 商户评论
-                     .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;
-    }
 }
 

+ 23 - 20
alien-store/src/main/java/shop/alien/store/service/impl/StoreCommentAppealServiceImpl.java

@@ -354,13 +354,23 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
         }
         commentDetail.setImgList(imgList);
 
+        // 处理评价图片(common_rating.image_urls 已经是URL字符串,不是ID)
         if (StringUtils.isNotEmpty(commentDetail.getCommentImgId())) {
             String[] split2 = commentDetail.getCommentImgId().split(",");
             List<String> imgList2 = new ArrayList<>();
             for (String s : split2) {
-                StoreImg storeImg = storeImgMapper.selectById(s);
-                if (null != storeImg) {
-                    imgList2.add(storeImg.getImgUrl());
+                String trimmedUrl = s.trim();
+                if (StringUtils.isNotEmpty(trimmedUrl)) {
+                    // 如果已经是URL格式(包含http://或https://),直接使用
+                    if (trimmedUrl.startsWith("http://") || trimmedUrl.startsWith("https://")) {
+                        imgList2.add(trimmedUrl);
+                    } else {
+                        // 否则尝试作为ID查询(兼容旧数据)
+                        StoreImg storeImg = storeImgMapper.selectById(trimmedUrl);
+                        if (null != storeImg) {
+                            imgList2.add(storeImg.getImgUrl());
+                        }
+                    }
                 }
             }
             commentDetail.setCommentImgList(imgList2);
@@ -468,15 +478,15 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
                 
                 if (ratingId != null) {
                     // 1. 删除评价(逻辑删除 common_rating 表)
+                    // 注意:因为 deleteFlag 字段有 @TableLogic 注解,必须使用原生 SQL 绕过限制
                     CommonRating rating = commonRatingMapper.selectById(ratingId);
-                    if (rating != null && rating.getDeleteFlag() == 0) {
-                        rating.setDeleteFlag(1);
-                        rating.setUpdatedTime(new Date());
-                        commonRatingMapper.updateById(rating);
-                        log.info("删除评价成功,ratingId={}", ratingId);
+                    if (rating != null) {
+                        // 使用原生 SQL 方法直接更新 delete_flag
+                        int rows = commonRatingMapper.logicDeleteById(ratingId);
+                        log.info("删除评价结果,ratingId={},影响行数={}", ratingId, rows);
                     }
                     
-                    // 2. 查询该评价下的所有评论ID
+                    // 2. 查询该评价下的所有评论ID(用于后续删除点赞记录)
                     LambdaQueryWrapper<CommonComment> commentQueryWrapper = new LambdaQueryWrapper<>();
                     commentQueryWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
                                       .eq(CommonComment::getSourceId, ratingId)
@@ -484,17 +494,10 @@ public class StoreCommentAppealServiceImpl extends ServiceImpl<StoreCommentAppea
                     List<CommonComment> comments = commonCommentMapper.selectList(commentQueryWrapper);
                     List<Long> commentIds = comments.stream().map(CommonComment::getId).collect(Collectors.toList());
                     
-                    // 3. 删除该评价下的所有评论(逻辑删除 common_comment 表)
-                    if (!comments.isEmpty()) {
-                        LambdaUpdateWrapper<CommonComment> commentWrapper = new LambdaUpdateWrapper<>();
-                        commentWrapper.eq(CommonComment::getSourceType, CommentSourceTypeEnum.STORE_COMMENT.getType())
-                                      .eq(CommonComment::getSourceId, ratingId)
-                                      .eq(CommonComment::getDeleteFlag, 0);
-                        commentWrapper.set(CommonComment::getDeleteFlag, 1);
-                        commentWrapper.set(CommonComment::getUpdatedTime, new Date());
-                        commonCommentMapper.update(null, commentWrapper);
-                        log.info("删除评价下的评论成功,ratingId={},评论数={}", ratingId, comments.size());
-                    }
+                    // 3. 删除该评价下的所有评论(使用原生 SQL 绕过 @TableLogic 限制)
+                    int commentRows = commonCommentMapper.logicDeleteBySourceId(
+                            CommentSourceTypeEnum.STORE_COMMENT.getType(), ratingId);
+                    log.info("删除评价下的评论结果,ratingId={},影响行数={}", ratingId, commentRows);
                     
                     // 4. 删除评价的点赞记录(type=7 表示评价点赞)
                     LambdaUpdateWrapper<LifeLikeRecord> ratingLikeWrapper = new LambdaUpdateWrapper<>();