Commit e869aaee836cb96554e83cfd6a4b0088b76aa125
1 parent
ffe4afaa
【功能新增】AI:增加函数的管理
Showing
12 changed files
with
401 additions
and
18 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java
| ... | ... | @@ -32,29 +32,33 @@ public interface ErrorCodeConstants { |
| 32 | 32 | ErrorCode CHAT_STREAM_ERROR = new ErrorCode(1_040_004_001, "对话生成异常!"); |
| 33 | 33 | |
| 34 | 34 | // ========== API 绘画 1-040-005-000 ========== |
| 35 | - ErrorCode IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "图片不存在!"); | |
| 36 | - ErrorCode IMAGE_MIDJOURNEY_SUBMIT_FAIL = new ErrorCode(1_022_005_001, "Midjourney 提交失败!原因:{}"); | |
| 37 | - ErrorCode IMAGE_CUSTOM_ID_NOT_EXISTS = new ErrorCode(1_022_005_002, "Midjourney 按钮 customId 不存在! {}"); | |
| 35 | + ErrorCode IMAGE_NOT_EXISTS = new ErrorCode(1_040_005_000, "图片不存在!"); | |
| 36 | + ErrorCode IMAGE_MIDJOURNEY_SUBMIT_FAIL = new ErrorCode(1_040_005_001, "Midjourney 提交失败!原因:{}"); | |
| 37 | + ErrorCode IMAGE_CUSTOM_ID_NOT_EXISTS = new ErrorCode(1_040_005_002, "Midjourney 按钮 customId 不存在! {}"); | |
| 38 | 38 | |
| 39 | 39 | // ========== API 音乐 1-040-006-000 ========== |
| 40 | - ErrorCode MUSIC_NOT_EXISTS = new ErrorCode(1_022_006_000, "音乐不存在!"); | |
| 40 | + ErrorCode MUSIC_NOT_EXISTS = new ErrorCode(1_040_006_000, "音乐不存在!"); | |
| 41 | 41 | |
| 42 | - // ========== API 写作 1-022-007-000 ========== | |
| 43 | - ErrorCode WRITE_NOT_EXISTS = new ErrorCode(1_022_007_000, "作文不存在!"); | |
| 44 | - ErrorCode WRITE_STREAM_ERROR = new ErrorCode(1_022_07_001, "写作生成异常!"); | |
| 42 | + // ========== API 写作 1-040-007-000 ========== | |
| 43 | + ErrorCode WRITE_NOT_EXISTS = new ErrorCode(1_040_007_000, "作文不存在!"); | |
| 44 | + ErrorCode WRITE_STREAM_ERROR = new ErrorCode(1_040_07_001, "写作生成异常!"); | |
| 45 | 45 | |
| 46 | 46 | // ========== API 思维导图 1-040-008-000 ========== |
| 47 | 47 | ErrorCode MIND_MAP_NOT_EXISTS = new ErrorCode(1_040_008_000, "思维导图不存在!"); |
| 48 | 48 | |
| 49 | - // ========== API 知识库 1-022-008-000 ========== | |
| 50 | - ErrorCode KNOWLEDGE_NOT_EXISTS = new ErrorCode(1_022_008_000, "知识库不存在!"); | |
| 49 | + // ========== API 知识库 1-040-009-000 ========== | |
| 50 | + ErrorCode KNOWLEDGE_NOT_EXISTS = new ErrorCode(1_040_009_000, "知识库不存在!"); | |
| 51 | 51 | |
| 52 | - ErrorCode KNOWLEDGE_DOCUMENT_NOT_EXISTS = new ErrorCode(1_022_008_101, "文档不存在!"); | |
| 53 | - ErrorCode KNOWLEDGE_DOCUMENT_FILE_EMPTY = new ErrorCode(1_022_008_102, "文档内容为空!"); | |
| 54 | - ErrorCode KNOWLEDGE_DOCUMENT_FILE_DOWNLOAD_FAIL = new ErrorCode(1_022_008_102, "文件下载失败!"); | |
| 55 | - ErrorCode KNOWLEDGE_DOCUMENT_FILE_READ_FAIL = new ErrorCode(1_022_008_102, "文档加载失败!"); | |
| 52 | + ErrorCode KNOWLEDGE_DOCUMENT_NOT_EXISTS = new ErrorCode(1_040_009_101, "文档不存在!"); | |
| 53 | + ErrorCode KNOWLEDGE_DOCUMENT_FILE_EMPTY = new ErrorCode(1_040_009_102, "文档内容为空!"); | |
| 54 | + ErrorCode KNOWLEDGE_DOCUMENT_FILE_DOWNLOAD_FAIL = new ErrorCode(1_040_009_102, "文件下载失败!"); | |
| 55 | + ErrorCode KNOWLEDGE_DOCUMENT_FILE_READ_FAIL = new ErrorCode(1_040_009_102, "文档加载失败!"); | |
| 56 | 56 | |
| 57 | - ErrorCode KNOWLEDGE_SEGMENT_NOT_EXISTS = new ErrorCode(1_022_008_202, "段落不存在!"); | |
| 58 | - ErrorCode KNOWLEDGE_SEGMENT_CONTENT_TOO_LONG = new ErrorCode(1_022_008_203, "内容 Token 数为 {},超过最大限制 {}"); | |
| 57 | + ErrorCode KNOWLEDGE_SEGMENT_NOT_EXISTS = new ErrorCode(1_040_009_202, "段落不存在!"); | |
| 58 | + ErrorCode KNOWLEDGE_SEGMENT_CONTENT_TOO_LONG = new ErrorCode(1_040_009_203, "内容 Token 数为 {},超过最大限制 {}"); | |
| 59 | + | |
| 60 | + // ========== AI 工具 1-040-010-000 ========== | |
| 61 | + ErrorCode TOOL_NOT_EXISTS = new ErrorCode(1_040_010_000, "工具不存在"); | |
| 62 | + ErrorCode TOOL_NAME_NOT_EXISTS = new ErrorCode(1_040_010_001, "工具({})找不到 Bean"); | |
| 59 | 63 | |
| 60 | 64 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/AiToolController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.model; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolRespVO; | |
| 8 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiToolDO; | |
| 10 | +import cn.iocoder.yudao.module.ai.service.model.AiToolService; | |
| 11 | +import io.swagger.v3.oas.annotations.Operation; | |
| 12 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | +import jakarta.annotation.Resource; | |
| 15 | +import jakarta.validation.Valid; | |
| 16 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | +import org.springframework.validation.annotation.Validated; | |
| 18 | +import org.springframework.web.bind.annotation.*; | |
| 19 | + | |
| 20 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 21 | + | |
| 22 | + | |
| 23 | +@Tag(name = "管理后台 - AI 工具") | |
| 24 | +@RestController | |
| 25 | +@RequestMapping("/ai/tool") | |
| 26 | +@Validated | |
| 27 | +public class AiToolController { | |
| 28 | + | |
| 29 | + @Resource | |
| 30 | + private AiToolService toolService; | |
| 31 | + | |
| 32 | + @PostMapping("/create") | |
| 33 | + @Operation(summary = "创建AI 工具") | |
| 34 | + @PreAuthorize("@ss.hasPermission('ai:tool:create')") | |
| 35 | + public CommonResult<Long> createTool(@Valid @RequestBody AiToolSaveReqVO createReqVO) { | |
| 36 | + return success(toolService.createTool(createReqVO)); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @PutMapping("/update") | |
| 40 | + @Operation(summary = "更新AI 工具") | |
| 41 | + @PreAuthorize("@ss.hasPermission('ai:tool:update')") | |
| 42 | + public CommonResult<Boolean> updateTool(@Valid @RequestBody AiToolSaveReqVO updateReqVO) { | |
| 43 | + toolService.updateTool(updateReqVO); | |
| 44 | + return success(true); | |
| 45 | + } | |
| 46 | + | |
| 47 | + @DeleteMapping("/delete") | |
| 48 | + @Operation(summary = "删除AI 工具") | |
| 49 | + @Parameter(name = "id", description = "编号", required = true) | |
| 50 | + @PreAuthorize("@ss.hasPermission('ai:tool:delete')") | |
| 51 | + public CommonResult<Boolean> deleteTool(@RequestParam("id") Long id) { | |
| 52 | + toolService.deleteTool(id); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @GetMapping("/get") | |
| 57 | + @Operation(summary = "获得AI 工具") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 59 | + @PreAuthorize("@ss.hasPermission('ai:tool:query')") | |
| 60 | + public CommonResult<AiToolRespVO> getTool(@RequestParam("id") Long id) { | |
| 61 | + AiToolDO tool = toolService.getTool(id); | |
| 62 | + return success(BeanUtils.toBean(tool, AiToolRespVO.class)); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @GetMapping("/page") | |
| 66 | + @Operation(summary = "获得AI 工具分页") | |
| 67 | + @PreAuthorize("@ss.hasPermission('ai:tool:query')") | |
| 68 | + public CommonResult<PageResult<AiToolRespVO>> getToolPage(@Valid AiToolPageReqVO pageReqVO) { | |
| 69 | + PageResult<AiToolDO> pageResult = toolService.getToolPage(pageReqVO); | |
| 70 | + return success(BeanUtils.toBean(pageResult, AiToolRespVO.class)); | |
| 71 | + } | |
| 72 | + | |
| 73 | +} | |
| 0 | 74 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/tool/AiToolPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 6 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 7 | +import lombok.Data; | |
| 8 | +import lombok.EqualsAndHashCode; | |
| 9 | +import lombok.ToString; | |
| 10 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 11 | + | |
| 12 | +import java.time.LocalDateTime; | |
| 13 | + | |
| 14 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 15 | + | |
| 16 | +@Schema(description = "管理后台 - AI 工具分页 Request VO") | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +public class AiToolPageReqVO extends PageParam { | |
| 21 | + | |
| 22 | + @Schema(description = "工具名称", example = "王五") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "工具描述", example = "你猜") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "状态", example = "1") | |
| 29 | + @InEnum(CommonStatusEnum.class) | |
| 30 | + private Integer status; | |
| 31 | + | |
| 32 | + @Schema(description = "创建时间") | |
| 33 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 34 | + private LocalDateTime[] createTime; | |
| 35 | + | |
| 36 | +} | |
| 0 | 37 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/tool/AiToolRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +@Schema(description = "管理后台 - AI 工具 Response VO") | |
| 9 | +@Data | |
| 10 | +public class AiToolRespVO { | |
| 11 | + | |
| 12 | + @Schema(description = "工具编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19661") | |
| 13 | + private Long id; | |
| 14 | + | |
| 15 | + @Schema(description = "工具名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | |
| 16 | + private String name; | |
| 17 | + | |
| 18 | + @Schema(description = "工具描述", example = "你猜") | |
| 19 | + private String description; | |
| 20 | + | |
| 21 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 22 | + private Integer status; | |
| 23 | + | |
| 24 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 25 | + private LocalDateTime createTime; | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/model/vo/tool/AiToolSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import jakarta.validation.constraints.NotEmpty; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - AI 工具新增/修改 Request VO") | |
| 10 | +@Data | |
| 11 | +public class AiToolSaveReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "工具编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19661") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @Schema(description = "工具名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | |
| 17 | + @NotEmpty(message = "工具名称不能为空") | |
| 18 | + private String name; | |
| 19 | + | |
| 20 | + @Schema(description = "工具描述", example = "你猜") | |
| 21 | + private String description; | |
| 22 | + | |
| 23 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 24 | + @InEnum(CommonStatusEnum.class) | |
| 25 | + private Integer status; | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/model/AiToolDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.dataobject.model; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 4 | +import cn.iocoder.yudao.module.ai.service.model.tool.DirectoryListToolFunction; | |
| 5 | +import cn.iocoder.yudao.module.ai.service.model.tool.WeatherQueryToolFunction; | |
| 6 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 8 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 9 | +import lombok.*; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * AI 工具 DO | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +@TableName("ai_tool") | |
| 17 | +@KeySequence("ai_tool_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 18 | +@Data | |
| 19 | +@EqualsAndHashCode(callSuper = true) | |
| 20 | +@ToString(callSuper = true) | |
| 21 | +@Builder | |
| 22 | +@NoArgsConstructor | |
| 23 | +@AllArgsConstructor | |
| 24 | +public class AiToolDO extends BaseDO { | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 工具编号 | |
| 28 | + */ | |
| 29 | + @TableId | |
| 30 | + private Long id; | |
| 31 | + /** | |
| 32 | + * 工具名称 | |
| 33 | + * | |
| 34 | + * 对应 Bean 的名字,例如说: | |
| 35 | + * 1. {@link DirectoryListToolFunction} 的 Bean 名字是 directory_list | |
| 36 | + * 2. {@link WeatherQueryToolFunction} 的 Bean 名字是 weather_query | |
| 37 | + */ | |
| 38 | + private String name; | |
| 39 | + /** | |
| 40 | + * 工具描述 | |
| 41 | + */ | |
| 42 | + private String description; | |
| 43 | + /** | |
| 44 | + * 状态 | |
| 45 | + * | |
| 46 | + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum} | |
| 47 | + */ | |
| 48 | + private Integer status; | |
| 49 | + | |
| 50 | +} | |
| 0 | 51 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/model/AiToolMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.dal.mysql.model; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiToolDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * AI 工具 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface AiToolMapper extends BaseMapperX<AiToolDO> { | |
| 17 | + | |
| 18 | + default PageResult<AiToolDO> selectPage(AiToolPageReqVO reqVO) { | |
| 19 | + return selectPage(reqVO, new LambdaQueryWrapperX<AiToolDO>() | |
| 20 | + .likeIfPresent(AiToolDO::getName, reqVO.getName()) | |
| 21 | + .eqIfPresent(AiToolDO::getDescription, reqVO.getDescription()) | |
| 22 | + .eqIfPresent(AiToolDO::getStatus, reqVO.getStatus()) | |
| 23 | + .betweenIfPresent(AiToolDO::getCreateTime, reqVO.getCreateTime()) | |
| 24 | + .orderByDesc(AiToolDO::getId)); | |
| 25 | + } | |
| 26 | + | |
| 27 | +} | |
| 0 | 28 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiToolService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.service.model; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiToolDO; | |
| 7 | +import jakarta.validation.Valid; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * AI 工具 Service 接口 | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +public interface AiToolService { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 创建AI 工具 | |
| 18 | + * | |
| 19 | + * @param createReqVO 创建信息 | |
| 20 | + * @return 编号 | |
| 21 | + */ | |
| 22 | + Long createTool(@Valid AiToolSaveReqVO createReqVO); | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 更新AI 工具 | |
| 26 | + * | |
| 27 | + * @param updateReqVO 更新信息 | |
| 28 | + */ | |
| 29 | + void updateTool(@Valid AiToolSaveReqVO updateReqVO); | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 删除AI 工具 | |
| 33 | + * | |
| 34 | + * @param id 编号 | |
| 35 | + */ | |
| 36 | + void deleteTool(Long id); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 获得AI 工具 | |
| 40 | + * | |
| 41 | + * @param id 编号 | |
| 42 | + * @return AI 工具 | |
| 43 | + */ | |
| 44 | + AiToolDO getTool(Long id); | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * 获得AI 工具分页 | |
| 48 | + * | |
| 49 | + * @param pageReqVO 分页查询 | |
| 50 | + * @return AI 工具分页 | |
| 51 | + */ | |
| 52 | + PageResult<AiToolDO> getToolPage(AiToolPageReqVO pageReqVO); | |
| 53 | + | |
| 54 | +} | |
| 0 | 55 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/AiToolServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.service.model; | |
| 2 | + | |
| 3 | +import cn.hutool.extra.spring.SpringUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.model.vo.tool.AiToolSaveReqVO; | |
| 8 | +import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiToolDO; | |
| 9 | +import cn.iocoder.yudao.module.ai.dal.mysql.model.AiToolMapper; | |
| 10 | +import jakarta.annotation.Resource; | |
| 11 | +import org.springframework.beans.factory.NoSuchBeanDefinitionException; | |
| 12 | +import org.springframework.stereotype.Service; | |
| 13 | +import org.springframework.validation.annotation.Validated; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 16 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.TOOL_NAME_NOT_EXISTS; | |
| 17 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.TOOL_NOT_EXISTS; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * AI 工具 Service 实现类 | |
| 21 | + * | |
| 22 | + * @author 芋道源码 | |
| 23 | + */ | |
| 24 | +@Service | |
| 25 | +@Validated | |
| 26 | +public class AiToolServiceImpl implements AiToolService { | |
| 27 | + | |
| 28 | + @Resource | |
| 29 | + private AiToolMapper toolMapper; | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public Long createTool(AiToolSaveReqVO createReqVO) { | |
| 33 | + // 校验名称是否存在 | |
| 34 | + validateToolNameExists(createReqVO.getName()); | |
| 35 | + | |
| 36 | + // 插入 | |
| 37 | + AiToolDO tool = BeanUtils.toBean(createReqVO, AiToolDO.class); | |
| 38 | + toolMapper.insert(tool); | |
| 39 | + return tool.getId(); | |
| 40 | + } | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public void updateTool(AiToolSaveReqVO updateReqVO) { | |
| 44 | + // 1.1 校验存在 | |
| 45 | + validateToolExists(updateReqVO.getId()); | |
| 46 | + // 1.2 校验名称是否存在 | |
| 47 | + validateToolNameExists(updateReqVO.getName()); | |
| 48 | + | |
| 49 | + // 2. 更新 | |
| 50 | + AiToolDO updateObj = BeanUtils.toBean(updateReqVO, AiToolDO.class); | |
| 51 | + toolMapper.updateById(updateObj); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + public void deleteTool(Long id) { | |
| 56 | + // 校验存在 | |
| 57 | + validateToolExists(id); | |
| 58 | + // 删除 | |
| 59 | + toolMapper.deleteById(id); | |
| 60 | + } | |
| 61 | + | |
| 62 | + private void validateToolExists(Long id) { | |
| 63 | + if (toolMapper.selectById(id) == null) { | |
| 64 | + throw exception(TOOL_NOT_EXISTS); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + private void validateToolNameExists(String name) { | |
| 69 | + try { | |
| 70 | + SpringUtil.getBean(name); | |
| 71 | + } catch (NoSuchBeanDefinitionException e) { | |
| 72 | + throw exception(TOOL_NAME_NOT_EXISTS, name); | |
| 73 | + } | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Override | |
| 77 | + public AiToolDO getTool(Long id) { | |
| 78 | + return toolMapper.selectById(id); | |
| 79 | + } | |
| 80 | + | |
| 81 | + @Override | |
| 82 | + public PageResult<AiToolDO> getToolPage(AiToolPageReqVO pageReqVO) { | |
| 83 | + return toolMapper.selectPage(pageReqVO); | |
| 84 | + } | |
| 85 | + | |
| 86 | +} | |
| 0 | 87 | \ No newline at end of file | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/tool/function/DirectoryListToolFunction.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/tool/DirectoryListToolFunction.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/tool/function/WeatherQueryToolFunction.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/model/tool/WeatherQueryToolFunction.java
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/tool/package-info.java deleted