From 4cc87539d8af08377876520129b82d03dd71c267 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Wed, 24 Apr 2024 17:09:24 +0800 Subject: [PATCH] =?UTF-8?q?chat=E8=A7=92=E8=89=B2=E5=A2=9E=E5=8A=A0=20add?= =?UTF-8?q?=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/ai/convert/ChatRoleConvert.java | 9 +++++++++ .../module/ai/service/ChatRoleService.java | 2 +- .../ai/service/impl/ChatRoleServiceImpl.java | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java index de5bece68..c3c7cb7f0 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/convert/ChatRoleConvert.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.ai.convert; import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; +import cn.iocoder.yudao.module.ai.vo.ChatRoleAddReq; import cn.iocoder.yudao.module.ai.vo.ChatRoleListRes; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -26,4 +27,12 @@ public interface ChatRoleConvert { * @return */ List convertChatRoleListRes(List roleList); + + /** + * 转换 - AiChatRoleDO + * + * @param req + * @return + */ + AiChatRoleDO convertAiChatRoleDO(ChatRoleAddReq req); } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java index 839e29ad7..2b7734107 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java @@ -28,7 +28,7 @@ public interface ChatRoleService { * @param req * @return */ - ChatRoleListRes add(ChatRoleAddReq req); + void add(ChatRoleAddReq req); /** * chat角色 - 修改 diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java index 1d46367fb..3285785ea 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java @@ -3,8 +3,12 @@ package cn.iocoder.yudao.module.ai.service.impl; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.ai.convert.ChatRoleConvert; import cn.iocoder.yudao.module.ai.dal.dataobject.AiChatRoleDO; +import cn.iocoder.yudao.module.ai.enums.ChatRoleClassifyEnum; +import cn.iocoder.yudao.module.ai.enums.ChatRoleSourceEnum; +import cn.iocoder.yudao.module.ai.enums.ChatRoleVisibilityEnum; import cn.iocoder.yudao.module.ai.mapper.AiChatRoleMapper; import cn.iocoder.yudao.module.ai.service.ChatRoleService; import cn.iocoder.yudao.module.ai.vo.*; @@ -47,8 +51,17 @@ public class ChatRoleServiceImpl implements ChatRoleService { } @Override - public ChatRoleListRes add(ChatRoleAddReq req) { - return null; + public void add(ChatRoleAddReq req) { + // 转换enum,并校验enum + ChatRoleClassifyEnum.valueOfClassify(req.getClassify()); + ChatRoleVisibilityEnum.valueOfType(req.getVisibility()); + ChatRoleSourceEnum.valueOfType(req.getRoleSource()); + // 转换do + AiChatRoleDO insertAiChatRoleDO = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req); + insertAiChatRoleDO.setUserId(SecurityFrameworkUtils.getLoginUserId()); + insertAiChatRoleDO.setUseCount(0); + // 保存 + aiChatRoleMapper.insert(insertAiChatRoleDO); } @Override