From ce00cf05c0f8d0be74796e0b8a0d23c19f47e2bd Mon Sep 17 00:00:00 2001 From: zhouwentao <1577701412@qq.com> Date: Mon, 18 Sep 2023 20:45:50 +0800 Subject: [PATCH] =?UTF-8?q?updates=20=E5=9B=9E=E4=BC=A0=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=BA=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/api/controller/ApiController.java | 5 ++ .../service/impl/OcrIdentifyServiceImpl.java | 2 +- .../modules/ocr/utils/CallBackWlyUtils.java | 72 ++++++++++++++++--- 3 files changed, 67 insertions(+), 12 deletions(-) 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 a551e02..613aece 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 @@ -18,6 +18,7 @@ import org.jeecg.modules.ocr.service.IOcrIdentifyDetailService; import org.jeecg.modules.ocr.service.IOcrIdentifyService; import org.jeecg.modules.ocr.service.IOcrRuleCheckService; import org.jeecg.modules.ocr.service.impl.TaskService; +import org.jeecg.modules.ocr.utils.CallBackWlyUtils; import org.jeecg.modules.ocr.utils.FileOUtils; import org.jeecg.modules.ocr.utils.ImageUtils; import org.jeecg.modules.ocr.dto.OcrIdentifyDTO; @@ -255,7 +256,11 @@ public class ApiController { //ocrIdentifyService.getSemanticInfo(semanticResponseJson); /*OcrRuleCheckVo ocrRuleCheckVo = byId.getOcrRuleCheckVo(); Map configRuleMap = ocrRuleCheckVo.getConfigRuleMap();*/ + OcrIdentifyDTO identifyDTO = ocrIdentifyService.findById("1703642249574752258"); + List identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(identifyDTO.getId()); + CallBackWlyUtils.callbackWly(identifyDTO,identifyDetailList); return Result.OK(""); } + } \ No newline at end of file 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 ecd4f76..2baec19 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 @@ -529,7 +529,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl jsonObjects = new ArrayList<>(); - //成功率 - BigDecimal textRateBigd = new BigDecimal(0); //总明细数量 int detail_detailCount = 0; - for (OcrIdentifyDetail identifyDetail : identifyDetails) { - if (StringUtils.isNotBlank(identifyDetail.getDataStructured())) { - List jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class); - if (CollectionUtils.isNotEmpty(jsonObjects1)) { - double textRate = jsonObjects.stream().mapToDouble(o->o.getDouble("textRate")).sum(); - textRateBigd = textRateBigd.add(new BigDecimal(textRate)); - detail_detailCount += jsonObjects1.size(); - jsonObjects.addAll(jsonObjects1); + int detailValidationCount=0; + String taskResultInfo = ocrIdentify.getTaskResultInfo(); + if (StringUtils.isNotBlank(taskResultInfo)) { + //循环获取哪些字段通过了 + List taskResultInfoList = JSONArray.parseArray(taskResultInfo).toJavaList(JSONObject.class); + detail_detailCount=taskResultInfoList.size(); + for (JSONObject jsonObject : taskResultInfoList) { + Boolean ruleValidation = (Boolean) jsonObject.getOrDefault("ruleValidation", false); + if (ruleValidation) { + //通过了, + detailValidationCount++; } } } //组装回调参数 + //成功率 double imageTagRetrievePercentage = 0.0d; if (detail_detailCount > 0) { - BigDecimal divide = textRateBigd.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP); + BigDecimal divide = new BigDecimal(detailValidationCount).divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); imageTagRetrievePercentage = divide.doubleValue(); } if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) { @@ -95,4 +97,52 @@ public class CallBackWlyUtils { } } } + + public static boolean callbackWly2(OcrIdentify ocrIdentify, List identifyDetails) { + String requestId = ocrIdentify.getRequestId(); + //请求对象 + CallBackWlyResult result = new CallBackWlyResult(); + + List jsonObjects = new ArrayList<>(); + //成功率 + BigDecimal textRateBigd = new BigDecimal(0); + //总明细数量 + int detail_detailCount = 0; + for (OcrIdentifyDetail identifyDetail : identifyDetails) { + if (StringUtils.isNotBlank(identifyDetail.getDataStructured())) { + List jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class); + if (CollectionUtils.isNotEmpty(jsonObjects1)) { + double textRate = jsonObjects.stream().mapToDouble(o->o.getDouble("textRate")).sum(); + textRateBigd = textRateBigd.add(new BigDecimal(textRate)); + detail_detailCount += jsonObjects1.size(); + jsonObjects.addAll(jsonObjects1); + } + } + } + + //组装回调参数 + double imageTagRetrievePercentage = 0.0d; + if (detail_detailCount > 0) { + BigDecimal divide = textRateBigd.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP); + imageTagRetrievePercentage = divide.doubleValue(); + } + if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) { + result.setRuleValidation(true); + }else{ + result.setRuleValidation(false); + } + result.setImageTagRetrievePercentage(imageTagRetrievePercentage + ""); + result.setRetrieveReviewCompliance(imageTagRetrievePercentage+""); + result.setFailureReason(ocrIdentify.getErrorMsg()); + if (CollectionUtils.isEmpty(jsonObjects)) { + return false; + } + result.setOcrResult(jsonObjects); + + log.info("请求无量云回调接口"); + JSONObject semanticResponseJson = null; + return false; + } + + }