Commit 66d020892019ead137c71a9263c2b99ca0103a3c
1 parent
00c2ca8b
1、增加获取最新的对话
2、增加获取top100的对话
Showing
2 changed files
with
39 additions
and
2 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dataobject/AiChatConversationDO.java
| ... | ... | @@ -30,10 +30,10 @@ public class AiChatConversationDO extends BaseDO { |
| 30 | 30 | @Schema(description = "chat角色名称") |
| 31 | 31 | private String chatRoleName; |
| 32 | 32 | |
| 33 | - @Schema(description = "对话标题(有程序自动生成)") | |
| 33 | + @Schema(description = "聊天标题(有程序自动生成)") | |
| 34 | 34 | private String chatTitle; |
| 35 | 35 | |
| 36 | - @Schema(description = "对话标题(有程序自动生成)") | |
| 36 | + @Schema(description = "聊天次数(有程序自动生成)") | |
| 37 | 37 | private Integer chatCount; |
| 38 | 38 | |
| 39 | 39 | @Schema(description = "对话类型(roleChat、userChat)") | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/mapper/AiChatConversationMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.mapper; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 3 | 7 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | 8 | import cn.iocoder.yudao.module.ai.dataobject.AiChatConversationDO; |
| 9 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |
| 5 | 10 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 11 | import org.apache.ibatis.annotations.Param; |
| 7 | 12 | import org.apache.ibatis.annotations.Update; |
| 8 | 13 | import org.springframework.stereotype.Repository; |
| 9 | 14 | |
| 15 | +import java.util.List; | |
| 16 | + | |
| 10 | 17 | /** |
| 11 | 18 | * message mapper |
| 12 | 19 | * |
| ... | ... | @@ -21,4 +28,34 @@ public interface AiChatConversationMapper extends BaseMapperX<AiChatConversation |
| 21 | 28 | @Update("update ai_chat_conversation set chat_count = chat_count + 1 where id = #{id}") |
| 22 | 29 | void updateIncrChatCount(@Param("id") Long id); |
| 23 | 30 | |
| 31 | + /** | |
| 32 | + * 查询 - 最新的对话 | |
| 33 | + * | |
| 34 | + * @param loginUserId | |
| 35 | + */ | |
| 36 | + default AiChatConversationDO selectLatestConversation(Long loginUserId) { | |
| 37 | + PageResult<AiChatConversationDO> pageResult = selectPage(new PageParam().setPageNo(1).setPageSize(1), | |
| 38 | + new LambdaQueryWrapper<AiChatConversationDO>() | |
| 39 | + .eq(AiChatConversationDO::getUserId, loginUserId) | |
| 40 | + .orderByDesc(AiChatConversationDO::getId)); | |
| 41 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 42 | + return null; | |
| 43 | + } | |
| 44 | + return pageResult.getList().get(0); | |
| 45 | + } | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 查询 - 前100 | |
| 49 | + * | |
| 50 | + * @param search | |
| 51 | + */ | |
| 52 | + default List<AiChatConversationDO> selectTop100Conversation(Long loginUserId, String search) { | |
| 53 | + LambdaQueryWrapper<AiChatConversationDO> queryWrapper | |
| 54 | + = new LambdaQueryWrapper<AiChatConversationDO>().eq(AiChatConversationDO::getUserId, loginUserId); | |
| 55 | + if (!StrUtil.isBlank(search)) { | |
| 56 | + queryWrapper.like(AiChatConversationDO::getChatTitle, search); | |
| 57 | + } | |
| 58 | + queryWrapper.orderByDesc(AiChatConversationDO::getId); | |
| 59 | + return selectPage(new PageParam().setPageNo(1).setPageSize(100), queryWrapper).getList(); | |
| 60 | + } | |
| 24 | 61 | } | ... | ... |