|
|
|
|
@ -24,6 +24,7 @@ import org.jeecg.modules.ocr.utils.ImageUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.StrCharUtil;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.SimulateChecksVO;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@ -60,6 +61,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
RedisUtil redisUtil;
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrIdentifyCallbackLogService ocrIdentifyCallbackLogService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OcrIdentifyVo findById(String id) {
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = baseMapper.findById(id);
|
|
|
|
|
@ -112,7 +114,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
|
//压缩图片
|
|
|
|
|
if(true){
|
|
|
|
|
if (true) {
|
|
|
|
|
String fileUrl = "/data/ocrImage/thumbnail" + imgPath.substring(0, i);
|
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
|
@ -125,14 +127,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
|
|
|
|
|
}
|
|
|
|
|
//绘制虚线
|
|
|
|
|
if(true){
|
|
|
|
|
if (true) {
|
|
|
|
|
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
|
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
|
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult);
|
|
|
|
|
if (resultToPoints.size()>0) {
|
|
|
|
|
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(),resultToPoints,outputImagePath);
|
|
|
|
|
if (resultToPoints.size() > 0) {
|
|
|
|
|
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath);
|
|
|
|
|
ocrIdentifyDetail.setDrawDashedImageUrl(outputImagePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -140,7 +142,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//ocrIdentifyDetail.setStatus(taskStatus);
|
|
|
|
|
ocrIdentifyDetail.setStatus("");
|
|
|
|
|
ocrIdentifyDetail.setMessage(message);
|
|
|
|
|
ocrIdentifyDetail.setExecutionTime(executionTime/1000);
|
|
|
|
|
ocrIdentifyDetail.setExecutionTime(executionTime / 1000);
|
|
|
|
|
ocrIdentifyDetail.setSemanticResult(semanticResult.toJSONString());
|
|
|
|
|
ocrIdentifyDetailService.save(ocrIdentifyDetail);
|
|
|
|
|
}
|
|
|
|
|
@ -149,13 +151,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(identifyId);
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects());
|
|
|
|
|
String text=null;//ocr 识别的文本
|
|
|
|
|
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();//校验的字段名称
|
|
|
|
|
@ -174,8 +177,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ocrArray.size()>0) {
|
|
|
|
|
ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
ocrArrayFor:
|
|
|
|
|
for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = null;
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
@ -185,82 +189,82 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
if ("101".equals(ruleInfo)) {
|
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没识别值
|
|
|
|
|
mapPutIfTrue(fieldRightMap,field,true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true);
|
|
|
|
|
}else{
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
}else{
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
} else if(StringUtils.isBlank(inputText)){
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,null);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
} else if(Double.valueOf(ruleInfo)>=1 && Double.valueOf(ruleInfo)<=99){
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (v>=Double.valueOf(ruleInfo)) {
|
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
|
//准确度 可靠
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
}else{
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size()>0) {
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size() > 0) {
|
|
|
|
|
if (!fieldRightMap.containsValue(false)) {
|
|
|
|
|
ocrIdentifyDetail.setStatus("1");//全部通过
|
|
|
|
|
} else if(fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)){
|
|
|
|
|
} else if (fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)) {
|
|
|
|
|
ocrIdentifyDetail.setStatus("2");//有成功,有失败(部分)
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
} else{
|
|
|
|
|
} else {
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//有失败的
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//有失败的
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
@ -317,7 +321,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
|
if(true) {
|
|
|
|
|
if (true) {
|
|
|
|
|
if (identifyDetailList != null && identifyDetailList.size() > 0) {
|
|
|
|
|
Map<String, OcrResult2> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
|
String tag = null;
|
|
|
|
|
@ -336,7 +340,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
|
//失败时就是未获取到结果
|
|
|
|
|
result.setFailureReason(result.getTagName()+"未获取到结果");
|
|
|
|
|
result.setFailureReason(result.getTagName() + "未获取到结果");
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -350,18 +354,18 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";"));
|
|
|
|
|
// if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckSplitChar)) {
|
|
|
|
|
if (errorResults.size() > 0) {
|
|
|
|
|
//匹配失败.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
} else {
|
|
|
|
|
//匹配成功.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
}
|
|
|
|
|
if (errorResults.size() > 0) {
|
|
|
|
|
//匹配失败.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
} else {
|
|
|
|
|
//匹配成功.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
}
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus,"1");
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime,new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "1");
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime, new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.update(updateWrapper);
|
|
|
|
|
@ -369,11 +373,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Async
|
|
|
|
|
public void updateTaskResultInfo(String id){
|
|
|
|
|
public void updateTaskResultInfo(String id) {
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId());
|
|
|
|
|
|
|
|
|
|
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
/*for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult());
|
|
|
|
|
String imgPath = identifyDetail.getImageUrl();
|
|
|
|
|
// 进行数据化 结构
|
|
|
|
|
@ -381,7 +384,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects());
|
|
|
|
|
////
|
|
|
|
|
String text=null;//ocr 识别的文本,
|
|
|
|
|
String text = null;//ocr 识别的文本,
|
|
|
|
|
Double probability = 0d;
|
|
|
|
|
//用于数据结构化的对象
|
|
|
|
|
List<OcrResult> ocrResultList = new ArrayList<>();
|
|
|
|
|
@ -389,7 +392,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
StringBuffer rMessage = new StringBuffer();
|
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
//==========================
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
checkSemanticFor:
|
|
|
|
|
for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
|
@ -407,8 +411,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ocrArray.size()>0) {
|
|
|
|
|
ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
ocrArrayFor:
|
|
|
|
|
for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = null;
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
@ -418,26 +423,26 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
if ("101".equals(ruleInfo)) {
|
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没识别值
|
|
|
|
|
mapPutIfTrue(fieldRightMap,field,true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true);
|
|
|
|
|
}else{
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true);
|
|
|
|
|
} else {
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
}else{
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
} else if(StringUtils.isBlank(inputText)){
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true);
|
|
|
|
|
@ -445,67 +450,65 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
} else if(Double.valueOf(ruleInfo)>=1 && Double.valueOf(ruleInfo)<=99){
|
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (v>=Double.valueOf(ruleInfo)) {
|
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
|
//准确度 可靠
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
}else{
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v);
|
|
|
|
|
}
|
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, "", true,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false,v);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList,value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size()>0) {
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size() > 0) {
|
|
|
|
|
if (!fieldRightMap.containsValue(false)) {
|
|
|
|
|
identifyDetail.setStatus("1");//全部通过
|
|
|
|
|
} else if(fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)){
|
|
|
|
|
} else if (fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)) {
|
|
|
|
|
identifyDetail.setStatus("2");//有成功,有失败(部分)
|
|
|
|
|
identifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
} else{
|
|
|
|
|
} else {
|
|
|
|
|
identifyDetail.setStatus("0");//有失败的
|
|
|
|
|
identifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
identifyDetail.setStatus("0");//有失败的
|
|
|
|
|
identifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
identifyDetail.setDataStructured(JSONArray.toJSONString(ocrResultList));//数据结构化
|
|
|
|
|
ocrIdentifyDetailService.updateById(identifyDetail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
//=======规则检查配置
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
|
|
|
|
|
|
//===================
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
/*LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
@ -568,13 +571,13 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
private static int getStringPercent(String text, String inputText) {
|
|
|
|
|
String[] inputTextSplit = inputText.split(".");
|
|
|
|
|
String[] textSplit = text.split(".");
|
|
|
|
|
int trueNum=0;
|
|
|
|
|
int trueNum = 0;
|
|
|
|
|
for (int i = 0; i < inputTextSplit.length; i++) {
|
|
|
|
|
if (textSplit.length>=i){
|
|
|
|
|
if (textSplit.length >= i) {
|
|
|
|
|
for (int p = 0; p < textSplit.length; p++) {
|
|
|
|
|
trueNum++;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -582,8 +585,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void callbackWly(String ocrIdentifyId){
|
|
|
|
|
OcrIdentifyCallbackLog ocrIdentifyCallbackLog=new OcrIdentifyCallbackLog();
|
|
|
|
|
public void callbackWly(String ocrIdentifyId) {
|
|
|
|
|
OcrIdentifyCallbackLog ocrIdentifyCallbackLog = new OcrIdentifyCallbackLog();
|
|
|
|
|
ocrIdentifyCallbackLog.setIdentifyId(ocrIdentifyId);
|
|
|
|
|
|
|
|
|
|
Date date = new Date();
|
|
|
|
|
@ -593,7 +596,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
long time = date.getTime();
|
|
|
|
|
//回调 无量云接口
|
|
|
|
|
OcrIdentify ocrIdentify = super.getById(ocrIdentifyId);
|
|
|
|
|
if (ocrIdentify!=null) {
|
|
|
|
|
if (ocrIdentify != null) {
|
|
|
|
|
if (StringUtils.isBlank(ocrIdentify.getRequestId())) {
|
|
|
|
|
ocrIdentify.setRequestId(time + "");
|
|
|
|
|
}
|
|
|
|
|
@ -640,7 +643,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
try {
|
|
|
|
|
ocrIdentifyCallbackLog.setStartTime(new Date());
|
|
|
|
|
semanticResponseJson = RestUtil.post("https://192.168.1.21:8686/api/task/image/ocr/callback", requestBody);
|
|
|
|
|
} catch (org.springframework.web.client.ResourceAccessException e){
|
|
|
|
|
} catch (org.springframework.web.client.ResourceAccessException e) {
|
|
|
|
|
log.error("请求无量云回调接口失败-拒绝连接 (Connection refused)");
|
|
|
|
|
log.error(e.getMessage());
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@ -680,17 +683,31 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param ocrResultList
|
|
|
|
|
* @param fieldName
|
|
|
|
|
* @param field
|
|
|
|
|
* @param inputText
|
|
|
|
|
* @param ocrText
|
|
|
|
|
* @param ocrPrecisionRate
|
|
|
|
|
* @param imgPath
|
|
|
|
|
* @param failureReason
|
|
|
|
|
* @param ruleValidation
|
|
|
|
|
* @param d
|
|
|
|
|
* @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) {
|
|
|
|
|
OcrResult ocrResult = new OcrResult();
|
|
|
|
|
ocrResult.setTag(field);
|
|
|
|
|
ocrResult.setTagName(fieldName);
|
|
|
|
|
ocrResult.setOcrText(ocrText);
|
|
|
|
|
ocrResult.setInputText(inputText);
|
|
|
|
|
ocrResult.setOcrPrecisionRate(ocrPrecisionRate == null ? 0d : ocrPrecisionRate);
|
|
|
|
|
if (d==null) {
|
|
|
|
|
if (d == null) {
|
|
|
|
|
ocrResult.setTextRate(0d);
|
|
|
|
|
}else{
|
|
|
|
|
ocrResult.setTextRate(new BigDecimal(d).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
} else {
|
|
|
|
|
ocrResult.setTextRate(new BigDecimal(d).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
|
|
}
|
|
|
|
|
System.out.println("-----------------");
|
|
|
|
|
System.out.println(failureReason);
|
|
|
|
|
@ -707,6 +724,18 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrResultList = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
ocrResult.setRuleValidation(ruleValidation);
|
|
|
|
|
if ("0".equals(ruleValidationValue)) {
|
|
|
|
|
ocrResult.setRuleValidationText("有名称就算过");
|
|
|
|
|
}else if(Double.valueOf(ruleValidationValue)>0 &&Double.valueOf(ruleValidationValue)<=99){
|
|
|
|
|
ocrResult.setRuleValidationText("匹配度>="+ruleValidationValue);
|
|
|
|
|
}else if("100".equals(ruleValidation)){
|
|
|
|
|
ocrResult.setRuleValidationText("名称必须与参数完全一致");
|
|
|
|
|
}else if("101".equals(ruleValidationValue)){
|
|
|
|
|
ocrResult.setRuleValidationText("有值必须匹配无值算过");
|
|
|
|
|
}else if("isrule=1".equals(ruleValidationValue)){
|
|
|
|
|
ocrResult.setRuleValidationText("依据输入参数必须一致判断");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ocrResultList.add(ocrResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -721,11 +750,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
* @param imgPath
|
|
|
|
|
* @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) {
|
|
|
|
|
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) {
|
|
|
|
|
if (ruleValidation) {
|
|
|
|
|
ocrResultAdd(ocrResultList,fieldName,field,inputText,ocrText,ocrPrecisionRate,imgPath,failureReason,ruleValidation,100d);
|
|
|
|
|
}else{
|
|
|
|
|
ocrResultAdd(ocrResultList,fieldName,field,inputText,ocrText,ocrPrecisionRate,imgPath,failureReason,ruleValidation,0d);
|
|
|
|
|
ocrResultAdd(ocrResultList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 100d,ruleValidationValue);
|
|
|
|
|
} else {
|
|
|
|
|
ocrResultAdd(ocrResultList, fieldName, field, inputText, ocrText, ocrPrecisionRate, imgPath, failureReason, ruleValidation, 0d,ruleValidationValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -757,7 +786,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断 规则检查配置 是不是 isrule=1
|
|
|
|
|
if (configRuleMap.keySet().contains("isrule")&&"1".equals((String)configRuleMap.get("isrule"))) {
|
|
|
|
|
if (configRuleMap.keySet().contains("isrule") && "1".equals((String) configRuleMap.get("isrule"))) {
|
|
|
|
|
//isrule=1
|
|
|
|
|
for (String field : inputMap.keySet()) {
|
|
|
|
|
fieldName = fieldMap.get(field);
|
|
|
|
|
@ -769,7 +798,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
copyEntity.setFieldName(fieldName);
|
|
|
|
|
checkSemanticModelMap.put(field, copyEntity);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
if (fieldMap != null) {
|
|
|
|
|
for (String field : fieldMap.keySet()) {
|
|
|
|
|
copyEntity = new CheckSemanticModel();
|
|
|
|
|
@ -810,15 +839,15 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
String parameter = jsonObject.getString("parameter");
|
|
|
|
|
try {
|
|
|
|
|
int i = new Random().nextInt(10);
|
|
|
|
|
while (i==0){
|
|
|
|
|
while (i == 0) {
|
|
|
|
|
i = new Random().nextInt(10);
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(i*1000);
|
|
|
|
|
Thread.sleep(i * 1000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
String task_ = (String) redisUtil.get("task_" + taskLevel);
|
|
|
|
|
log.info("历史任务:"+task_);
|
|
|
|
|
log.info("历史任务:" + task_);
|
|
|
|
|
if (task_ == null || task_.equals("[]")) {
|
|
|
|
|
//无历史任务
|
|
|
|
|
TaskModel task = new TaskModel(taskId, taskLevel, taskType, "0", parameter);
|
|
|
|
|
@ -860,11 +889,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateMasterTaskStartTime(String id) {
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper=new LambdaUpdateWrapper<>();
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStartTime,new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus,"2");
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStartTime, new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "2");
|
|
|
|
|
updateWrapper.isNull(OcrIdentify::getStartTime);
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId,id);
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
super.update(updateWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -873,15 +902,157 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//执行次数已达到指定次数的任务id
|
|
|
|
|
List<String> identifyIdList = ocrIdentifyCallbackLogService.findIdentifyIdGroupGtCount(autoPushNoticeMaxNum);
|
|
|
|
|
//获取 待通知的任务,排除已达到指定次数的任务
|
|
|
|
|
LambdaQueryWrapper<OcrIdentify> queryWrapper=new LambdaQueryWrapper<>();
|
|
|
|
|
if (identifyIdList!=null&&identifyIdList.size()>0) {
|
|
|
|
|
queryWrapper.notIn(OcrIdentify::getId,identifyIdList);
|
|
|
|
|
LambdaQueryWrapper<OcrIdentify> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
if (identifyIdList != null && identifyIdList.size() > 0) {
|
|
|
|
|
queryWrapper.notIn(OcrIdentify::getId, identifyIdList);
|
|
|
|
|
}
|
|
|
|
|
queryWrapper.eq(OcrIdentify::getNoticeStatus,0);
|
|
|
|
|
queryWrapper.eq(OcrIdentify::getNoticeStatus, 0);
|
|
|
|
|
List<OcrIdentify> list = super.list(queryWrapper);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void simulateChecks(SimulateChecksVO simulateChecksVO) {
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIds(simulateChecksVO.getIdentifyDetailIdList());
|
|
|
|
|
//遍历任务,做匹配
|
|
|
|
|
int i1=1;
|
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
|
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\":\"儿科专家门诊\"}]}");
|
|
|
|
|
}
|
|
|
|
|
i1++;
|
|
|
|
|
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
|
|
|
|
|
String imgPath = ocrIdentifyDetail.getImageUrl();
|
|
|
|
|
if (StringUtils.isBlank(semanticResultJson)) continue;
|
|
|
|
|
String doctorName = simulateChecksVO.getDoctorName();
|
|
|
|
|
String hospitalName = simulateChecksVO.getHospitalName();
|
|
|
|
|
String departmentName = simulateChecksVO.getDepartmentName();
|
|
|
|
|
String time = simulateChecksVO.getTime();
|
|
|
|
|
List<JSONObject> sourceJson = new ArrayList<>();
|
|
|
|
|
if (StringUtils.isNotBlank(doctorName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"doctorName\", \"inputText\":\"%s\"}", doctorName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(hospitalName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"hospitalName\", \"inputText\":\"%s\"}", hospitalName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(departmentName)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"departmentName\", \"inputText\":\"%s\"}", departmentName)));
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(time)) {
|
|
|
|
|
sourceJson.add(JSONObject.parseObject(String.format("{\"tag\":\"time\", \"inputText\":\"%s\"}", time)));
|
|
|
|
|
}
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(semanticResultJson);
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), sourceJson);
|
|
|
|
|
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(","));
|
|
|
|
|
text = null;
|
|
|
|
|
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 = null;
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
log.info("ocrItem:");
|
|
|
|
|
log.info(ocrItem.toJSONString());
|
|
|
|
|
if ("101".equals(ruleInfo)) {
|
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没识别值
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.contains(inputText)) {
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
//没有输入值.
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,null);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo);
|
|
|
|
|
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) {
|
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (v >= Double.valueOf(ruleInfo)) {
|
|
|
|
|
//准确度 可靠
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
ocrResultAdd(ocrResultList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("----------------------");
|
|
|
|
|
for (OcrResult result : ocrResultList) {
|
|
|
|
|
System.out.println(result.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void executeTask() {
|
|
|
|
|
//获取任务
|
|
|
|
|
|