diff --git a/Debate_backend/src/main/java/com/learning/newdemo/mapper/DebateHistoryMapper.java b/Debate_backend/src/main/java/com/learning/newdemo/mapper/DebateHistoryMapper.java index 96af56e..a134315 100644 --- a/Debate_backend/src/main/java/com/learning/newdemo/mapper/DebateHistoryMapper.java +++ b/Debate_backend/src/main/java/com/learning/newdemo/mapper/DebateHistoryMapper.java @@ -2,35 +2,31 @@ package com.learning.newdemo.mapper; import com.learning.newdemo.entity.DebateHistory; import org.apache.ibatis.annotations.*; - import java.util.List; @Mapper public interface DebateHistoryMapper { + // 注意:所有方法名必须与XML中的id严格匹配 - @Insert("INSERT INTO debate_history(user_id, topic, stance, content, review, rounds) " + - "VALUES(#{userId}, #{topic}, #{stance}, #{content}, #{review}, #{rounds})") - @Options(useGeneratedKeys = true, keyProperty = "id") int insert(DebateHistory debateHistory); - @Select("SELECT * FROM debate_history WHERE user_id = #{userId} ORDER BY create_time DESC") List selectByUserId(@Param("userId") Integer userId); - @Select("SELECT * FROM debate_history WHERE user_id = #{userId} ORDER BY create_time DESC LIMIT #{limit}") - List selectLatestByUserId(@Param("userId") Integer userId, @Param("limit") Integer limit); + List selectLatestByUserId( + @Param("userId") Integer userId, + @Param("limit") Integer limit + ); - @Select("SELECT * FROM debate_history WHERE id = #{id}") DebateHistory selectByPrimaryKey(@Param("id") Integer id); - @Update("UPDATE debate_history SET review = #{review} WHERE id = #{id}") - int updateReview(@Param("id") Integer id, @Param("review") String review); + int updateReviewResult( + @Param("id") Integer id, + @Param("reviewResult") String reviewResult + ); - @Delete("DELETE FROM debate_history WHERE user_id = #{userId} AND id NOT IN " + - "(SELECT id FROM (SELECT id FROM debate_history WHERE user_id = #{userId} " + - "ORDER BY create_time DESC LIMIT 10) t)") - int cleanOverflowHistories(@Param("userId") Integer userId); + // 关联查询方法 + DebateHistory selectWithArgument(@Param("id") Integer id); - @Select("SELECT * FROM debate_history WHERE user_id = #{userId} AND topic LIKE CONCAT('%',#{keyword},'%') " + - "ORDER BY create_time DESC") - List searchByKeyword(@Param("userId") Integer userId, @Param("keyword") String keyword); + // 清理历史记录 + int cleanOverflowHistories(@Param("userId") Integer userId); } diff --git a/Debate_backend/src/main/resources/mapper/DebateHistoryMapper.xml b/Debate_backend/src/main/resources/mapper/DebateHistoryMapper.xml index 98ce52c..d6408e0 100644 --- a/Debate_backend/src/main/resources/mapper/DebateHistoryMapper.xml +++ b/Debate_backend/src/main/resources/mapper/DebateHistoryMapper.xml @@ -1,5 +1,6 @@ - + @@ -16,8 +17,8 @@ - - + @@ -30,77 +31,41 @@ - id, user_id, argument_id, topic, position, total_rounds, debate_content, review_result, create_time + id, user_id, argument_id, topic, position, total_rounds, + debate_content, review_result, create_time - dh.id, dh.user_id, dh.argument_id, dh.topic, dh.position, dh.total_rounds, - dh.debate_content, dh.review_result, dh.create_time, + dh.id, dh.user_id, dh.argument_id, dh.topic, dh.position, + dh.total_rounds, dh.debate_content, dh.review_result, dh.create_time, ah.id as arg_id, ah.user_id as arg_user_id, ah.topic as arg_topic, ah.argument_content as arg_content, ah.position as arg_position, ah.create_time as arg_create_time - INSERT INTO debate_history ( - user_id, argument_id, topic, position, total_rounds, debate_content + user_id, argument_id, topic, position, + total_rounds, debate_content, create_time + ) VALUES ( + #{userId}, #{argumentId}, #{topic}, + #{position,typeHandler=org.apache.ibatis.type.EnumTypeHandler}, + #{totalRounds}, #{debateContent}, NOW() ) - VALUES ( - #{userId,jdbcType=INTEGER}, - #{argumentId,jdbcType=INTEGER}, - #{topic,jdbcType=VARCHAR}, - #{position,jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler}, - #{totalRounds,jdbcType=SMALLINT}, - #{debateContent,jdbcType=LONGVARCHAR} - ) - - - - - - - - - - - - - - - UPDATE debate_history - SET review_result = #{reviewResult,jdbcType=LONGVARCHAR} - WHERE id = #{id,jdbcType=INTEGER} - - - - - \ No newline at end of file + LIMIT 10 + ) t + ) + +