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 new file mode 100644 index 0000000..a9a0699 --- /dev/null +++ b/src/main/java/com/beauty/aide/common/model/entity/ChatRecordDO.java @@ -0,0 +1,17 @@ +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/controller/ChatController.java b/src/main/java/com/beauty/aide/controller/ChatController.java index b7406d9..aa49249 100644 --- a/src/main/java/com/beauty/aide/controller/ChatController.java +++ b/src/main/java/com/beauty/aide/controller/ChatController.java @@ -1,9 +1,18 @@ package com.beauty.aide.controller; +import com.beauty.aide.adaptor.TongYiAdaptor; +import com.beauty.aide.common.errors.UserErrorCode; +import com.beauty.aide.common.model.vo.AccountVO; +import com.beauty.aide.common.result.ResultDO; +import com.beauty.aide.manager.AccountManager; import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + /** * @author xiaoliu */ @@ -12,7 +21,30 @@ @Slf4j public class ChatController { + @Resource + private HttpServletRequest request; + @Resource + private AccountManager accountManager; + @Resource + private TongYiAdaptor tongYiAdaptor; +// @Resource +// private ChatRecordDAO chatRecordDAO; + + // @TODO 创建一个新会话 + // @TODO 发送问题 + @PostMapping("/sendMessage") + 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); + } // @TODO 查看我的问题 diff --git a/src/main/java/com/beauty/aide/utils/CommonUtil.java b/src/main/java/com/beauty/aide/utils/CommonUtil.java new file mode 100644 index 0000000..d1e8fe6 --- /dev/null +++ b/src/main/java/com/beauty/aide/utils/CommonUtil.java @@ -0,0 +1,20 @@ +package com.beauty.aide.utils; + +import org.springframework.util.DigestUtils; + +import java.nio.charset.StandardCharsets; + +/** + * @author xiaoliu + */ +public class CommonUtil { + + public static String md5(String content) { + return DigestUtils.md5DigestAsHex(content.getBytes(StandardCharsets.UTF_8)); + } + + public static String md5(String content, String salt) { + return md5(String.format("%s%s", content, salt)); + } + +}