parent
de19873c67
commit
16dccb1f00
@ -0,0 +1,23 @@
|
||||
package com.learning.newdemo.Dto;
|
||||
|
||||
import com.learning.newdemo.entity.WxArgument;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ArgumentDetailDTO {
|
||||
private Integer id;
|
||||
private String userMessage;
|
||||
private String content;
|
||||
private Integer sequence;
|
||||
private Date createTime;
|
||||
|
||||
public ArgumentDetailDTO(WxArgument wxArgument) {
|
||||
this.id = wxArgument.getId();
|
||||
this.userMessage = wxArgument.getUserMessage();
|
||||
this.content = wxArgument.getContent();
|
||||
this.sequence = wxArgument.getSequence();
|
||||
this.createTime = wxArgument.getCreateTime();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.learning.newdemo.Dto;
|
||||
|
||||
import com.learning.newdemo.entity.WxConversation;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ConversationDTO {
|
||||
private Long id;
|
||||
private String type; // "debate"/"argument"/"review"
|
||||
private String title;
|
||||
private String preview; // AI回复的前10个字符
|
||||
private Date updateTime;
|
||||
|
||||
public ConversationDTO(WxConversation wxConversation) {
|
||||
this.id = wxConversation.getId();
|
||||
this.type = wxConversation.getType();
|
||||
this.title = wxConversation.getTitle();
|
||||
this.preview = wxConversation.getPreview();
|
||||
this.updateTime = wxConversation.getUpdateTime();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.learning.newdemo.Dto;
|
||||
|
||||
import com.learning.newdemo.entity.WxDebate;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class DebateDetailDTO {
|
||||
private Long id;
|
||||
private String userMessage;
|
||||
private String content;
|
||||
private Integer sequence;
|
||||
private Date createTime;
|
||||
|
||||
public DebateDetailDTO(WxDebate wxDebate) {
|
||||
this.id = wxDebate.getId();
|
||||
this.userMessage = wxDebate.getUserMessage();
|
||||
this.content = wxDebate.getContent();
|
||||
this.sequence = wxDebate.getSequence();
|
||||
this.createTime = wxDebate.getCreateTime();
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.learning.newdemo.Dto;
|
||||
|
||||
import com.learning.newdemo.entity.WxReview;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class ReviewDetailDTO {
|
||||
private Long id;
|
||||
private String userMessage; // 用户消息
|
||||
private String content; // AI回复内容
|
||||
private Integer sequence; // 消息序号
|
||||
private Date createTime;
|
||||
|
||||
public ReviewDetailDTO(WxReview wxReview) {
|
||||
this.id = wxReview.getId();
|
||||
this.userMessage = wxReview.getUserMessage();
|
||||
this.content = wxReview.getContent();
|
||||
this.sequence = wxReview.getSequence();
|
||||
this.createTime = wxReview.getCreateTime();
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.learning.newdemo.controller;
|
||||
|
||||
|
||||
import com.learning.newdemo.Dto.ArgumentDetailDTO;
|
||||
import com.learning.newdemo.Dto.ConversationDTO;
|
||||
import com.learning.newdemo.Dto.DebateDetailDTO;
|
||||
import com.learning.newdemo.Dto.ReviewDetailDTO;
|
||||
import com.learning.newdemo.common.Result;
|
||||
import com.learning.newdemo.entity.WxArgument;
|
||||
import com.learning.newdemo.entity.WxConversation;
|
||||
import com.learning.newdemo.entity.WxDebate;
|
||||
import com.learning.newdemo.entity.WxReview;
|
||||
import com.learning.newdemo.mapper.WxArgumentMapper;
|
||||
import com.learning.newdemo.mapper.WxConversationMapper;
|
||||
import com.learning.newdemo.mapper.WxDebateMapper;
|
||||
import com.learning.newdemo.mapper.WxReviewMapper;
|
||||
import com.learning.newdemo.util.JwtUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("api/conversation")
|
||||
public class WxConversationController {
|
||||
private final WxConversationMapper wxConversationMapper;
|
||||
private final WxDebateMapper wxDebateMapper;
|
||||
private final WxArgumentMapper wxArgumentMapper;
|
||||
private final WxReviewMapper wxReviewMapper;
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
public WxConversationController(WxConversationMapper wxConversationMapper, WxDebateMapper wxDebateMapper, WxArgumentMapper wxArgumentMapper, WxReviewMapper wxReviewMapper, JwtUtil jwtUtil) {
|
||||
this.wxConversationMapper = wxConversationMapper;
|
||||
this.wxDebateMapper = wxDebateMapper;
|
||||
this.wxArgumentMapper = wxArgumentMapper;
|
||||
this.wxReviewMapper = wxReviewMapper;
|
||||
this.jwtUtil = jwtUtil;
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<List<ConversationDTO>> getConversationList(@RequestHeader("Authorization") String token){
|
||||
try{
|
||||
int userId = jwtUtil.getUserIdFromToken(token);
|
||||
|
||||
List<WxConversation> conversations = wxConversationMapper.selectByUserId(userId);
|
||||
|
||||
List<ConversationDTO> result = conversations.stream()
|
||||
.map(conv -> new ConversationDTO(
|
||||
conv))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return Result.success(result);
|
||||
} catch (Exception e){
|
||||
log.error("获取对话失败");
|
||||
return Result.error("获取对话失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping( "/debate/{conversation}")
|
||||
public Result<List<DebateDetailDTO>> getDebate(@PathVariable("conversation") Long conversationId) {
|
||||
try{
|
||||
|
||||
List<WxDebate> wxDebates = wxDebateMapper.selectByConversationId(conversationId);
|
||||
|
||||
List<DebateDetailDTO> debateDetailDTOS = wxDebates.stream().map(DebateDetailDTO::new).collect(Collectors.toList());
|
||||
|
||||
return Result.success(debateDetailDTOS);
|
||||
} catch (Exception e) {
|
||||
log.error("获取辩论失败", e);
|
||||
return Result.error("获取辩论失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/argument/{conversationId}")
|
||||
public Result<List<ArgumentDetailDTO>> getArgument(@PathVariable Long conversationId) {
|
||||
try {
|
||||
List <WxArgument> wxArguments = wxArgumentMapper.selectByConversationId(conversationId);
|
||||
|
||||
List <ArgumentDetailDTO> argumentDetailDTOS = wxArguments.stream().map(ArgumentDetailDTO::new).collect(Collectors.toList());
|
||||
|
||||
return Result.success(argumentDetailDTOS);
|
||||
} catch ( Exception e) {
|
||||
log.error("获取立论失败", e);
|
||||
return Result.error("获取立论失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/review/{conversationId}")
|
||||
public Result<List<ReviewDetailDTO>> getReview(@PathVariable Long conversationId) {
|
||||
try {
|
||||
List<WxReview> wxReviews = wxReviewMapper.selectByConversationId(conversationId);
|
||||
|
||||
List<ReviewDetailDTO> reviewDetailDTOS = wxReviews.stream().map(ReviewDetailDTO::new).collect(Collectors.toList());
|
||||
|
||||
return Result.success(reviewDetailDTOS);
|
||||
} catch ( Exception e){
|
||||
log.error("获取评论失败", e);
|
||||
return Result.error("获取评论失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.learning.newdemo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class WxConversation {
|
||||
private Long id;
|
||||
private int userId;
|
||||
private String type;
|
||||
private String title;
|
||||
private String preview;
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.learning.newdemo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class WxDebate {
|
||||
private Long id;
|
||||
private Long conversationId;
|
||||
private String content;
|
||||
private String userMessage;
|
||||
private Integer sequence;
|
||||
private Date createTime;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.learning.newdemo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class WxReview {
|
||||
private Long id;
|
||||
private Long conversationId; // 关联的对话活动ID
|
||||
private String content; // AI回复内容
|
||||
private String userMessage; // 用户消息
|
||||
private Integer sequence; // 消息序号
|
||||
private Date createTime;
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.learning.newdemo.mapper;
|
||||
|
||||
import com.learning.newdemo.entity.WxArgument;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WxArgumentMapper {
|
||||
List<WxArgument> selectByConversationId(long conversationId);
|
||||
int insert(WxArgument wxArgument);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.learning.newdemo.mapper;
|
||||
|
||||
import com.learning.newdemo.entity.WxConversation;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WxConversationMapper {
|
||||
List<WxConversation> selectByUserId(Integer userId);
|
||||
int insert(WxConversation wxConversation);
|
||||
int updatePreview(Long conversationId, String preview);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.learning.newdemo.mapper;
|
||||
|
||||
import com.learning.newdemo.entity.WxDebate;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WxDebateMapper {
|
||||
List<WxDebate> selectByConversationId(Long conversationId);
|
||||
int insert(WxDebate wxDebate);
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.learning.newdemo.mapper;
|
||||
|
||||
import com.learning.newdemo.entity.WxReview;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface WxReviewMapper {
|
||||
List<WxReview> selectByConversationId(Long conversationId);
|
||||
int insert(WxReview wxReview);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
-- 创建数据库
|
||||
CREATE DATABASE IF NOT EXISTS wx_miniapp DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
|
||||
-- 使用数据库
|
||||
USE wx_miniapp;
|
||||
|
||||
-- 创建微信用户表
|
||||
CREATE TABLE IF NOT EXISTS `wx_user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`openid` varchar(100) NOT NULL COMMENT '微信openid',
|
||||
`nickname` varchar(50) DEFAULT NULL COMMENT '昵称',
|
||||
`avatar_url` varchar(500) DEFAULT NULL COMMENT '头像URL',
|
||||
`gender` tinyint(4) DEFAULT NULL COMMENT '性别 0-未知 1-男 2-女',
|
||||
`country` varchar(50) DEFAULT NULL COMMENT '国家',
|
||||
`province` varchar(50) DEFAULT NULL COMMENT '省份',
|
||||
`city` varchar(50) DEFAULT NULL COMMENT '城市',
|
||||
`language` varchar(50) DEFAULT NULL COMMENT '语言',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_openid` (`openid`) COMMENT 'openid唯一索引'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信用户表';
|
@ -0,0 +1,45 @@
|
||||
<?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.WxArgumentMapper">
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxArgument">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="conversation_id" property="conversationId" jdbcType="BIGINT"/>
|
||||
<result column="topic" property="topic" jdbcType="VARCHAR"/>
|
||||
<result column="stance" property="stance" jdbcType="VARCHAR"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="user_message" property="userMessage" jdbcType="LONGVARCHAR"/>
|
||||
<result column="sequence" property="sequence" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 可复用的列名列表 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, topic, stance, content, user_message, sequence, create_time
|
||||
</sql>
|
||||
|
||||
<!-- 按 conversationId 查询并按 sequence 排序 -->
|
||||
<select id="selectByConversationId" resultMap="BaseResultMap" parameterType="java.lang.Long">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM wx_argument_record
|
||||
WHERE conversation_id = #{conversationId,jdbcType=BIGINT}
|
||||
ORDER BY sequence
|
||||
</select>
|
||||
|
||||
<!-- 插入新记录 -->
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxArgument" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_argument_record (
|
||||
conversation_id, topic, stance, content, user_message, sequence, create_time
|
||||
)
|
||||
VALUES (
|
||||
#{conversationId,jdbcType=BIGINT},
|
||||
#{topic,jdbcType=VARCHAR},
|
||||
#{stance,jdbcType=VARCHAR},
|
||||
#{content,jdbcType=LONGVARCHAR},
|
||||
#{userMessage,jdbcType=LONGVARCHAR},
|
||||
#{sequence,jdbcType=INTEGER},
|
||||
#{createTime,jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
</mapper>
|
@ -0,0 +1,49 @@
|
||||
<?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.WxConversationMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxConversation">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="user_id" property="userId" jdbcType="BIGINT"/>
|
||||
<result column="type" property="type" jdbcType="VARCHAR"/>
|
||||
<result column="title" property="title" jdbcType="VARCHAR"/>
|
||||
<result column="preview" property="preview" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 可复用的列名列表 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, type, title, preview, create_time, update_time
|
||||
</sql>
|
||||
|
||||
<!-- 按用户ID和类型查询对话活动 (用于接口4.1) -->
|
||||
<select id="selectByUserId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM wx_conversation
|
||||
WHERE user_id = #{userId}
|
||||
ORDER BY update_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 插入新对话活动 (用于接口3.1/3.2/3.3) -->
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxConversation"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_conversation (
|
||||
user_id, type, title, preview, create_time, update_time
|
||||
)
|
||||
VALUES (
|
||||
#{userId}, #{type}, #{title}, #{preview}, #{createTime}, #{updateTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新对话预览信息 (用于更新最后一次AI回复的预览) -->
|
||||
<update id="updatePreview">
|
||||
UPDATE wx_conversation
|
||||
SET
|
||||
preview = #{preview},
|
||||
update_time = NOW()
|
||||
WHERE id = #{conversationId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,38 @@
|
||||
<?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.WxDebateMapper">
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxDebate">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="conversation_id" property="conversationId" jdbcType="BIGINT"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="user_message" property="userMessage" jdbcType="LONGVARCHAR"/>
|
||||
<result column="sequence" property="sequence" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, content, user_message, sequence, create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectByConversationId" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from wx_debate_record
|
||||
where conversation_id = #{conversationId}
|
||||
ORDER BY sequence
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxDebate"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_debate_record (
|
||||
conversation_id, content, user_message, sequence, create_time
|
||||
)
|
||||
VALUES (
|
||||
#{conversationId,jdbcType=BIGINT},
|
||||
#{content,jdbcType=LONGNVARCHAR},
|
||||
#{userMessage,jdbcType=LONGNVARCHAR},
|
||||
#{sequence,jdbcType=INTEGER},
|
||||
#{createTime, jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
</mapper>
|
@ -0,0 +1,38 @@
|
||||
<?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.WxReviewMapper">
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxReview">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="conversation_id" property="conversationId" jdbcType="BIGINT"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="user_message" property="userMessage" jdbcType="LONGVARCHAR"/>
|
||||
<result column="sequence" property="sequence" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, content, user_message, sequence, create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectByConversationId" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from wx_review_record
|
||||
where conversation_id = #{conversationId}
|
||||
ORDER BY sequence
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxDebate"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_review_record (
|
||||
conversation_id, content, user_message, sequence, create_time
|
||||
)
|
||||
VALUES (
|
||||
#{conversationId,jdbcType=BIGINT},
|
||||
#{content,jdbcType=LONGNVARCHAR},
|
||||
#{userMessage,jdbcType=LONGNVARCHAR},
|
||||
#{sequence,jdbcType=INTEGER},
|
||||
#{createTime, jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
</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.
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.
@ -1,22 +0,0 @@
|
||||
-- 创建数据库
|
||||
CREATE DATABASE IF NOT EXISTS wx_miniapp DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
|
||||
-- 使用数据库
|
||||
USE wx_miniapp;
|
||||
|
||||
-- 创建微信用户表
|
||||
CREATE TABLE IF NOT EXISTS `wx_user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`openid` varchar(100) NOT NULL COMMENT '微信openid',
|
||||
`nickname` varchar(50) DEFAULT NULL COMMENT '昵称',
|
||||
`avatar_url` varchar(500) DEFAULT NULL COMMENT '头像URL',
|
||||
`gender` tinyint(4) DEFAULT NULL COMMENT '性别 0-未知 1-男 2-女',
|
||||
`country` varchar(50) DEFAULT NULL COMMENT '国家',
|
||||
`province` varchar(50) DEFAULT NULL COMMENT '省份',
|
||||
`city` varchar(50) DEFAULT NULL COMMENT '城市',
|
||||
`language` varchar(50) DEFAULT NULL COMMENT '语言',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_openid` (`openid`) COMMENT 'openid唯一索引'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信用户表';
|
@ -0,0 +1,45 @@
|
||||
<?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.WxArgumentMapper">
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxArgument">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="conversation_id" property="conversationId" jdbcType="BIGINT"/>
|
||||
<result column="topic" property="topic" jdbcType="VARCHAR"/>
|
||||
<result column="stance" property="stance" jdbcType="VARCHAR"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="user_message" property="userMessage" jdbcType="LONGVARCHAR"/>
|
||||
<result column="sequence" property="sequence" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 可复用的列名列表 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, topic, stance, content, user_message, sequence, create_time
|
||||
</sql>
|
||||
|
||||
<!-- 按 conversationId 查询并按 sequence 排序 -->
|
||||
<select id="selectByConversationId" resultMap="BaseResultMap" parameterType="java.lang.Long">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM wx_argument_record
|
||||
WHERE conversation_id = #{conversationId,jdbcType=BIGINT}
|
||||
ORDER BY sequence
|
||||
</select>
|
||||
|
||||
<!-- 插入新记录 -->
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxArgument" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_argument_record (
|
||||
conversation_id, topic, stance, content, user_message, sequence, create_time
|
||||
)
|
||||
VALUES (
|
||||
#{conversationId,jdbcType=BIGINT},
|
||||
#{topic,jdbcType=VARCHAR},
|
||||
#{stance,jdbcType=VARCHAR},
|
||||
#{content,jdbcType=LONGVARCHAR},
|
||||
#{userMessage,jdbcType=LONGVARCHAR},
|
||||
#{sequence,jdbcType=INTEGER},
|
||||
#{createTime,jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
</mapper>
|
@ -0,0 +1,49 @@
|
||||
<?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.WxConversationMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxConversation">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="user_id" property="userId" jdbcType="BIGINT"/>
|
||||
<result column="type" property="type" jdbcType="VARCHAR"/>
|
||||
<result column="title" property="title" jdbcType="VARCHAR"/>
|
||||
<result column="preview" property="preview" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 可复用的列名列表 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, type, title, preview, create_time, update_time
|
||||
</sql>
|
||||
|
||||
<!-- 按用户ID和类型查询对话活动 (用于接口4.1) -->
|
||||
<select id="selectByUserId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM wx_conversation
|
||||
WHERE user_id = #{userId}
|
||||
ORDER BY update_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 插入新对话活动 (用于接口3.1/3.2/3.3) -->
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxConversation"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_conversation (
|
||||
user_id, type, title, preview, create_time, update_time
|
||||
)
|
||||
VALUES (
|
||||
#{userId}, #{type}, #{title}, #{preview}, #{createTime}, #{updateTime}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新对话预览信息 (用于更新最后一次AI回复的预览) -->
|
||||
<update id="updatePreview">
|
||||
UPDATE wx_conversation
|
||||
SET
|
||||
preview = #{preview},
|
||||
update_time = NOW()
|
||||
WHERE id = #{conversationId}
|
||||
</update>
|
||||
|
||||
</mapper>
|
@ -0,0 +1,38 @@
|
||||
<?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.WxDebateMapper">
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxDebate">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="conversation_id" property="conversationId" jdbcType="BIGINT"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="user_message" property="userMessage" jdbcType="LONGVARCHAR"/>
|
||||
<result column="sequence" property="sequence" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, content, user_message, sequence, create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectByConversationId" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from wx_debate_record
|
||||
where conversation_id = #{conversationId}
|
||||
ORDER BY sequence
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxDebate"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_debate_record (
|
||||
conversation_id, content, user_message, sequence, create_time
|
||||
)
|
||||
VALUES (
|
||||
#{conversationId,jdbcType=BIGINT},
|
||||
#{content,jdbcType=LONGNVARCHAR},
|
||||
#{userMessage,jdbcType=LONGNVARCHAR},
|
||||
#{sequence,jdbcType=INTEGER},
|
||||
#{createTime, jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
</mapper>
|
@ -0,0 +1,38 @@
|
||||
<?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.WxReviewMapper">
|
||||
<resultMap id="BaseResultMap" type="com.learning.newdemo.entity.WxReview">
|
||||
<id column="id" property="id" jdbcType="BIGINT"/>
|
||||
<result column="conversation_id" property="conversationId" jdbcType="BIGINT"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="user_message" property="userMessage" jdbcType="LONGVARCHAR"/>
|
||||
<result column="sequence" property="sequence" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, content, user_message, sequence, create_time
|
||||
</sql>
|
||||
|
||||
<select id="selectByConversationId" resultMap="BaseResultMap">
|
||||
select
|
||||
<include refid="Base_Column_List"/>
|
||||
from wx_review_record
|
||||
where conversation_id = #{conversationId}
|
||||
ORDER BY sequence
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="com.learning.newdemo.entity.WxDebate"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO wx_review_record (
|
||||
conversation_id, content, user_message, sequence, create_time
|
||||
)
|
||||
VALUES (
|
||||
#{conversationId,jdbcType=BIGINT},
|
||||
#{content,jdbcType=LONGNVARCHAR},
|
||||
#{userMessage,jdbcType=LONGNVARCHAR},
|
||||
#{sequence,jdbcType=INTEGER},
|
||||
#{createTime, jdbcType=TIMESTAMP}
|
||||
)
|
||||
</insert>
|
||||
</mapper>
|
@ -1,19 +0,0 @@
|
||||
create database if not exists wx_miniapp default charset utf8mb4;
|
||||
|
||||
use wx_miniapp;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `wx_user` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`openid` varchar(100) NOT NULL COMMENT '微信openid',
|
||||
`nickname` varchar(50) DEFAULT NULL COMMENT '昵称',
|
||||
`avatar_url` varchar(500) DEFAULT NULL COMMENT '头像URL',
|
||||
`gender` tinyint(4) DEFAULT NULL COMMENT '性别 0-未知 1-男 2-女',
|
||||
`country` varchar(50) DEFAULT NULL COMMENT '国家',
|
||||
`province` varchar(50) DEFAULT NULL COMMENT '省份',
|
||||
`city` varchar(50) DEFAULT NULL COMMENT '城市',
|
||||
`language` varchar(50) DEFAULT NULL COMMENT '语言',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_openid` (`openid`) COMMENT 'openid唯一索引'
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='微信用户表';
|
Loading…
Reference in new issue