|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.kgraph.common.core.domain.BaseResponse;
|
|
|
import com.kgraph.common.core.domain.entity.SysDictData;
|
|
|
import com.kgraph.common.utils.DateUtils;
|
|
|
+import com.kgraph.common.utils.file.FileUtils;
|
|
|
import com.kgraph.graph.neo4j.DTO.DocInfo;
|
|
|
import com.kgraph.graph.neo4j.DTO.KgDTO;
|
|
|
import com.kgraph.graph.neo4j.DTO.KgDocDTO;
|
|
@@ -28,6 +29,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -199,13 +201,20 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
|
|
|
// 更新子任务状态
|
|
|
extractKnowledgeSubTaskMapper.updateSubTaskStatusById(id, status, null, null);
|
|
|
|
|
|
- // save resultJson
|
|
|
- extractResultService.updateExtractResult(extractResult);
|
|
|
- String result = extractResult.getResult();
|
|
|
- JSONObject extractResultJson = JSONObject.parseObject(result);
|
|
|
-
|
|
|
- // 审批 则同步到图数据库
|
|
|
+ // 审批 则同步到图数据库 保存json
|
|
|
if (ExtractKnowledgeSubTask.REVIEWED.equals(status)) {
|
|
|
+
|
|
|
+ // save resultJson
|
|
|
+ String resultPath = sysDictDataService.getValueByTypeAndValue("kg_algorithm", "resultPath");
|
|
|
+ String result = extractResult.getResultData();
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileUtils.writeJsonToFile(result,resultPath+extractResult.getResult());
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("抽取结果保存失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject extractResultJson = JSONObject.parseObject(result);
|
|
|
JSONArray knowledgeList = extractResultJson.getJSONArray("knowledgeList");
|
|
|
List<KgDTO> list = new ArrayList<>(knowledgeList.size());
|
|
|
for (int i = 0; i < knowledgeList.size(); i++) {
|
|
@@ -263,16 +272,34 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
|
|
|
}
|
|
|
|
|
|
private void processSuccess(KgDocDTO kgDocDTO) {
|
|
|
- // 更新状态
|
|
|
- List<TripletInfo> tripletInfoList = new ArrayList<>(kgDocDTO.getKnowledgeList().size());
|
|
|
Long subTaskId = kgDocDTO.getDocInfo().getSubTaskId();
|
|
|
- for (KgDTO kgDTO : kgDocDTO.getKnowledgeList()) {
|
|
|
- TripletInfo tripletInfo = TripletInfo.buildByKgDocDTO(kgDTO, subTaskId);
|
|
|
- tripletInfoList.add(tripletInfo);
|
|
|
+ String dictValue = sysDictDataService.getValueByTypeAndValue("kg_algorithm","resultPath");
|
|
|
+ ExtractResult extractResultDb = extractResultService.getResultBySubTaskId(subTaskId);
|
|
|
+ String resultPath = kgDocDTO.getResultPath();
|
|
|
+ if(StringUtils.isNotBlank(resultPath) && StringUtils.isNotBlank(dictValue)){
|
|
|
+ resultPath = resultPath.replace(dictValue,"");
|
|
|
+ }
|
|
|
+ if(extractResultDb == null) {
|
|
|
+ ExtractResult extractResult = new ExtractResult();
|
|
|
+ extractResult.setSubTaskId(subTaskId);
|
|
|
+ if (KgDocDTO.EXTRACT.equals(kgDocDTO.getResultType())) {
|
|
|
+ extractResult.setResult(resultPath);
|
|
|
+ } else {
|
|
|
+ extractResult.setSentence(resultPath);
|
|
|
+ }
|
|
|
+ extractResultService.insertExtractResult(extractResult);
|
|
|
+ } else {
|
|
|
+ if (KgDocDTO.EXTRACT.equals(kgDocDTO.getResultType())) {
|
|
|
+ extractResultDb.setResult(resultPath);
|
|
|
+ } else {
|
|
|
+ extractResultDb.setSentence(resultPath);
|
|
|
+ }
|
|
|
+ extractResultService.updateExtractResult(extractResultDb);
|
|
|
}
|
|
|
- tripletInfoService.createList(tripletInfoList);
|
|
|
// 更新task状态
|
|
|
- updateSubTaskStatusById(subTaskId, ExtractKnowledgeSubTask.TO_BE_REVIEWED, kgDocDTO.getMsg());
|
|
|
+ if(KgDocDTO.EXTRACT.equals(kgDocDTO.getResultType())){
|
|
|
+ updateSubTaskStatusById(subTaskId, ExtractKnowledgeSubTask.TO_BE_REVIEWED, kgDocDTO.getMsg());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void updateSubTaskStatusById(Long subTaskId, String status, String msg) {
|