|
@@ -15,6 +15,7 @@ import com.pavis.backend.slim.common.utils.FileUtils;
|
|
|
import com.pavis.backend.slim.common.utils.SecurityUtils;
|
|
|
import com.pavis.backend.slim.framework.minio.MinioStorage;
|
|
|
import com.pavis.backend.slim.project.system.client.AlgKgClient;
|
|
|
+import com.pavis.backend.slim.project.system.client.AlgKgTestClient;
|
|
|
import com.pavis.backend.slim.project.system.domain.AnnotationList;
|
|
|
import com.pavis.backend.slim.project.system.domain.SysFile;
|
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ConvertAlgRes;
|
|
@@ -23,6 +24,7 @@ import com.pavis.backend.slim.project.system.domain.vo.TreeFile;
|
|
|
import com.pavis.backend.slim.project.system.mapper.AnnotationListMapper;
|
|
|
import com.pavis.backend.slim.project.system.mapper.SysFileMapper;
|
|
|
import com.pavis.backend.slim.project.system.service.SysFileService;
|
|
|
+import feign.Request;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -49,6 +51,7 @@ import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -68,6 +71,9 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
|
|
|
@Resource
|
|
|
private AnnotationListMapper annotationListMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AlgKgTestClient algKgTestClient;
|
|
|
+
|
|
|
@Override
|
|
|
public SysFile uploadFile(MultipartFile file) {
|
|
|
SysFile sysFile = uploadFile(file, "", Constant.DIR_SEP, false);
|
|
@@ -345,7 +351,26 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
|
|
|
int updateText = baseMapper.updateById(sysFile);
|
|
|
log.info("更新文本内容结果updateText:{}", updateText);
|
|
|
}
|
|
|
- } else {
|
|
|
+ // 更新标注数据。
|
|
|
+ List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getFileId, algRes.getFileId()));
|
|
|
+ if (!CollectionUtils.isEmpty(annotationLists)){
|
|
|
+ for (AnnotationList annotationList : annotationLists) {
|
|
|
+ annotationList.setParseStatus(1);
|
|
|
+ annotationList.setTextContent(algRes.getText());
|
|
|
+ annotationListMapper.updateById(annotationList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (null != algRes.getErrorCode() && "-1".equals(algRes.getErrorCode())){
|
|
|
+ log.info("算法解析txt文本内容出错,无法解析。");
|
|
|
+ List<AnnotationList> annotationLists = annotationListMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getFileId, algRes.getFileId()));
|
|
|
+ if (!CollectionUtils.isEmpty(annotationLists)){
|
|
|
+ for (AnnotationList annotationList : annotationLists) {
|
|
|
+ annotationList.setParseStatus(-1);
|
|
|
+ annotationList.setTextContent("");
|
|
|
+ annotationListMapper.updateById(annotationList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
log.info("算法文档转换txt接口 TXT未解析成功:{}", JSON.toJSONString(algRes));
|
|
|
}
|
|
|
}
|
|
@@ -405,25 +430,36 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
|
|
|
@Override
|
|
|
public Boolean handsToParseTxt(String kgId, String fileId) {
|
|
|
List<SysFile> sysFiles = baseMapper.selectList(new QueryWrapper<SysFile>().lambda().eq(SysFile::getFileId, fileId));
|
|
|
- String objectKey = "";
|
|
|
- String identifier = "";
|
|
|
- if (!CollectionUtils.isEmpty(sysFiles)){
|
|
|
- objectKey = sysFiles.get(0).getObjectKey();
|
|
|
- identifier = sysFiles.get(0).getIdentifier();
|
|
|
- }
|
|
|
- List<ConvertDocToTxt> convertDocToTxts = new ArrayList<>();
|
|
|
- convertDocToTxts.add(ConvertDocToTxt.builder().fileId(fileId).objectKey(objectKey).identifier(identifier).isNew(false).build());
|
|
|
- if (!CollectionUtils.isEmpty(convertDocToTxts)) {
|
|
|
- Map<String, Object> algMap = new HashMap<>();
|
|
|
- algMap.put("files", convertDocToTxts);
|
|
|
- try {
|
|
|
- // 调用算法,获取文档转换为txt的文本内容。
|
|
|
- String convertToTxtResTmp = algKgClient.convertToTxt(JSON.toJSONString(algMap));
|
|
|
- dealAlgTxtRes(convertToTxtResTmp);
|
|
|
- }catch (Exception ex){
|
|
|
- ex.printStackTrace();
|
|
|
- log.info("手动调用算法获取txt文本内容返回结果 ex:{}",ex);
|
|
|
- return false;
|
|
|
+ if (!CollectionUtils.isEmpty(sysFiles) && null == sysFiles.get(0).getTextContent()){
|
|
|
+ String objectKey = "";
|
|
|
+ String identifier = "";
|
|
|
+ if (!CollectionUtils.isEmpty(sysFiles)){
|
|
|
+ objectKey = sysFiles.get(0).getObjectKey();
|
|
|
+ identifier = sysFiles.get(0).getIdentifier();
|
|
|
+ }
|
|
|
+ List<ConvertDocToTxt> convertDocToTxts = new ArrayList<>();
|
|
|
+ // convertDocToTxts.add(ConvertDocToTxt.builder().fileId(fileId).objectKey(objectKey).identifier(identifier).isNew(false).build());
|
|
|
+ convertDocToTxts.add(ConvertDocToTxt.builder().fileId(fileId).objectKey(objectKey).identifier(identifier).isNew(true).build());
|
|
|
+ if (!CollectionUtils.isEmpty(convertDocToTxts)) {
|
|
|
+ Map<String, Object> algMap = new HashMap<>();
|
|
|
+ algMap.put("files", convertDocToTxts);
|
|
|
+ log.info("实时请求算法获取txt内容入参 convertDocToTxts:{}",JSON.toJSONString(algMap));
|
|
|
+ try {
|
|
|
+ // 调用算法,获取文档转换为txt的文本内容。
|
|
|
+ // String convertToTxtResTmp = algKgClient.convertToTxt(JSON.toJSONString(algMap));
|
|
|
+ // Thread.sleep(20000);
|
|
|
+ // log.info("实时请求算法获取解析结果 convertToTxtResTmp:{}",convertToTxtResTmp);
|
|
|
+ // dealAlgTxtRes(convertToTxtResTmp);
|
|
|
+
|
|
|
+ // todo 实时调用算法获取解析得txt文本内容,。
|
|
|
+ String convertToTxtResTmp = algKgTestClient.testConvertToTxt(JSON.toJSONString(algMap),new Request.Options(30, TimeUnit.SECONDS, 30, TimeUnit.SECONDS, true));
|
|
|
+ log.info("实时请求算法获取解析结果 convertToTxtResTmp:{}",convertToTxtResTmp);
|
|
|
+ dealAlgTxtRes(convertToTxtResTmp);
|
|
|
+ }catch (Exception ex){
|
|
|
+ ex.printStackTrace();
|
|
|
+ log.info("手动调用算法获取txt文本内容返回结果 ex:{}",ex);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return true;
|