|
@@ -103,15 +103,24 @@ public class ChatServiceImpl implements ChatService {
|
|
|
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
|
|
|
|
- // [DB] 查询对话历史记录 (按时间升序排序,最新的在最后面) (用于对话上下文)
|
|
|
- LambdaQueryWrapper<Chat> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(Chat::getDel_flag, -1);
|
|
|
- wrapper.eq(Chat::getHistory_code, finalHistory_code);
|
|
|
- wrapper.orderByDesc(Chat::getCreate_time);
|
|
|
- List<Chat> chatList = chatDao.selectList(wrapper);
|
|
|
-
|
|
|
-
|
|
|
- // [INSERT][提问]
|
|
|
+ // [DB] 查询对话历史记录 (用于对话上下文)
|
|
|
+ // - 按 [创建时间]、[Id] 降序,最新的在最后面
|
|
|
+ // - 排除 [THINK-思考] 的内容,但允许 [Null]
|
|
|
+ List<Chat> chatList = chatDao.selectList(
|
|
|
+ new LambdaQueryWrapper<Chat>()
|
|
|
+ .eq(Chat::getDel_flag, -1)
|
|
|
+ .eq(Chat::getHistory_code, finalHistory_code)
|
|
|
+ .and(wrapper -> wrapper
|
|
|
+ .ne(Chat::getContent_type, "THINK")
|
|
|
+ .or()
|
|
|
+ .isNull(Chat::getContent_type))
|
|
|
+ .orderByDesc(Chat::getCreate_time)
|
|
|
+ .orderByDesc(Chat::getId)
|
|
|
+ );
|
|
|
+ System.out.println("chatList size: " + chatList.size());
|
|
|
+
|
|
|
+
|
|
|
+ // [INSERT][提问] 内容
|
|
|
Chat userChat = new Chat();
|
|
|
BeanUtil.copyProperties(chat, userChat);
|
|
|
chatDao.insert(userChat);
|
|
@@ -176,11 +185,12 @@ public class ChatServiceImpl implements ChatService {
|
|
|
@Override
|
|
|
public PageEntity selectChatList(Chat chat) {
|
|
|
|
|
|
- String history_code = chat.getHistory_code();
|
|
|
-
|
|
|
- ChatHistory chatHistory = chatHistoryDao.selectOne(new LambdaQueryWrapper<ChatHistory>()
|
|
|
- .eq(ChatHistory::getDel_flag, chat.getDel_flag())
|
|
|
- .eq(ChatHistory::getHistory_code, history_code));
|
|
|
+ ChatHistory chatHistory = chatHistoryDao.selectOne(
|
|
|
+ new LambdaQueryWrapper<ChatHistory>()
|
|
|
+ .eq(ChatHistory::getUser_id, chat.getUser_id())
|
|
|
+ .eq(ChatHistory::getHistory_code, chat.getHistory_code())
|
|
|
+ .eq(ChatHistory::getDel_flag, chat.getDel_flag())
|
|
|
+ );
|
|
|
if (chatHistory == null) throw new CustException("对话历史不存在");
|
|
|
|
|
|
PageUtils.startPage(); // 分页
|
|
@@ -195,17 +205,35 @@ public class ChatServiceImpl implements ChatService {
|
|
|
@Override
|
|
|
public Map<String, Object> deleteChat(Chat chat) {
|
|
|
|
|
|
- String history_code = chat.getHistory_code();
|
|
|
+ // [软删除] 删除对话
|
|
|
+ chat.setDel_flag(1);
|
|
|
+
|
|
|
+ chatDao.update(chat, new LambdaQueryWrapper<Chat>()
|
|
|
+ .eq(Chat::getUser_id, chat.getUser_id())
|
|
|
+ .eq(Chat::getDel_flag, -1)
|
|
|
+ .eq(Chat::getHistory_code, chat.getHistory_code())
|
|
|
+ );
|
|
|
|
|
|
- LambdaQueryWrapper<Chat> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(Chat::getDel_flag, -1);
|
|
|
- wrapper.eq(Chat::getHistory_code, history_code);
|
|
|
+ return Map.of("history_code", chat.getHistory_code());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除我的对话 (软删除)(单条)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> deleteChatOne(Chat chat) {
|
|
|
|
|
|
// [软删除] 删除对话
|
|
|
chat.setDel_flag(1);
|
|
|
- chatDao.update(chat, wrapper);
|
|
|
|
|
|
- return Map.of("history_code", chat.getHistory_code());
|
|
|
+ chatDao.update(chat, new LambdaQueryWrapper<Chat>()
|
|
|
+ .eq(Chat::getUser_id, chat.getUser_id())
|
|
|
+ .eq(Chat::getDel_flag, -1)
|
|
|
+ .eq(Chat::getId, chat.getId())
|
|
|
+ );
|
|
|
+ System.out.println(chat);
|
|
|
+
|
|
|
+ return Map.of("id", chat.getId());
|
|
|
}
|
|
|
|
|
|
|