mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	【调整】调整AI聊天,message列表、删除message
This commit is contained in:
		| @@ -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<List<AiChatConversationRespVO>> getConversationList(@ModelAttribute AiChatConversationListReqVO listReqVO) { | ||||
|         return success(aiChatConversationService.listConversation(listReqVO)); | ||||
|     public CommonResult<List<AiChatConversationRespVO>> getConversationList() { | ||||
|         return success(aiChatConversationService.listConversation()); | ||||
|     } | ||||
|  | ||||
|     // TODO @fan:实现一下 | ||||
|   | ||||
| @@ -31,7 +31,7 @@ public class AiChatMessageController { | ||||
|     @Operation(summary = "发送消息(段式)", description = "一次性返回,响应较慢") | ||||
|     @PostMapping("/send") | ||||
|     public CommonResult<AiChatMessageRespVO> 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<List<AiChatMessageRespVO>> 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<Boolean> delete(@RequestParam("id") Long id) { | ||||
|         return success(null); | ||||
|     public CommonResult<Boolean> deleteMessage(@RequestParam("id") Long id) { | ||||
|         return success(chatService.deleteMessage(id)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -20,10 +20,18 @@ public interface AiChatMessageConvert { | ||||
|     AiChatMessageConvert INSTANCE = Mappers.getMapper(AiChatMessageConvert.class); | ||||
|  | ||||
|     /** | ||||
|      * 转换  ChatMessageListRes | ||||
|      * 转换 ChatMessageListRes | ||||
|      * | ||||
|      * @param list | ||||
|      * @return | ||||
|      */ | ||||
|     List<AiChatMessageRespVO> convert(List<AiChatMessageDO> list); | ||||
|  | ||||
|     /** | ||||
|      * 转换 AiChatMessageRespVO | ||||
|      * | ||||
|      * @param aiChatMessageDOList | ||||
|      * @return | ||||
|      */ | ||||
|     List<AiChatMessageRespVO> convertAiChatMessageRespVOList(List<AiChatMessageDO> aiChatMessageDOList); | ||||
| } | ||||
|   | ||||
| @@ -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<AiChatMessageDO> { | ||||
|         ); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询 - 根据 对话id查询 | ||||
|      * | ||||
|      * @param conversationId | ||||
|      */ | ||||
|     default List<AiChatMessageDO> selectByConversationId(Long conversationId) { | ||||
|         return selectList() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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<AiChatConversationRespVO> listConversation(AiChatConversationListReqVO req); | ||||
|     List<AiChatConversationRespVO> listConversation(); | ||||
|  | ||||
|     /** | ||||
|      * 获取 - 对话 | ||||
| @@ -54,4 +55,11 @@ public interface AiChatConversationService { | ||||
|      */ | ||||
|     Boolean deleteConversation(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 校验 - 是否存在 | ||||
|      * | ||||
|      * @param id | ||||
|      * @return | ||||
|      */ | ||||
|     AiChatConversationDO validateExists(Long id); | ||||
| } | ||||
|   | ||||
| @@ -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<AiChatMessageRespVO> getMessageListByConversationId(Long conversationId); | ||||
|  | ||||
|     /** | ||||
|      * 删除 - 删除message | ||||
|      * | ||||
|      * @param id | ||||
|      * @return | ||||
|      */ | ||||
|     Boolean deleteMessage(Long id); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -98,12 +98,12 @@ public class AiChatConversationServiceImpl implements AiChatConversationService | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public List<AiChatConversationRespVO> listConversation(AiChatConversationListReqVO listReqVO) { | ||||
|     public List<AiChatConversationRespVO> listConversation() { | ||||
|         // 获取用户id | ||||
|         Long loginUserId = SecurityFrameworkUtils.getLoginUserId(); | ||||
|         // 查询前100对话 | ||||
|         List<AiChatConversationDO> 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); | ||||
|   | ||||
| @@ -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<AiChatMessageRespVO> getMessageListByConversationId(Long conversationId) { | ||||
|         // 校验对话是否存在 | ||||
|         chatConversationService.validateExists(conversationId); | ||||
|         // 获取对话所有 message | ||||
|         List<AiChatMessageDO> aiChatMessageDOList = aiChatMessageMapper.selectByConversationId(conversationId); | ||||
|         // 转换 AiChatMessageRespVO | ||||
|        return AiChatMessageConvert.INSTANCE.convertAiChatMessageRespVOList(aiChatMessageDOList); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Boolean deleteMessage(Long id) { | ||||
|         return aiChatMessageMapper.deleteById(id) > 0; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 cherishsince
					cherishsince