|
|
@ -355,7 +355,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Async
|
|
|
|
@Async
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
log.info("id:{}",id);
|
|
|
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
//4.更新主任务状态
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
@ -412,7 +411,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
|
|
|
|
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
|
|
|
|
//=======规则检查配置
|
|
|
|
//=======规则检查配置
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo();
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo();
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
Map<String, Map<String, Object>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
//===================
|
|
|
|
//===================
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -551,27 +550,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
* @param configRuleMap 1/0 map
|
|
|
|
* @param configRuleMap 1/0 map
|
|
|
|
* @param fieldMap 字段含义 map
|
|
|
|
* @param fieldMap 字段含义 map
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, String> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) {
|
|
|
|
public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, Object> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) {
|
|
|
|
if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) {
|
|
|
|
if (configRuleMap!=null && CollectionUtils.isNotEmpty(configRuleMap.keySet())) {
|
|
|
|
//将 configRuleMap的 key 创建一个Set
|
|
|
|
//缩写转全称
|
|
|
|
Set<String> keySet = new HashSet<>(configRuleMap.keySet());
|
|
|
|
OcrJudgmentTools.abbreviationToFullName(configRuleMap);
|
|
|
|
//循环keySet,判断字段是否是缩写,如果是缩写就把缩写的全称put一下
|
|
|
|
|
|
|
|
for (String s : keySet) {
|
|
|
|
|
|
|
|
String value = configRuleMap.get(s);
|
|
|
|
|
|
|
|
if ("hn".equals(s)) {
|
|
|
|
|
|
|
|
configRuleMap.put("hospitalName",value);
|
|
|
|
|
|
|
|
}else if("dn".equals(s)) {
|
|
|
|
|
|
|
|
configRuleMap.put("doctorName", value);
|
|
|
|
|
|
|
|
}else if("dmn".equals(s)) {
|
|
|
|
|
|
|
|
configRuleMap.put("departmentName", value);
|
|
|
|
|
|
|
|
}else if("tm".equals(s) || ("time".equals(s))) {
|
|
|
|
|
|
|
|
configRuleMap.put("time", value);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
configRuleMap.put(s,value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>();
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>();
|
|
|
|
//校验正确的值
|
|
|
|
//校验正确的值
|
|
|
|
Map<String, String> inputMap = new LinkedHashMap<>();
|
|
|
|
Map<String, String> inputMap = new LinkedHashMap<>();
|
|
|
@ -611,7 +594,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
copyEntity.setField(field);
|
|
|
|
copyEntity.setField(field);
|
|
|
|
//1/0
|
|
|
|
//1/0
|
|
|
|
if (configRuleMap != null && configRuleMap.containsKey(field)) {
|
|
|
|
if (configRuleMap != null && configRuleMap.containsKey(field)) {
|
|
|
|
configRule = configRuleMap.get(field);
|
|
|
|
configRule =String.valueOf(configRuleMap.get(field));
|
|
|
|
copyEntity.setRuleInfo(configRule);
|
|
|
|
copyEntity.setRuleInfo(configRule);
|
|
|
|
//端字段含义
|
|
|
|
//端字段含义
|
|
|
|
fieldName = fieldMap.get(field);
|
|
|
|
fieldName = fieldMap.get(field);
|
|
|
@ -736,6 +719,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
|
|
|
|
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
|
|
|
|
Date startDataCheckTime = new Date();
|
|
|
|
Date startDataCheckTime = new Date();
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
|
|
|
|
|
|
|
|
OcrRuleCheckDTO ocrRuleCheckVo = ocrRuleCheckService.findById(simulateChecksVO.getRuleCheckId());
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
|
|
|
|
i1++;
|
|
|
|
i1++;
|
|
|
|
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
|
|
|
|
String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
|
|
|
@ -785,11 +769,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
|
|
|
|
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
//============================绘制虚线
|
|
|
|
//============================绘制虚线
|
|
|
|
|
|
|
|
// JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
|
|
|
|
|
|
|
|
// String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
|
|
|
|
// //判断新目录是否存在,不存在则新建
|
|
|
|
|
|
|
|
// FileOUtils.folderCreate(fileUrl);
|
|
|
|
|
|
|
|
// String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
|
|
|
|
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
|
|
|
|
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
// String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
|
|
|
|
String fileUrl = imgPath.substring(0, i);
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
String outputImagePath = fileUrl + "\\"+imgPath.substring(i + 1, imgPath.length());
|
|
|
|
if (semanticResult2!=null) {
|
|
|
|
if (semanticResult2!=null) {
|
|
|
|
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
|
|
|
|
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
|
|
|
|
boolean hasPoints=true;
|
|
|
|
boolean hasPoints=true;
|
|
|
@ -807,8 +797,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//============================
|
|
|
|
//============================
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
@ -911,6 +899,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
if (ocrArray.size() > 0) {
|
|
|
|
|
|
|
|
if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){
|
|
|
|
for (JSONObject ocrItem : ocrArray) {
|
|
|
|
for (JSONObject ocrItem : ocrArray) {
|
|
|
|
text = null;
|
|
|
|
text = null;
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
@ -971,6 +960,62 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (ocrRuleCheckVo.getType()!= null&&ocrRuleCheckVo.getType()==2) {
|
|
|
|
|
|
|
|
for (JSONObject ocrItem : ocrArray) {
|
|
|
|
|
|
|
|
text = null;
|
|
|
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
|
|
|
if ("101".equals(ruleInfo)) {
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
|
|
|
|
|
|
|
|
//没识别值
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true, ruleInfo);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName()).append("参数不匹配<br>");
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
|
|
|
|
|
|
|
|
} else if (StringUtils.isBlank(inputText)) {
|
|
|
|
|
|
|
|
//没有输入值.
|
|
|
|
|
|
|
|
fieldRightMap.put(field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值", false, ruleInfo);
|
|
|
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
|
|
|
//不必校验,有识别到就行,通过
|
|
|
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo);
|
|
|
|
|
|
|
|
} else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) {
|
|
|
|
|
|
|
|
//在1~99之间,根据精准度匹配
|
|
|
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
|
|
|
//准确度 可靠
|
|
|
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo);
|
|
|
|
|
|
|
|
} else if ("100".equals(ruleInfo)) {
|
|
|
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
|
|
|
double v = StrCharUtil.similarityRatio(inputText, text);
|
|
|
|
|
|
|
|
if (text.equals(inputText)) {
|
|
|
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
rMessage.append(value.getFieldName()).append("参数不匹配<br>");
|
|
|
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
|
|
|
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
|
|
|
|
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
@ -1006,9 +1051,20 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
//没有匹配结果
|
|
|
|
//没有匹配结果
|
|
|
|
responseBody.put("taskResult",1);
|
|
|
|
responseBody.put("taskResult",1);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
|
|
|
|
if(ocrRuleCheckVo.getType()==null||ocrRuleCheckVo.getType()==1){
|
|
|
|
long count = fieldRightMap.values().stream().filter(o->!o).count();
|
|
|
|
long count = fieldRightMap.values().stream().filter(o->!o).count();
|
|
|
|
//long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count();
|
|
|
|
//long count = ocrResultDTOList.stream().filter(o -> !o.getRuleValidation()).count();
|
|
|
|
responseBody.put("taskResult",count>0?0:1);//匹配成功或失败
|
|
|
|
responseBody.put("taskResult",count>0?0:1);//匹配成功或失败
|
|
|
|
|
|
|
|
}else if(ocrRuleCheckVo.getType()!=null&&ocrRuleCheckVo.getType()==2){
|
|
|
|
|
|
|
|
log.info(ocrResultDTOList.toString());
|
|
|
|
|
|
|
|
String configRule = ocrRuleCheckVo.getConfigRule();
|
|
|
|
|
|
|
|
Map<String,Object> params=new HashMap<>();
|
|
|
|
|
|
|
|
for(OcrResultDTO ocrResultDTO:ocrResultDTOList){
|
|
|
|
|
|
|
|
params.put(ocrResultDTO.getTag(),ocrResultDTO.getTextRate());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean rest=OcrJudgmentTools.judment(configRule,params);
|
|
|
|
|
|
|
|
responseBody.put("taskResult",rest?0:1);
|
|
|
|
|
|
|
|
}
|
|
|
|
Set<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet());
|
|
|
|
Set<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toSet());
|
|
|
|
List<OcrResultDTO> newResultDTOList=new ArrayList<>();
|
|
|
|
List<OcrResultDTO> newResultDTOList=new ArrayList<>();
|
|
|
|
//过滤掉0的值
|
|
|
|
//过滤掉0的值
|
|
|
@ -1136,10 +1192,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
//============================绘制虚线
|
|
|
|
//============================绘制虚线
|
|
|
|
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
|
|
|
|
JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
|
|
|
|
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
// String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
|
|
|
|
|
|
|
|
String fileUrl = imgPath.substring(0, i);
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
FileOUtils.folderCreate(fileUrl);
|
|
|
|
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
String outputImagePath = fileUrl + "\\"+imgPath.substring(i + 1, imgPath.length());
|
|
|
|
if (semanticResult2!=null) {
|
|
|
|
if (semanticResult2!=null) {
|
|
|
|
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
|
|
|
|
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
|
|
|
|
boolean hasPoints=true;
|
|
|
|
boolean hasPoints=true;
|
|
|
|