|
|
@@ -2,6 +2,7 @@ package com.storlead.knowledge.api;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
@@ -23,11 +24,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -114,42 +118,38 @@ public class KnowledgeController {
|
|
|
|
|
|
@GetMapping("training/page")
|
|
|
@ApiOperation("分页获取AI训练记录")
|
|
|
- public Result<IPage<AiTrainingEntity>> pageTraining(@RequestParam(defaultValue = "1") Integer pageIndex,
|
|
|
+ public Result<IPage<AiTrainingVO>> pageTraining(@RequestParam(defaultValue = "1") Integer pageIndex,
|
|
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
|
|
@RequestParam(required = false) String keyword,
|
|
|
@RequestParam(required = false) String datasetsId) {
|
|
|
IPage<AiTrainingEntity> result = aiTrainingService.pageVO(pageIndex, pageSize, keyword, datasetsId);
|
|
|
//https://api.dify.ai/v1/datasets/{dataset_id}/documents/{batch}/indexing-status
|
|
|
String url = difyProperties.getBaseUrl() ;
|
|
|
+ List <AiTrainingVO> list = new ArrayList<>();
|
|
|
for (AiTrainingEntity vo : result.getRecords()) {
|
|
|
+ AiTrainingVO vo1 = AiTrainingVO.transformVo(vo);
|
|
|
+
|
|
|
+ vo1.setCompletedDcumentCount(0);
|
|
|
+ List<AiDatasetsFileEntity> files = aiDatasetsFileService.pageVO(1, 1000, null, vo.getId()).getRecords();
|
|
|
+ vo1.setTotalDocumentCount(files.size());
|
|
|
if (vo.getStatus()==0){
|
|
|
- List<AiDatasetsFileEntity> files = aiDatasetsFileService.pageVO(1, 1000, null, vo.getId()).getRecords();
|
|
|
Boolean flag = true;
|
|
|
+
|
|
|
for (AiDatasetsFileEntity file : files) {
|
|
|
String url2 = difyProperties.getBaseUrl() + "datasets/"+vo.getDatasetsId()+"/documents/"+file.getBatch()+"/indexing-status";
|
|
|
Result<Object> result1 = httpService.get(url2, null, "Bearer "+difyProperties.getDatasetApiKey(), new TypeReference<>() {});
|
|
|
if (result1.isSuccess()) {
|
|
|
// 从Dify返回结果中提取document_id
|
|
|
Object responseData = result1.getResult();
|
|
|
-
|
|
|
JSONObject root = new JSONObject((Map<String, Object>) responseData);
|
|
|
JSONArray data = root.getJSONArray("data");
|
|
|
String indexing_status = data.getJSONObject(0).getString("indexing_status");
|
|
|
-
|
|
|
-// String indexing_status = null;
|
|
|
-// if (responseData instanceof Map) {
|
|
|
-// Object data = ((Map<?, ?>) responseData).get("data");
|
|
|
-// if (data instanceof Map) {
|
|
|
-// Object status = ((Map<?, ?>) data).get("indexing_status");
|
|
|
-// if (status != null) {
|
|
|
-// indexing_status = status.toString();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
file.setIndexingStatus(indexing_status);
|
|
|
aiDatasetsFileService.updateById(file);
|
|
|
if (!"completed".equals(indexing_status)) {
|
|
|
flag = false;
|
|
|
+ }else{
|
|
|
+ vo1.setCompletedDcumentCount(vo1.getCompletedDcumentCount()+1);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -157,9 +157,18 @@ public class KnowledgeController {
|
|
|
vo.setStatus(1);
|
|
|
aiTrainingService.updateById(vo);
|
|
|
}
|
|
|
+ }else{
|
|
|
+ vo1.setTotalDocumentCount(files.size());
|
|
|
+ vo1.setCompletedDcumentCount(files.size());
|
|
|
}
|
|
|
+ list.add(vo1);
|
|
|
}
|
|
|
- return Result.ok(result);
|
|
|
+ Page<AiTrainingVO> page = new Page<>(pageIndex, pageSize);
|
|
|
+ page.setRecords(list);
|
|
|
+ page.setTotal(result.getTotal());
|
|
|
+ page.setPages(result.getPages());
|
|
|
+ page.setCurrent(result.getCurrent());
|
|
|
+ return Result.ok(page);
|
|
|
}
|
|
|
|
|
|
@GetMapping("training/{id}")
|