diff --git a/src/main/java/com/beauty/aide/common/model/entity/BaseDO.java b/src/main/java/com/beauty/aide/common/model/entity/BaseDO.java index 910177c..05a0a7c 100644 --- a/src/main/java/com/beauty/aide/common/model/entity/BaseDO.java +++ b/src/main/java/com/beauty/aide/common/model/entity/BaseDO.java @@ -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 @@ -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; /** * 状态 diff --git a/src/main/java/com/beauty/aide/common/model/entity/ChatRecordDO.java b/src/main/java/com/beauty/aide/common/model/entity/ChatRecordDO.java deleted file mode 100644 index a9a0699..0000000 --- a/src/main/java/com/beauty/aide/common/model/entity/ChatRecordDO.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.beauty.aide.common.model.entity; - -import lombok.Data; - -/** - * @author xiaoliu - */ -@Data -public class ChatRecordDO extends BaseDO { - - private String sessionId; - private String content; - private String answer; - private Long userId; - private String status; - -} diff --git a/src/main/java/com/beauty/aide/common/model/entity/QuestionRecordDO.java b/src/main/java/com/beauty/aide/common/model/entity/QuestionRecordDO.java new file mode 100644 index 0000000..6230e31 --- /dev/null +++ b/src/main/java/com/beauty/aide/common/model/entity/QuestionRecordDO.java @@ -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; + +} diff --git a/src/main/java/com/beauty/aide/controller/ChatController.java b/src/main/java/com/beauty/aide/controller/ChatController.java index aa49249..cb91134 100644 --- a/src/main/java/com/beauty/aide/controller/ChatController.java +++ b/src/main/java/com/beauty/aide/controller/ChatController.java @@ -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; @@ -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 sendMessage(String question,String uuid) { + public ResultDO 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 查看我的问题 diff --git a/src/main/java/com/beauty/aide/mapper/QuestionRecordDAO.java b/src/main/java/com/beauty/aide/mapper/QuestionRecordDAO.java new file mode 100644 index 0000000..531bcf7 --- /dev/null +++ b/src/main/java/com/beauty/aide/mapper/QuestionRecordDAO.java @@ -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 { + + + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5739d04..c673541 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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: diff --git a/src/main/resources/mapper/QuestionRecordDAO.xml b/src/main/resources/mapper/QuestionRecordDAO.xml new file mode 100644 index 0000000..97fec19 --- /dev/null +++ b/src/main/resources/mapper/QuestionRecordDAO.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + +