Skip to content

Commit

Permalink
提问保存问题与答案
Browse files Browse the repository at this point in the history
  • Loading branch information
Upzzh committed Jan 18, 2024
1 parent 9358e33 commit 664740f
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 30 deletions.
9 changes: 6 additions & 3 deletions src/main/java/com/beauty/aide/common/model/entity/BaseDO.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.beauty.aide.common.model.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.time.LocalDateTime;

/**
* @author xiaoliu
Expand All @@ -15,17 +17,18 @@ public class BaseDO implements Serializable {
/**
* 主键
*/
@TableId(value = "id",type = IdType.AUTO)
protected Long id;

/**
* 创建时间
*/
protected Date createTime;
protected LocalDateTime createTime;

/**
* 修改时间
*/
protected Date updateTime;
protected LocalDateTime updateTime;

/**
* 状态
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.beauty.aide.common.model.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author xiaoliu
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("question_record")
public class QuestionRecordDO extends BaseDO {

private String sessionId;
private String question;
private String answer;
private Long createUserId;

}
29 changes: 20 additions & 9 deletions src/main/java/com/beauty/aide/controller/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.beauty.aide.adaptor.TongYiAdaptor;
import com.beauty.aide.common.errors.UserErrorCode;
import com.beauty.aide.common.model.entity.QuestionRecordDO;
import com.beauty.aide.common.model.vo.AccountVO;
import com.beauty.aide.common.result.ResultDO;
import com.beauty.aide.manager.AccountManager;
import com.beauty.aide.mapper.QuestionRecordDAO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -27,23 +29,32 @@ public class ChatController {
private AccountManager accountManager;
@Resource
private TongYiAdaptor tongYiAdaptor;
// @Resource
// private ChatRecordDAO chatRecordDAO;
@Resource
private QuestionRecordDAO questionRecordDAO;

// @TODO 创建一个新会话

// @TODO 发送问题
/**
* 发送提问
* @param question 问题
* @param uuid 会话唯一标识
* @return 答案
*/
@PostMapping("/sendMessage")
public ResultDO<String> sendMessage(String question,String uuid) {
public ResultDO<String> sendMessage(String question, String uuid) {
AccountVO user = accountManager.getLoginUser(request);
if (user == null) {
return ResultDO.errorOf(UserErrorCode.USER_NOT_LOGIN);
}

String messgae = tongYiAdaptor.sendChatRequest(question, uuid);
// @TODO 存储问题数据库

return ResultDO.succOf(messgae);
String message = tongYiAdaptor.sendChatRequest(question, uuid);
// 存储问题数据库
QuestionRecordDO questionRecord = new QuestionRecordDO();
questionRecord.setQuestion(question);
questionRecord.setAnswer(message);
questionRecord.setSessionId(uuid);
questionRecord.setCreateUserId(user.getId());
questionRecordDAO.insert(questionRecord);
return ResultDO.succOf(message);
}

// @TODO 查看我的问题
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/beauty/aide/mapper/QuestionRecordDAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.beauty.aide.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.beauty.aide.common.model.entity.QuestionRecordDO;

public interface QuestionRecordDAO extends BaseMapper<QuestionRecordDO> {



}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ server:
max-age: 2592000
mybatis-plus:
configuration:
map-underscore-to-camel-case: false
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/mapper/QuestionRecordDAO.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?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.beauty.aide.mapper.QuestionRecordDAO">
<resultMap id="resultMap" type="com.beauty.aide.common.model.entity.QuestionRecordDO">
<id property="id" column="id" jdbcType="BIGINT"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="status" column="status" jdbcType="VARCHAR"/>
</resultMap>



</mapper>

0 comments on commit 664740f

Please sign in to comment.