|
|
@ -192,7 +192,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//=========================
|
|
|
|
//=========================
|
|
|
|
|
|
|
|
|
|
|
@ -292,6 +291,98 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Async
|
|
|
|
@Async
|
|
|
|
public void updateTaskResultInfo(String id){
|
|
|
|
public void updateTaskResultInfo(String id){
|
|
|
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
|
|
|
/*if(true){
|
|
|
|
|
|
|
|
// 进行数据化 结构
|
|
|
|
|
|
|
|
if (semanticResult != null) {
|
|
|
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects());
|
|
|
|
|
|
|
|
////
|
|
|
|
|
|
|
|
String text=null;//ocr 识别的文本,
|
|
|
|
|
|
|
|
Double probability = 0d;
|
|
|
|
|
|
|
|
//用于数据结构化的对象
|
|
|
|
|
|
|
|
List<OcrResult> ocrResultList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
|
|
|
//==========================
|
|
|
|
|
|
|
|
checkSemanticFor:
|
|
|
|
|
|
|
|
for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
|
|
|
String inputText = value.getInputText();//校验文本 ,ocr识别的文本如果不包含该内容,则算作失败.
|
|
|
|
|
|
|
|
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
|
|
|
|
|
|
|
|
boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList()));
|
|
|
|
|
|
|
|
//查看ocr识别返回的字段名称中是否有当前这个字段名称
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ocrArray.size()>0) {
|
|
|
|
|
|
|
|
ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
|
|
|
log.info("ocrItem:");
|
|
|
|
|
|
|
|
log.info(ocrItem.toJSONString());
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
|
|
|
} else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) {
|
|
|
|
|
|
|
|
//不必校验,有值就行,通过
|
|
|
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(inputText) || text.contains(inputText)) {
|
|
|
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName() + "不匹配<br>");
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size() > 0 && !fieldRightMap.containsValue(false)) {
|
|
|
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//全部通过
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ocrIdentifyDetail.setStatus("1");//有失败的
|
|
|
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
//4.更新主任务状态
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|