master
周文涛 2 years ago
parent ed6b8df54a
commit 2c78c3e01f

@ -2,6 +2,8 @@ package org.jeecg.modules.ocr.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;

@ -12,14 +12,14 @@ import lombok.Data;
public class OcrResult2 { public class OcrResult2 {
@ApiModelProperty(value = "检索字段名称") @ApiModelProperty(value = "检索字段名称")
private String tag; private String tag;
@ApiModelProperty(value = "api输入值") /*@ApiModelProperty(value = "api输入值")
private String inputText; private String inputText;
@ApiModelProperty(value = "ocr识别文本") @ApiModelProperty(value = "ocr识别文本")
private String ocrText; private String ocrText;
@ApiModelProperty(value = "ocr识别置信度") @ApiModelProperty(value = "ocr识别置信度")
private Double ocrPrecisionRate; private Double ocrPrecisionRate;
@ApiModelProperty(value = "图片来源") @ApiModelProperty(value = "图片来源")
private SourceImage sourceImage; private SourceImage sourceImage;*/
@ApiModelProperty(value = "失败原因") @ApiModelProperty(value = "失败原因")
private String failureReason; private String failureReason;
@ApiModelProperty(value = "规则验证结果") @ApiModelProperty(value = "规则验证结果")

@ -26,6 +26,7 @@ public interface IOcrIdentifyService extends IService<OcrIdentify> {
*/ */
@Async @Async
public void callbackWly(String ocrIdentifyId); public void callbackWly(String ocrIdentifyId);
public void updateTaskResultInfo(String id); public void updateTaskResultInfo(String id);
/** /**

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

Loading…
Cancel
Save