Browse Source

add:知识库删除文件级联删除文件分段信息和向量库

zhongwei
luyie 2 months ago
parent
commit
04d2e4b493
  1. 8
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/KnowledgeFileInfoController.java
  2. 7
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/KnowledgeFileInfoService.java
  3. 18
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

8
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/KnowledgeFileInfoController.java

@ -1,8 +1,11 @@
package com.hnac.gglm.bigmodel.maintenance.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileFragment;
import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.gglm.bigmodel.maintenance.service.KnowledgeFileFragmentService;
import com.hnac.gglm.bigmodel.maintenance.service.KnowledgeFileInfoService;
import com.hnac.gglm.bigmodel.maintenance.vo.IdRequest;
import com.hnac.gglm.bigmodel.maintenance.vo.IdsRequest;
@ -21,6 +24,8 @@ import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/9/10 16:44
@ -66,7 +71,8 @@ public class KnowledgeFileInfoController {
@ApiOperation(value = "删除")
@ApiOperationSupport(order = 5)
public R remove(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) {
return R.status(knowledgeFileInfoService.removeByIds(Func.toLongList(",", ids)));
List<Long> idsList = Func.toLongList(",", ids);
return R.status(knowledgeFileInfoService.removeRecursive( idsList));
}
@PostMapping(value = "/upload", produces = MediaType.APPLICATION_PROBLEM_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)

7
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/KnowledgeFileInfoService.java

@ -9,12 +9,15 @@ import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/9/10 16:42
*/
public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> {
String SEGMENT_URL= "/kn/doc_segment";
String SEGMENT_URL = "/kn/doc_segment";
String VICTOR_DATABASE_NAME = "knowledge_data";
Boolean store(IdRequest req);
@ -23,4 +26,6 @@ public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> {
IPage<KnowledgeFileInfo> listPage(IPage<KnowledgeFileInfo> page, KnowledgeFileInfo req);
R<BladeFile> upload(MultipartFile file);
Boolean removeRecursive(List<Long> idsList);
}

18
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

@ -8,12 +8,16 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.gglm.bigmodel.configuration.BigModelInvokeApi;
import com.hnac.gglm.bigmodel.maintenance.constants.StoreStatus;
import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileFragment;
import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileInfo;
import com.hnac.gglm.bigmodel.maintenance.mapper.KnowledgeFileInfoMapper;
import com.hnac.gglm.bigmodel.maintenance.service.KnowledgeFileFragmentService;
import com.hnac.gglm.bigmodel.maintenance.service.KnowledgeFileInfoService;
import com.hnac.gglm.bigmodel.maintenance.vo.IdRequest;
import com.hnac.gglm.bigmodel.maintenance.vo.IdsRequest;
import com.hnac.gglm.bigmodel.utils.RequestClientUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.oss.model.BladeFile;
@ -41,7 +45,9 @@ import java.util.Map;
@DS("hznlm")
public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoMapper, KnowledgeFileInfo> implements KnowledgeFileInfoService {
private final KnowledgeFileInfoMapper knowledgeFileInfoMapper;
private final KnowledgeFileFragmentService fileFragmentService;
private final IOssClient ossClient;
private final BigModelInvokeApi invokeApi;
@Value("${gglm.url}")
private String interactionUrl;
@ -110,4 +116,16 @@ public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoM
public R<BladeFile> upload(MultipartFile file) {
return ossClient.putFile(file);
}
@Override
public Boolean removeRecursive(List<Long> idsList) {
Boolean result = removeByIds(idsList);
if (result) {
fileFragmentService.remove(Wrappers.<KnowledgeFileFragment>lambdaQuery().in(KnowledgeFileFragment::getDocId, idsList));
Map<String, String> deleteTableParams = new HashMap<>(1);
deleteTableParams.put("table_name", VICTOR_DATABASE_NAME);
RequestClientUtil.postCall(interactionUrl + invokeApi.getDeleteTable(), deleteTableParams);
}
return result;
}
}

Loading…
Cancel
Save