Commit a0b3bd32b0d283003d099a00ccd6ffcc7a3818b3
1 parent
3556e460
测试 role,列表和添加
Showing
6 changed files
with
18 additions
and
18 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/ChatRoleController.java
| @@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.*; | @@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.*; | ||
| 19 | */ | 19 | */ |
| 20 | @Tag(name = "A4-chat角色") | 20 | @Tag(name = "A4-chat角色") |
| 21 | @RestController | 21 | @RestController |
| 22 | -@RequestMapping("/ai/chat/role") | 22 | +@RequestMapping("/ai/chat") |
| 23 | @Slf4j | 23 | @Slf4j |
| 24 | @AllArgsConstructor | 24 | @AllArgsConstructor |
| 25 | public class ChatRoleController { | 25 | public class ChatRoleController { |
| @@ -27,34 +27,35 @@ public class ChatRoleController { | @@ -27,34 +27,35 @@ public class ChatRoleController { | ||
| 27 | private final ChatRoleService chatRoleService; | 27 | private final ChatRoleService chatRoleService; |
| 28 | 28 | ||
| 29 | @Operation(summary = "chat角色 - 角色列表") | 29 | @Operation(summary = "chat角色 - 角色列表") |
| 30 | - @GetMapping("/list") | 30 | + @GetMapping("/role/list") |
| 31 | public PageResult<ChatRoleListRes> list(@Validated @ModelAttribute ChatRoleListReq req) { | 31 | public PageResult<ChatRoleListRes> list(@Validated @ModelAttribute ChatRoleListReq req) { |
| 32 | return chatRoleService.list(req); | 32 | return chatRoleService.list(req); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | @Operation(summary = "chat角色 - 添加") | 35 | @Operation(summary = "chat角色 - 添加") |
| 36 | - @PutMapping("/add") | 36 | + @PutMapping("/role") |
| 37 | public CommonResult<Void> add(@Validated @RequestBody ChatRoleAddReq req) { | 37 | public CommonResult<Void> add(@Validated @RequestBody ChatRoleAddReq req) { |
| 38 | chatRoleService.add(req); | 38 | chatRoleService.add(req); |
| 39 | return CommonResult.success(null); | 39 | return CommonResult.success(null); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | @Operation(summary = "chat角色 - 修改") | 42 | @Operation(summary = "chat角色 - 修改") |
| 43 | - @PostMapping("/update") | ||
| 44 | - public CommonResult<Void> update(@Validated @RequestBody ChatRoleUpdateReq req) { | ||
| 45 | - chatRoleService.update(req); | 43 | + @PostMapping("/role/{id}") |
| 44 | + public CommonResult<Void> update(@PathVariable("id") Long id, | ||
| 45 | + @Validated @RequestBody ChatRoleUpdateReq req) { | ||
| 46 | + chatRoleService.update(id, req); | ||
| 46 | return CommonResult.success(null); | 47 | return CommonResult.success(null); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | @Operation(summary = "chat角色 - 修改可见性") | 50 | @Operation(summary = "chat角色 - 修改可见性") |
| 50 | - @PostMapping("/update-visibility") | 51 | + @PostMapping("/role/update-visibility") |
| 51 | public CommonResult<Void> updateVisibility(@Validated @RequestBody ChatRoleUpdateVisibilityReq req) { | 52 | public CommonResult<Void> updateVisibility(@Validated @RequestBody ChatRoleUpdateVisibilityReq req) { |
| 52 | chatRoleService.updateVisibility(req); | 53 | chatRoleService.updateVisibility(req); |
| 53 | return CommonResult.success(null); | 54 | return CommonResult.success(null); |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | @Operation(summary = "chat角色 - 修改可见性") | 57 | @Operation(summary = "chat角色 - 修改可见性") |
| 57 | - @DeleteMapping("/delete") | 58 | + @DeleteMapping("/role") |
| 58 | public CommonResult<Void> delete(@RequestParam("chatRoleId") Long chatRoleId) { | 59 | public CommonResult<Void> delete(@RequestParam("chatRoleId") Long chatRoleId) { |
| 59 | chatRoleService.delete(chatRoleId); | 60 | chatRoleService.delete(chatRoleId); |
| 60 | return CommonResult.success(null); | 61 | return CommonResult.success(null); |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/AiChatRoleDO.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ai.dal.dataobject; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.ai.dal.dataobject; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import com.baomidou.mybatisplus.annotation.IdType; | 4 | import com.baomidou.mybatisplus.annotation.IdType; |
| 5 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | +import com.baomidou.mybatisplus.annotation.TableName; | ||
| 6 | import lombok.Data; | 7 | import lombok.Data; |
| 7 | import lombok.experimental.Accessors; | 8 | import lombok.experimental.Accessors; |
| 8 | 9 | ||
| @@ -14,6 +15,7 @@ import lombok.experimental.Accessors; | @@ -14,6 +15,7 @@ import lombok.experimental.Accessors; | ||
| 14 | */ | 15 | */ |
| 15 | @Data | 16 | @Data |
| 16 | @Accessors(chain = true) | 17 | @Accessors(chain = true) |
| 18 | +@TableName("ai_chat_role") | ||
| 17 | public class AiChatRoleDO extends BaseDO { | 19 | public class AiChatRoleDO extends BaseDO { |
| 18 | /** | 20 | /** |
| 19 | * 编号,表示聊天角色在数据库中的唯一标识符 | 21 | * 编号,表示聊天角色在数据库中的唯一标识符 |
| @@ -52,7 +54,7 @@ public class AiChatRoleDO extends BaseDO { | @@ -52,7 +54,7 @@ public class AiChatRoleDO extends BaseDO { | ||
| 52 | private String classify; | 54 | private String classify; |
| 53 | 55 | ||
| 54 | /** | 56 | /** |
| 55 | - * 发布状态,0表示仅自己可见,1表示公开,2表示禁用 | 57 | + * 发布状态,private 表示仅自己可见,public表示公开,disable表示禁用 |
| 56 | */ | 58 | */ |
| 57 | private String visibility; | 59 | private String visibility; |
| 58 | 60 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/ChatRoleService.java
| @@ -33,9 +33,10 @@ public interface ChatRoleService { | @@ -33,9 +33,10 @@ public interface ChatRoleService { | ||
| 33 | /** | 33 | /** |
| 34 | * chat角色 - 修改 | 34 | * chat角色 - 修改 |
| 35 | * | 35 | * |
| 36 | + * @param id | ||
| 36 | * @param req | 37 | * @param req |
| 37 | */ | 38 | */ |
| 38 | - void update(ChatRoleUpdateReq req); | 39 | + void update(Long id, ChatRoleUpdateReq req); |
| 39 | 40 | ||
| 40 | 41 | ||
| 41 | /** | 42 | /** |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/ChatRoleServiceImpl.java
| @@ -67,15 +67,16 @@ public class ChatRoleServiceImpl implements ChatRoleService { | @@ -67,15 +67,16 @@ public class ChatRoleServiceImpl implements ChatRoleService { | ||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | @Override | 69 | @Override |
| 70 | - public void update(ChatRoleUpdateReq req) { | 70 | + public void update(Long id, ChatRoleUpdateReq req) { |
| 71 | // 转换enum,并校验enum | 71 | // 转换enum,并校验enum |
| 72 | ChatRoleClassifyEnum.valueOfClassify(req.getClassify()); | 72 | ChatRoleClassifyEnum.valueOfClassify(req.getClassify()); |
| 73 | ChatRoleVisibilityEnum.valueOfType(req.getVisibility()); | 73 | ChatRoleVisibilityEnum.valueOfType(req.getVisibility()); |
| 74 | ChatRoleSourceEnum.valueOfType(req.getRoleSource()); | 74 | ChatRoleSourceEnum.valueOfType(req.getRoleSource()); |
| 75 | // 检查角色是否存在 | 75 | // 检查角色是否存在 |
| 76 | - validateChatRoleExists(req.getId()); | 76 | + validateChatRoleExists(id); |
| 77 | // 转换do | 77 | // 转换do |
| 78 | AiChatRoleDO updateChatRole = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req); | 78 | AiChatRoleDO updateChatRole = ChatRoleConvert.INSTANCE.convertAiChatRoleDO(req); |
| 79 | + updateChatRole.setId(id); | ||
| 79 | aiChatRoleMapper.updateById(updateChatRole); | 80 | aiChatRoleMapper.updateById(updateChatRole); |
| 80 | } | 81 | } |
| 81 | 82 |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleAddReq.java
| @@ -37,7 +37,7 @@ public class ChatRoleAddReq extends PageParam { | @@ -37,7 +37,7 @@ public class ChatRoleAddReq extends PageParam { | ||
| 37 | private String classify; | 37 | private String classify; |
| 38 | 38 | ||
| 39 | @NotNull | 39 | @NotNull |
| 40 | - @Schema(description = "发布状态,0表示仅自己可见,1表示公开,2表示禁用") | 40 | + @Schema(description = "发布状态,private 表示仅自己可见,public表示公开,disable表示禁用\n") |
| 41 | private String visibility; | 41 | private String visibility; |
| 42 | 42 | ||
| 43 | @NotNull | 43 | @NotNull |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/vo/ChatRoleUpdateReq.java
| @@ -16,11 +16,6 @@ import lombok.experimental.Accessors; | @@ -16,11 +16,6 @@ import lombok.experimental.Accessors; | ||
| 16 | @Accessors(chain = true) | 16 | @Accessors(chain = true) |
| 17 | public class ChatRoleUpdateReq extends PageParam { | 17 | public class ChatRoleUpdateReq extends PageParam { |
| 18 | 18 | ||
| 19 | - | ||
| 20 | - @NotNull | ||
| 21 | - @Schema(description = "编号") | ||
| 22 | - private Long id; | ||
| 23 | - | ||
| 24 | @NotNull | 19 | @NotNull |
| 25 | @Schema(description = "模型编号,关联到角色使用的特定模型") | 20 | @Schema(description = "模型编号,关联到角色使用的特定模型") |
| 26 | private String modelId; | 21 | private String modelId; |