(database):

-立论、辩论(含复盘)实体类和Mapper映射
- 新增 Position 枚举类,用于表示用户的持方(正方/反方)
main
weidoudou7 2 months ago
parent de19873c67
commit 5e2956da8d

@ -0,0 +1,21 @@
package com.learning.newdemo.entity;
import com.learning.newdemo.enums.Position;
import lombok.Data;
import java.util.Date;
@Data
public class ArgumentHistory {
private Integer id;
private Integer userId; // 关联用户ID
private String topic; // 辩题
private String argumentContent; // 立论内容
private Position position; // 用户持方(枚举类型)
private Date createTime; // 创建时间
}

@ -0,0 +1,28 @@
package com.learning.newdemo.entity;
import com.learning.newdemo.enums.Position;
import lombok.Data;
import java.util.Date;
@Data
public class DebateHistory {
private Integer id;
private Integer userId; // 关联用户ID
private Integer argumentId; // 关联立论记录ID
private String topic; // 辩题
private Position position; // 用户持方
private Short totalRounds; // 总回合数
private String debateContent; // 所有辩论内容JSON格式
private String reviewResult; // 复盘分析内容
private Date createTime; // 创建时间
private ArgumentHistory argumentHistory; //关联的立论记录
}

@ -0,0 +1,36 @@
package com.learning.newdemo.enums;
public enum Position {
POSITIVE("正方"),
NEGATIVE("反方");
private final String name;
Position(String name) {
this.name = name;
}
public String getName() {
return name;
}
/**
*
* Position
* 使
*
* @param name
* @return null
*/
public static Position getPosition(String name) {
// 遍历Position枚举中的所有值
for (Position position : Position.values()) {
// 比较当前枚举实例的名称是否与传入的名称相同
if (position.getName().equals(name)) {
// 如果相同,则返回当前枚举实例
return position;
}
}
// 如果遍历结束后没有找到匹配的枚举则返回null
return null;
}
}

@ -0,0 +1,71 @@
package com.learning.newdemo.mapper;
import com.learning.newdemo.entity.ArgumentHistory;
import com.learning.newdemo.enums.Position;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ArgumentHistoryMapper {
/**
*
* @param argumentHistory
* @return
*/
int insert(ArgumentHistory argumentHistory);
/**
* ID
* @param userId ID
* @return
*/
List<ArgumentHistory> selectByUserId(@Param("userId") Integer userId);
/**
* ID
* @param userId ID
* @param position /
* @return
*/
List<ArgumentHistory> selectByUserAndPosition(
@Param("userId") Integer userId,
@Param("position") Position position);
/**
* ID
* @param id ID
* @return
*/
ArgumentHistory selectByPrimaryKey(@Param("id") Integer id);
/**
*
* @param userId ID
* @return
*/
ArgumentHistory selectLatestByUserId(@Param("userId") Integer userId);
/**
* IDi
*
* @param userId ID
* @param limit
* @return i
*/
List<ArgumentHistory> selectLatestByUserIdWithLimit(
@Param("userId") Integer userId,
@Param("limit") Integer limit);
/**
* IDi
*
* @param userId ID
* @param position
* @param limit
* @return i
*/
List<ArgumentHistory> selectLatestByUserAndPositionWithLimit(
@Param("userId") Integer userId,
@Param("position") Position position,
@Param("limit") Integer limit);
}

@ -0,0 +1,59 @@
package com.learning.newdemo.mapper;
import com.learning.newdemo.entity.DebateHistory;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DebateHistoryMapper {
/**
*
* @param debateHistory
* @return
*/
int insert(DebateHistory debateHistory);
/**
* ID
* @param userId ID
* @return
*/
List<DebateHistory> selectByUserId(@Param("userId") Integer userId);
/**
* IDi
* @param userId ID
* @param limit
* @return i
*/
List<DebateHistory> selectLatestByUserId(@Param("userId") Integer userId, @Param("limit") Integer limit);
/**
* ID
* @param argumentId ID
* @return
*/
List<DebateHistory> selectByArgumentId(@Param("argumentId") Integer argumentId);
/**
*
* @param id ID
* @return
*/
DebateHistory selectByPrimaryKey(@Param("id") Integer id);
/**
*
* @param id ID
* @param reviewResult
* @return
*/
int updateReviewResult(@Param("id") Integer id, @Param("reviewResult") String reviewResult);
/**
*
* @param id ID
* @return
*/
DebateHistory selectWithArgument(@Param("id") Integer id);
}

@ -0,0 +1,89 @@
<?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.ArgumentHistoryMapper">
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.ArgumentHistory">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="user_id" property="userId" jdbcType="INTEGER"/>
<result column="topic" property="topic" jdbcType="VARCHAR"/>
<result column="argument_content" property="argumentContent" jdbcType="LONGVARCHAR"/>
<result column="position" property="position"
typeHandler="org.apache.ibatis.type.EnumTypeHandler"
jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, user_id, topic, argument_content, position, create_time
</sql>
<!-- 插入立论记录 -->
<insert id="insert" parameterType="com.learning.newdemo.entity.ArgumentHistory"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO argument_history (
user_id, topic, argument_content, position
)
VALUES (
#{userId,jdbcType=INTEGER},
#{topic,jdbcType=VARCHAR},
#{argumentContent,jdbcType=LONGVARCHAR},
#{position,jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler}
)
</insert>
<!-- 根据用户ID查询 -->
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM argument_history
WHERE user_id = #{userId,jdbcType=INTEGER}
ORDER BY create_time DESC
</select>
<!-- 根据用户ID和持方查询 -->
<select id="selectByUserAndPosition" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM argument_history
WHERE user_id = #{userId,jdbcType=INTEGER}
AND position = #{position,jdbcType=VARCHAR, typeHandler=org.apache.ibatis.type.EnumTypeHandler}
ORDER BY create_time DESC
</select>
<!-- 根据主键查询 -->
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM argument_history
WHERE id = #{id,jdbcType=INTEGER}
</select>
<!-- 获取用户最新立论记录 -->
<select id="selectLatestByUserId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM argument_history
WHERE user_id = #{userId,jdbcType=INTEGER}
ORDER BY create_time DESC
LIMIT 1
</select>
<!-- 根据用户ID查询最新的i条记录 -->
<select id="selectLatestByUserIdWithLimit" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM argument_history
WHERE user_id = #{userId,jdbcType=INTEGER}
ORDER BY create_time DESC
LIMIT #{limit,jdbcType=INTEGER}
</select>
<!-- 根据用户ID和持方查询最新的i条记录 -->
<select id="selectLatestByUserAndPositionWithLimit" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM argument_history
WHERE user_id = #{userId,jdbcType=INTEGER}
<if test="position != null">
AND position = #{position,jdbcType=VARCHAR,
typeHandler=org.apache.ibatis.type.EnumTypeHandler}
</if>
ORDER BY create_time DESC
LIMIT #{limit,jdbcType=INTEGER}
</select>
</mapper>

@ -0,0 +1,106 @@
<?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
)
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}
)
</insert>
<!-- 根据用户ID查询 -->
<select id="selectByUserId" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM debate_history
WHERE user_id = #{userId,jdbcType=INTEGER}
ORDER BY create_time DESC
</select>
<!-- 根据用户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
</select>
<!-- 根据主键查询 -->
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
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>
Loading…
Cancel
Save