blob: edf2d26a819db344c450a5a7d1e33c04c0c602b6 [file] [log] [blame]
夜雨声烦070c05a2025-05-13 20:33:50 +08001package com.example.g8backend.mapper;
2
3import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4import com.example.g8backend.entity.PostRating;
5import org.apache.ibatis.annotations.Param;
6import org.apache.ibatis.annotations.Select;
7
8public interface PostRatingMapper extends BaseMapper<PostRating> {
9 // 自定义查询平均分
10 @Select("SELECT AVG(rating) FROM post_ratings WHERE post_id = #{postId}")
11 Double calculateAverageRating(@Param("postId") Long postId);
12
13 @Select("SELECT COUNT(*) FROM post_ratings WHERE post_id = #{postId}")
14 Integer getRatingCount(@Param("postId") Long postId);
15
16 @Select("SELECT COUNT(DISTINCT user_id) FROM post_ratings WHERE post_id = #{postId}")
17 Long selectRatingUserCount(@Param("postId") Long postId);
18}