Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
|
d40a16a1b6 | 4 months ago |
|
9f8fef15c7 | 4 months ago |
|
af00d8c8e8 | 4 months ago |
|
ec278aab9b | 4 months ago |
|
c6ec6954a6 | 4 months ago |
|
4d9b5a2e69 | 4 months ago |
|
dbdd037ed7 | 4 months ago |
|
81ed1db029 | 4 months ago |
|
6fb1111ce2 | 4 months ago |
|
5e2956da8d | 4 months ago |
@ -0,0 +1,37 @@
|
||||
package com.learning.newdemo.controller;
|
||||
|
||||
import com.learning.newdemo.common.Result;
|
||||
import com.learning.newdemo.entity.DebateHistory;
|
||||
import com.learning.newdemo.service.DebateHistoryService;
|
||||
import com.learning.newdemo.util.JwtUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/debate-history")
|
||||
@RequiredArgsConstructor
|
||||
public class DebateHistoryController {
|
||||
|
||||
private final DebateHistoryService historyService;
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
@PostMapping
|
||||
public Result<?> saveHistory(@RequestBody DebateHistory history,
|
||||
@RequestHeader("Authorization") String token) {
|
||||
Integer userId = jwtUtil.getUserIdFromToken(token);
|
||||
if (userId == null) {
|
||||
return Result.error(401, "无效的认证令牌");
|
||||
}
|
||||
history.setUserId(userId);
|
||||
historyService.saveDebateHistory(history);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Result<List<DebateHistory>> getHistories(@RequestHeader("Authorization") String token) {
|
||||
Integer userId = jwtUtil.getUserIdFromToken(token);
|
||||
return Result.success(historyService.getHistoriesByUser(userId));
|
||||
}
|
||||
}
|
@ -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,9 @@
|
||||
package com.learning.newdemo.service;
|
||||
|
||||
import com.learning.newdemo.entity.DebateHistory;
|
||||
import java.util.List;
|
||||
|
||||
public interface DebateHistoryService {
|
||||
void saveDebateHistory(DebateHistory history);
|
||||
List<DebateHistory> getHistoriesByUser(Integer userId);
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
|
||||
|
||||
package com.learning.newdemo.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface WxDebateService {
|
||||
String GetDebate(String history, String userMessage);
|
||||
}
|
||||
Map<String, Object> GetDebate(String history, String userMessage, int currentRound, int maxRounds);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
// DebateHistoryServiceImpl.java
|
||||
package com.learning.newdemo.service.impl;
|
||||
|
||||
import com.learning.newdemo.entity.DebateHistory;
|
||||
import com.learning.newdemo.mapper.DebateHistoryMapper;
|
||||
import com.learning.newdemo.service.DebateHistoryService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional
|
||||
public class DebateHistoryServiceImpl implements DebateHistoryService {
|
||||
|
||||
private final DebateHistoryMapper historyMapper;
|
||||
|
||||
@Override
|
||||
public void saveDebateHistory(DebateHistory history) {
|
||||
historyMapper.insert(history);
|
||||
// 清理超出10条的旧记录
|
||||
historyMapper.cleanOverflowHistories(history.getUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DebateHistory> getHistoriesByUser(Integer userId) {
|
||||
return historyMapper.selectLatestByUserId(userId, 10);
|
||||
}
|
||||
}
|
@ -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>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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>
|
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 3.8 KiB |
@ -0,0 +1,31 @@
|
||||
#-------------------------------------------------------------------------------#
|
||||
# Qodana analysis is configured by qodana.yaml file #
|
||||
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
|
||||
#-------------------------------------------------------------------------------#
|
||||
version: "1.0"
|
||||
|
||||
#Specify inspection profile for code analysis
|
||||
profile:
|
||||
name: qodana.starter
|
||||
|
||||
#Enable inspections
|
||||
#include:
|
||||
# - name: <SomeEnabledInspectionId>
|
||||
|
||||
#Disable inspections
|
||||
#exclude:
|
||||
# - name: <SomeDisabledInspectionId>
|
||||
# paths:
|
||||
# - <path/where/not/run/inspection>
|
||||
|
||||
projectJDK: 17 #(Applied in CI/CD pipeline)
|
||||
|
||||
#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
|
||||
#bootstrap: sh ./prepare-qodana.sh
|
||||
|
||||
#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
|
||||
#plugins:
|
||||
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)
|
||||
|
||||
#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
|
||||
linter: jetbrains/qodana-jvm-community:latest
|
Loading…
Reference in new issue