feat: 拉取聊天记录

11111
winter 1 year ago
parent 56700192d9
commit d1bb7d56a9

@ -35,6 +35,13 @@ public class AiController {
List<ChatSession> sessions = chatSessionService.listMySession();
return R.success(sessions);
}
@GetMapping("chat/history/{sessionId}")
@ApiOperation("查询我的聊天记录")
public R<List<ChatSession.Message>> getHistory(@PathVariable String sessionId) {
List<ChatSession.Message> history = chatSessionService.listMyHistory(sessionId);
return R.success(history);
}
@PostMapping("session/create")
@ApiOperation("创建聊天会话")
public R<String> createSession() {

@ -13,6 +13,7 @@ import java.util.List;
*/
@Repository
public interface ChatSessionRepository extends CosmosRepository<ChatSession, String> {
ChatSession findChatSessionByIdAndCode(String id, String code);
@Query("select c.id, c.code, c.title, c.userId, c.createTime from c where c.code = 'ChatSession' and c.id = @sessionId")
List<ChatSession> findBySessionId(String sessionId);

@ -18,4 +18,6 @@ public interface ChatSessionService {
ChatSession updateSession(UpdateSessionDto updateSessionDto);
void deleteSession(String id);
List<ChatSession.Message> listMyHistory(String sessionId);
}

@ -76,7 +76,7 @@ public class ChatSessionServiceImpl implements ChatSessionService {
}
CosmosPatchOperations options = CosmosPatchOperations.create()
.replace("/title", title);
chatSessionRepository.save(id, PK.of(PK.CHAT_SESSION),ChatSession.class, options);
chatSessionRepository.save(id, PK.of(PK.CHAT_SESSION), ChatSession.class, options);
return null;
}
@ -91,4 +91,15 @@ public class ChatSessionServiceImpl implements ChatSessionService {
}
chatSessionRepository.deleteById(id, PK.of(PK.CHAT_SESSION));
}
@Override
public List<Message> listMyHistory(String sessionId) {
User user = SecurityUtil.getLoginUser();
String userId = user.getId();
ChatSession session = chatSessionRepository.findChatSessionByIdAndCode(sessionId, PK.CHAT_SESSION);
if (!userId.equals(session.getUserId())) {
throw new ServiceException(ErrorCode.NO_AUTH_ERROR);
}
return session.getHistory();
}
}

Loading…
Cancel
Save