diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationController.java index 988490a6f..7bd3c5a14 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatConversationController.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.ai.controller.admin.chat; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationCreateReqVO; -import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationListReqVO; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; import cn.iocoder.yudao.module.ai.service.AiChatConversationService; @@ -47,8 +46,8 @@ public class AiChatConversationController { // TODO done @fan:实现一下 @GetMapping("/list") @Operation(summary = "获得聊天会话列表") - public CommonResult> getConversationList(@ModelAttribute AiChatConversationListReqVO listReqVO) { - return success(aiChatConversationService.listConversation(listReqVO)); + public CommonResult> getConversationList() { + return success(aiChatConversationService.listConversation()); } // TODO @fan:实现一下 diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java index 63e947e59..285611cbe 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/chat/AiChatMessageController.java @@ -31,7 +31,7 @@ public class AiChatMessageController { @Operation(summary = "发送消息(段式)", description = "一次性返回,响应较慢") @PostMapping("/send") public CommonResult sendMessage(@Validated @ModelAttribute AiChatMessageSendReqVO sendReqVO) { - // TODO @fan:使用 static import;这样就 success 就行了; + // TODO done @fan:使用 static import;这样就 success 就行了; return success(chatService.chat(sendReqVO)); } @@ -49,14 +49,14 @@ public class AiChatMessageController { @GetMapping("/list-by-conversation-id") @Parameter(name = "conversationId", required = true, description = "会话编号", example = "1024") public CommonResult> getMessageListByConversationId(@RequestParam("conversationId") Long conversationId) { - return success(null); + return success(chatService.getMessageListByConversationId(conversationId)); } @Operation(summary = "删除消息") @DeleteMapping("/delete") @Parameter(name = "id", required = true, description = "消息编号", example = "1024") - public CommonResult delete(@RequestParam("id") Long id) { - return success(null); + public CommonResult deleteMessage(@RequestParam("id") Long id) { + return success(chatService.deleteMessage(id)); } } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java index c84ecb404..d067a26f3 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/AiChatMessageConvert.java @@ -20,10 +20,18 @@ public interface AiChatMessageConvert { AiChatMessageConvert INSTANCE = Mappers.getMapper(AiChatMessageConvert.class); /** - * 转换 ChatMessageListRes + * 转换 ChatMessageListRes * * @param list * @return */ List convert(List list); + + /** + * 转换 AiChatMessageRespVO + * + * @param aiChatMessageDOList + * @return + */ + List convertAiChatMessageRespVOList(List aiChatMessageDOList); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatMessageMapper.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatMessageMapper.java index 515e34333..4e2100aff 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatMessageMapper.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiChatMessageMapper.java @@ -6,6 +6,8 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; +import java.util.List; + /** * message mapper * @@ -29,4 +31,12 @@ public interface AiChatMessageMapper extends BaseMapperX { ); } + /** + * 查询 - 根据 对话id查询 + * + * @param conversationId + */ + default List selectByConversationId(Long conversationId) { + return selectList() + } } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java index 663cde77a..1abf2476f 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatConversationService.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatCo import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationListReqVO; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationRespVO; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatConversationUpdateReqVO; +import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatConversationDO; +import org.jetbrains.annotations.NotNull; import java.util.List; @@ -34,10 +36,9 @@ public interface AiChatConversationService { /** * 获取 - 对话列表 * - * @param req * @return */ - List listConversation(AiChatConversationListReqVO req); + List listConversation(); /** * 获取 - 对话 @@ -54,4 +55,11 @@ public interface AiChatConversationService { */ Boolean deleteConversation(Long id); + /** + * 校验 - 是否存在 + * + * @param id + * @return + */ + AiChatConversationDO validateExists(Long id); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java index e25062e78..27ece6b14 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/AiChatService.java @@ -4,6 +4,8 @@ import cn.iocoder.yudao.module.ai.controller.Utf8SseEmitter; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; +import java.util.List; + /** * 聊天 chat * @@ -29,4 +31,21 @@ public interface AiChatService { * @return */ void chatStream(AiChatMessageSendReqVO req, Utf8SseEmitter sseEmitter); + + /** + * 获取 - 获取对话 message list + * + * @param conversationId + * @return + */ + List getMessageListByConversationId(Long conversationId); + + /** + * 删除 - 删除message + * + * @param id + * @return + */ + Boolean deleteMessage(Long id); + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java index 6fbafc659..5f45f27b6 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatConversationServiceImpl.java @@ -98,12 +98,12 @@ public class AiChatConversationServiceImpl implements AiChatConversationService } @Override - public List listConversation(AiChatConversationListReqVO listReqVO) { + public List listConversation() { // 获取用户id Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); // 查询前100对话 List top100Conversation - = aiChatConversationMapper.selectTop100Conversation(loginUserId, listReqVO.getTitle()); + = aiChatConversationMapper.selectTop100Conversation(loginUserId, null); return AiChatConversationConvert.INSTANCE.covnertChatConversationResList(top100Conversation); } @@ -118,7 +118,7 @@ public class AiChatConversationServiceImpl implements AiChatConversationService return aiChatConversationMapper.deleteById(id) > 0; } - private @NotNull AiChatConversationDO validateExists(Long id) { + public @NotNull AiChatConversationDO validateExists(Long id) { AiChatConversationDO aiChatConversationDO = aiChatConversationMapper.selectById(id); if (aiChatConversationDO == null) { throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CONVERSATION_NOT_EXISTS); diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java index b5e2634de..63ef59aa5 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiChatServiceImpl.java @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.conversation.AiChatCo import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageRespVO; import cn.iocoder.yudao.module.ai.controller.admin.chat.vo.message.AiChatMessageSendReqVO; import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiChatModalRes; +import cn.iocoder.yudao.module.ai.convert.AiChatMessageConvert; import cn.iocoder.yudao.module.ai.dal.dataobject.chat.AiChatMessageDO; import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatRoleDO; import cn.iocoder.yudao.module.ai.dal.mysql.AiChatConversationMapper; @@ -31,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional; import reactor.core.publisher.Flux; import java.io.IOException; +import java.util.List; import java.util.function.Consumer; /** @@ -187,4 +189,19 @@ public class AiChatServiceImpl implements AiChatService { } ); } + + @Override + public List getMessageListByConversationId(Long conversationId) { + // 校验对话是否存在 + chatConversationService.validateExists(conversationId); + // 获取对话所有 message + List aiChatMessageDOList = aiChatMessageMapper.selectByConversationId(conversationId); + // 转换 AiChatMessageRespVO + return AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); + } + + @Override + public Boolean deleteMessage(Long id) { + return aiChatMessageMapper.deleteById(id) > 0; + } }