夜雨声烦 | 070c05a | 2025-05-13 20:33:50 +0800 | [diff] [blame] | 1 | package com.example.g8backend.mapper; |
| 2 | |
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| 4 | import com.example.g8backend.entity.PostRating; |
| 5 | import org.apache.ibatis.annotations.Param; |
| 6 | import org.apache.ibatis.annotations.Select; |
| 7 | |
| 8 | public 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 | } |