优化知识库接口
This commit is contained in:
@@ -4,9 +4,17 @@ import com.gxwebsoft.ai.dto.KnowledgeBaseRequest;
|
|||||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||||
import com.gxwebsoft.common.core.web.ApiResult;
|
import com.gxwebsoft.common.core.web.ApiResult;
|
||||||
import com.gxwebsoft.common.core.web.BaseController;
|
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.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -42,9 +50,12 @@ public class KnowledgeBaseController extends BaseController {
|
|||||||
|
|
||||||
@Operation(summary = "查询知识库下的文档列表")
|
@Operation(summary = "查询知识库下的文档列表")
|
||||||
@GetMapping("/documents")
|
@GetMapping("/documents")
|
||||||
public ApiResult<?> listDocuments(String kbId) {
|
public ApiResult<?> listDocuments(String kbId, Integer pageSize, Integer pageNumber) {
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
return fail("查询文档列表失败:" + e.getMessage());
|
return fail("查询文档列表失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.gxwebsoft.ai.service;
|
|||||||
|
|
||||||
import com.gxwebsoft.ai.dto.KnowledgeBaseRequest;
|
import com.gxwebsoft.ai.dto.KnowledgeBaseRequest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
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.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -107,13 +108,14 @@ public class KnowledgeBaseServiceImpl implements KnowledgeBaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Object> listDocuments(String kbId) {
|
public Map<String,Object> listDocuments(String kbId, Integer pageSize, Integer pageNumber) {
|
||||||
List<Object> ret = new ArrayList<>();
|
Map<String,Object> ret = new HashMap<>();
|
||||||
String workspaceId = config.getWorkspaceId();
|
String workspaceId = config.getWorkspaceId();
|
||||||
try {
|
try {
|
||||||
Client client = clientFactory.createClient();
|
Client client = clientFactory.createClient();
|
||||||
ListIndexDocumentsResponse indexDocumentsResponse = KnowledgeBaseUtil.listIndexDocuments(client, workspaceId, kbId);
|
ListIndexDocumentsResponse indexDocumentsResponse = KnowledgeBaseUtil.listIndexDocuments(client, workspaceId, kbId, pageSize, pageNumber);
|
||||||
ret.addAll(indexDocumentsResponse.getBody().getData().getDocuments());
|
ret.put("data", indexDocumentsResponse.getBody().getData().getDocuments());
|
||||||
|
ret.put("total", indexDocumentsResponse.getBody().getData().getTotalCount());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("查询知识库下的文档列表失败: " + e.getMessage(), e);
|
throw new RuntimeException("查询知识库下的文档列表失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,9 +98,11 @@ public class KnowledgeBaseUtil {
|
|||||||
* @param indexId 知识库ID
|
* @param indexId 知识库ID
|
||||||
* @return 阿里云百炼服务的响应
|
* @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();
|
com.aliyun.bailian20231229.models.ListIndexDocumentsRequest listIndexDocumentsRequest = new com.aliyun.bailian20231229.models.ListIndexDocumentsRequest();
|
||||||
listIndexDocumentsRequest.setIndexId(indexId);
|
listIndexDocumentsRequest.setIndexId(indexId);
|
||||||
|
listIndexDocumentsRequest.setPageSize(pageSize);
|
||||||
|
listIndexDocumentsRequest.setPageNumber(pageNumber);
|
||||||
return client.listIndexDocuments(workspaceId, listIndexDocumentsRequest);
|
return client.listIndexDocuments(workspaceId, listIndexDocumentsRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public class OaCompanyController extends BaseController {
|
|||||||
return fail("单位唯一标识不能为空");
|
return fail("单位唯一标识不能为空");
|
||||||
}
|
}
|
||||||
if (oaCompanyService.save(oaCompany)) {
|
if (oaCompanyService.save(oaCompany)) {
|
||||||
|
try {
|
||||||
//查询知识库
|
//查询知识库
|
||||||
String kbId = knowledgeBaseService.getKnowledgeBaseId(oaCompany.getCompanyCode());
|
String kbId = knowledgeBaseService.getKnowledgeBaseId(oaCompany.getCompanyCode());
|
||||||
//新建知识库
|
//新建知识库
|
||||||
@@ -82,7 +83,9 @@ public class OaCompanyController extends BaseController {
|
|||||||
//绑定知识库
|
//绑定知识库
|
||||||
oaCompany.setKbId(kbId);
|
oaCompany.setKbId(kbId);
|
||||||
oaCompanyService.updateById(oaCompany);
|
oaCompanyService.updateById(oaCompany);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return fail("添加失败:"+e.getMessage());
|
||||||
|
}
|
||||||
return success("添加成功");
|
return success("添加成功");
|
||||||
}
|
}
|
||||||
return fail("添加失败");
|
return fail("添加失败");
|
||||||
|
|||||||
Reference in New Issue
Block a user