|
@@ -1,4 +1,4 @@
|
|
|
-package org.jeecg.modules.demo.gpt.service.impl;
|
|
|
+package org.jeecg.modules.adweb.gpt.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -14,10 +14,12 @@ import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.jeecg.common.util.SpringContextUtils;
|
|
|
import org.jeecg.common.util.UUIDGenerator;
|
|
|
-import org.jeecg.modules.demo.gpt.cache.LocalCache;
|
|
|
-import org.jeecg.modules.demo.gpt.listeners.OpenAISSEEventSourceListener;
|
|
|
-import org.jeecg.modules.demo.gpt.service.ChatService;
|
|
|
-import org.jeecg.modules.demo.gpt.vo.ChatHistoryVO;
|
|
|
+import org.jeecg.modules.adweb.gpt.cache.LocalCache;
|
|
|
+import org.jeecg.modules.adweb.gpt.entity.ChatHistory;
|
|
|
+import org.jeecg.modules.adweb.gpt.listeners.OpenAISSEEventSourceListener;
|
|
|
+import org.jeecg.modules.adweb.gpt.mapper.ChatHistoryMapper;
|
|
|
+import org.jeecg.modules.adweb.gpt.service.ChatService;
|
|
|
+import org.jeecg.modules.adweb.gpt.vo.ChatHistoryVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -25,6 +27,7 @@ import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
//update-begin---author:chenrui ---date:20240126 for:【QQYUN-7932】AI助手------------
|
|
@@ -38,6 +41,9 @@ import java.util.List;
|
|
|
@Slf4j
|
|
|
public class ChatServiceImpl implements ChatService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ChatHistoryMapper chatHistoryMapper;
|
|
|
+
|
|
|
//update-begin---author:chenrui ---date:20240223 for:[QQYUN-8225]聊天记录保存------------
|
|
|
private static final String CACHE_KEY_PREFIX = "ai:chart:";
|
|
|
|
|
@@ -177,10 +183,20 @@ public class ChatServiceImpl implements ChatService {
|
|
|
|
|
|
//update-begin---author:chenrui ---date:20240223 for:[QQYUN-8225]聊天记录保存------------
|
|
|
@Override
|
|
|
+// public Result<?> saveHistory(ChatHistoryVO chatHistoryVO) {
|
|
|
+// String uid = getUserId();
|
|
|
+// String cacheKey = CACHE_KEY_PREFIX + CACHE_KEY_MSG_HISTORY + ":" + uid;
|
|
|
+// redisTemplate.opsForValue().set(cacheKey, chatHistoryVO.getContent());
|
|
|
+// return Result.OK("保存成功");
|
|
|
+// }
|
|
|
public Result<?> saveHistory(ChatHistoryVO chatHistoryVO) {
|
|
|
String uid = getUserId();
|
|
|
- String cacheKey = CACHE_KEY_PREFIX + CACHE_KEY_MSG_HISTORY + ":" + uid;
|
|
|
- redisTemplate.opsForValue().set(cacheKey, chatHistoryVO.getContent());
|
|
|
+ ChatHistory chatHistory = new ChatHistory();
|
|
|
+ chatHistory.setUserId(uid);
|
|
|
+ chatHistory.setRole("USER");
|
|
|
+ chatHistory.setContent(chatHistoryVO.getContent());
|
|
|
+ chatHistory.setCreateTime(new Date());
|
|
|
+ chatHistoryMapper.insert(chatHistory);
|
|
|
return Result.OK("保存成功");
|
|
|
}
|
|
|
|