Commit 6b651baeed316f9963d420b1eb72161b809e1a1c
1 parent
0700c3f1
【新增】AI:知识库可见权限整理
Showing
9 changed files
with
60 additions
and
55 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeController.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.controller.admin.knowledge; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeCreateMyReqVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeCreateReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgePageReqVO; | |
| 8 | 8 | import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeRespVO; |
| 9 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeUpdateMyReqVO; | |
| 9 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeUpdateReqVO; | |
| 10 | 10 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 11 | 11 | import cn.iocoder.yudao.module.ai.service.knowledge.AiKnowledgeService; |
| 12 | 12 | import io.swagger.v3.oas.annotations.Operation; |
| ... | ... | @@ -28,24 +28,23 @@ public class AiKnowledgeController { |
| 28 | 28 | @Resource |
| 29 | 29 | private AiKnowledgeService knowledgeService; |
| 30 | 30 | |
| 31 | - @GetMapping("/my-page") | |
| 32 | - @Operation(summary = "获取【我的】知识库分页") | |
| 33 | - public CommonResult<PageResult<AiKnowledgeRespVO>> getKnowledgePageMy(@Validated PageParam pageReqVO) { | |
| 34 | - PageResult<AiKnowledgeDO> pageResult = knowledgeService.getKnowledgePageMy(getLoginUserId(), pageReqVO); | |
| 31 | + @GetMapping("/page") | |
| 32 | + @Operation(summary = "获取知识库分页") | |
| 33 | + public CommonResult<PageResult<AiKnowledgeRespVO>> getKnowledgePage(@Valid AiKnowledgePageReqVO pageReqVO) { | |
| 34 | + PageResult<AiKnowledgeDO> pageResult = knowledgeService.getKnowledgePage(getLoginUserId(), pageReqVO); | |
| 35 | 35 | return success(BeanUtils.toBean(pageResult, AiKnowledgeRespVO.class)); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - @PostMapping("/create-my") | |
| 39 | - @Operation(summary = "创建【我的】知识库") | |
| 40 | - public CommonResult<Long> createKnowledgeMy(@RequestBody @Valid AiKnowledgeCreateMyReqVO createReqVO) { | |
| 41 | - return success(knowledgeService.createKnowledgeMy(createReqVO, getLoginUserId())); | |
| 38 | + @PostMapping("/create") | |
| 39 | + @Operation(summary = "创建知识库") | |
| 40 | + public CommonResult<Long> createKnowledge(@RequestBody @Valid AiKnowledgeCreateReqVO createReqVO) { | |
| 41 | + return success(knowledgeService.createKnowledge(createReqVO, getLoginUserId())); | |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - @PutMapping("/update-my") | |
| 45 | - @Operation(summary = "更新【我的】知识库") | |
| 46 | - public CommonResult<Boolean> updateKnowledgeMy(@RequestBody @Valid AiKnowledgeUpdateMyReqVO updateReqVO) { | |
| 47 | - knowledgeService.updateKnowledgeMy(updateReqVO, getLoginUserId()); | |
| 44 | + @PutMapping("/update") | |
| 45 | + @Operation(summary = "更新知识库") | |
| 46 | + public CommonResult<Boolean> updateKnowledge(@RequestBody @Valid AiKnowledgeUpdateReqVO updateReqVO) { | |
| 47 | + knowledgeService.updateKnowledge(updateReqVO, getLoginUserId()); | |
| 48 | 48 | return success(true); |
| 49 | 49 | } |
| 50 | - | |
| 51 | 50 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/AiKnowledgeDocumentController.java
| ... | ... | @@ -36,7 +36,7 @@ public class AiKnowledgeDocumentController { |
| 36 | 36 | |
| 37 | 37 | @GetMapping("/page") |
| 38 | 38 | @Operation(summary = "获取文档分页") |
| 39 | - public CommonResult<PageResult<AiKnowledgeDocumentRespVO>> getKnowledgeDocumentPageMy(@Valid AiKnowledgeDocumentPageReqVO pageReqVO) { | |
| 39 | + public CommonResult<PageResult<AiKnowledgeDocumentRespVO>> getKnowledgeDocumentPage(@Valid AiKnowledgeDocumentPageReqVO pageReqVO) { | |
| 40 | 40 | PageResult<AiKnowledgeDocumentDO> pageResult = documentService.getKnowledgeDocumentPage(pageReqVO); |
| 41 | 41 | return success(BeanUtils.toBean(pageResult, AiKnowledgeDocumentRespVO.class)); |
| 42 | 42 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeCreateMyReqVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeCreateReqVO.java
| ... | ... | @@ -5,11 +5,9 @@ import jakarta.validation.constraints.NotBlank; |
| 5 | 5 | import jakarta.validation.constraints.NotNull; |
| 6 | 6 | import lombok.Data; |
| 7 | 7 | |
| 8 | -import java.util.List; | |
| 9 | - | |
| 10 | -@Schema(description = "管理后台 - AI 知识库创建【我的】 Request VO") | |
| 8 | +@Schema(description = "管理后台 - AI 知识库创建 Request VO") | |
| 11 | 9 | @Data |
| 12 | -public class AiKnowledgeCreateMyReqVO { | |
| 10 | +public class AiKnowledgeCreateReqVO { | |
| 13 | 11 | |
| 14 | 12 | @Schema(description = "知识库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "ruoyi-vue-pro 用户指南") |
| 15 | 13 | @NotBlank(message = "知识库名称不能为空") |
| ... | ... | @@ -18,8 +16,8 @@ public class AiKnowledgeCreateMyReqVO { |
| 18 | 16 | @Schema(description = "知识库描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "存储 ruoyi-vue-pro 操作文档") |
| 19 | 17 | private String description; |
| 20 | 18 | |
| 21 | - @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1]") | |
| 22 | - private List<Long> visibilityPermissions; | |
| 19 | + @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") | |
| 20 | + private String visibilityPermissions; | |
| 23 | 21 | |
| 24 | 22 | @Schema(description = "嵌入模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 25 | 23 | @NotNull(message = "嵌入模型不能为空") | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +@Schema(description = "管理后台 - AI 知识库的分页 Request VO") | |
| 8 | +@Data | |
| 9 | +public class AiKnowledgePageReqVO extends PageParam { | |
| 10 | + | |
| 11 | + @Schema(description = "知识库名称", example = "Java 开发手册") | |
| 12 | + private String name; | |
| 13 | + | |
| 14 | +} | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeUpdateMyReqVO.java renamed to yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/knowledge/vo/knowledge/AiKnowledgeUpdateReqVO.java
| ... | ... | @@ -5,11 +5,9 @@ import jakarta.validation.constraints.NotBlank; |
| 5 | 5 | import jakarta.validation.constraints.NotNull; |
| 6 | 6 | import lombok.Data; |
| 7 | 7 | |
| 8 | -import java.util.List; | |
| 9 | - | |
| 10 | 8 | @Schema(description = "管理后台 - AI 知识库更新【我的】 Request VO") |
| 11 | 9 | @Data |
| 12 | -public class AiKnowledgeUpdateMyReqVO { | |
| 10 | +public class AiKnowledgeUpdateReqVO { | |
| 13 | 11 | |
| 14 | 12 | @Schema(description = "对话编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1204") |
| 15 | 13 | @NotNull(message = "知识库编号不能为空") |
| ... | ... | @@ -22,8 +20,8 @@ public class AiKnowledgeUpdateMyReqVO { |
| 22 | 20 | @Schema(description = "知识库描述", requiredMode = Schema.RequiredMode.REQUIRED, example = "") |
| 23 | 21 | private String description; |
| 24 | 22 | |
| 25 | - @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1]") | |
| 26 | - private List<Long> visibilityPermissions; | |
| 23 | + @Schema(description = "可见权限,只能选择哪些人可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "1,2,3") | |
| 24 | + private String visibilityPermissions; | |
| 27 | 25 | |
| 28 | 26 | @Schema(description = "嵌入模型编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 29 | 27 | @NotNull(message = "嵌入模型不能为空") | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/knowledge/AiKnowledgeDO.java
| ... | ... | @@ -2,14 +2,10 @@ package cn.iocoder.yudao.module.ai.dal.dataobject.knowledge; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | -import com.baomidou.mybatisplus.annotation.TableField; | |
| 6 | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
| 7 | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
| 8 | -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; | |
| 9 | 7 | import lombok.Data; |
| 10 | 8 | |
| 11 | -import java.util.List; | |
| 12 | - | |
| 13 | 9 | /** |
| 14 | 10 | * AI 知识库 DO |
| 15 | 11 | * |
| ... | ... | @@ -44,8 +40,7 @@ public class AiKnowledgeDO extends BaseDO { |
| 44 | 40 | * <p> |
| 45 | 41 | * -1 所有人可见,其他为各自用户编号 |
| 46 | 42 | */ |
| 47 | - @TableField(typeHandler = JacksonTypeHandler.class) | |
| 48 | - private List<Long> visibilityPermissions; | |
| 43 | + private String visibilityPermissions; | |
| 49 | 44 | /** |
| 50 | 45 | * 嵌入模型编号 |
| 51 | 46 | */ | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/knowledge/AiKnowledgeMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.dal.mysql.knowledge; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | 6 | import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgePageReqVO; | |
| 8 | 8 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 9 | 9 | import org.apache.ibatis.annotations.Mapper; |
| 10 | 10 | |
| ... | ... | @@ -16,10 +16,11 @@ import org.apache.ibatis.annotations.Mapper; |
| 16 | 16 | @Mapper |
| 17 | 17 | public interface AiKnowledgeMapper extends BaseMapperX<AiKnowledgeDO> { |
| 18 | 18 | |
| 19 | - default PageResult<AiKnowledgeDO> selectPageByMy(Long userId, PageParam pageReqVO) { | |
| 19 | + default PageResult<AiKnowledgeDO> selectPage(Long userId, AiKnowledgePageReqVO pageReqVO) { | |
| 20 | 20 | return selectPage(pageReqVO, new LambdaQueryWrapperX<AiKnowledgeDO>() |
| 21 | - .eq(AiKnowledgeDO::getUserId, userId) | |
| 22 | 21 | .eq(AiKnowledgeDO::getStatus, CommonStatusEnum.ENABLE.getStatus()) |
| 22 | + .likeIfPresent(AiKnowledgeDO::getName, pageReqVO.getName()) | |
| 23 | + .and(e -> e.apply("FIND_IN_SET(" + userId + ",visibility_permissions)").or(m -> m.apply("FIND_IN_SET(-1,visibility_permissions)"))) | |
| 23 | 24 | .orderByDesc(AiKnowledgeDO::getId)); |
| 24 | 25 | } |
| 25 | 26 | } | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeService.java
| 1 | 1 | package cn.iocoder.yudao.module.ai.service.knowledge; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeCreateMyReqVO; | |
| 6 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeUpdateMyReqVO; | |
| 4 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeCreateReqVO; | |
| 5 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgePageReqVO; | |
| 6 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeUpdateReqVO; | |
| 7 | 7 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 8 | 8 | import org.springframework.ai.vectorstore.VectorStore; |
| 9 | 9 | |
| ... | ... | @@ -15,21 +15,21 @@ import org.springframework.ai.vectorstore.VectorStore; |
| 15 | 15 | public interface AiKnowledgeService { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * 创建【我的】知识库 | |
| 18 | + * 创建知识库 | |
| 19 | 19 | * |
| 20 | 20 | * @param createReqVO 创建信息 |
| 21 | 21 | * @param userId 用户编号 |
| 22 | 22 | * @return 编号 |
| 23 | 23 | */ |
| 24 | - Long createKnowledgeMy(AiKnowledgeCreateMyReqVO createReqVO, Long userId); | |
| 24 | + Long createKnowledge(AiKnowledgeCreateReqVO createReqVO, Long userId); | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * 创建【我的】知识库 | |
| 27 | + * 更新知识库 | |
| 28 | 28 | * |
| 29 | 29 | * @param updateReqVO 更新信息 |
| 30 | 30 | * @param userId 用户编号 |
| 31 | 31 | */ |
| 32 | - void updateKnowledgeMy(AiKnowledgeUpdateMyReqVO updateReqVO, Long userId); | |
| 32 | + void updateKnowledge(AiKnowledgeUpdateReqVO updateReqVO, Long userId); | |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * 校验知识库是否存在 |
| ... | ... | @@ -39,13 +39,13 @@ public interface AiKnowledgeService { |
| 39 | 39 | AiKnowledgeDO validateKnowledgeExists(Long id); |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | - * 获得【我的】知识库分页 | |
| 42 | + * 获得知识库分页 | |
| 43 | 43 | * |
| 44 | - * @param userId 用户编号 | |
| 45 | - * @param pageReqVO 分页查询 | |
| 44 | + * @param userId 用户编号 | |
| 45 | + * @param pageReqVO 分页查询 | |
| 46 | 46 | * @return 知识库分页 |
| 47 | 47 | */ |
| 48 | - PageResult<AiKnowledgeDO> getKnowledgePageMy(Long userId, PageParam pageReqVO); | |
| 48 | + PageResult<AiKnowledgeDO> getKnowledgePage(Long userId, AiKnowledgePageReqVO pageReqVO); | |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * 根据知识库编号获取向量存储实例 | ... | ... |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/knowledge/AiKnowledgeServiceImpl.java
| ... | ... | @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.ai.service.knowledge; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.ObjUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | -import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 8 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeCreateMyReqVO; | |
| 9 | -import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeUpdateMyReqVO; | |
| 7 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeCreateReqVO; | |
| 8 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgePageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.ai.controller.admin.knowledge.vo.knowledge.AiKnowledgeUpdateReqVO; | |
| 10 | 10 | import cn.iocoder.yudao.module.ai.dal.dataobject.knowledge.AiKnowledgeDO; |
| 11 | 11 | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiChatModelDO; |
| 12 | 12 | import cn.iocoder.yudao.module.ai.dal.mysql.knowledge.AiKnowledgeMapper; |
| ... | ... | @@ -38,7 +38,7 @@ public class AiKnowledgeServiceImpl implements AiKnowledgeService { |
| 38 | 38 | private AiApiKeyService apiKeyService; |
| 39 | 39 | |
| 40 | 40 | @Override |
| 41 | - public Long createKnowledgeMy(AiKnowledgeCreateMyReqVO createReqVO, Long userId) { | |
| 41 | + public Long createKnowledge(AiKnowledgeCreateReqVO createReqVO, Long userId) { | |
| 42 | 42 | // 1. 校验模型配置 |
| 43 | 43 | AiChatModelDO model = chatModelService.validateChatModel(createReqVO.getModelId()); |
| 44 | 44 | |
| ... | ... | @@ -50,7 +50,7 @@ public class AiKnowledgeServiceImpl implements AiKnowledgeService { |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | @Override |
| 53 | - public void updateKnowledgeMy(AiKnowledgeUpdateMyReqVO updateReqVO, Long userId) { | |
| 53 | + public void updateKnowledge(AiKnowledgeUpdateReqVO updateReqVO, Long userId) { | |
| 54 | 54 | // 1.1 校验知识库存在 |
| 55 | 55 | AiKnowledgeDO knowledgeBaseDO = validateKnowledgeExists(updateReqVO.getId()); |
| 56 | 56 | if (ObjUtil.notEqual(knowledgeBaseDO.getUserId(), userId)) { |
| ... | ... | @@ -75,8 +75,8 @@ public class AiKnowledgeServiceImpl implements AiKnowledgeService { |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | @Override |
| 78 | - public PageResult<AiKnowledgeDO> getKnowledgePageMy(Long userId, PageParam pageReqVO) { | |
| 79 | - return knowledgeMapper.selectPageByMy(userId, pageReqVO); | |
| 78 | + public PageResult<AiKnowledgeDO> getKnowledgePage(Long userId, AiKnowledgePageReqVO pageReqVO) { | |
| 79 | + return knowledgeMapper.selectPage(userId, pageReqVO); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | @Override | ... | ... |