|
|
|
@ -14,10 +14,7 @@ import org.jeecg.common.util.RestUtil;
|
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentify;
|
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
|
|
|
|
import org.jeecg.modules.ocr.mapper.OcrIdentifyMapper;
|
|
|
|
|
import org.jeecg.modules.ocr.model.CheckSemanticModel;
|
|
|
|
|
import org.jeecg.modules.ocr.model.OcrResult;
|
|
|
|
|
import org.jeecg.modules.ocr.model.SourceImage;
|
|
|
|
|
import org.jeecg.modules.ocr.model.TaskModel;
|
|
|
|
|
import org.jeecg.modules.ocr.model.*;
|
|
|
|
|
import org.jeecg.modules.ocr.service.*;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.ArrayOUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
@ -291,12 +288,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
@Override
|
|
|
|
|
@Async
|
|
|
|
|
public void updateTaskResultInfo(String id){
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
/*if(true){
|
|
|
|
|
/*OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId());
|
|
|
|
|
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult());
|
|
|
|
|
String imgPath = identifyDetail.getImageUrl();
|
|
|
|
|
// 进行数据化 结构
|
|
|
|
|
if (semanticResult != null) {
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects());
|
|
|
|
|
////
|
|
|
|
|
String text=null;//ocr 识别的文本,
|
|
|
|
@ -307,13 +306,13 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
//==========================
|
|
|
|
|
checkSemanticFor:
|
|
|
|
|
for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
String inputText = value.getInputText();//校验文本 ,ocr识别的文本如果不包含该内容,则算作失败.
|
|
|
|
|
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
|
|
|
|
|
text = null;
|
|
|
|
|
boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList()));
|
|
|
|
|
//查看ocr识别返回的字段名称中是否有当前这个字段名称
|
|
|
|
|
if (b) {
|
|
|
|
@ -334,9 +333,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
log.info(ocrItem.toJSONString());
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
rMessage.append(value.getFieldName() + "_参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "_参数未获取到结果", false);
|
|
|
|
|
} else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) {
|
|
|
|
|
//不必校验,有值就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
@ -347,49 +346,43 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "不匹配<br>");
|
|
|
|
|
rMessage.append(value.getFieldName() + "_参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "_参数不匹配", false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
rMessage.append(value.getFieldName() + "_参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "_参数未获取到结果", false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
rMessage.append(value.getFieldName() + "_参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, null, 0d, imgPath, value.getFieldName() + "_参数未获取到结果", false);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size() > 0 && !fieldRightMap.containsValue(false)) {
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//全部通过
|
|
|
|
|
identifyDetail.setStatus("0");//全部通过
|
|
|
|
|
} else {
|
|
|
|
|
ocrIdentifyDetail.setStatus("1");//有失败的
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
identifyDetail.setStatus("1");//有失败的
|
|
|
|
|
identifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
|
identifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
|
ocrIdentifyDetailService.updateById(identifyDetail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
|
if(true) {
|
|
|
|
|
if (identifyDetailList != null && identifyDetailList.size() > 0) {
|
|
|
|
|
Map<String, OcrResult> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
|
Map<String, OcrResult2> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
|
String tag = null;
|
|
|
|
|
boolean ruleValidation = false;
|
|
|
|
|
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
|
|
|
|
@ -397,11 +390,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
String dataStructured = ocrIdentifyDetail.getDataStructured();
|
|
|
|
|
if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) {
|
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(dataStructured);
|
|
|
|
|
List<OcrResult> resultList = jsonArray.toJavaList(OcrResult.class);
|
|
|
|
|
for (OcrResult result : resultList) {
|
|
|
|
|
List<OcrResult2> resultList = jsonArray.toJavaList(OcrResult2.class);
|
|
|
|
|
for (OcrResult2 result : resultList) {
|
|
|
|
|
tag = result.getTag();
|
|
|
|
|
ruleValidation = result.getRuleValidation();
|
|
|
|
|
OcrResult lastResult = fieldRightMap.get(tag);
|
|
|
|
|
OcrResult2 lastResult = fieldRightMap.get(tag);
|
|
|
|
|
if (ruleValidation) {
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
@ -411,8 +404,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
|
|
|
|
|
List<OcrResult> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
|
List<OcrResult> ocrResults = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
List<OcrResult2> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
|
List<OcrResult2> ocrResults = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo);
|
|
|
|
|
if (errorResults.size() > 0) {
|
|
|
|
|