|
@@ -1,5 +1,7 @@
|
|
|
package com.kgraph.graph.suport.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+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;
|
|
@@ -9,9 +11,11 @@ import com.kgraph.graph.neo4j.DTO.KgDocDTO;
|
|
|
import com.kgraph.graph.neo4j.seavice.IKgService;
|
|
|
import com.kgraph.graph.suport.domain.ExtractKnowledgeSubTask;
|
|
|
import com.kgraph.graph.suport.domain.ExtractKnowledgeTask;
|
|
|
+import com.kgraph.graph.suport.domain.ExtractResult;
|
|
|
import com.kgraph.graph.suport.domain.TripletInfo;
|
|
|
import com.kgraph.graph.suport.mapper.ExtractKnowledgeSubTaskMapper;
|
|
|
import com.kgraph.graph.suport.service.IExtractKnowledgeSubTaskService;
|
|
|
+import com.kgraph.graph.suport.service.IExtractResultService;
|
|
|
import com.kgraph.graph.suport.service.ITripletInfoService;
|
|
|
import com.kgraph.system.service.ISysDictDataService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -51,6 +55,9 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
|
|
|
@Autowired
|
|
|
private ISysDictDataService sysDictDataService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ IExtractResultService extractResultService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询知识抽取子任务
|
|
|
*
|
|
@@ -162,8 +169,9 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
|
|
|
logger.error("response is null, url:{}, docInfo:{}", finalUrl, docInfo);
|
|
|
} else if (response.getCode() != 200) {
|
|
|
logger.error("request is error! errorMsg: {}, url:{}, docInfo:{}", response.getMsg(), finalUrl, docInfo);
|
|
|
+ } else {
|
|
|
+ logger.info("算法推送成功,url:{}, docInfo:{}", finalUrl, docInfo);
|
|
|
}
|
|
|
- logger.info("算法推送成功,url:{}, docInfo:{}", finalUrl, docInfo);
|
|
|
});
|
|
|
} catch (Exception e) {
|
|
|
logger.error("算法请求报错", e);
|
|
@@ -186,15 +194,33 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
|
|
|
@Override
|
|
|
@Transactional
|
|
|
@Async
|
|
|
- public void approveSubTask(Long id, String status) {
|
|
|
+ public void approveSubTask(Long id, String status, ExtractResult extractResult) {
|
|
|
+
|
|
|
+ // 更新子任务状态
|
|
|
extractKnowledgeSubTaskMapper.updateSubTaskStatusById(id, status, null, null);
|
|
|
- // TODO 以下逻辑可优化成异步执行
|
|
|
+
|
|
|
+ // save resultJson
|
|
|
+ extractResultService.updateExtractResult(extractResult);
|
|
|
+ String result = extractResult.getResult();
|
|
|
+ JSONObject extractResultJson = JSONObject.parseObject(result);
|
|
|
+
|
|
|
+ // 审批 则同步到图数据库
|
|
|
if (ExtractKnowledgeSubTask.REVIEWED.equals(status)) {
|
|
|
- List<KgDTO> kgDTOList = tripletInfoService.getKgDTO(id);
|
|
|
- kgService.create(kgDTOList);
|
|
|
+ JSONArray knowledgeList = extractResultJson.getJSONArray("knowledgeList");
|
|
|
+ List<KgDTO> list = new ArrayList<>(knowledgeList.size());
|
|
|
+ for (int i = 0; i < knowledgeList.size(); i++) {
|
|
|
+ JSONObject jsonObject = knowledgeList.getJSONObject(i);
|
|
|
+ KgDTO kgDTO = JSONObject.parseObject(jsonObject.toString(), KgDTO.class);
|
|
|
+ list.add(kgDTO);
|
|
|
+ }
|
|
|
+ kgService.create(list);
|
|
|
+ // 更新子任务状态为完成
|
|
|
extractKnowledgeSubTaskMapper.updateSubTaskStatusById(id, ExtractKnowledgeSubTask.DOWN, null, null);
|
|
|
}
|
|
|
+
|
|
|
+ // 更新任务状态
|
|
|
extractKnowledgeSubTaskMapper.updateTaskStatusBySubTaskId(id);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -202,6 +228,36 @@ public class ExtractKnowledgeSubTaskServiceImpl implements IExtractKnowledgeSubT
|
|
|
extractKnowledgeSubTaskMapper.updateTaskStatusBySubTaskId(subTaskId);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void saveKnowledge(JSONObject extractResult) {
|
|
|
+ Integer code = extractResult.getInteger("code");
|
|
|
+ switch (code) {
|
|
|
+ case 200:
|
|
|
+ processSuccess(extractResult);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ processFail(extractResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processFail(JSONObject extractResult) {
|
|
|
+ updateSubTaskStatusById(extractResult.getJSONObject("docInfo").getLong("subTaskId"), ExtractKnowledgeSubTask.FAILED, extractResult.getString("msg"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void processSuccess(JSONObject extractResult) {
|
|
|
+// JSONArray relationList = extractResult.getJSONObject("knowledgeList").getJSONArray("relationList");
|
|
|
+// int size = relationList.size();
|
|
|
+// for(int i = 0; i < size; i++){
|
|
|
+// JSONObject jsonObject = relationList.getJSONObject(i);
|
|
|
+// jsonObject.put("id",i);
|
|
|
+// }
|
|
|
+ Long subTaskId = extractResult.getJSONObject("docInfo").getLong("subTaskId");
|
|
|
+ extractResultService.insertExtractResult(subTaskId, extractResult.toString());
|
|
|
+ // 更新task状态
|
|
|
+ updateSubTaskStatusById(subTaskId, ExtractKnowledgeSubTask.TO_BE_REVIEWED, extractResult.getString("msg"));
|
|
|
+ }
|
|
|
+
|
|
|
private void processFail(KgDocDTO kgDocDTO) {
|
|
|
updateSubTaskStatusById(kgDocDTO.getDocInfo().getSubTaskId(), ExtractKnowledgeSubTask.FAILED, kgDocDTO.getMsg());
|
|
|
}
|