|
@@ -1,5 +1,6 @@
|
|
package com.pavis.backend.slim.project.system.service.impl;
|
|
package com.pavis.backend.slim.project.system.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -7,9 +8,11 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.pavis.backend.slim.common.utils.CommonUtils;
|
|
import com.pavis.backend.slim.common.utils.CommonUtils;
|
|
|
|
+import com.pavis.backend.slim.common.utils.SecurityUtils;
|
|
import com.pavis.backend.slim.common.utils.SnowflakeIdWorkerUtils;
|
|
import com.pavis.backend.slim.common.utils.SnowflakeIdWorkerUtils;
|
|
import com.pavis.backend.slim.project.system.client.AlgKgClient;
|
|
import com.pavis.backend.slim.project.system.client.AlgKgClient;
|
|
import com.pavis.backend.slim.project.system.domain.AnnotationList;
|
|
import com.pavis.backend.slim.project.system.domain.AnnotationList;
|
|
|
|
+import com.pavis.backend.slim.project.system.domain.annotation.AnnotationFront;
|
|
import com.pavis.backend.slim.project.system.domain.annotation.AnnotationListParam;
|
|
import com.pavis.backend.slim.project.system.domain.annotation.AnnotationListParam;
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ConvertAlgRes;
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ConvertAlgRes;
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ImportAnnotationDataset;
|
|
import com.pavis.backend.slim.project.system.domain.annotation.ImportAnnotationDataset;
|
|
@@ -45,8 +48,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public PageInfo getAnnotationLists(AnnotationListParam annotationListParam) {
|
|
public PageInfo getAnnotationLists(AnnotationListParam annotationListParam) {
|
|
- List<AnnotationList> annotationLists = new ArrayList<>();
|
|
|
|
- annotationLists = baseMapper.selectAnnotationList(annotationListParam);
|
|
|
|
|
|
+ List<AnnotationList> annotationLists = baseMapper.selectAnnotationList(annotationListParam);
|
|
// 获取txt文本内容为空,向算法请求txt文本内容并更新。
|
|
// 获取txt文本内容为空,向算法请求txt文本内容并更新。
|
|
if (!CollectionUtils.isEmpty(annotationLists)) {
|
|
if (!CollectionUtils.isEmpty(annotationLists)) {
|
|
// 过滤出textContent为空的数据。
|
|
// 过滤出textContent为空的数据。
|
|
@@ -78,23 +80,27 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
if (1 == importAnnotationDataset.getImportType()) {
|
|
if (1 == importAnnotationDataset.getImportType()) {
|
|
annotationList.setParseStatus(1);
|
|
annotationList.setParseStatus(1);
|
|
annotationList.setAnnotationStatus(0);
|
|
annotationList.setAnnotationStatus(0);
|
|
- List<AnnotationList> annotations = baseMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, importAnnotationDataset.getKgId())
|
|
|
|
- .eq(AnnotationList::getFileId, importDataset.getFileId()));
|
|
|
|
- if (!CollectionUtils.isEmpty(annotations)){
|
|
|
|
- annotationList.setId(annotations.get(0).getId());
|
|
|
|
- int upRes = baseMapper.updateById(annotationList);
|
|
|
|
- saveResLists.add(upRes);
|
|
|
|
- }else {
|
|
|
|
- int saveRes = baseMapper.insert(annotationList);
|
|
|
|
- saveResLists.add(saveRes);
|
|
|
|
- }
|
|
|
|
|
|
+ // 判重处理。
|
|
|
|
+ // List<AnnotationList> annotations = baseMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, importAnnotationDataset.getKgId())
|
|
|
|
+ // .eq(AnnotationList::getFileId, importDataset.getFileId()));
|
|
|
|
+ // if (!CollectionUtils.isEmpty(annotations)){
|
|
|
|
+ // annotationList.setId(annotations.get(0).getId());
|
|
|
|
+ // int upRes = baseMapper.updateById(annotationList);
|
|
|
|
+ // saveResLists.add(upRes);
|
|
|
|
+ // }else {
|
|
|
|
+ // int saveRes = baseMapper.insert(annotationList);
|
|
|
|
+ // saveResLists.add(saveRes);
|
|
|
|
+ // }
|
|
|
|
+ // 不判重。
|
|
|
|
+ int saveRes = baseMapper.insert(annotationList);
|
|
|
|
+ saveResLists.add(saveRes);
|
|
annotationLists.add(annotationList);
|
|
annotationLists.add(annotationList);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 获取算法txt文本内容.
|
|
// 获取算法txt文本内容.
|
|
toAlgTxt(annotationLists);
|
|
toAlgTxt(annotationLists);
|
|
// 返回数据。
|
|
// 返回数据。
|
|
- log.info("saveResLists:{}",JSON.toJSONString(saveResLists));
|
|
|
|
|
|
+ log.info("saveResLists:{}", JSON.toJSONString(saveResLists));
|
|
if (saveResLists.contains(0)) {
|
|
if (saveResLists.contains(0)) {
|
|
return false;
|
|
return false;
|
|
} else {
|
|
} else {
|
|
@@ -103,12 +109,12 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public Boolean importLocalAnnotationDataset(String kgId,MultipartFile file) {
|
|
|
|
|
|
+ public Boolean importLocalAnnotationDataset(String kgId, MultipartFile file) {
|
|
// todo 文件重复上传。知识库文档重复上传。
|
|
// todo 文件重复上传。知识库文档重复上传。
|
|
try {
|
|
try {
|
|
String s = DigestUtils.md5Hex(file.getBytes());
|
|
String s = DigestUtils.md5Hex(file.getBytes());
|
|
- log.info("file to MD5:{}",s);
|
|
|
|
- }catch (Exception ex){
|
|
|
|
|
|
+ log.info("file to MD5:{}", s);
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
|
}
|
|
}
|
|
SnowflakeIdWorkerUtils idWorker = new SnowflakeIdWorkerUtils(0, 0);
|
|
SnowflakeIdWorkerUtils idWorker = new SnowflakeIdWorkerUtils(0, 0);
|
|
@@ -118,18 +124,38 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
annotationList.setOriginalName(file.getOriginalFilename());
|
|
annotationList.setOriginalName(file.getOriginalFilename());
|
|
annotationList.setAnnotationStatus(0);
|
|
annotationList.setAnnotationStatus(0);
|
|
annotationList.setParseStatus(0);
|
|
annotationList.setParseStatus(0);
|
|
|
|
+ // 设置基本信息,创建人、创建时间等。
|
|
|
|
+ // annotationList.setUserId(SecurityUtils.getUserId());
|
|
|
|
+ annotationList.setCreateBy(SecurityUtils.getUsername());
|
|
|
|
+ annotationList.setCreateTime(DateUtil.date());
|
|
|
|
+ annotationList.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
+ annotationList.setUpdateTime(DateUtil.date());
|
|
Map<String, Object> algMap = new HashMap<>();
|
|
Map<String, Object> algMap = new HashMap<>();
|
|
- algMap.put("file",file);
|
|
|
|
- algMap.put("fileId",annotationList.getFileId());
|
|
|
|
- String algTxtByFile = algKgClient.getAlgTxtByFile(algMap);
|
|
|
|
- log.info("算法algTxtByFile:{}",JSON.toJSONString(algTxtByFile));
|
|
|
|
|
|
+ algMap.put("file", file);
|
|
|
|
+ algMap.put("fileId", annotationList.getFileId());
|
|
|
|
+ // String algTxtByFile = algKgClient.getAlgTxtByFile(algMap);
|
|
|
|
+ JSONArray algTxtByFile = algKgClient.getAlgTxtByFile(algMap);
|
|
|
|
+ log.info("算法algTxtByFile:{}", JSON.toJSONString(algTxtByFile));
|
|
List<AnnotationList> annotationLists = new ArrayList<>();
|
|
List<AnnotationList> annotationLists = new ArrayList<>();
|
|
annotationLists.add(annotationList);
|
|
annotationLists.add(annotationList);
|
|
try {
|
|
try {
|
|
- dealAlgToTxtRes(algTxtByFile,annotationLists,false);
|
|
|
|
|
|
+ dealAlgToTxtRes(algTxtByFile.toString(), annotationLists, false);
|
|
return true;
|
|
return true;
|
|
- }catch (Exception ex){
|
|
|
|
- log.info("算法本地文件转txt异常 ex:{}",ex);
|
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ log.info("算法本地文件转txt异常 ex:{}", ex);
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean saveAnnotation(AnnotationFront annotationFront) {
|
|
|
|
+ List<AnnotationList> annotationLists = baseMapper.selectList(new QueryWrapper<AnnotationList>().lambda().eq(AnnotationList::getKgId, annotationFront.getKgId()).eq(AnnotationList::getFileId, annotationFront.getFileId()));
|
|
|
|
+ if(annotationLists.size() > 0){
|
|
|
|
+ for (AnnotationList annotationList : annotationLists) {
|
|
|
|
+ annotationList.setTextFront(annotationFront.getTextFront());
|
|
|
|
+ int upRes = baseMapper.updateById(annotationList);
|
|
|
|
+ return upRes > 0 ? true : false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@@ -148,15 +174,16 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
algMap.put("fileIds", fileIds);
|
|
algMap.put("fileIds", fileIds);
|
|
log.info("algMap:{}", JSON.toJSONString(algMap));
|
|
log.info("algMap:{}", JSON.toJSONString(algMap));
|
|
String algTxtTmp = algKgClient.getAlgTxt(JSON.toJSONString(algMap));
|
|
String algTxtTmp = algKgClient.getAlgTxt(JSON.toJSONString(algMap));
|
|
- dealAlgToTxtRes(algTxtTmp, hasNullTexts,true);
|
|
|
|
|
|
+ dealAlgToTxtRes(algTxtTmp, hasNullTexts, true);
|
|
log.info("实时调用算法获取txt文本内容结束");
|
|
log.info("实时调用算法获取txt文本内容结束");
|
|
}
|
|
}
|
|
|
|
|
|
- public void dealAlgToTxtRes(String algTxtTmp, List<AnnotationList> hasNullTexts,Boolean upFlag) {
|
|
|
|
|
|
+ public void dealAlgToTxtRes(String algTxtTmp, List<AnnotationList> hasNullTexts, Boolean upFlag) {
|
|
if (null != algTxtTmp && StringUtils.isNotEmpty(algTxtTmp) && CommonUtils.isJsonArray(algTxtTmp)) {
|
|
if (null != algTxtTmp && StringUtils.isNotEmpty(algTxtTmp) && CommonUtils.isJsonArray(algTxtTmp)) {
|
|
// 解析算法返回数据。
|
|
// 解析算法返回数据。
|
|
try {
|
|
try {
|
|
List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp, ConvertAlgRes.class);
|
|
List<ConvertAlgRes> convertAlgRes = JSONArray.parseArray(algTxtTmp, ConvertAlgRes.class);
|
|
|
|
+ log.info("解析算法返回数据convertAlgRes:{}",JSON.toJSONString(convertAlgRes));
|
|
if (!CollectionUtils.isEmpty(convertAlgRes)) {
|
|
if (!CollectionUtils.isEmpty(convertAlgRes)) {
|
|
for (ConvertAlgRes algRes : convertAlgRes) {
|
|
for (ConvertAlgRes algRes : convertAlgRes) {
|
|
if (null != algRes.getErrorCode() && "0".equals(algRes.getErrorCode())) {
|
|
if (null != algRes.getErrorCode() && "0".equals(algRes.getErrorCode())) {
|
|
@@ -164,11 +191,13 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
for (AnnotationList hasNullText : hasNullTexts) {
|
|
for (AnnotationList hasNullText : hasNullTexts) {
|
|
if (algRes.getFileId().equals(hasNullText.getFileId())) {
|
|
if (algRes.getFileId().equals(hasNullText.getFileId())) {
|
|
hasNullText.setTextContent(algRes.getText());
|
|
hasNullText.setTextContent(algRes.getText());
|
|
- if (upFlag){
|
|
|
|
|
|
+ if (upFlag) {
|
|
|
|
+ hasNullText.setUpdateBy(SecurityUtils.getUsername());
|
|
|
|
+ hasNullText.setUpdateTime(DateUtil.date());
|
|
// true 更新textContent.
|
|
// true 更新textContent.
|
|
int updateText = baseMapper.updateById(hasNullText);
|
|
int updateText = baseMapper.updateById(hasNullText);
|
|
log.info("更新文本内容结果updateText:{}", updateText);
|
|
log.info("更新文本内容结果updateText:{}", updateText);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
// false 新增textContent
|
|
// false 新增textContent
|
|
int saveRes = baseMapper.insert(hasNullText);
|
|
int saveRes = baseMapper.insert(hasNullText);
|
|
log.info("新增文本内容结果updateText:{}", saveRes);
|
|
log.info("新增文本内容结果updateText:{}", saveRes);
|
|
@@ -176,9 +205,10 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (null != algRes.getErrorCode() && "-1".equals(algRes.getErrorCode()) && false == upFlag){
|
|
|
|
|
|
+ if (null != algRes.getErrorCode() && "-1".equals(algRes.getErrorCode()) && false == upFlag) {
|
|
for (AnnotationList hasNullText : hasNullTexts) {
|
|
for (AnnotationList hasNullText : hasNullTexts) {
|
|
hasNullText.setParseStatus(-1);
|
|
hasNullText.setParseStatus(-1);
|
|
|
|
+ // hasNullText.setUserId(SecurityUtils.getUserId());
|
|
int saveRes = baseMapper.insert(hasNullText);
|
|
int saveRes = baseMapper.insert(hasNullText);
|
|
log.info("解析出错 新增文本内容结果updateText:{}", saveRes);
|
|
log.info("解析出错 新增文本内容结果updateText:{}", saveRes);
|
|
}
|
|
}
|
|
@@ -190,7 +220,7 @@ public class AnnotationListServiceImpl extends ServiceImpl<AnnotationListMapper,
|
|
log.info("获取算法解析txt文本内容返回结果 返回数据为NULL ex convertAlgRes:{}", JSON.toJSONString(convertAlgRes));
|
|
log.info("获取算法解析txt文本内容返回结果 返回数据为NULL ex convertAlgRes:{}", JSON.toJSONString(convertAlgRes));
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
- log.info("获取算法解析txt文本内容返回结果 返回数据异常 NOT JSONArray ex:{}", JSON.toJSONString(algTxtTmp));
|
|
|
|
|
|
+ log.info("获取算法解析txt文本内容返回结果 返回数据异常 NOT JSONArray ex:{}", ex);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
log.info("获取算法解析txt文本内容返回结果接口异常 ex convertToTxtResTmp:{}", algTxtTmp);
|
|
log.info("获取算法解析txt文本内容返回结果接口异常 ex convertToTxtResTmp:{}", algTxtTmp);
|