From 9e6fa254f7187f4b315166735dfb1434cc98b223 Mon Sep 17 00:00:00 2001 From: zhouwentao <1577701412@qq.com> Date: Thu, 3 Aug 2023 13:49:30 +0800 Subject: [PATCH] updates --- .../service/impl/OcrIdentifyServiceImpl.java | 131 +++++++++--------- 1 file changed, 65 insertions(+), 66 deletions(-) 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 facac22..99e96f8 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 @@ -73,7 +73,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl().eq(OcrIdentifyDetail::getIdentifyId, identifyId).eq(OcrIdentifyDetail::getImageUrl, imgPath)); - if (count>0) { + if (count > 0) { //该图片已识别过 log.error("该图片已识别过了"); return; @@ -147,27 +147,28 @@ public class OcrIdentifyServiceImpl extends ServiceImpl"); + mapPutIfTrue(fieldRightMap, field, false); + ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "参数未获取到结果", false); + } else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) { + //不必校验,有值就行,通过 fieldRightMap.put(field, true); - }else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) { - // 1 不需要校验,只需要有返回ocr识别值 ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true); - fieldRightMap.put(field, true); - } else { - if (StringUtils.isBlank(text) || !text.contains(inputText)) { - //识别结果为空,识别结果 匹配不上 校验文本 - mapPutIfTrue(fieldRightMap, field, false); + } else if ("0".equals(ruleInfo)) { + //必定验证参数,必须有值且匹配 + if (StringUtils.isBlank(inputText) || text.contains(inputText)) { + fieldRightMap.put(field, true); + ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true); + } else { rMessage.append(value.getFieldName() + "不匹配
"); + mapPutIfTrue(fieldRightMap, field, false); ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false); - } else { - ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true); - fieldRightMap.put(field, true); } } } @@ -191,12 +192,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl identifyUrlList) { @@ -222,7 +220,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl updateWrapper = new LambdaUpdateWrapper(); updateWrapper.eq(OcrIdentify::getId, id); @@ -240,67 +238,67 @@ public class OcrIdentifyServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(OcrIdentifyDetail::getIdentifyId,id); + queryWrapper.eq(OcrIdentifyDetail::getIdentifyId, id); queryWrapper.isNotNull(OcrIdentifyDetail::getDataStructured); List identifyDetails = ocrIdentifyDetailService.list(queryWrapper); - if (identifyDetails!=null) { - List jsonObjects=new ArrayList<>(); - boolean ruleValidation=false;//失败 + if (identifyDetails != null) { + List jsonObjects = new ArrayList<>(); + boolean ruleValidation = false;//失败 //成功率 BigDecimal ocrPrecisionRateBigD = new BigDecimal(0); //总明细数量 - Integer detail_detailCount=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; + 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)); - detail_detailCount+=jsonObjects1.size(); + ocrPrecisionRateBigD = ocrPrecisionRateBigD.add(new BigDecimal(ocrPrecisionRate)); + detail_detailCount += jsonObjects1.size(); } jsonObjects.addAll(jsonObjects1); } //组装回调参数 - JSONObject requestBody=new JSONObject(); - requestBody.put("requestId",ocrIdentify.getRequestId()); - requestBody.put("ruleValidation",ruleValidation); - if (detail_detailCount==0) { - requestBody.put("imageTagRetrievePercentage",0); - }else{ + JSONObject requestBody = new JSONObject(); + requestBody.put("requestId", ocrIdentify.getRequestId()); + requestBody.put("ruleValidation", ruleValidation); + if (detail_detailCount == 0) { + requestBody.put("imageTagRetrievePercentage", 0); + } else { BigDecimal divide = ocrPrecisionRateBigD.divide(new BigDecimal(detail_detailCount), 2, BigDecimal.ROUND_HALF_UP); - requestBody.put("imageTagRetrievePercentage",divide.doubleValue()); + requestBody.put("imageTagRetrievePercentage", divide.doubleValue()); } - requestBody.put("retrieveReviewCompliance",0); - requestBody.put("failureReason",""); + requestBody.put("retrieveReviewCompliance", 0); + requestBody.put("failureReason", ""); log.info("请求无量云回调接口"); - JSONObject semanticResponseJson=null; + JSONObject semanticResponseJson = null; try { semanticResponseJson = RestUtil.post("https://192.168.1.21:8686/api/task/image/ocr/callback", requestBody); - }catch (Exception e){ + } catch (Exception e) { log.info("请求无量云回调接口失败"); e.printStackTrace(); - }finally { + } finally { log.info("回调返回------------------"); - if (semanticResponseJson!=null) { + if (semanticResponseJson != null) { log.info(semanticResponseJson.toJSONString()); - updateWrapper.set(OcrIdentify::getNoticeStatus,"1"); - }else{ + updateWrapper.set(OcrIdentify::getNoticeStatus, "1"); + } else { log.info("回调返回-----:null"); } } - }else{ - updateWrapper.set(OcrIdentify::getNoticeStatus,"0"); + } else { + updateWrapper.set(OcrIdentify::getNoticeStatus, "0"); } } @@ -403,6 +401,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl jsonObjects = Arrays.asList(task); task_ = JSONObject.toJSONString(jsonObjects); } else { @@ -426,10 +425,10 @@ 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 (staskList == null || staskList.size() == 0) { //该任务不存在, 看看 库表里 该任务是否已执行成功了 String overTask = (String) redisUtil.get("over_task"); - if (org.apache.commons.lang.StringUtils.isNotBlank(overTask)&&Arrays.asList(overTask.split(",")).contains(taskId)) { + if (org.apache.commons.lang.StringUtils.isNotBlank(overTask) && Arrays.asList(overTask.split(",")).contains(taskId)) { //库表里已执行过 return Result.OK("该任务已执行结束"); } else { @@ -447,7 +446,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl !t.equals(task_id)).collect(Collectors.joining(",")); if (StringUtils.isBlank(collect)) { //如果主任务下的子任务已清空,删除key - redisUtil.del("identify_"+masterTaskId); + redisUtil.del("identify_" + masterTaskId); //刷新Ocr识别任务状态 - updateOcrIdentifyStatus(masterTaskId,"1"); - log.error("更新任务状态,id:"+masterTaskId); - }else{ + updateOcrIdentifyStatus(masterTaskId, "1"); + log.error("更新任务状态,id:" + masterTaskId); + } else { //主任务还存在,刷新主任务明细 - redisUtil.set("identify_"+masterTaskId,collect); + redisUtil.set("identify_" + masterTaskId, collect); } } } else {