历史记录后端

main
liulianbuqu 2 months ago
parent c6ec6954a6
commit ec278aab9b

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.learning.newdemo.mapper.DebateHistoryMapper"> <mapper namespace="com.learning.newdemo.mapper.DebateHistoryMapper">
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.DebateHistory"> <resultMap id="BaseResultMap" type="com.learning.newdemo.entity.DebateHistory">
@ -16,8 +17,8 @@
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<!-- 包含关联立论记录的结果映射 --> <resultMap id="WithArgumentResultMap" type="com.learning.newdemo.entity.DebateHistory"
<resultMap id="WithArgumentResultMap" type="com.learning.newdemo.entity.DebateHistory" extends="BaseResultMap"> extends="BaseResultMap">
<association property="argumentHistory" javaType="com.learning.newdemo.entity.ArgumentHistory"> <association property="argumentHistory" javaType="com.learning.newdemo.entity.ArgumentHistory">
<id column="arg_id" property="id"/> <id column="arg_id" property="id"/>
<result column="arg_user_id" property="userId"/> <result column="arg_user_id" property="userId"/>
@ -30,77 +31,41 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
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
</sql> </sql>
<sql id="WithArgument_Column_List"> <sql id="WithArgument_Column_List">
dh.id, dh.user_id, dh.argument_id, dh.topic, dh.position, dh.total_rounds, dh.id, dh.user_id, dh.argument_id, dh.topic, dh.position,
dh.debate_content, dh.review_result, dh.create_time, 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.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.argument_content as arg_content, ah.position as arg_position,
ah.create_time as arg_create_time ah.create_time as arg_create_time
</sql> </sql>
<!-- 插入辩论记录 -->
<insert id="insert" parameterType="com.learning.newdemo.entity.DebateHistory" <insert id="insert" parameterType="com.learning.newdemo.entity.DebateHistory"
useGeneratedKeys="true" keyProperty="id"> useGeneratedKeys="true" keyProperty="id">
INSERT INTO debate_history ( 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 ( ) VALUES (
#{userId,jdbcType=INTEGER}, #{userId}, #{argumentId}, #{topic},
#{argumentId,jdbcType=INTEGER}, #{position,typeHandler=org.apache.ibatis.type.EnumTypeHandler},
#{topic,jdbcType=VARCHAR}, #{totalRounds}, #{debateContent}, NOW()
#{position,jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler},
#{totalRounds,jdbcType=SMALLINT},
#{debateContent,jdbcType=LONGVARCHAR}
) )
</insert> </insert>
<!-- 根据用户ID查询 --> <!-- 清理历史记录保留最近10条 -->
<select id="selectByUserId" resultMap="BaseResultMap"> <delete id="cleanOverflowHistories">
SELECT <include refid="Base_Column_List"/> DELETE FROM debate_history
FROM debate_history WHERE user_id = #{userId}
WHERE user_id = #{userId,jdbcType=INTEGER} AND id NOT IN (
ORDER BY create_time DESC SELECT id FROM (
</select> SELECT id FROM debate_history
WHERE user_id = #{userId}
<!-- 根据用户ID查询最新的i条记录 -->
<select id="selectLatestByUserId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM debate_history
WHERE user_id = #{userId,jdbcType=INTEGER}
ORDER BY create_time DESC
LIMIT #{limit,jdbcType=INTEGER}
</select>
<!-- 根据立论记录ID查询 -->
<select id="selectByArgumentId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM debate_history
WHERE argument_id = #{argumentId,jdbcType=INTEGER}
ORDER BY create_time DESC ORDER BY create_time DESC
</select> LIMIT 10
) t
<!-- 根据主键查询 --> )
<select id="selectByPrimaryKey" resultMap="BaseResultMap"> </delete>
SELECT <include refid="Base_Column_List"/>
FROM debate_history
WHERE id = #{id,jdbcType=INTEGER}
</select>
<!-- 更新复盘分析内容 -->
<update id="updateReviewResult">
UPDATE debate_history
SET review_result = #{reviewResult,jdbcType=LONGVARCHAR}
WHERE id = #{id,jdbcType=INTEGER}
</update>
<!-- 查询辩论记录及其关联的立论内容 -->
<select id="selectWithArgument" resultMap="WithArgumentResultMap">
SELECT <include refid="WithArgument_Column_List"/>
FROM debate_history dh
JOIN argument_history ah ON dh.argument_id = ah.id
WHERE dh.id = #{id,jdbcType=INTEGER}
</select>
</mapper> </mapper>
Loading…
Cancel
Save