diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrIdentify.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrIdentify.java index 5ffc9d8..c8139f6 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrIdentify.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/entity/OcrIdentify.java @@ -2,6 +2,8 @@ package org.jeecg.modules.ocr.entity; import java.io.Serializable; import java.util.Date; + +import com.alibaba.fastjson.annotation.JSONField; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/model/OcrResult2.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/model/OcrResult2.java index 0205537..176d084 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/model/OcrResult2.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/model/OcrResult2.java @@ -12,14 +12,14 @@ import lombok.Data; public class OcrResult2 { @ApiModelProperty(value = "检索字段名称") private String tag; - @ApiModelProperty(value = "api输入值") + /*@ApiModelProperty(value = "api输入值") private String inputText; @ApiModelProperty(value = "ocr识别文本") private String ocrText; @ApiModelProperty(value = "ocr识别置信度") private Double ocrPrecisionRate; @ApiModelProperty(value = "图片来源") - private SourceImage sourceImage; + private SourceImage sourceImage;*/ @ApiModelProperty(value = "失败原因") private String failureReason; @ApiModelProperty(value = "规则验证结果") diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/IOcrIdentifyService.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/IOcrIdentifyService.java index ecdfc7d..698e0aa 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/IOcrIdentifyService.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/IOcrIdentifyService.java @@ -26,6 +26,7 @@ public interface IOcrIdentifyService extends IService { */ @Async public void callbackWly(String ocrIdentifyId); + public void updateTaskResultInfo(String id); /** diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java index dc26f89..83b9e4d 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/service/impl/OcrIdentifyServiceImpl.java @@ -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 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 checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects()); //// String text=null;//ocr 识别的文本, @@ -307,13 +306,13 @@ public class OcrIdentifyServiceImpl extends ServiceImpl 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 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"); + rMessage.append(value.getFieldName() + "_参数未获取到结果
"); 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"); + rMessage.append(value.getFieldName() + "_参数不匹配
"); 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() + "参数未获取到结果
"); + rMessage.append(value.getFieldName() + "_参数未获取到结果
"); 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() + "参数未获取到结果
"); - ocrResultAdd(ocrResultList, field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false); + rMessage.append(value.getFieldName() + "_参数未获取到结果
"); + 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 updateWrapper = new LambdaUpdateWrapper(); updateWrapper.eq(OcrIdentify::getId, id); List identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id); if(true) { if (identifyDetailList != null && identifyDetailList.size() > 0) { - Map fieldRightMap = new LinkedHashMap<>(); + Map fieldRightMap = new LinkedHashMap<>(); String tag = null; boolean ruleValidation = false; /////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的. @@ -397,11 +390,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl resultList = jsonArray.toJavaList(OcrResult.class); - for (OcrResult result : resultList) { + List 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 errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList()); - List ocrResults = fieldRightMap.values().stream().collect(Collectors.toList()); + List errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList()); + List ocrResults = fieldRightMap.values().stream().collect(Collectors.toList()); String taskResultInfo = JSONArray.toJSONString(ocrResults); updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo); if (errorResults.size() > 0) {