diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/aspect/AutoLogAspect.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/aspect/AutoLogAspect.java index 7738835..3be5439 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/aspect/AutoLogAspect.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/aspect/AutoLogAspect.java @@ -15,6 +15,7 @@ import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.enums.ModuleType; import org.jeecg.common.constant.enums.OperateTypeEnum; +import org.jeecg.common.exception.JeecgBootException; import org.jeecg.modules.base.service.BaseCommonService; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.IpUtils; @@ -52,17 +53,18 @@ public class AutoLogAspect { } @Around("logPointCut()") - public Object around(ProceedingJoinPoint point) throws Throwable { + public void around(ProceedingJoinPoint point) throws Throwable { long beginTime = System.currentTimeMillis(); //执行方法 - Object result = point.proceed(); - //执行时长(毫秒) - long time = System.currentTimeMillis() - beginTime; - - //保存日志 - saveSysLog(point, time, result); - - return result; + try{ + Object result = point.proceed(); + long time = System.currentTimeMillis() - beginTime; + saveSysLog(point, time, result); + }catch (Exception e){ + long time = System.currentTimeMillis() - beginTime; + saveSysLog(point, time, e.getMessage()); + throw new JeecgBootException(e.getMessage()); + } } private void saveSysLog(ProceedingJoinPoint joinPoint, long time, Object obj) { @@ -95,6 +97,8 @@ public class AutoLogAspect { //获取request HttpServletRequest request = SpringContextUtils.getHttpServletRequest(); + dto.setRequestUrl(request.getRequestURL().toString()); + dto.setRequestType(request.getMethod()); //请求的参数 dto.setRequestParam(getReqestParams(request,joinPoint)); //设置IP地址 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 fb26250..115941d 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 @@ -10,6 +10,9 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.aspect.annotation.AutoLog; +import org.jeecg.common.constant.CommonConstant; +import org.jeecg.common.constant.enums.ModuleType; import org.jeecg.common.system.vo.DictModel; import org.jeecg.common.util.*; import org.jeecg.modules.ocr.entity.OcrIdentify; @@ -64,6 +67,7 @@ public class ApiController { @RequestMapping("/identify") @Transactional @ResponseBody + @AutoLog(value = "api接口-通用识别",logType = CommonConstant.OPERATE_TYPE_1) public Result pushSemantic(@RequestBody JSONObject requestBody) throws InterruptedException { // if (!"test".equals(profiles)) { // return Result.error("当前环境不支持该功能,请访问测试环境"); 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 5072313..c313ccf 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 @@ -27,6 +27,26 @@ import java.util.List; @Slf4j public class CallBackWlyUtils { + public static void main(String[] args) { + String taskResultInfo="[{\"failureReason\":\"\",\"inputText\":\"柳州市鱼峰区羊角山卫生院\",\"ocrPrecisionRate\":0.976898738386339,\"ocrText\":\"柳州市鱼峰区羊角山卫生院\",\"ruleValidation\":true,\"sourceImage\":{\"fileName\":\"5465539931838045.jpg\",\"path\":\"/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\",\"previewUrl\":\"http://47.103.213.109:8072/files/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\"},\"tag\":\"hospitalName\",\"tagName\":\"医院名称\",\"textRate\":100.0},{\"failureReason\":\"姓名未获取到结果\",\"inputText\":\"罗爱兰\",\"ocrPrecisionRate\":0.976898738386339,\"ruleValidation\":false,\"sourceImage\":{\"fileName\":\"5465539931838045.jpg\",\"path\":\"/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\",\"previewUrl\":\"http://47.103.213.109:8072/files/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\"},\"tag\":\"doctorName\",\"tagName\":\"姓名\",\"textRate\":0.0},{\"failureReason\":\"科室未获取到结果\",\"inputText\":\"全科\",\"ocrPrecisionRate\":0.976898738386339,\"ruleValidation\":false,\"sourceImage\":{\"fileName\":\"5465539931838045.jpg\",\"path\":\"/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\",\"previewUrl\":\"http://47.103.213.109:8072/files/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\"},\"tag\":\"departmentName\",\"tagName\":\"科室\",\"textRate\":0.0},{\"failureReason\":\"时间未获取到结果\",\"inputText\":\"2023-09-18\",\"ocrPrecisionRate\":0.976898738386339,\"ruleValidation\":false,\"sourceImage\":{\"fileName\":\"5465539931838045.jpg\",\"path\":\"/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\",\"previewUrl\":\"http://47.103.213.109:8072/files/nfs/ocr/shared_directory/78f6ba0bea8f4a1db9af6e3a4116c2a1/5465539931838045.jpg\"},\"tag\":\"time\",\"tagName\":\"时间\",\"textRate\":0.0}]"; + List taskResultInfoList = JSONArray.parseArray(taskResultInfo).toJavaList(JSONObject.class); + BigDecimal imageTagRetrievePercentage = new BigDecimal("0"); + for (JSONObject jsonObject : taskResultInfoList) { + Double ruleValidation = jsonObject.getDouble("textRate"); + if (ruleValidation!=null) { + BigDecimal bigDecimal = new BigDecimal(ruleValidation).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); + if(imageTagRetrievePercentage.compareTo(BigDecimal.ZERO)!=0){ + imageTagRetrievePercentage=imageTagRetrievePercentage.multiply(bigDecimal); + }else{ + imageTagRetrievePercentage=imageTagRetrievePercentage.add(bigDecimal); + } + } + } + + imageTagRetrievePercentage = imageTagRetrievePercentage.multiply(new BigDecimal(100)); + System.out.println(imageTagRetrievePercentage); + } + public static boolean callbackWly(OcrIdentify ocrIdentify, List identifyDetails) { String requestId = ocrIdentify.getRequestId(); log.info("数据准备:{}",requestId); @@ -37,16 +57,27 @@ public class CallBackWlyUtils { //总明细数量 int detail_detailCount = 0; int detailValidationCount=0; + BigDecimal imageTagRetrievePercentage = new BigDecimal("0");//成功率 String taskResultInfo = ocrIdentify.getTaskResultInfo(); if (StringUtils.isNotBlank(taskResultInfo)) { //循环获取哪些字段通过了 List taskResultInfoList = JSONArray.parseArray(taskResultInfo).toJavaList(JSONObject.class); - detail_detailCount=taskResultInfoList.size(); +// detail_detailCount=taskResultInfoList.size(); +// for (JSONObject jsonObject : taskResultInfoList) { +// Boolean ruleValidation = (Boolean) jsonObject.getOrDefault("ruleValidation", false); +// if (ruleValidation) { +// //通过了, +// detailValidationCount++; +// } +// } for (JSONObject jsonObject : taskResultInfoList) { - Boolean ruleValidation = (Boolean) jsonObject.getOrDefault("ruleValidation", false); - if (ruleValidation) { - //通过了, - detailValidationCount++; + Double ruleValidation = jsonObject.getDouble("textRate"); + if (ruleValidation!=null) { + if(imageTagRetrievePercentage.compareTo(BigDecimal.ZERO)!=0){ + imageTagRetrievePercentage=imageTagRetrievePercentage.multiply(new BigDecimal(ruleValidation)); + }else{ + imageTagRetrievePercentage=imageTagRetrievePercentage.add(new BigDecimal(ruleValidation)); + } } } } @@ -62,12 +93,10 @@ public class CallBackWlyUtils { //组装回调参数 - //成功率 - double imageTagRetrievePercentage = 0.0d; - if (detail_detailCount > 0) { - BigDecimal divide = new BigDecimal(detailValidationCount).divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); - imageTagRetrievePercentage = divide.doubleValue(); - } +// if (detail_detailCount > 0) { +// BigDecimal divide = new BigDecimal(detailValidationCount).divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); + imageTagRetrievePercentage = imageTagRetrievePercentage.divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); +// } if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) { result.setRuleValidation(true); }else{ @@ -88,9 +117,9 @@ public class CallBackWlyUtils { CallBackWlyRequestBody callBackWlyRequestBody = new CallBackWlyRequestBody(); callBackWlyRequestBody.setRequestId(requestId); callBackWlyRequestBody.setResult(result); - System.out.println("============================================="); - System.out.println(JSONObject.toJSONString(callBackWlyRequestBody)); - System.out.println("============================================="); + log.info("============================================="); + log.info(JSONObject.toJSONString(callBackWlyRequestBody)); + log.info("============================================="); semanticResponseJson = RestUtil.post("https://192.168.1.100:8894/api/task/image/ocr/callback", JSONObject.parseObject(JSONObject.toJSONString(callBackWlyRequestBody, SerializerFeature.WriteNullStringAsEmpty))); } catch (org.springframework.web.client.ResourceAccessException e) { log.error("请求无量云回调接口失败-拒绝连接 (Connection refused)");