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 da3f83548..2fdb16681 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 @@ -73,22 +73,37 @@ public class ChatRoleServiceImpl implements ChatRoleService { ChatRoleVisibilityEnum.valueOfType(req.getVisibility()); ChatRoleSourceEnum.valueOfType(req.getRoleSource()); // 检查角色是否存在 - AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(req.getId()); - if (aiChatRoleDO == null) { - throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CHAT_ROLE_NOT_EXIST); - } + validateChatRoleExists(req.getId()); // 转换do AiChatRoleDO updateChatRole = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req); aiChatRoleMapper.updateById(updateChatRole); } + @Override public void updateVisibility(ChatRoleUpdateVisibilityReq req) { - + // 转换enum,并校验enum + ChatRoleVisibilityEnum.valueOfType(req.getVisibility()); + // 检查角色是否存在 + validateChatRoleExists(req.getId()); + // 更新 + aiChatRoleMapper.updateById(new AiChatRoleDO() + .setId(req.getId()) + .setVisibility(req.getVisibility()) + ); } @Override public void delete(Long chatRoleId) { } + + private AiChatRoleDO validateChatRoleExists(Long id) { + AiChatRoleDO aiChatRoleDO = aiChatRoleMapper.selectById(id); + if (aiChatRoleDO == null) { + throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_CHAT_ROLE_NOT_EXIST); + } + return aiChatRoleDO; + } + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateVisibilityReq.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateVisibilityReq.java index 3ae25f4ab..22241dc0d 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateVisibilityReq.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateVisibilityReq.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.ai.vo; import cn.iocoder.yudao.framework.common.pojo.PageParam; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.experimental.Accessors; @@ -15,6 +16,11 @@ import lombok.experimental.Accessors; @Accessors(chain = true) public class ChatRoleUpdateVisibilityReq extends PageParam { - @Schema(description = "查询") - private String search; + @NotNull + @Schema(description = "编号") + private Long id; + + @NotNull + @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用") + private String visibility; }