|
|
|
@ -1,6 +1,5 @@
|
|
|
|
package org.jeecg.modules.ocr.service.impl;
|
|
|
|
package org.jeecg.modules.ocr.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
|
|
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.query.LambdaQueryWrapper;
|
|
|
|
@ -9,9 +8,9 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
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;
|
|
|
|
import org.jeecg.common.constant.OcrConstant;
|
|
|
|
import org.jeecg.common.constant.OcrConstant;
|
|
|
|
import org.jeecg.common.util.CommonUtils;
|
|
|
|
|
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
|
import org.jeecg.common.util.RestUtil;
|
|
|
|
import org.jeecg.common.util.RestUtil;
|
|
|
|
|
|
|
|
import org.jeecg.modules.ocr.dto.OcrResultDTO;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentify;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentify;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyCallbackLog;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyCallbackLog;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
|
|
|
@ -22,8 +21,8 @@ import org.jeecg.modules.ocr.utils.ArrayOUtils;
|
|
|
|
import org.jeecg.modules.ocr.utils.FileOUtils;
|
|
|
|
import org.jeecg.modules.ocr.utils.FileOUtils;
|
|
|
|
import org.jeecg.modules.ocr.utils.ImageUtils;
|
|
|
|
import org.jeecg.modules.ocr.utils.ImageUtils;
|
|
|
|
import org.jeecg.modules.ocr.utils.StrCharUtil;
|
|
|
|
import org.jeecg.modules.ocr.utils.StrCharUtil;
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
import org.jeecg.modules.ocr.dto.OcrIdentifyDTO;
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
import org.jeecg.modules.ocr.dto.OcrRuleCheckDTO;
|
|
|
|
import org.jeecg.modules.ocr.vo.SimulateChecksVO;
|
|
|
|
import org.jeecg.modules.ocr.vo.SimulateChecksVO;
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
@ -63,20 +62,20 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
|
|
|
|
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public OcrIdentifyVo findById(String id) {
|
|
|
|
public OcrIdentifyDTO findById(String id) {
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = baseMapper.findById(id);
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = baseMapper.findById(id);
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentifyVo.getSourceJson())) {
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentifyDTO.getSourceJson())) {
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(ocrIdentifyVo.getSourceJson());
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(ocrIdentifyDTO.getSourceJson());
|
|
|
|
List<JSONObject> jsonObjects = jsonArray.toJavaList(JSONObject.class);
|
|
|
|
List<JSONObject> jsonObjects = jsonArray.toJavaList(JSONObject.class);
|
|
|
|
ocrIdentifyVo.setSourceJsonObjects(jsonObjects);
|
|
|
|
ocrIdentifyDTO.setSourceJsonObjects(jsonObjects);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//规则检查配置信息
|
|
|
|
//规则检查配置信息
|
|
|
|
String ruleCheck = ocrIdentifyVo.getRuleCheck();
|
|
|
|
String ruleCheck = ocrIdentifyDTO.getRuleCheck();
|
|
|
|
if (StringUtils.isNotBlank(ruleCheck)) {
|
|
|
|
if (StringUtils.isNotBlank(ruleCheck)) {
|
|
|
|
OcrRuleCheckVo ocrRuleCheck = ocrRuleCheckService.findById(ocrIdentifyVo.getRuleCheck());
|
|
|
|
OcrRuleCheckDTO ocrRuleCheck = ocrRuleCheckService.findById(ocrIdentifyDTO.getRuleCheck());
|
|
|
|
ocrIdentifyVo.setOcrRuleCheckVo(ocrRuleCheck);
|
|
|
|
ocrIdentifyDTO.setOcrRuleCheckVo(ocrRuleCheck);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ocrIdentifyVo;
|
|
|
|
return ocrIdentifyDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -148,13 +147,13 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//===================
|
|
|
|
//===================
|
|
|
|
if (semanticResult != null) {
|
|
|
|
if (semanticResult != null) {
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(identifyId);
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = this.findById(identifyId);
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo();
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects());
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyDTO.getSourceJsonObjects());
|
|
|
|
String text = null;//ocr 识别的文本
|
|
|
|
String text = null;//ocr 识别的文本
|
|
|
|
Double probability = 0d;
|
|
|
|
Double probability = 0d;
|
|
|
|
//用于数据结构化的对象
|
|
|
|
//用于数据结构化的对象
|
|
|
|
List<OcrResult> ocrResultList = new ArrayList<>();
|
|
|
|
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
//==========================
|
|
|
|
//==========================
|
|
|
|
@ -190,16 +189,16 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
//没识别值
|
|
|
|
//没识别值
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -207,37 +206,37 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
//没有输入值.
|
|
|
|
//没有输入值.
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,null);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,null);
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
//准确度 可靠
|
|
|
|
//准确度 可靠
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -245,11 +244,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -268,7 +267,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
ocrIdentifyDetail.setStatus("0");//有失败的
|
|
|
|
ocrIdentifyDetail.setStatus("0");//有失败的
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
ocrIdentifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultDTOList));//数据结构化
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
ocrIdentifyDetailService.updateById(ocrIdentifyDetail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//=========================
|
|
|
|
//=========================
|
|
|
|
@ -316,14 +315,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
@Async
|
|
|
|
@Async
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
//4.更新主任务状态
|
|
|
|
//4.更新主任务状态
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo();
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
if (true) {
|
|
|
|
if (true) {
|
|
|
|
if (identifyDetailList != null && identifyDetailList.size() > 0) {
|
|
|
|
if (identifyDetailList != null && identifyDetailList.size() > 0) {
|
|
|
|
Map<String, OcrResult2> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
Map<String, OcrResultDTO> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
String tag = null;
|
|
|
|
String tag = null;
|
|
|
|
boolean ruleValidation = false;
|
|
|
|
boolean ruleValidation = false;
|
|
|
|
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
|
|
|
|
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
|
|
|
|
@ -331,11 +330,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
String dataStructured = ocrIdentifyDetail.getDataStructured();
|
|
|
|
String dataStructured = ocrIdentifyDetail.getDataStructured();
|
|
|
|
if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) {
|
|
|
|
if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) {
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(dataStructured);
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(dataStructured);
|
|
|
|
List<OcrResult2> resultList = jsonArray.toJavaList(OcrResult2.class);
|
|
|
|
List<OcrResultDTO> resultList = jsonArray.toJavaList(OcrResultDTO.class);
|
|
|
|
for (OcrResult2 result : resultList) {
|
|
|
|
for (OcrResultDTO result : resultList) {
|
|
|
|
tag = result.getTag();
|
|
|
|
tag = result.getTag();
|
|
|
|
ruleValidation = result.getRuleValidation();
|
|
|
|
ruleValidation = result.getRuleValidation();
|
|
|
|
OcrResult2 lastResult = fieldRightMap.get(tag);
|
|
|
|
OcrResultDTO lastResult = fieldRightMap.get(tag);
|
|
|
|
if (ruleValidation) {
|
|
|
|
if (ruleValidation) {
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
@ -347,8 +346,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
|
|
|
|
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
|
|
|
|
List<OcrResult2> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
List<OcrResultDTO> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
List<OcrResult2> ocrResults = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
List<OcrResultDTO> ocrResultDTOS = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
//TODO 后续考虑需要修正复杂程度. 支持 & + || 一起
|
|
|
|
//TODO 后续考虑需要修正复杂程度. 支持 & + || 一起
|
|
|
|
|
|
|
|
|
|
|
|
@ -362,7 +361,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
//匹配成功.
|
|
|
|
//匹配成功.
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResultDTOS);
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "1");
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "1");
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime, new Date());
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime, new Date());
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo);
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo);
|
|
|
|
@ -374,8 +373,8 @@ 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);
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId());
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyDTO.getId());
|
|
|
|
/*for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
/*for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult());
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult());
|
|
|
|
String imgPath = identifyDetail.getImageUrl();
|
|
|
|
String imgPath = identifyDetail.getImageUrl();
|
|
|
|
@ -507,7 +506,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
//=======规则检查配置
|
|
|
|
//=======规则检查配置
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo();
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
//===================
|
|
|
|
//===================
|
|
|
|
//4.更新主任务状态
|
|
|
|
//4.更新主任务状态
|
|
|
|
@ -564,8 +563,25 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
int stringPercent = getStringPercent("张三", "张三脏");
|
|
|
|
List<OcrResultDTO> list=new ArrayList<>();
|
|
|
|
System.out.println(stringPercent);
|
|
|
|
OcrResultDTO result = new OcrResultDTO();
|
|
|
|
|
|
|
|
result.setTextRate(10d);
|
|
|
|
|
|
|
|
list.add(result);
|
|
|
|
|
|
|
|
OcrResultDTO result2 = new OcrResultDTO();
|
|
|
|
|
|
|
|
result2.setTextRate(44d);
|
|
|
|
|
|
|
|
list.add(result2);
|
|
|
|
|
|
|
|
OcrResultDTO result3 = new OcrResultDTO();
|
|
|
|
|
|
|
|
result3.setTextRate(12d);
|
|
|
|
|
|
|
|
list.add(result3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取最小
|
|
|
|
|
|
|
|
Double min = list.stream().sorted((a, b) -> a.getTextRate().compareTo(b.getTextRate())).findFirst().get().getTextRate();
|
|
|
|
|
|
|
|
//获取最大
|
|
|
|
|
|
|
|
Double max = list.stream().sorted((a, b) -> b.getTextRate().compareTo(a.getTextRate())).findFirst().get().getTextRate();
|
|
|
|
|
|
|
|
//获取最大
|
|
|
|
|
|
|
|
//ocrResultList.stream().sorted((a,b)->a.getTextRate()-b.getTextRate()).findAny().get();
|
|
|
|
|
|
|
|
//int stringPercent = getStringPercent("张三", "张三脏");
|
|
|
|
|
|
|
|
//System.out.println(stringPercent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static int getStringPercent(String text, String inputText) {
|
|
|
|
private static int getStringPercent(String text, String inputText) {
|
|
|
|
@ -685,7 +701,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param ocrResultList
|
|
|
|
* @param ocrResultDTOList
|
|
|
|
* @param fieldName
|
|
|
|
* @param fieldName
|
|
|
|
* @param field
|
|
|
|
* @param field
|
|
|
|
* @param inputText
|
|
|
|
* @param inputText
|
|
|
|
@ -697,17 +713,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
* @param d
|
|
|
|
* @param d
|
|
|
|
* @param ruleValidationValue 检查要求
|
|
|
|
* @param ruleValidationValue 检查要求
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static void ocrResultAdd(List<OcrResult> ocrResultList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d,String ruleValidationValue) {
|
|
|
|
public static void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, Double d, String ruleValidationValue) {
|
|
|
|
OcrResult ocrResult = new OcrResult();
|
|
|
|
OcrResultDTO ocrResultDTO = new OcrResultDTO();
|
|
|
|
ocrResult.setTag(field);
|
|
|
|
ocrResultDTO.setTag(field);
|
|
|
|
ocrResult.setTagName(fieldName);
|
|
|
|
ocrResultDTO.setTagName(fieldName);
|
|
|
|
ocrResult.setOcrText(ocrText);
|
|
|
|
ocrResultDTO.setOcrText(ocrText);
|
|
|
|
ocrResult.setInputText(inputText);
|
|
|
|
ocrResultDTO.setInputText(inputText);
|
|
|
|
ocrResult.setOcrPrecisionRate(ocrPrecisionRate == null ? 0d : ocrPrecisionRate);
|
|
|
|
ocrResultDTO.setOcrPrecisionRate(ocrPrecisionRate == null ? 0d : ocrPrecisionRate);
|
|
|
|
if (d == null) {
|
|
|
|
if (d == null) {
|
|
|
|
ocrResult.setTextRate(0d);
|
|
|
|
ocrResultDTO.setTextRate(0d);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ocrResult.setTextRate(new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
ocrResultDTO.setTextRate(new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("-----------------");
|
|
|
|
System.out.println("-----------------");
|
|
|
|
System.out.println(failureReason);
|
|
|
|
System.out.println(failureReason);
|
|
|
|
@ -717,32 +733,33 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
sourceImage.setPath(imgPath);
|
|
|
|
sourceImage.setPath(imgPath);
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
sourceImage.setFileName(imgPath.substring(i + 1, imgPath.length()));
|
|
|
|
sourceImage.setFileName(imgPath.substring(i + 1, imgPath.length()));
|
|
|
|
ocrResult.setSourceImage(sourceImage);
|
|
|
|
sourceImage.setPreviewUrl(OcrConstant.FILE_REVIEW_URL_PREFIX+imgPath);
|
|
|
|
|
|
|
|
ocrResultDTO.setSourceImage(sourceImage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ocrResult.setFailureReason(failureReason);
|
|
|
|
ocrResultDTO.setFailureReason(failureReason);
|
|
|
|
if (ocrResultList == null) {
|
|
|
|
if (ocrResultDTOList == null) {
|
|
|
|
ocrResultList = new ArrayList<>();
|
|
|
|
ocrResultDTOList = new ArrayList<>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ocrResult.setRuleValidation(ruleValidation);
|
|
|
|
ocrResultDTO.setRuleValidation(ruleValidation);
|
|
|
|
if ("0".equals(ruleValidationValue)) {
|
|
|
|
if ("0".equals(ruleValidationValue)) {
|
|
|
|
ocrResult.setRuleValidationText("有名称就算过");
|
|
|
|
ocrResultDTO.setRuleValidationText("有名称就算过");
|
|
|
|
}else if(Double.valueOf(ruleValidationValue)>0 &&Double.valueOf(ruleValidationValue)<=99){
|
|
|
|
}else if(Double.valueOf(ruleValidationValue)>0 &&Double.valueOf(ruleValidationValue)<=99){
|
|
|
|
ocrResult.setRuleValidationText("匹配度>="+ruleValidationValue);
|
|
|
|
ocrResultDTO.setRuleValidationText("匹配度>="+ruleValidationValue);
|
|
|
|
}else if("100".equals(ruleValidation)){
|
|
|
|
}else if("100".equals(ruleValidation)){
|
|
|
|
ocrResult.setRuleValidationText("名称必须与参数完全一致");
|
|
|
|
ocrResultDTO.setRuleValidationText("名称必须与参数完全一致");
|
|
|
|
}else if("101".equals(ruleValidationValue)){
|
|
|
|
}else if("101".equals(ruleValidationValue)){
|
|
|
|
ocrResult.setRuleValidationText("有值必须匹配无值算过");
|
|
|
|
ocrResultDTO.setRuleValidationText("有值必须匹配无值算过");
|
|
|
|
}else if("isrule=1".equals(ruleValidationValue)){
|
|
|
|
}else if("isrule=1".equals(ruleValidationValue)){
|
|
|
|
ocrResult.setRuleValidationText("依据输入参数必须一致判断");
|
|
|
|
ocrResultDTO.setRuleValidationText("依据输入参数必须一致判断");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ocrResultList.add(ocrResult);
|
|
|
|
ocrResultDTOList.add(ocrResultDTO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 将数据 疯转成 OcrResult,追加到 ocrResultList
|
|
|
|
* 将数据 疯转成 OcrResult,追加到 ocrResultList
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param ocrResultList
|
|
|
|
* @param ocrResultDTOList
|
|
|
|
* @param field
|
|
|
|
* @param field
|
|
|
|
* @param inputText
|
|
|
|
* @param inputText
|
|
|
|
* @param ocrText
|
|
|
|
* @param ocrText
|
|
|
|
@ -750,11 +767,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
* @param imgPath
|
|
|
|
* @param imgPath
|
|
|
|
* @param failureReason
|
|
|
|
* @param failureReason
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static void ocrResultAdd(List<OcrResult> ocrResultList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation,String ruleValidationValue) {
|
|
|
|
public static void ocrResultAdd(List<OcrResultDTO> ocrResultDTOList, String fieldName, String field, String inputText, String ocrText, Double ocrPrecisionRate, String imgPath, String failureReason, Boolean ruleValidation, String ruleValidationValue) {
|
|
|
|
if (ruleValidation) {
|
|
|
|
if (ruleValidation) {
|
|
|
|
ocrResultAdd(ocrResultList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 100d,ruleValidationValue);
|
|
|
|
ocrResultAdd(ocrResultDTOList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 100d,ruleValidationValue);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ocrResultAdd(ocrResultList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 0d,ruleValidationValue);
|
|
|
|
ocrResultAdd(ocrResultDTOList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 0d,ruleValidationValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -912,10 +929,13 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void simulateChecks(SimulateChecksVO simulateChecksVO) {
|
|
|
|
public JSONObject simulateChecks(SimulateChecksVO simulateChecksVO) {
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIds(simulateChecksVO.getIdentifyDetailIdList());
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIds(simulateChecksVO.getIdentifyDetailIdList());
|
|
|
|
//遍历任务,做匹配
|
|
|
|
//遍历任务,做匹配
|
|
|
|
int i1=1;
|
|
|
|
int i1=1;
|
|
|
|
|
|
|
|
//用于数据结构化的对象
|
|
|
|
|
|
|
|
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
|
|
|
|
|
|
|
|
Date startDataCheckTime = new Date();
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
if (i1==1) {
|
|
|
|
if (i1==1) {
|
|
|
|
ocrIdentifyDetail.setSemanticResult("{\"ocr_res\":[[[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],[\"北京市朝阳区三里屯社区卫生服务中心\",0.9670220613479614]],[[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],[\"儿科专家门诊\",0.984556257724762]],[[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],[\"Pediatric srecialistclinic\",0.8756008148193359]]],\"其他\":[{\"area\":[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],\"end\":26,\"ocrText\":\"Pediatric srecialistclinic\",\"probability\":0.9925054592526585,\"start\":0,\"text\":\"Pediatric srecialistclinic\"}],\"医院名称\":[{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区三里屯社区卫生服务中心\",\"probability\":0.9681764264135495,\"start\":0,\"text\":\"北京市朝阳区三里屯社区卫生服务中心\"},{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区农光里医院\",\"probability\":0.95,\"start\":0,\"text\":\"北京市朝阳区农光里医院\"}],\"姓名\":[],\"时间\":[],\"科室\":[{\"area\":[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],\"end\":6,\"ocrText\":\"儿科专家门诊\",\"probability\":0.9836859327676066,\"start\":0,\"text\":\"儿科专家门诊\"}]}");
|
|
|
|
ocrIdentifyDetail.setSemanticResult("{\"ocr_res\":[[[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],[\"北京市朝阳区三里屯社区卫生服务中心\",0.9670220613479614]],[[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],[\"儿科专家门诊\",0.984556257724762]],[[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],[\"Pediatric srecialistclinic\",0.8756008148193359]]],\"其他\":[{\"area\":[[117.0,2496.0],[1036.0,2473.0],[1038.0,2577.0],[119.0,2600.0]],\"end\":26,\"ocrText\":\"Pediatric srecialistclinic\",\"probability\":0.9925054592526585,\"start\":0,\"text\":\"Pediatric srecialistclinic\"}],\"医院名称\":[{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区三里屯社区卫生服务中心\",\"probability\":0.9681764264135495,\"start\":0,\"text\":\"北京市朝阳区三里屯社区卫生服务中心\"},{\"area\":[[1282.0,1576.0],[2764.0,1594.0],[2763.0,1671.0],[1281.0,1653.0]],\"end\":17,\"ocrText\":\"北京市朝阳区农光里医院\",\"probability\":0.95,\"start\":0,\"text\":\"北京市朝阳区农光里医院\"}],\"姓名\":[],\"时间\":[],\"科室\":[{\"area\":[[132.0,2244.0],[1062.0,2214.0],[1069.0,2455.0],[140.0,2485.0]],\"end\":6,\"ocrText\":\"儿科专家门诊\",\"probability\":0.9836859327676066,\"start\":0,\"text\":\"儿科专家门诊\"}]}");
|
|
|
|
@ -942,12 +962,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"time\", \"inputText\":\"%s\"}", time)));
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"time\", \"inputText\":\"%s\"}", time)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(semanticResultJson);
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(semanticResultJson);
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson);
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson);
|
|
|
|
String text = null;//ocr 识别的文本
|
|
|
|
String text = null;//ocr 识别的文本
|
|
|
|
Double probability = 0d;
|
|
|
|
Double probability = 0d;
|
|
|
|
//用于数据结构化的对象
|
|
|
|
|
|
|
|
List<OcrResult> ocrResultList = new ArrayList<>();
|
|
|
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
//==========================
|
|
|
|
//==========================
|
|
|
|
@ -982,16 +1000,16 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
//没识别值
|
|
|
|
//没识别值
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -999,37 +1017,37 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
//没有输入值.
|
|
|
|
//没有输入值.
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,ruleInfo);
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
//准确度 可靠
|
|
|
|
//准确度 可靠
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1037,25 +1055,35 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
System.out.println("----------------------");
|
|
|
|
System.out.println("----------------------");
|
|
|
|
for (OcrResult result : ocrResultList) {
|
|
|
|
for (OcrResultDTO result : ocrResultDTOList) {
|
|
|
|
System.out.println(result.toString());
|
|
|
|
System.out.println(result.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取最小
|
|
|
|
}
|
|
|
|
ocrResultList.stream().sorted((a,b)->a.getTextRate().compareTo(b.getTextRate())).findFirst().get();
|
|
|
|
Date overDataCheckTime = new Date();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject responseBody=new JSONObject();
|
|
|
|
|
|
|
|
//获取最小
|
|
|
|
|
|
|
|
Double min = ocrResultDTOList.stream().sorted((a, b) -> a.getTextRate().compareTo(b.getTextRate())).findFirst().get().getTextRate();
|
|
|
|
//获取最大
|
|
|
|
//获取最大
|
|
|
|
//ocrResultList.stream().sorted((a,b)->a.getTextRate()-b.getTextRate()).findAny().get();
|
|
|
|
Double max = ocrResultDTOList.stream().sorted((a, b) -> b.getTextRate().compareTo(a.getTextRate())).findFirst().get().getTextRate();
|
|
|
|
//.sorted(OcrResult::getTextRate).findFirst();
|
|
|
|
//OCR和NlU执行时间总和(秒)
|
|
|
|
}
|
|
|
|
double ocrAndNluTimeSum = identifyDetailList.stream().mapToDouble(i -> (i.getOcrTime() == null ? 0 : i.getOcrTime()) + (i.getNluTime() == null ? 0 : i.getNluTime())).sum();
|
|
|
|
|
|
|
|
//执行时间(毫秒)
|
|
|
|
|
|
|
|
double executionTime = (ocrAndNluTimeSum * 1000) + overDataCheckTime.getTime() - startDataCheckTime.getTime();
|
|
|
|
|
|
|
|
responseBody.put("min",min);
|
|
|
|
|
|
|
|
responseBody.put("max",max);
|
|
|
|
|
|
|
|
responseBody.put("executionTime",executionTime);
|
|
|
|
|
|
|
|
responseBody.put("detailList", ocrResultDTOList);
|
|
|
|
|
|
|
|
return responseBody;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@ -1215,4 +1243,5 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
return taskList;
|
|
|
|
return taskList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|