|
|
@@ -7,6 +7,7 @@ import com.storlead.framework.common.result.Result;
|
|
|
import com.storlead.knowledge.config.DifyProperties;
|
|
|
import com.storlead.knowledge.pojo.dto.DocumentDTO;
|
|
|
import com.storlead.knowledge.pojo.dto.KnowledgeDTO;
|
|
|
+import com.storlead.knowledge.service.KnowledgeBaseService;
|
|
|
import com.storlead.knowledge.utils.HttpService;
|
|
|
import com.storlead.knowledge.utils.JacksonHolder;
|
|
|
import com.storlead.knowledge.pojo.dto.QueryPageDTO;
|
|
|
@@ -32,6 +33,9 @@ public class DocumentController {
|
|
|
@Resource
|
|
|
private DifyProperties difyProperties;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private KnowledgeBaseService baseService;
|
|
|
+
|
|
|
|
|
|
@GetMapping("{dataset_id}/documents")
|
|
|
@ApiOperation("获取知识库文档")
|
|
|
@@ -58,8 +62,9 @@ public class DocumentController {
|
|
|
|
|
|
@DeleteMapping("{dataset_id}/documents/{document_id}")
|
|
|
@ApiOperation("删除指定ID的文档")
|
|
|
- public Result<Object> deleteDocument(@PathVariable String dataset_id , @PathVariable String document_id) {
|
|
|
+ public Result<Object> deleteDocument(@PathVariable String dataset_id , @PathVariable String document_id) throws JsonProcessingException {
|
|
|
String url = difyProperties.getBaseUrl() + "datasets/"+dataset_id + "/documents/"+document_id;
|
|
|
+ baseService.updateKonwledgeBase(dataset_id, new KnowledgeDTO ("all_team_members"));
|
|
|
return httpService.delete(
|
|
|
url,
|
|
|
null,
|
|
|
@@ -75,6 +80,7 @@ public class DocumentController {
|
|
|
// System.out.println(body);
|
|
|
// System.out.println(url);
|
|
|
// System.out.println(difyProperties.getDatasetApiKey());
|
|
|
+ baseService.updateKonwledgeBase(dataset_id, new KnowledgeDTO ("all_team_members"));
|
|
|
return httpService.post(url, null, "Bearer "+difyProperties.getDatasetApiKey(), body, new TypeReference<>() {});
|
|
|
}
|
|
|
|
|
|
@@ -84,8 +90,9 @@ public class DocumentController {
|
|
|
@RequestParam("file") MultipartFile file,
|
|
|
@RequestParam("data") String data,
|
|
|
@PathVariable String dataset_id
|
|
|
- ) {
|
|
|
+ ) throws JsonProcessingException {
|
|
|
String url = difyProperties.getBaseUrl() +"datasets/"+ dataset_id + "/document/create-by-file";
|
|
|
+ baseService.updateKonwledgeBase(dataset_id, new KnowledgeDTO ("all_team_members"));
|
|
|
return httpService.uploadWithJson(
|
|
|
url,
|
|
|
file,
|
|
|
@@ -102,6 +109,7 @@ public class DocumentController {
|
|
|
@PathVariable String dataset_id,
|
|
|
@PathVariable String document_id
|
|
|
) throws JsonProcessingException {
|
|
|
+ baseService.updateKonwledgeBase(dataset_id, new KnowledgeDTO ("all_team_members"));
|
|
|
String url = difyProperties.getBaseUrl() +"datasets/"+dataset_id + "/documents/"+document_id+"/update-by-text";
|
|
|
String body = JacksonHolder.OBJECT_MAPPER.writeValueAsString(knowledgeDTO);
|
|
|
return httpService.patch(url, null, "Bearer "+difyProperties.getDatasetApiKey(), body, new TypeReference<>() {});
|
|
|
@@ -116,7 +124,8 @@ public class DocumentController {
|
|
|
@RequestParam("data") String data, //格式 {"indexing_technique":"high_quality","doc_form":"text_model","doc_language":"English","process_rule":{"mode":"automatic"}}
|
|
|
@PathVariable String dataset_id,
|
|
|
@PathVariable String document_id
|
|
|
- ) {
|
|
|
+ ) throws JsonProcessingException {
|
|
|
+ baseService.updateKonwledgeBase(dataset_id, new KnowledgeDTO ("all_team_members"));
|
|
|
String url = difyProperties.getBaseUrl() + "datasets/"+dataset_id + "/documents/"+ document_id+"/create-by-file";
|
|
|
return httpService.uploadWithJson(
|
|
|
url,
|