diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java index 8011617..6cb4241 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/ApiController.java @@ -21,6 +21,7 @@ import org.jeecg.modules.ocr.service.IOcrRuleCheckService; import org.jeecg.modules.ocr.service.impl.TaskService; import org.jeecg.modules.ocr.utils.FileOUtils; import org.jeecg.modules.ocr.utils.ImageUtils; +import org.jeecg.modules.ocr.vo.OcrIdentifyVo; import org.jeecg.modules.ocr.vo.OcrRuleCheckVo; import org.jeecg.modules.system.service.ISysDictService; import org.springframework.scheduling.annotation.Async; @@ -33,6 +34,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -223,7 +225,10 @@ public class ApiController { @ApiOperation(value = "调试101") @PostMapping(value = "/test_101") public Result test101(@RequestBody JSONObject jsonObject){ - + OcrIdentifyVo byId = ocrIdentifyService.findById("1692068694831755265"); + ocrIdentifyService.updateTaskResultInfo(byId.getId()); + /*OcrRuleCheckVo ocrRuleCheckVo = byId.getOcrRuleCheckVo(); + Map configRuleMap = ocrRuleCheckVo.getConfigRuleMap();*/ return Result.OK(""); } 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 a2d384a..6a15838 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 @@ -141,13 +141,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl fieldNameList = Arrays.asList(fieldName.split(",")); + text = null; boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList())); //查看ocr识别返回的字段名称中是否有当前这个字段名称 if (b) { @@ -162,29 +159,64 @@ public class OcrIdentifyServiceImpl extends ServiceImpl0) { ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) { JSONObject ocrItem = ocrArray.get(i); + text = null; text = ocrItem.getString("text");//ocr 识别的文本 probability = ocrItem.getDouble("probability");//置信度 log.info("ocrItem:"); log.info(ocrItem.toJSONString()); - if (StringUtils.isBlank(text)) { - //ocr识别参数为空,不通过 - rMessage.append(value.getFieldName() + "参数未获取到结果
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultList, field,value.getFieldName(), inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false); - } else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) { - //不必校验,有值就行,通过 - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true); - } else if ("0".equals(ruleInfo)) { - //必定验证参数,必须有值且匹配 - double v = StrCharUtil.similarityRatio(inputText, text); - if (StringUtils.isBlank(inputText) || text.contains(inputText) || inputText.contains(text)) { - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); - } else { - rMessage.append(value.getFieldName() + "不匹配
"); + if ("101".equals(ruleInfo)) { + if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { + //没识别值 + mapPutIfTrue(fieldRightMap,field,true); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true); + }else{ + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.contains(inputText)) { + mapPutIfTrue(fieldRightMap, field, true); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); + }else{ + rMessage.append(value.getFieldName() + "参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v); + } + } + }else{ + if (StringUtils.isBlank(text)) { + //ocr识别参数为空,不通过 + rMessage.append(value.getFieldName() + "参数未获取到结果
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false,v); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false); + } else if(StringUtils.isBlank(inputText)){ + //没有输入值. + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true); + } else if ("0".equals(ruleInfo)) { + //不必校验,有识别到就行,通过 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true); + } else if(Double.valueOf(ruleInfo)>=1 && Double.valueOf(ruleInfo)<=99){ + //在1~99之间,根据精准度匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (v>=Double.valueOf(ruleInfo)) { + //准确度 可靠 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); + }else{ + rMessage.append(value.getFieldName() + "参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v); + } + } else if ("100".equals(ruleInfo)) { + //必定验证参数,必须有值且匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); + } else { + rMessage.append(value.getFieldName() + "参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v); + } } } } @@ -193,7 +225,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl"); ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false); @@ -324,7 +355,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId()); - /*for (OcrIdentifyDetail identifyDetail : identifyDetails) { + for (OcrIdentifyDetail identifyDetail : identifyDetails) { JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult()); String imgPath = identifyDetail.getImageUrl(); // 进行数据化 结构 @@ -344,7 +375,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl fieldNameList = Arrays.asList(fieldName.split(",")); text = null; boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList())); @@ -366,37 +397,70 @@ public class OcrIdentifyServiceImpl extends ServiceImpl"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "_参数未获取到结果", false); - } else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) { - //不必校验,有值就行,通过 - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true); - } else if ("0".equals(ruleInfo)) { - //必定验证参数,必须有值且匹配 - double v = StrCharUtil.similarityRatio(inputText, text); - if (StringUtils.isBlank(inputText) || text.contains(inputText) || inputText.contains(text)) { - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); - } else { - rMessage.append(value.getFieldName() + "_参数不匹配
"); + if ("101".equals(ruleInfo)) { + if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { + //没识别值 + mapPutIfTrue(fieldRightMap,field,true); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true); + }else{ + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.contains(inputText)) { + mapPutIfTrue(fieldRightMap, field, true); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); + }else{ + rMessage.append(value.getFieldName() + "参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v); + } + } + }else{ + if (StringUtils.isBlank(text)) { + //ocr识别参数为空,不通过 + rMessage.append(value.getFieldName() + "参数未获取到结果
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "_参数不匹配", false,v); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false); + } else if(StringUtils.isBlank(inputText)){ + //没有输入值. + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true); + } else if ("0".equals(ruleInfo)) { + //不必校验,有识别到就行,通过 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true); + } else if(Double.valueOf(ruleInfo)>=1 && Double.valueOf(ruleInfo)<=99){ + //在1~99之间,根据精准度匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (v>=Double.valueOf(ruleInfo)) { + //准确度 可靠 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); + }else{ + rMessage.append(value.getFieldName() + "参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v); + } + } else if ("100".equals(ruleInfo)) { + //必定验证参数,必须有值且匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v); + } else { + rMessage.append(value.getFieldName() + "参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v); + } } } } }else{ - rMessage.append(value.getFieldName() + "_参数未获取到结果
"); + rMessage.append(value.getFieldName() + "参数未获取到结果
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "_参数未获取到结果", false); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false); } - } else { - rMessage.append(value.getFieldName() + "_参数未获取到结果
"); - ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "_参数未获取到结果", false); + rMessage.append(value.getFieldName() + "参数未获取到结果
"); + ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false); fieldRightMap.put(field, false); } } @@ -418,7 +482,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper(); + /*LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper(); updateWrapper.eq(OcrIdentify::getId, id); List identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id); if(true) { @@ -475,7 +539,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl getCheckSemanticModelMap(Map configRuleMap, Map fieldMap, List sourceJsonObjects) { Map checkSemanticModelMap = new LinkedHashMap<>(); - //校验正确的值 Map inputMap = new LinkedHashMap<>(); if (sourceJsonObjects != null && sourceJsonObjects.size() > 0) { @@ -671,28 +734,43 @@ public class OcrIdentifyServiceImpl extends ServiceImpl