|
|
|
|
@ -1,7 +1,9 @@
|
|
|
|
|
package org.jeecg.modules.ocr.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.checkerframework.checker.units.qual.C;
|
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentify;
|
|
|
|
|
@ -15,6 +17,7 @@ import org.jeecg.modules.ocr.service.IOcrIdentifyDetailService;
|
|
|
|
|
import org.jeecg.modules.ocr.service.IOcrIdentifyService;
|
|
|
|
|
import org.jeecg.modules.ocr.service.IOcrRuleCheckDetailService;
|
|
|
|
|
import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.ArrayCUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
@ -23,10 +26,8 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: ocr识别
|
|
|
|
|
@ -64,7 +65,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
@Override
|
|
|
|
|
public void getSemanticInfo(JSONObject responseBody) {
|
|
|
|
|
log.debug("打印 ocr 结果:"+responseBody.toString());
|
|
|
|
|
String identifyId = responseBody.getString("identifyId");//任务id
|
|
|
|
|
String identifyId = responseBody.getString("task_id");//任务id
|
|
|
|
|
String imgPath = responseBody.getString("img_path");//图片路径
|
|
|
|
|
String imgName = null;//图片名称
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
|
@ -103,7 +104,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
List<OcrResult> ocrResultList=new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
StringBuffer rMessage=new StringBuffer();
|
|
|
|
|
rMessage.append(message).append("<br/>");
|
|
|
|
|
rMessage.append("<br/>");
|
|
|
|
|
Map<String,Boolean> fieldRightMap=new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
//==========================
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
@ -111,13 +112,24 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
String inputText = value.getInputText();//校验文本 ,ocr识别的文本如果不包含该内容,则算作失败.
|
|
|
|
|
if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
|
|
|
|
|
boolean b = ArrayCUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList()));
|
|
|
|
|
//查看ocr识别返回的字段名称中是否有当前这个字段名称
|
|
|
|
|
if (semanticResult.keySet().contains(fieldName)) {
|
|
|
|
|
//TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确。
|
|
|
|
|
JSONArray ocrArray = semanticResult.getJSONArray(fieldName);
|
|
|
|
|
if (b) {
|
|
|
|
|
//TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
|
|
|
|
|
List<JSONObject> ocrArray=new ArrayList<>();
|
|
|
|
|
for (String s : fieldNameList) {
|
|
|
|
|
JSONArray jsonArray = semanticResult.getJSONArray(s);
|
|
|
|
|
if (jsonArray!=null&& jsonArray.size()>0) {
|
|
|
|
|
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ocrArrayFor:for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
copyOcrResult=new OcrResult();
|
|
|
|
|
JSONObject ocrItem = ocrArray.getJSONObject(i);
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
|
|
|
|
|
@ -140,19 +152,19 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
rMessage.append(field+"_未查到ocr结果,");
|
|
|
|
|
ocrResultAdd(ocrResultList,field,inputText,null,0d,imgPath,"未查到ocr结果",false);
|
|
|
|
|
ocrResultList.add(copyOcrResult);
|
|
|
|
|
fieldRightMap.put(field,false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
if (fieldRightMap!=null&&fieldRightMap.values().size()>0&&!fieldRightMap.containsValue(false)) {
|
|
|
|
|
ocrIdentifyDetail.setStatus("1");
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//全部通过
|
|
|
|
|
}else{
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");
|
|
|
|
|
ocrIdentifyDetail.setStatus("1");//有失败的
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//=========================
|
|
|
|
|
}
|
|
|
|
|
|