post_rating
Change-Id: Ia1a6fb3f87b793a6307046e36951c1fb36b213c8
diff --git a/src/main/java/com/example/g8backend/mapper/PostRatingMapper.java b/src/main/java/com/example/g8backend/mapper/PostRatingMapper.java
new file mode 100644
index 0000000..edf2d26
--- /dev/null
+++ b/src/main/java/com/example/g8backend/mapper/PostRatingMapper.java
@@ -0,0 +1,18 @@
+package com.example.g8backend.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.g8backend.entity.PostRating;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+public interface PostRatingMapper extends BaseMapper<PostRating> {
+ // 自定义查询平均分
+ @Select("SELECT AVG(rating) FROM post_ratings WHERE post_id = #{postId}")
+ Double calculateAverageRating(@Param("postId") Long postId);
+
+ @Select("SELECT COUNT(*) FROM post_ratings WHERE post_id = #{postId}")
+ Integer getRatingCount(@Param("postId") Long postId);
+
+ @Select("SELECT COUNT(DISTINCT user_id) FROM post_ratings WHERE post_id = #{postId}")
+ Long selectRatingUserCount(@Param("postId") Long postId);
+}
\ No newline at end of file