Commit 6b8174a5a6474dd0ab2be7c1e3fb3b378456ec4d
1 parent
64fdd045
增加message list 查询
Showing
5 changed files
with
51 additions
and
4 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/ErrorCodeConstants.java
| ... | ... | @@ -21,8 +21,10 @@ public interface ErrorCodeConstants { |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - ErrorCode AI_CHAT_CONTINUE_NOT_EXIST = new ErrorCode(1_022_000_020, "chat对话不存在!");; | |
| 25 | - ErrorCode AI_CHAT_ROLE_NOT_EXIST = new ErrorCode(1_022_000_020, "chatRole不存在!");; | |
| 24 | + ErrorCode AI_CHAT_CONTINUE_NOT_EXIST = new ErrorCode(1_022_000_020, "chat对话不存在!"); | |
| 25 | + ErrorCode AI_CHAT_CONVERSATION_NOT_YOURS = new ErrorCode(1_022_000_021, "这条chat对话不是你的!"); | |
| 26 | + | |
| 27 | + ErrorCode AI_CHAT_ROLE_NOT_EXIST = new ErrorCode(1_022_000_040, "chatRole不存在!"); | |
| 26 | 28 | |
| 27 | 29 | |
| 28 | 30 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatMessageConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.convert; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatMessageDO; | |
| 4 | +import cn.iocoder.yudao.module.ai.vo.ChatMessageListRes; | |
| 5 | +import org.mapstruct.Mapper; | |
| 6 | +import org.mapstruct.factory.Mappers; | |
| 7 | + | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 聊天 对话 convert | |
| 12 | + * | |
| 13 | + * @author fansili | |
| 14 | + * @time 2024/4/18 16:39 | |
| 15 | + * @since 1.0 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface ChatMessageConvert { | |
| 19 | + | |
| 20 | + ChatMessageConvert INSTANCE = Mappers.getMapper(ChatMessageConvert.class); | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 转换 ChatMessageListRes | |
| 24 | + * | |
| 25 | + * @param list | |
| 26 | + * @return | |
| 27 | + */ | |
| 28 | + List<ChatMessageListRes> convert(List<AiChatMessageDO> list); | |
| 29 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/mapper/AiChatMessageMapper.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ai.mapper; |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 5 | 5 | import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatMessageDO; |
| 6 | +import cn.iocoder.yudao.module.ai.vo.ChatMessageReq; | |
| 6 | 7 | import org.apache.ibatis.annotations.Mapper; |
| 7 | 8 | import org.springframework.stereotype.Repository; |
| 8 | 9 | |
| ... | ... | @@ -28,4 +29,5 @@ public interface AiChatMessageMapper extends BaseMapperX<AiChatMessageDO> { |
| 28 | 29 | .eq(AiChatMessageDO::getId, id) |
| 29 | 30 | ); |
| 30 | 31 | } |
| 32 | + | |
| 31 | 33 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatMessageServiceImpl.java
| ... | ... | @@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.ai.service.impl; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | 6 | import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; |
| 6 | 7 | import cn.iocoder.yudao.module.ai.ErrorCodeConstants; |
| 8 | +import cn.iocoder.yudao.module.ai.convert.ChatMessageConvert; | |
| 7 | 9 | import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatConversationDO; |
| 10 | +import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatMessageDO; | |
| 8 | 11 | import cn.iocoder.yudao.module.ai.mapper.AiChatConversationMapper; |
| 9 | 12 | import cn.iocoder.yudao.module.ai.mapper.AiChatMessageMapper; |
| 10 | 13 | import cn.iocoder.yudao.module.ai.service.ChatMessageService; |
| ... | ... | @@ -14,6 +17,8 @@ import lombok.AllArgsConstructor; |
| 14 | 17 | import lombok.extern.slf4j.Slf4j; |
| 15 | 18 | import org.springframework.stereotype.Service; |
| 16 | 19 | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 17 | 22 | /** |
| 18 | 23 | * chat message |
| 19 | 24 | * |
| ... | ... | @@ -31,7 +36,15 @@ public class ChatMessageServiceImpl implements ChatMessageService { |
| 31 | 36 | |
| 32 | 37 | @Override |
| 33 | 38 | public PageResult<ChatMessageListRes> list(ChatMessageReq req) { |
| 34 | - return null; | |
| 39 | + // 查询 | |
| 40 | + LambdaQueryWrapperX<AiChatMessageDO> queryWrapperX = new LambdaQueryWrapperX<>(); | |
| 41 | + queryWrapperX.eq(AiChatMessageDO::getChatConversationId, req.getChatConversationId()); | |
| 42 | + // 默认排序 | |
| 43 | + queryWrapperX.orderByDesc(AiChatMessageDO::getId); | |
| 44 | + PageResult<AiChatMessageDO> pageResult = aiChatMessageMapper.selectPage(req, queryWrapperX); | |
| 45 | + // 转换 res | |
| 46 | + List<ChatMessageListRes> messageListResList = ChatMessageConvert.INSTANCE.convert(pageResult.getList()); | |
| 47 | + return new PageResult(messageListResList, pageResult.getTotal()); | |
| 35 | 48 | } |
| 36 | 49 | |
| 37 | 50 | @Override | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatMessageReq.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.vo; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 3 | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 5 | import jakarta.validation.constraints.NotNull; |
| 5 | 6 | import lombok.Data; |
| ... | ... | @@ -14,7 +15,7 @@ import lombok.experimental.Accessors; |
| 14 | 15 | */ |
| 15 | 16 | @Data |
| 16 | 17 | @Accessors(chain = true) |
| 17 | -public class ChatMessageReq { | |
| 18 | +public class ChatMessageReq extends PageParam { | |
| 18 | 19 | |
| 19 | 20 | @Schema(description = "聊天ID,关联到特定的会话或对话") |
| 20 | 21 | @NotNull | ... | ... |