parent
8e129d80c6
commit
b758bd4f87
@ -0,0 +1,19 @@
|
|||||||
|
package org.jeecg.modules.ocr.model.wlycallback;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 回调无量云对象
|
||||||
|
* @Author ZhouWenTao
|
||||||
|
* @Date 2023/9/1 14:42
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CallBackWlyRequestBody implements Serializable {
|
||||||
|
@ApiModelProperty(value = "请求唯一标识")
|
||||||
|
private String requestId;
|
||||||
|
@ApiModelProperty(value = "请求参数")
|
||||||
|
private CallBackWlyResult result;
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package org.jeecg.modules.ocr.model.wlycallback;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description
|
||||||
|
* @Author ZhouWenTao
|
||||||
|
* @Date 2023/9/1 14:43
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CallBackWlyResult implements Serializable {
|
||||||
|
@ApiModelProperty(value = "是否通过")
|
||||||
|
boolean ruleValidation=false;
|
||||||
|
@ApiModelProperty(value = "检索信息与审核数据的符合度")
|
||||||
|
String retrieveReviewCompliance;
|
||||||
|
@ApiModelProperty(value = "图片检索的信息与元数据的符合度百分比")
|
||||||
|
String imageTagRetrievePercentage;
|
||||||
|
@ApiModelProperty(value = "任务失败原因,若成功则为空")
|
||||||
|
String failureReason;
|
||||||
|
@ApiModelProperty(value = "ocr识别结果集")
|
||||||
|
List<JSONObject> ocrResult;
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
package org.jeecg.modules.ocr.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.jeecg.common.util.RestUtil;
|
||||||
|
import org.jeecg.modules.ocr.entity.OcrIdentify;
|
||||||
|
import org.jeecg.modules.ocr.entity.OcrIdentifyCallbackLog;
|
||||||
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
||||||
|
import org.jeecg.modules.ocr.model.wlycallback.CallBackWlyRequestBody;
|
||||||
|
import org.jeecg.modules.ocr.model.wlycallback.CallBackWlyResult;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description
|
||||||
|
* @Author ZhouWenTao
|
||||||
|
* @Date 2023/9/1 14:47
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class CallBackWlyUtils {
|
||||||
|
|
||||||
|
public static boolean callbackWly(OcrIdentify ocrIdentify, List<OcrIdentifyDetail> identifyDetails) {
|
||||||
|
String requestId = ocrIdentify.getRequestId();
|
||||||
|
//请求对象
|
||||||
|
CallBackWlyResult result = new CallBackWlyResult();
|
||||||
|
|
||||||
|
List<JSONObject> jsonObjects = new ArrayList<>();
|
||||||
|
boolean ruleValidation = false;//失败
|
||||||
|
//成功率
|
||||||
|
BigDecimal ocrPrecisionRateBigD = new BigDecimal(0);
|
||||||
|
//总明细数量
|
||||||
|
Integer detail_detailCount = 0;
|
||||||
|
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
||||||
|
List<JSONObject> 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));
|
||||||
|
detail_detailCount += jsonObjects1.size();
|
||||||
|
}
|
||||||
|
jsonObjects.addAll(jsonObjects1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//组装回调参数
|
||||||
|
double imageTagRetrievePercentage = 0.0d;
|
||||||
|
if (detail_detailCount > 0) {
|
||||||
|
BigDecimal divide = ocrPrecisionRateBigD.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP);
|
||||||
|
imageTagRetrievePercentage = divide.doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setRuleValidation(ruleValidation);
|
||||||
|
result.setImageTagRetrievePercentage(imageTagRetrievePercentage + "");
|
||||||
|
result.setRetrieveReviewCompliance("0");
|
||||||
|
result.setFailureReason(ocrIdentify.getErrorMsg());
|
||||||
|
result.setOcrResult(jsonObjects);
|
||||||
|
|
||||||
|
log.info("请求无量云回调接口");
|
||||||
|
JSONObject semanticResponseJson = null;
|
||||||
|
try {
|
||||||
|
CallBackWlyRequestBody callBackWlyRequestBody = new CallBackWlyRequestBody();
|
||||||
|
callBackWlyRequestBody.setRequestId(requestId);
|
||||||
|
callBackWlyRequestBody.setResult(result);
|
||||||
|
System.out.println("=============================================");
|
||||||
|
System.out.println(JSONObject.toJSONString(callBackWlyRequestBody));
|
||||||
|
System.out.println("=============================================");
|
||||||
|
semanticResponseJson = RestUtil.post("https://192.168.1.21:8686/api/task/image/ocr/callback", JSONObject.parseObject(JSONObject.toJSONString(callBackWlyRequestBody)));
|
||||||
|
} catch (org.springframework.web.client.ResourceAccessException e) {
|
||||||
|
log.error("请求无量云回调接口失败-拒绝连接 (Connection refused)");
|
||||||
|
log.error(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("请求无量云回调接口失败");
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
log.info("回调返回------------------");
|
||||||
|
if (semanticResponseJson != null) {
|
||||||
|
log.info(semanticResponseJson.toJSONString());
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
log.info("回调返回-----:null");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue