优化知识库接口
This commit is contained in:
@@ -4,9 +4,17 @@ import com.gxwebsoft.ai.dto.KnowledgeBaseRequest;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.enterprise.entity.Enterprise;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -42,9 +50,12 @@ public class KnowledgeBaseController extends BaseController {
|
||||
|
||||
@Operation(summary = "查询知识库下的文档列表")
|
||||
@GetMapping("/documents")
|
||||
public ApiResult<?> listDocuments(String kbId) {
|
||||
public ApiResult<?> listDocuments(String kbId, Integer pageSize, Integer pageNumber) {
|
||||
try {
|
||||
return success(knowledgeBaseService.listDocuments(kbId));
|
||||
Map<String,Object> map = knowledgeBaseService.listDocuments(kbId, pageSize, pageNumber);
|
||||
List<Object> data = Convert.toList(Object.class, map.get("data"));
|
||||
Long total = MapUtil.getLong(map, "total");
|
||||
return success(new PageResult<Object>(data, total));
|
||||
} catch (Exception e) {
|
||||
return fail("查询文档列表失败:" + e.getMessage());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.gxwebsoft.ai.service;
|
||||
|
||||
import com.gxwebsoft.ai.dto.KnowledgeBaseRequest;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -37,7 +37,7 @@ public interface KnowledgeBaseService {
|
||||
/**
|
||||
* 查询知识库下的文档列表
|
||||
*/
|
||||
List<Object> listDocuments(String kbId);
|
||||
Map<String,Object> listDocuments(String kbId, Integer pageSize, Integer pageNumber);
|
||||
|
||||
/**
|
||||
* 删除知识库下的文档
|
||||
|
||||
@@ -19,10 +19,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@@ -107,13 +108,14 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> listDocuments(String kbId) {
|
||||
List<Object> ret = new ArrayList<>();
|
||||
public Map<String,Object> listDocuments(String kbId, Integer pageSize, Integer pageNumber) {
|
||||
Map<String,Object> ret = new HashMap<>();
|
||||
String workspaceId = config.getWorkspaceId();
|
||||
try {
|
||||
Client client = clientFactory.createClient();
|
||||
ListIndexDocumentsResponse indexDocumentsResponse = KnowledgeBaseUtil.listIndexDocuments(client, workspaceId, kbId);
|
||||
ret.addAll(indexDocumentsResponse.getBody().getData().getDocuments());
|
||||
ListIndexDocumentsResponse indexDocumentsResponse = KnowledgeBaseUtil.listIndexDocuments(client, workspaceId, kbId, pageSize, pageNumber);
|
||||
ret.put("data", indexDocumentsResponse.getBody().getData().getDocuments());
|
||||
ret.put("total", indexDocumentsResponse.getBody().getData().getTotalCount());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("查询知识库下的文档列表失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -98,9 +98,11 @@ public class KnowledgeBaseUtil {
|
||||
* @param indexId 知识库ID
|
||||
* @return 阿里云百炼服务的响应
|
||||
*/
|
||||
public static ListIndexDocumentsResponse listIndexDocuments(com.aliyun.bailian20231229.Client client, String workspaceId, String indexId) throws Exception {
|
||||
public static ListIndexDocumentsResponse listIndexDocuments(com.aliyun.bailian20231229.Client client, String workspaceId, String indexId, Integer pageSize, Integer pageNumber) throws Exception {
|
||||
com.aliyun.bailian20231229.models.ListIndexDocumentsRequest listIndexDocumentsRequest = new com.aliyun.bailian20231229.models.ListIndexDocumentsRequest();
|
||||
listIndexDocumentsRequest.setIndexId(indexId);
|
||||
listIndexDocumentsRequest.setPageSize(pageSize);
|
||||
listIndexDocumentsRequest.setPageNumber(pageNumber);
|
||||
return client.listIndexDocuments(workspaceId, listIndexDocumentsRequest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user