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 85956d2..23d6759 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 @@ -145,7 +145,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl ocrResultDTOList = new ArrayList<>(); - StringBuffer rMessage = new StringBuffer(); + StringBuilder rMessage = new StringBuilder(); Map fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map //========================== //========================== - checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) { + 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())); + //boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.keySet())); //查看ocr识别返回的字段名称中是否有当前这个字段名称 - if (b) { + if (true) { //TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确 List ocrArray = new ArrayList<>(); for (String s : fieldNameList) { @@ -183,9 +183,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl 0) { - ocrArrayFor: - for (int i = 0; i < ocrArray.size(); i++) { - JSONObject ocrItem = ocrArray.get(i); + for (JSONObject ocrItem : ocrArray) { text = null; text = ocrItem.getString("text");//ocr 识别的文本 probability = ocrItem.getDouble("probability");//置信度 @@ -195,54 +193,54 @@ public class OcrIdentifyServiceImpl extends ServiceImpl"); + rMessage.append(value.getFieldName()).append("参数不匹配
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); } } } else { if (StringUtils.isBlank(text)) { //ocr识别参数为空,不通过 - rMessage.append(value.getFieldName() + "参数未获取到结果
"); + rMessage.append(value.getFieldName()).append("参数未获取到结果
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); } else if (StringUtils.isBlank(inputText)) { //没有输入值. fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, ruleInfo); } else if ("0".equals(ruleInfo)) { //不必校验,有识别到就行,通过 fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo); } else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) { //在1~99之间,根据精准度匹配 double v = StrCharUtil.similarityRatio(inputText, text); if (v >= Double.parseDouble(ruleInfo)) { //准确度 可靠 fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); } else { rMessage.append(value.getFieldName()).append("参数不匹配
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); } } else if ("100".equals(ruleInfo)) { //必定验证参数,必须有值且匹配 double v = StrCharUtil.similarityRatio(inputText, text); if (text.equals(inputText)) { fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); } else { rMessage.append(value.getFieldName()).append("参数不匹配
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); } } } @@ -250,16 +248,16 @@ public class OcrIdentifyServiceImpl extends ServiceImpl"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); } } else { rMessage.append(value.getFieldName()).append("参数未获取到结果
"); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); fieldRightMap.put(field, false); } } - if (fieldRightMap != null && fieldRightMap.values().size() > 0) { + if (!fieldRightMap.isEmpty() && CollectionUtils.isNotEmpty(fieldRightMap.values())) { if (!fieldRightMap.containsValue(false)) { ocrIdentifyDetail.setStatus("1");//全部通过 } else if (fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)) { @@ -294,22 +292,22 @@ public class OcrIdentifyServiceImpl extends ServiceImpl result = pushTask(requestBody); log.info("---------------"); log.info(result.toString()); /*semanticResponseJson = RestUtil.post(OcrConstant.api_test_identify_url, requestBody); @@ -323,56 +321,51 @@ public class OcrIdentifyServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper(); + 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<>(); - String tag = null; - boolean ruleValidation = false; - /////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的. - for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { - String dataStructured = ocrIdentifyDetail.getDataStructured(); - if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) { - JSONArray jsonArray = JSONObject.parseArray(dataStructured); - List resultList = jsonArray.toJavaList(OcrResultDTO.class); - for (OcrResultDTO result : resultList) { - tag = result.getTag(); - ruleValidation = result.getRuleValidation(); - OcrResultDTO lastResult = fieldRightMap.get(tag); - if (ruleValidation) { - fieldRightMap.put(tag, result); - } else if (lastResult == null || !lastResult.getRuleValidation()) { - //失败时就是未获取到结果 - result.setFailureReason(result.getTagName() + "未获取到结果"); - fieldRightMap.put(tag, result); - } + if (identifyDetailList != null && identifyDetailList.size() > 0) { + Map fieldRightMap = new LinkedHashMap<>(); + String tag = null; + boolean ruleValidation = false; + /////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的. + for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { + String dataStructured = ocrIdentifyDetail.getDataStructured(); + if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) { + JSONArray jsonArray = JSONObject.parseArray(dataStructured); + List resultList = jsonArray.toJavaList(OcrResultDTO.class); + for (OcrResultDTO result : resultList) { + tag = result.getTag(); + ruleValidation = result.getRuleValidation(); + OcrResultDTO lastResult = fieldRightMap.get(tag); + if (ruleValidation) { + fieldRightMap.put(tag, result); + } else if (lastResult == null || !lastResult.getRuleValidation()) { + //失败时就是未获取到结果 + result.setFailureReason(result.getTagName() + "未获取到结果"); + fieldRightMap.put(tag, result); } } } - //如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败 - List errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList()); - List ocrResultDTOS = fieldRightMap.values().stream().collect(Collectors.toList()); - - //TODO 后续考虑需要修正复杂程度. 支持 & + || 一起 - - String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";")); + } + //如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败 + List errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList()); + List ocrResultDTOS = new ArrayList<>(fieldRightMap.values()); + //TODO 后续考虑需要修正复杂程度. 支持 & + || 一起 + String errorMsg = errorResults.stream().map(OcrResultDTO::getFailureReason).collect(Collectors.joining(";")); // if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckSplitChar)) { - if (errorResults.size() > 0) { - //匹配失败. - updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg); - updateWrapper.set(OcrIdentify::getTaskResult, 0); - } else { - //匹配成功. - updateWrapper.set(OcrIdentify::getTaskResult, 1); - } - String taskResultInfo = JSONArray.toJSONString(ocrResultDTOS); - updateWrapper.set(OcrIdentify::getStatus, "1"); - updateWrapper.set(OcrIdentify::getEndTime, new Date()); - updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo); + if (errorResults.size() > 0) { + //匹配失败. + updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg); + updateWrapper.set(OcrIdentify::getTaskResult, 0); + } else { + //匹配成功. + updateWrapper.set(OcrIdentify::getTaskResult, 1); } + String taskResultInfo = JSONArray.toJSONString(ocrResultDTOS); + updateWrapper.set(OcrIdentify::getStatus, "1"); + updateWrapper.set(OcrIdentify::getEndTime, new Date()); + updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo); } super.update(updateWrapper); } @@ -418,25 +411,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl map, String key, Boolean flag) { + if (!map.containsKey(key) || !map.get(key).equals(true)) { map.put(key, flag); } } /** * - * @param ocrResultDTOList - * @param fieldName - * @param field - * @param inputText - * @param ocrText - * @param ocrPrecisionRate - * @param imgPath - * @param failureReason - * @param ruleValidation - * @param d * @param ruleValidationValue 检查要求 */ public static void ocrResultAdd(List ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d, String ruleValidationValue) { @@ -487,14 +469,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, String ruleValidationValue) { if (ruleValidation) { @@ -509,7 +483,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl getCheckSemanticModelMap(Map configRuleMap, Map fieldMap, List sourceJsonObjects) { Map checkSemanticModelMap = new LinkedHashMap<>(); @@ -532,7 +505,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl pushTask(JSONObject jsonObject) { //获取优先级1的任务 String taskId = jsonObject.getString("taskId"); String taskType = jsonObject.getString("taskType"); @@ -597,7 +570,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl jsonObjects = Arrays.asList(task); + List jsonObjects = Collections.singletonList(task); task_ = JSONObject.toJSONString(jsonObjects); } else { //有历史任务 @@ -606,7 +579,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl taskList = jsonArray.toJavaList(TaskModel.class); List staskList = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).collect(Collectors.toList()); TaskModel task = null; - if (staskList == null || staskList.size() == 0) { + if (CollectionUtils.isEmpty(staskList)) { //该任务不存在, 看看 库表里 该任务是否已执行成功了 String overTask = (String) redisUtil.get("over_task"); if (org.apache.commons.lang.StringUtils.isNotBlank(overTask) && Arrays.asList(overTask.split(",")).contains(taskId)) { @@ -653,8 +626,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl list = super.list(queryWrapper); - return list; + return super.list(queryWrapper); } @Override @@ -667,9 +639,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { - /*if (i1==1) { - ocrIdentifyDetail.setSemanticResult("{\"ocr_res\":[[[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],[\"北京市朝阳区三里屯社区卫生服务中心\",0.9670220613479614]],[[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],[\"儿科专家门诊\",0.984556257724762]],[[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],[\"Pediatric srecialistclinic\",0.8756008148193359]]],\"其他\":[{\"area\":[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],\"end\":26,\"ocrText\":\"Pediatric srecialistclinic\",\"probability\":0.9925054592526585,\"start\":0,\"text\":\"Pediatric srecialistclinic\"}],\"医院名称\":[{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区三里屯社区卫生服务中心\",\"probability\":0.9681764264135495,\"start\":0,\"text\":\"北京市朝阳区三里屯社区卫生服务中心\"},{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区农光里医院\",\"probability\":0.95,\"start\":0,\"text\":\"北京市朝阳区农光里医院\"}],\"姓名\":[],\"时间\":[],\"科室\":[{\"area\":[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],\"end\":6,\"ocrText\":\"儿科专家门诊\",\"probability\":0.9836859327676066,\"start\":0,\"text\":\"儿科专家门诊\"}]}"); - }*/ i1++; String semanticResultJson = ocrIdentifyDetail.getSemanticResult(); String imgPath = ocrIdentifyDetail.getImageUrl(); @@ -717,122 +686,118 @@ public class OcrIdentifyServiceImpl extends ServiceImpl> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2); - if (CollectionUtils.isNotEmpty(resultToPoints)) { - ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath); - imgPath = outputImagePath; - } + //============================绘制虚线 + JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result"); + String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i); + //判断新目录是否存在,不存在则新建 + FileOUtils.folderCreate(fileUrl); + String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length()); + if (semanticResult2!=null) { + List> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2); + if (CollectionUtils.isNotEmpty(resultToPoints)) { + ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath); + imgPath = outputImagePath; } } + //============================ } OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId()); Map checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson); String text = null;//ocr 识别的文本 Double probability = 0d; - StringBuffer rMessage = new StringBuffer(); + StringBuilder rMessage = new StringBuilder(); //========================== - checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) { + 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.getJSONObject("semantic_result").keySet().stream().collect(Collectors.toList())); + //boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet())); //查看ocr识别返回的字段名称中是否有当前这个字段名称 - if (b) { - //TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确 - List ocrArray = new ArrayList<>(); - for (String s : fieldNameList) { - JSONArray jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s); - if (jsonArray != null && jsonArray.size() > 0) { - ocrArray.addAll(jsonArray.toJavaList(JSONObject.class)); - } + //TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确 + List ocrArray = new ArrayList<>(); + for (String s : fieldNameList) { + JSONArray jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s); + if (jsonArray != null && jsonArray.size() > 0) { + ocrArray.addAll(jsonArray.toJavaList(JSONObject.class)); } - if (ocrArray.size() > 0) { - 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");//置信度 - if ("101".equals(ruleInfo)) { - if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { - //没识别值 + } + if (ocrArray.size() > 0) { + for (JSONObject ocrItem : ocrArray) { + text = null; + text = ocrItem.getString("text");//ocr 识别的文本 + probability = ocrItem.getDouble("probability");//置信度 + if ("101".equals(ruleInfo)) { + if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) { + //没识别值 + mapPutIfTrue(fieldRightMap, field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true, ruleInfo); + } else { + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.contains(inputText)) { mapPutIfTrue(fieldRightMap, field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101"); } else { - double v = StrCharUtil.similarityRatio(inputText, text); - if (text.contains(inputText)) { - mapPutIfTrue(fieldRightMap, field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101"); - } else { - rMessage.append(value.getFieldName() + "参数不匹配
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo); - } - } - } else { - if (StringUtils.isBlank(text)) { - //ocr识别参数为空,不通过 - rMessage.append(value.getFieldName() + "参数未获取到结果
"); + rMessage.append(value.getFieldName()).append("参数不匹配
"); mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); - } else if (StringUtils.isBlank(inputText)) { - //没有输入值. + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } + } + } else { + if (StringUtils.isBlank(text)) { + //ocr识别参数为空,不通过 + rMessage.append(value.getFieldName()).append("参数未获取到结果
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); + } else if (StringUtils.isBlank(inputText)) { + //没有输入值. + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, ruleInfo); + } else if ("0".equals(ruleInfo)) { + //不必校验,有识别到就行,通过 + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo); + } else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) { + //在1~99之间,根据精准度匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (v >= Double.parseDouble(ruleInfo)) { + //准确度 可靠 fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,ruleInfo); - } else if ("0".equals(ruleInfo)) { - //不必校验,有识别到就行,通过 + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); + } + } else if ("100".equals(ruleInfo)) { + //必定验证参数,必须有值且匹配 + double v = StrCharUtil.similarityRatio(inputText, text); + if (text.equals(inputText)) { fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo); - } 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(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo); - } else { - rMessage.append(value.getFieldName() + "参数不匹配
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo); - } - } else if ("100".equals(ruleInfo)) { - //必定验证参数,必须有值且匹配 - double v = StrCharUtil.similarityRatio(inputText, text); - if (text.equals(inputText)) { - fieldRightMap.put(field, true); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo); - } else { - rMessage.append(value.getFieldName() + "参数不匹配
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo); - } + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo); + } else { + rMessage.append(value.getFieldName()).append("参数不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo); } } } - } else { - rMessage.append(value.getFieldName() + "参数未获取到结果
"); - mapPutIfTrue(fieldRightMap, field, false); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); } } else { - rMessage.append(value.getFieldName() + "参数未获取到结果
"); - ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); - fieldRightMap.put(field, false); + rMessage.append(value.getFieldName()).append("参数未获取到结果
"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); } + + /*if (b) { + } else { + rMessage.append(value.getFieldName()).append("参数未获取到结果
"); + ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo); + fieldRightMap.put(field, false); + }*/ } } Date overDataCheckTime = new Date(); @@ -842,8 +807,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl (i.getOcrTime() == null ? 0 : i.getOcrTime()) + (i.getNluTime() == null ? 0 : i.getNluTime())).sum(); //执行时间(毫秒) - double dataStructuredTime = new BigDecimal(overDataCheckTime.getTime() - startDataCheckTime.getTime()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); - double executionTime = new BigDecimal(ocrAndNluTimeSum+(dataStructuredTime/1000)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); + double dataStructuredTime = new BigDecimal(overDataCheckTime.getTime() - startDataCheckTime.getTime()).setScale(2, RoundingMode.HALF_UP).doubleValue(); + double executionTime = new BigDecimal(ocrAndNluTimeSum+(dataStructuredTime/1000)).setScale(2, RoundingMode.HALF_UP).doubleValue(); responseBody.put("dataStructuredTime",dataStructuredTime); responseBody.put("allExecutionTime",executionTime); @@ -859,17 +824,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl!o).count(); //long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count(); responseBody.put("taskResult",count>0?0:1);//匹配成功或失败 - List haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getOcrPrecisionRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toList()); + List haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toList()); //过滤掉0的值 - ocrResultDTOList = ocrResultDTOList.stream().filter(o->haveRateTagList.contains(o.getTag()) && o.getOcrPrecisionRate()>0).collect(Collectors.toList()); + ocrResultDTOList = ocrResultDTOList.stream().filter(o->haveRateTagList.contains(o.getTag()) && o.getTextRate()>0).collect(Collectors.toList()); } //获取最小 - Double min = 0d; + double min = 0d; //获取最大 - Double max = 0d; + double max = 0d; if (CollectionUtils.isNotEmpty(ocrResultDTOList)) { - min = ocrResultDTOList.stream().sorted((a, b) -> a.getTextRate().compareTo(b.getTextRate())).findFirst().get().getTextRate(); - max = ocrResultDTOList.stream().sorted((a, b) -> b.getTextRate().compareTo(a.getTextRate())).findFirst().get().getTextRate(); + min = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).min().getAsDouble(); + max = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).max().getAsDouble(); } responseBody.put("min",min); responseBody.put("max",max); @@ -889,7 +854,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl waitingTaskList = taskList.stream().filter(t -> t.getTaskStatus().equals("0")).collect(Collectors.toList()); - if (waitingTaskList != null) { + if (CollectionUtils.isNotEmpty(waitingTaskList)) { while (waitingTaskList.size() > 0) { //取第一个任务 TaskModel taskModel = waitingTaskList.get(0); @@ -910,14 +875,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl taskList = getTaskList(); if (taskList != null && taskList.size() > 0) { TaskModel taskModel = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).findFirst().get(); - if (taskModel != null) { + if (taskModel!=null) { int taskLevel = taskModel.getTaskLevel(); String task = (String) redisUtil.get("task_" + taskLevel); JSONArray taskJsonArray = JSONObject.parseArray(task); @@ -971,7 +936,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl !t.equals(task_id)).collect(Collectors.joining(",")); + String collect = Arrays.stream(masterTask.split(",")).filter(t -> !t.equals(task_id)).collect(Collectors.joining(",")); if (StringUtils.isBlank(collect)) { //如果主任务下的子任务已清空,删除key redisUtil.del("identify_" + masterTaskId); @@ -984,7 +949,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl objects,List objects2){ boolean flag=false; - for (String object : objects) { - o2For:for (String o : objects2) { - if (object.contains(o) || o.contains(object)) { - return true; + for (String o : objects) { + for (String object : objects2) { + if (o.contains("姓名") || o.contains("医生")) { + flag = Arrays.asList("姓名", "医生", "医生名称").contains(object); + }else if(o.contains("科室")){ + flag = Arrays.asList("科室","科室名称").contains(object); + }else if(o.contains("医院")){ + flag = Arrays.asList("医院","医院名称").contains(object); + }else{ + flag = object.contains(o) || o.contains(object); } } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/CallBackWlyUtils.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/CallBackWlyUtils.java index 01f1e8f..62aaf5a 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/CallBackWlyUtils.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/ocr/utils/CallBackWlyUtils.java @@ -35,20 +35,16 @@ public class CallBackWlyUtils { CallBackWlyResult result = new CallBackWlyResult(); List jsonObjects = new ArrayList<>(); - boolean ruleValidation = false;//失败 //成功率 - BigDecimal ocrPrecisionRateBigD = new BigDecimal(0); + BigDecimal textRateBigd = new BigDecimal(0); //总明细数量 Integer detail_detailCount = 0; for (OcrIdentifyDetail identifyDetail : identifyDetails) { List jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class); if (jsonObjects1 != null) { - long ruleValidationCount = jsonObjects.stream().filter(o -> o.getBooleanValue("ruleValidation") == false).count(); - if (ruleValidationCount == 0) { - ruleValidation = true; - } - double ocrPrecisionRate = jsonObjects.stream().mapToDouble(o -> o.getDouble("ocrPrecisionRate")).sum(); - ocrPrecisionRateBigD = ocrPrecisionRateBigD.add(new BigDecimal(ocrPrecisionRate)); + //double ocrPrecisionRate = jsonObjects.stream().mapToDouble(o -> o.getDouble("ocrPrecisionRate")).sum(); + double textRate = jsonObjects.stream().mapToDouble(o->o.getDouble("textRate")).sum(); + textRateBigd = textRateBigd.add(new BigDecimal(textRate)); detail_detailCount += jsonObjects1.size(); } jsonObjects.addAll(jsonObjects1); @@ -57,13 +53,16 @@ public class CallBackWlyUtils { //组装回调参数 double imageTagRetrievePercentage = 0.0d; if (detail_detailCount > 0) { - BigDecimal divide = ocrPrecisionRateBigD.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP); + BigDecimal divide = textRateBigd.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP); imageTagRetrievePercentage = divide.doubleValue(); } - - result.setRuleValidation(ruleValidation); + if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) { + result.setRuleValidation(true); + }else{ + result.setRuleValidation(false); + } result.setImageTagRetrievePercentage(imageTagRetrievePercentage + ""); - result.setRetrieveReviewCompliance("0"); + result.setRetrieveReviewCompliance(imageTagRetrievePercentage+""); result.setFailureReason(ocrIdentify.getErrorMsg()); result.setOcrResult(jsonObjects);