master
周文涛 2 years ago
parent 333df0f37e
commit 23c6ea5164

@ -2,6 +2,7 @@ package org.jeecg.modules.ocr.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
@ -26,6 +27,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -232,6 +234,57 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
updateWrapper.set(OcrIdentify::getEndTime, new Date()); updateWrapper.set(OcrIdentify::getEndTime, new Date());
updateWrapper.set(OcrIdentify::getStatus, "1"); updateWrapper.set(OcrIdentify::getStatus, "1");
super.update(updateWrapper); super.update(updateWrapper);
//回调 无量云接口
if(false){
OcrIdentify ocrIdentify = super.getById(id);
if (StringUtils.isNotBlank(ocrIdentify.getRequestId())) {
LambdaQueryWrapper<OcrIdentifyDetail> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OcrIdentifyDetail::getIdentifyId,id);
queryWrapper.isNotNull(OcrIdentifyDetail::getDataStructured);
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.list(queryWrapper);
if (identifyDetails!=null) {
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);
}
//组装回调参数
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("retrieveReviewCompliance",0);
requestBody.put("failureReason","");
log.debug("请求无量云回调接口");
JSONObject semanticResponseJson = RestUtil.post("https://192.168.1.21:8686/api/task/image/ocr/callback", requestBody);
log.error(semanticResponseJson.toJSONString());
}
}
}
} }
public static void mapPutIfTrue(Map map, String key, Boolean flag) { public static void mapPutIfTrue(Map map, String key, Boolean flag) {

Loading…
Cancel
Save