|
|
|
@ -101,7 +101,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrIdentifyDetail.setImageName(imgName);
|
|
|
|
|
ocrIdentifyDetail.setImageUrl(imgPath);
|
|
|
|
|
//ocrIdentifyDetail.setStatus(taskStatus);
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");
|
|
|
|
|
ocrIdentifyDetail.setStatus("");
|
|
|
|
|
ocrIdentifyDetail.setMessage(message);
|
|
|
|
|
ocrIdentifyDetail.setExecutionTime(executionTime);
|
|
|
|
|
ocrIdentifyDetail.setSemanticResult(semanticResult.toJSONString());
|
|
|
|
@ -111,19 +111,15 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
if (semanticResult != null) {
|
|
|
|
|
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()) {
|
|
|
|
|
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) {
|
|
|
|
|
String field = value.getField();
|
|
|
|
|
String fieldName = value.getFieldName();//校验的字段名称
|
|
|
|
|
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断,1-不绝对判断
|
|
|
|
@ -181,10 +177,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size() > 0 && !fieldRightMap.containsValue(false)) {
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size()>0) {
|
|
|
|
|
if (!fieldRightMap.containsValue(false)) {
|
|
|
|
|
ocrIdentifyDetail.setStatus("1");//全部通过
|
|
|
|
|
} else {
|
|
|
|
|
} else if(fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)){
|
|
|
|
|
ocrIdentifyDetail.setStatus("2");//有成功,有失败(部分)
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
} else{
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//有失败的
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
ocrIdentifyDetail.setStatus("0");//有失败的
|
|
|
|
|
ocrIdentifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
@ -236,15 +239,15 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
@Async
|
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime, new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "1");
|
|
|
|
|
/*获取 明细 的成功或失败.*/
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
|
if(true) {
|
|
|
|
|
if (identifyDetailList != null && identifyDetailList.size() > 0) {
|
|
|
|
|
Map<String, OcrResult> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
|
Map<String, OcrResult2> fieldRightMap = new LinkedHashMap<>();
|
|
|
|
|
String tag = null;
|
|
|
|
|
boolean ruleValidation = false;
|
|
|
|
|
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
|
|
|
|
@ -252,11 +255,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
String dataStructured = ocrIdentifyDetail.getDataStructured();
|
|
|
|
|
if (org.apache.commons.lang.StringUtils.isNotBlank(dataStructured)) {
|
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(dataStructured);
|
|
|
|
|
List<OcrResult> resultList = jsonArray.toJavaList(OcrResult.class);
|
|
|
|
|
for (OcrResult result : resultList) {
|
|
|
|
|
List<OcrResult2> resultList = jsonArray.toJavaList(OcrResult2.class);
|
|
|
|
|
for (OcrResult2 result : resultList) {
|
|
|
|
|
tag = result.getTag();
|
|
|
|
|
ruleValidation = result.getRuleValidation();
|
|
|
|
|
OcrResult lastResult = fieldRightMap.get(tag);
|
|
|
|
|
OcrResult2 lastResult = fieldRightMap.get(tag);
|
|
|
|
|
if (ruleValidation) {
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
@ -266,38 +269,55 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
|
|
|
|
|
List<OcrResult> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
|
List<OcrResult> ocrResults = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo);
|
|
|
|
|
List<OcrResult2> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
|
List<OcrResult2> ocrResults = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//TODO 后续考虑需要修正复杂程度. 支持 & + || 一起
|
|
|
|
|
|
|
|
|
|
String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";"));
|
|
|
|
|
if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckSplitChar)) {
|
|
|
|
|
if (errorResults.size() > 0) {
|
|
|
|
|
//匹配失败.
|
|
|
|
|
String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";"));
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
} else {
|
|
|
|
|
//匹配成功.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
}
|
|
|
|
|
}else if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckOrChar)){
|
|
|
|
|
Map<String, String> fieldMap = configRuleTypeMap.get(OcrConstant.ruleCheckSplitChar);
|
|
|
|
|
//获取成功的字段.
|
|
|
|
|
List<String> successFields = ocrResults.stream().filter(o -> o.getRuleValidation()).map(c->c.getTag()).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
|
|
|
|
|
fieldMapFor: for (String s : fieldMap.keySet()) {
|
|
|
|
|
if (successFields.contains(s)) {
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
break fieldMapFor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.update(updateWrapper);
|
|
|
|
|
/*System.out.println("已通过一条!");*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Async
|
|
|
|
|
public void updateTaskResultInfo(String id){
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId());
|
|
|
|
|
/*List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.listByIdentifyId(ocrIdentifyVo.getId());
|
|
|
|
|
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
JSONObject semanticResult = JSONObject.parseObject(identifyDetail.getSemanticResult());
|
|
|
|
|
String imgPath = identifyDetail.getImageUrl();
|
|
|
|
|
// 进行数据化 结构
|
|
|
|
|
if (semanticResult != null) {
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
if (ocrRuleCheckVo.getConfigName().contains("科室")) {
|
|
|
|
|
System.out.println("111");
|
|
|
|
|
}
|
|
|
|
|
Map<String, CheckSemanticModel> checkSemanticModelMap = getCheckSemanticModelMap(ocrRuleCheckVo.getConfigRuleMap(), ocrRuleCheckVo.getFieldMap(), ocrIdentifyVo.getSourceJsonObjects());
|
|
|
|
|
////
|
|
|
|
|
String text=null;//ocr 识别的文本,
|
|
|
|
@ -367,17 +387,30 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//其中有一个字段 全部都是 失败,则该图片失败.
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size() > 0 && !fieldRightMap.containsValue(false)) {
|
|
|
|
|
if (fieldRightMap != null && fieldRightMap.values().size()>0) {
|
|
|
|
|
if (!fieldRightMap.containsValue(false)) {
|
|
|
|
|
identifyDetail.setStatus("1");//全部通过
|
|
|
|
|
} else {
|
|
|
|
|
} else if(fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)){
|
|
|
|
|
identifyDetail.setStatus("2");//有成功,有失败(部分)
|
|
|
|
|
identifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
} else{
|
|
|
|
|
identifyDetail.setStatus("0");//有失败的
|
|
|
|
|
identifyDetail.setMessage(rMessage.toString());
|
|
|
|
|
}
|
|
|
|
|
}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>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
@ -408,17 +441,37 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
|
|
|
|
|
List<OcrResult2> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
|
|
|
|
|
List<OcrResult2> ocrResults = fieldRightMap.values().stream().collect(Collectors.toList());
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo);
|
|
|
|
|
|
|
|
|
|
//TODO 后续考虑需要修正复杂程度. 支持 & + || 一起
|
|
|
|
|
|
|
|
|
|
String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";"));
|
|
|
|
|
if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckSplitChar)) {
|
|
|
|
|
if (errorResults.size() > 0) {
|
|
|
|
|
//匹配失败.
|
|
|
|
|
String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";"));
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
} else {
|
|
|
|
|
//匹配成功.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
}
|
|
|
|
|
}else if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckOrChar)){
|
|
|
|
|
Map<String, String> fieldMap = configRuleTypeMap.get(OcrConstant.ruleCheckSplitChar);
|
|
|
|
|
//获取成功的字段.
|
|
|
|
|
List<String> successFields = ocrResults.stream().filter(o -> o.getRuleValidation()).map(c->c.getTag()).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
|
|
|
|
|
fieldMapFor: for (String s : fieldMap.keySet()) {
|
|
|
|
|
if (successFields.contains(s)) {
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
break fieldMapFor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResultInfo,taskResultInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
super.update(updateWrapper);
|
|
|
|
|