|
@@ -18,6 +18,7 @@ import com.backendsys.utils.v2.PageUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -27,9 +28,60 @@ import java.util.concurrent.CompletableFuture;
|
|
|
@Service
|
|
|
public class ChatHistoryServiceImpl implements ChatHistoryService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ChatDao chatDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ChatHistoryDao chatHistoryDao;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取我的对话历史列表
|
|
|
+ */
|
|
|
@Override
|
|
|
- public PageEntity selectChatHistoryist(String history_code) {
|
|
|
- return null;
|
|
|
+ public PageEntity selectChatHistoryList() {
|
|
|
+ PageUtils.startPage(); // 分页
|
|
|
+ LambdaQueryWrapper<ChatHistory> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(ChatHistory::getDel_flag, -1);
|
|
|
+ wrapper.orderByAsc(ChatHistory::getCreate_time);
|
|
|
+ List<ChatHistory> list = chatHistoryDao.selectList(wrapper);
|
|
|
+ return new PageInfoResult(list).toEntity();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除我的对话历史
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Map<String, Object> deleteChatHistory(ChatHistory chatHistory) {
|
|
|
+
|
|
|
+ String history_code = chatHistory.getHistory_code();
|
|
|
+
|
|
|
+ ChatHistory chatHistoryDetail = chatHistoryDao.selectOne(new LambdaQueryWrapper<ChatHistory>()
|
|
|
+ .eq(ChatHistory::getDel_flag, -1)
|
|
|
+ .eq(ChatHistory::getHistory_code, history_code));
|
|
|
+ if (chatHistoryDetail == null) throw new CustException("history_code 不存在");
|
|
|
+ chatHistoryDetail.setDel_flag(1);
|
|
|
+ // [软删除] 删除对话记录
|
|
|
+ chatHistoryDao.updateById(chatHistoryDetail);
|
|
|
+
|
|
|
+ List<Chat> chatList = chatDao.selectList(new LambdaQueryWrapper<Chat>()
|
|
|
+ .eq(Chat::getDel_flag, -1)
|
|
|
+ .eq(Chat::getHistory_code, history_code));
|
|
|
+ if (chatList != null && !chatList.isEmpty()) {
|
|
|
+ chatList.stream().forEach(chat -> {
|
|
|
+ // [软删除] 删除对话
|
|
|
+ chat.setDel_flag(1);
|
|
|
+ System.out.println(chat);
|
|
|
+ chatDao.updateById(chat);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+// // 删除对话记录
|
|
|
+// chatHistoryDao.delete(new LambdaQueryWrapper<ChatHistory>().eq(ChatHistory::getHistory_code, history_code));
|
|
|
+
|
|
|
+// // 删除对话
|
|
|
+// chatDao.delete(new LambdaQueryWrapper<Chat>().eq(Chat::getHistory_code, history_code));
|
|
|
+
|
|
|
+ return Map.of("history_code", chatHistory.getHistory_code());
|
|
|
}
|
|
|
}
|