debug
Change-Id: I5c4de18f786f8cc336d8ad66ae9b424d02ed3674
diff --git a/src/main/java/com/example/g8backend/mapper/PostMapper.java b/src/main/java/com/example/g8backend/mapper/PostMapper.java
index b5a5280..baebb17 100644
--- a/src/main/java/com/example/g8backend/mapper/PostMapper.java
+++ b/src/main/java/com/example/g8backend/mapper/PostMapper.java
@@ -1,19 +1,14 @@
package com.example.g8backend.mapper;
-
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.g8backend.entity.Post;
import com.example.g8backend.entity.PostLike;
import org.apache.ibatis.annotations.*;
-
import java.util.List;
-
@Mapper
public interface PostMapper extends BaseMapper<Post> {
-
// 获取用户的帖子
List<Post> getPostsByUserId(@Param("userId") Long userId);
-
// 搜索帖子
@Select("<script>" +
"SELECT p.* " +
@@ -35,32 +30,24 @@
List<Post> searchPosts(@Param("keyword") String keyword,
@Param("tagIds") List<Long> tagIds,
@Param("author") String author);
-
// 检查用户是否已经点赞该帖子
@Select("SELECT EXISTS (SELECT 1 FROM post_likes WHERE user_id = #{userId} AND post_id = #{postId})")
boolean existsByUserIdAndPostId(@Param("userId") Long userId, @Param("postId") Long postId);
-
// 插入一条点赞记录
@Insert("INSERT INTO post_likes (user_id, post_id) VALUES (#{userId}, #{postId})")
void insert(PostLike postLike);
-
// 删除用户对帖子的点赞记录
@Delete("DELETE FROM post_likes WHERE user_id = #{userId} AND post_id = #{postId}")
void deleteLikeByUserIdAndPostId(@Param("userId") Long userId, @Param("postId") Long postId);
-
// 获取某个帖子点赞数
@Select("SELECT COUNT(*) FROM post_likes WHERE post_id = #{postId}")
Long selectCount(@Param("postId") Long postId);
-
@Update("UPDATE posts SET view_count = view_count + 1 WHERE post_id = #{postId}")
void incrementViewCount(Long postId);
-
@Select("SELECT COUNT(*) FROM post_likes WHERE post_id = #{postId}")
Long selectLikeCount(Long postId);
-
@Select("SELECT post_id FROM post_views WHERE user_id = #{userId}")
List<Long> findViewedPostIds(Long userId);
-
@Update({
"<script>",
"UPDATE posts",
@@ -77,4 +64,4 @@
"</script>"
})
int batchUpdateHotScore(@Param("posts") List<Post> posts);
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/g8backend/mapper/PostTagMapper.java b/src/main/java/com/example/g8backend/mapper/PostTagMapper.java
index 184feb2..4c8cc1e 100644
--- a/src/main/java/com/example/g8backend/mapper/PostTagMapper.java
+++ b/src/main/java/com/example/g8backend/mapper/PostTagMapper.java
@@ -1,17 +1,27 @@
package com.example.g8backend.mapper;
-
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.g8backend.entity.Post;
import com.example.g8backend.entity.PostTag;
import com.example.g8backend.entity.Tag;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
-
+import org.apache.ibatis.annotations.Select;
import java.util.List;
-
@Mapper
public interface PostTagMapper extends BaseMapper<PostTag> {
List<Post> getPostsByTagIds(@Param("tagIds") Long[] tagIds);
List<Tag> getTagsByPostId(@Param("postId") Long postId);
int deleteByIds(@Param("postId") Long postId, @Param("tagId") Long tagId);
-}
+ @Select("SELECT tag_id FROM post_tag WHERE post_id = #{postId}")
+ List<Long> findTagIdsByPostId(Long postId);
+ @Select({
+ "<script>",
+ "SELECT post_id FROM post_tag",
+ "WHERE tag_id IN",
+ "<foreach item='tagId' collection='tagIds' open='(' separator=',' close=')'>",
+ "#{tagId}",
+ "</foreach>",
+ "</script>"
+ })
+ List<Long> findPostIdsByTagIds(@Param("tagIds") List<Long> tagIds);
+}
\ No newline at end of file
diff --git a/src/main/java/com/example/g8backend/mapper/UserTagPreferenceMapper.java b/src/main/java/com/example/g8backend/mapper/UserTagPreferenceMapper.java
new file mode 100644
index 0000000..c59ea8e
--- /dev/null
+++ b/src/main/java/com/example/g8backend/mapper/UserTagPreferenceMapper.java
@@ -0,0 +1,22 @@
+package com.example.g8backend.mapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.example.g8backend.entity.UserTagPreference;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import java.util.List;
+public interface UserTagPreferenceMapper extends BaseMapper<UserTagPreference> {
+ /**
+ * 插入或更新用户标签偏好权重
+ */
+ @Update("INSERT INTO user_tag_preference (user_id, tag_id, weight) " +
+ "VALUES (#{userId}, #{tagId}, #{increment}) " +
+ "ON DUPLICATE KEY UPDATE weight = weight + #{increment}")
+ void insertOrUpdateWeight(
+ @Param("userId") Long userId,
+ @Param("tagId") Long tagId,
+ @Param("increment") Double increment
+ );
+ @Select("SELECT * FROM user_tag_preference WHERE user_id = #{userId}")
+ List<UserTagPreference> selectByUserId(@Param("userId") Long userId);
+}
\ No newline at end of file