| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.approve.dto.KnowledgeBaseVectorVO; |
| | | import com.ruoyi.approve.pojo.KnowledgeBase; |
| | | import com.ruoyi.approve.pojo.KnowledgeBaseVector; |
| | | import com.ruoyi.approve.service.KnowledgeBaseService; |
| | | import com.ruoyi.approve.service.KnowledgeBaseVectorService; |
| | | import com.ruoyi.basic.dto.StorageAttachmentDTO; |
| | | import com.ruoyi.basic.dto.StorageBlobDTO; |
| | | import com.ruoyi.basic.pojo.StorageAttachment; |
| | | import com.ruoyi.basic.pojo.StorageBlob; |
| | | import com.ruoyi.basic.service.StorageAttachmentService; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.basic.service.StorageBlobService; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.framework.web.domain.AjaxResult; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | private KnowledgeBaseService knowledgeBaseService; |
| | | private KnowledgeBaseVectorService knowledgeBaseVectorService; |
| | | private StorageAttachmentService storageAttachmentService; |
| | | private StorageBlobService storageBlobService; |
| | | |
| | | /** |
| | | * 获取列表 |
| | |
| | | // 创建向量记录并触发向量化 |
| | | for (Long blobId : dto.getStorageBlobIds()) { |
| | | // 获取文件信息 |
| | | var blob = storageAttachmentService.getBaseMapper() |
| | | .selectOne(com.baomidou.mybatisplus.core.toolkit.Wrappers.<StorageAttachment>lambdaQuery() |
| | | .eq(StorageAttachment::getStorageBlobId, blobId) |
| | | .eq(StorageAttachment::getRecordType, "knowledge_base") |
| | | .eq(StorageAttachment::getRecordId, dto.getKnowledgeBaseId()) |
| | | .last("limit 1")); |
| | | |
| | | StorageBlob blob = storageBlobService.getById(blobId); |
| | | if (blob != null) { |
| | | // 获取文件名,需要从 storage_blob 表获取 |
| | | // 这里简化处理,实际需要查询 storage_blob 表 |
| | | String fileName = "file_" + blobId; |
| | | String fileType = "unknown"; |
| | | String fileName = blob.getOriginalFilename(); |
| | | String fileType = getFileExtension(fileName); |
| | | |
| | | knowledgeBaseVectorService.createVectorRecord( |
| | | dto.getKnowledgeBaseId(), |
| | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | private String getFileExtension(String fileName) { |
| | | if (fileName == null || !fileName.contains(".")) { |
| | | return "unknown"; |
| | | } |
| | | return fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase(); |
| | | } |
| | | |
| | | /** |
| | | * 删除知识库文件 |
| | | */ |