|
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -100,8 +101,7 @@ public class ChunkController {
|
|
|
|
|
|
|
|
@GetMapping("getAllChunks")
|
|
@GetMapping("getAllChunks")
|
|
|
@ApiOperation("获取所有的文本块")
|
|
@ApiOperation("获取所有的文本块")
|
|
|
- public Result<Object> getAllChunks() {
|
|
|
|
|
- KnowledgeStatisticsVO statistics = new KnowledgeStatisticsVO();
|
|
|
|
|
|
|
+ public Result<Object> getAllChunks(QueryPageDTO page) {
|
|
|
// 1. 调用Dify API获取所有知识库列表(使用较大分页以获取全部数据)
|
|
// 1. 调用Dify API获取所有知识库列表(使用较大分页以获取全部数据)
|
|
|
String url = difyProperties.getBaseUrl() + "datasets";
|
|
String url = difyProperties.getBaseUrl() + "datasets";
|
|
|
Result<Object> datasetsResult = httpService.get(
|
|
Result<Object> datasetsResult = httpService.get(
|
|
@@ -142,7 +142,7 @@ public class ChunkController {
|
|
|
String url2 = difyProperties.getBaseUrl() + "datasets/" + datasets_id + "/documents/" + document_id+"/segments";
|
|
String url2 = difyProperties.getBaseUrl() + "datasets/" + datasets_id + "/documents/" + document_id+"/segments";
|
|
|
Result<Object> chunks_result = httpService.get(
|
|
Result<Object> chunks_result = httpService.get(
|
|
|
url2,
|
|
url2,
|
|
|
- Map.of("page", 1, "limit", 10000),
|
|
|
|
|
|
|
+ page.getKeyword()==null?Map.of("page", 1, "limit", 10000):Map.of("page", 1, "limit", 10000,"keyword", page.getKeyword()),
|
|
|
"Bearer " + difyProperties.getDatasetApiKey(),
|
|
"Bearer " + difyProperties.getDatasetApiKey(),
|
|
|
new TypeReference<>() {
|
|
new TypeReference<>() {
|
|
|
});
|
|
});
|
|
@@ -151,7 +151,13 @@ public class ChunkController {
|
|
|
Map<?, ?> responseMap3 = (Map<?, ?>) responseData2;
|
|
Map<?, ?> responseMap3 = (Map<?, ?>) responseData2;
|
|
|
Object dataObj2 = responseMap3.get("data");
|
|
Object dataObj2 = responseMap3.get("data");
|
|
|
if (dataObj2 instanceof List<?> dataList2) {
|
|
if (dataObj2 instanceof List<?> dataList2) {
|
|
|
- results.addAll(dataList2);
|
|
|
|
|
|
|
+ //results.addAll(dataList2);
|
|
|
|
|
+ for (Object item2 : dataList2) {
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ Map<String, Object> datasetMap2 = (Map<String, Object>) item2;
|
|
|
|
|
+ datasetMap2.put("dataset_id", datasets_id);
|
|
|
|
|
+ results.add(datasetMap2);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -164,6 +170,25 @@ public class ChunkController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return Result.ok(results);
|
|
|
|
|
|
|
+ // 对结果进行分页
|
|
|
|
|
+ int total = results.size();
|
|
|
|
|
+ int pageIndex = page.getPageIndex() != null ? page.getPageIndex() : 1;
|
|
|
|
|
+ int pageSize = page.getPageSize() != null ? page.getPageSize() : 10;
|
|
|
|
|
+ int fromIndex = (pageIndex - 1) * pageSize;
|
|
|
|
|
+ int toIndex = Math.min(fromIndex + pageSize, total);
|
|
|
|
|
+
|
|
|
|
|
+ List<Object> pagedResults;
|
|
|
|
|
+ if (fromIndex >= total) {
|
|
|
|
|
+ pagedResults = new ArrayList<>();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ pagedResults = results.subList(fromIndex, toIndex);
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String,Object> resultMap = new HashMap<>() ;
|
|
|
|
|
+ resultMap.put("data", pagedResults);
|
|
|
|
|
+ resultMap.put("total", total);
|
|
|
|
|
+ resultMap.put("limit", pageSize);
|
|
|
|
|
+ resultMap.put("page", pageIndex);
|
|
|
|
|
+ resultMap.put("has_more", total > (fromIndex + pageSize));
|
|
|
|
|
+ return Result.ok(resultMap);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|