知识库修改

This commit is contained in:
limin 2025-01-05 17:45:13 +08:00
parent eca575b743
commit db90cd9a79
8 changed files with 69 additions and 2 deletions

View File

@ -65,8 +65,8 @@ public class KnowledgeBaseController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('llm:knowledge-base:query')")
public CommonResult<KnowledgeBaseRespVO> getKnowledgeBase(@RequestParam("id") Long id) {
KnowledgeBaseDO knowledgeBase = knowledgeBaseService.getKnowledgeBase(id);
return success(BeanUtils.toBean(knowledgeBase, KnowledgeBaseRespVO.class));
KnowledgeBaseRespVO KnowledgeBaseRespVO = knowledgeBaseService.getKnowledgeBase1(id);
return success(KnowledgeBaseRespVO);
}
@GetMapping("/page")

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.KnowledgeDocumentsRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.KnowledgeDocumentsSaveReqVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
@ -47,5 +49,7 @@ public class KnowledgeBaseRespVO {
@Schema(description = "文件引用")
@ExcelProperty("文件引用")
private String knowledgeFile;
@Schema(description = "文件引用上传")
private List<KnowledgeDocumentsRespVO> knowledgeDocuments;
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.KnowledgeDocumentsSaveReqVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
@ -34,4 +35,6 @@ public class KnowledgeBaseSaveReqVO {
@Schema(description = "文件引用")
private String knowledgeFile;
@Schema(description = "文件引用上传")
private List<KnowledgeDocumentsSaveReqVO> knowledgeDocuments;
}

View File

@ -35,5 +35,7 @@ public class KnowledgeDocumentsRespVO {
@Schema(description = "文件状态使用字典llm_file_status", example = "1")
@ExcelProperty("文件状态使用字典llm_file_status")
private Integer status;
@Schema(description = "文件id", example = "1")
private Long fileId;
}

View File

@ -25,4 +25,7 @@ public class KnowledgeDocumentsSaveReqVO {
@Schema(description = "文件状态使用字典llm_file_status", example = "1")
private Integer status;
@Schema(description = "文件id", example = "1")
private Long fileId;
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
@ -43,5 +44,9 @@ public class KnowledgeDocumentsDO extends BaseDO {
* 文件状态使用字典llm_file_status
*/
private Integer status;
/**
* 文件Id
*/
private Long fileId;
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.llm.service.knowledgebase;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo.KnowledgeBasePageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo.KnowledgeBaseRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo.KnowledgeBaseSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgebase.KnowledgeBaseDO;
@ -54,4 +55,11 @@ public interface KnowledgeBaseService {
PageResult<KnowledgeBaseDO> getKnowledgeBasePage(KnowledgeBasePageReqVO pageReqVO);
List<KnowledgeBaseDO> getKnowledgeBaseList();
/**
* 返回知识库详情
* @param id
* @return
*/
KnowledgeBaseRespVO getKnowledgeBase1(Long id);
}

View File

@ -1,11 +1,18 @@
package cn.iocoder.yudao.module.llm.service.knowledgebase;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo.KnowledgeBasePageReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo.KnowledgeBaseRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgebase.vo.KnowledgeBaseSaveReqVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.KnowledgeDocumentsRespVO;
import cn.iocoder.yudao.module.llm.controller.admin.knowledgedocuments.vo.KnowledgeDocumentsSaveReqVO;
import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgebase.KnowledgeBaseDO;
import cn.iocoder.yudao.module.llm.dal.dataobject.knowledgedocuments.KnowledgeDocumentsDO;
import cn.iocoder.yudao.module.llm.dal.mysql.knowledgebase.KnowledgeBaseMapper;
import cn.iocoder.yudao.module.llm.dal.mysql.knowledgedocuments.KnowledgeDocumentsMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -14,6 +21,7 @@ import static cn.iocoder.yudao.module.llm.enums.ErrorCodeConstants.KNOWLEDGE_BAS
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* 知识库 Service 实现类
@ -26,6 +34,8 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
@Resource
private KnowledgeBaseMapper knowledgeBaseMapper;
@Resource
private KnowledgeDocumentsMapper knowledgeDocumentsMapper;
@Override
public Long createKnowledgeBase(KnowledgeBaseSaveReqVO createReqVO) {
@ -43,6 +53,25 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
// 更新
KnowledgeBaseDO updateObj = BeanUtils.toBean(updateReqVO, KnowledgeBaseDO.class);
knowledgeBaseMapper.updateById(updateObj);
// 附表增加数据
if (!CollectionUtils.isAnyEmpty(updateReqVO.getKnowledgeDocuments())){
List<Long> ids = updateReqVO.getKnowledgeDocuments().stream().map(KnowledgeDocumentsSaveReqVO::getId).collect(Collectors.toList());
if (!CollectionUtils.isAnyEmpty(ids)){
knowledgeDocumentsMapper.delete(new LambdaQueryWrapperX<KnowledgeDocumentsDO>()
.eq(KnowledgeDocumentsDO::getKnowledgeBaseId, updateReqVO.getId())
.notIn(KnowledgeDocumentsDO::getId, ids));
}else {
knowledgeDocumentsMapper.delete(new LambdaQueryWrapperX<KnowledgeDocumentsDO>()
.eq(KnowledgeDocumentsDO::getKnowledgeBaseId, updateReqVO.getId()));
}
updateReqVO.getKnowledgeDocuments().forEach(
knowledgeDocuments -> {
KnowledgeDocumentsDO knowledgeDocumentsDO = BeanUtils.toBean(knowledgeDocuments, KnowledgeDocumentsDO.class);
knowledgeDocumentsDO.setKnowledgeBaseId(updateReqVO.getId());
knowledgeDocumentsMapper.insertOrUpdate(knowledgeDocumentsDO);
}
);
}
}
@Override
@ -74,4 +103,17 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
return knowledgeBaseMapper.selectList();
}
@Override
public KnowledgeBaseRespVO getKnowledgeBase1(Long id) {
KnowledgeBaseDO knowledgeBaseDO = knowledgeBaseMapper.selectById(id);
if (knowledgeBaseDO != null) {
KnowledgeBaseRespVO knowledgeBaseRespVO = BeanUtils.toBean(knowledgeBaseDO, KnowledgeBaseRespVO.class);
List<KnowledgeDocumentsDO> knowledgeDocuments = knowledgeDocumentsMapper.selectList(
KnowledgeDocumentsDO::getKnowledgeBaseId, id);
knowledgeBaseRespVO.setKnowledgeDocuments(BeanUtils.toBean(knowledgeDocuments, KnowledgeDocumentsRespVO.class));
return knowledgeBaseRespVO;
}
return null;
}
}