You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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">
<mapper namespace="com.learning.newdemo.mapper.DebateHistoryMapper">
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.DebateHistory">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="user_id" property="userId" jdbcType="INTEGER"/>
<result column="argument_id" property="argumentId" jdbcType="INTEGER"/>
<result column="topic" property="topic" jdbcType="VARCHAR"/>
<result column="position" property="position"
typeHandler="org.apache.ibatis.type.EnumTypeHandler"
jdbcType="VARCHAR"/>
<result column="total_rounds" property="totalRounds" jdbcType="SMALLINT"/>
<result column="debate_content" property="debateContent" jdbcType="LONGVARCHAR"/>
<result column="review_result" property="reviewResult" jdbcType="LONGVARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<resultMap id="WithArgumentResultMap" type="com.learning.newdemo.entity.DebateHistory"
extends="BaseResultMap">
<association property="argumentHistory" javaType="com.learning.newdemo.entity.ArgumentHistory">
<id column="arg_id" property="id"/>
<result column="arg_user_id" property="userId"/>
<result column="arg_topic" property="topic"/>
<result column="arg_content" property="argumentContent"/>
<result column="arg_position" property="position"
typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
<result column="arg_create_time" property="createTime"/>
</association>
</resultMap>
<sql id="Base_Column_List">
id, user_id, argument_id, topic, position, total_rounds,
debate_content, review_result, create_time
</sql>
<sql id="WithArgument_Column_List">
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
</sql>
<insert id="insert" parameterType="com.learning.newdemo.entity.DebateHistory"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO debate_history (
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()
)
</insert>
<!-- 清理历史记录保留最近10条 -->
<delete id="cleanOverflowHistories">
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
)
</delete>
</mapper>