master
周文涛 2 years ago
parent e38f4b4aa1
commit 97c9b08790

@ -145,7 +145,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
ocrIdentifyDetail.setMessage(message); ocrIdentifyDetail.setMessage(message);
ocrIdentifyDetail.setOcrTime(new BigDecimal(ocrTime).setScale(2, RoundingMode.HALF_UP).doubleValue()); ocrIdentifyDetail.setOcrTime(new BigDecimal(ocrTime).setScale(2, RoundingMode.HALF_UP).doubleValue());
ocrIdentifyDetail.setNluTime(new BigDecimal(nluTime).setScale(2, RoundingMode.HALF_UP).doubleValue()); ocrIdentifyDetail.setNluTime(new BigDecimal(nluTime).setScale(2, RoundingMode.HALF_UP).doubleValue());
if (semanticResult!=null) { if (semanticResult.isEmpty()) {
ocrIdentifyDetail.setSemanticResult(semanticResult.toJSONString()); ocrIdentifyDetail.setSemanticResult(semanticResult.toJSONString());
} }
ocrIdentifyDetailService.save(ocrIdentifyDetail); ocrIdentifyDetailService.save(ocrIdentifyDetail);
@ -160,20 +160,20 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
Double probability = 0d; Double probability = 0d;
//用于数据结构化的对象 //用于数据结构化的对象
List<OcrResultDTO> ocrResultDTOList = new ArrayList<>(); List<OcrResultDTO> ocrResultDTOList = new ArrayList<>();
StringBuffer rMessage = new StringBuffer(); StringBuilder rMessage = new StringBuilder();
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
//========================== //==========================
//========================== //==========================
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) { for (CheckSemanticModel value : checkSemanticModelMap.values()) {
String field = value.getField(); String field = value.getField();
String fieldName = value.getFieldName();//校验的字段名称 String fieldName = value.getFieldName();//校验的字段名称
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断 String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断
String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败 String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败
List<String> fieldNameList = Arrays.asList(fieldName.split(",")); List<String> fieldNameList = Arrays.asList(fieldName.split(","));
text = null; text = null;
boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList())); //boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.keySet()));
//查看ocr识别返回的字段名称中是否有当前这个字段名称 //查看ocr识别返回的字段名称中是否有当前这个字段名称
if (b) { if (true) {
//TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确 //TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
List<JSONObject> ocrArray = new ArrayList<>(); List<JSONObject> ocrArray = new ArrayList<>();
for (String s : fieldNameList) { for (String s : fieldNameList) {
@ -183,9 +183,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
} }
if (ocrArray.size() > 0) { if (ocrArray.size() > 0) {
ocrArrayFor: for (JSONObject ocrItem : ocrArray) {
for (int i = 0; i < ocrArray.size(); i++) {
JSONObject ocrItem = ocrArray.get(i);
text = null; text = null;
text = ocrItem.getString("text");//ocr 识别的文本 text = ocrItem.getString("text");//ocr 识别的文本
probability = ocrItem.getDouble("probability");//置信度 probability = ocrItem.getDouble("probability");//置信度
@ -195,54 +193,54 @@ 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(ocrResultDTOList, 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(ocrResultDTOList, 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()).append("参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, 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 {
if (StringUtils.isBlank(text)) { if (StringUtils.isBlank(text)) {
//ocr识别参数为空不通过 //ocr识别参数为空不通过
rMessage.append(value.getFieldName() + "参数未获取到结果<br>"); rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, 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(ocrResultDTOList, 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(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, ruleInfo);
} else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) { } else if (Double.parseDouble(ruleInfo) >= 1 && Double.parseDouble(ruleInfo) <= 99) {
//在1~99之间根据精准度匹配 //在1~99之间根据精准度匹配
double v = StrCharUtil.similarityRatio(inputText, text); double v = StrCharUtil.similarityRatio(inputText, text);
if (v >= Double.parseDouble(ruleInfo)) { if (v >= Double.parseDouble(ruleInfo)) {
//准确度 可靠 //准确度 可靠
fieldRightMap.put(field, true); fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, 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()).append("参数不匹配<br>"); rMessage.append(value.getFieldName()).append("参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, 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(ocrResultDTOList, 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()).append("参数不匹配<br>"); rMessage.append(value.getFieldName()).append("参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, 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);
} }
} }
} }
@ -250,16 +248,16 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} else { } else {
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>"); rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, 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()).append("参数未获取到结果<br>"); rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
ocrResultAdd(ocrResultDTOList, 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);
} }
} }
if (fieldRightMap != null && fieldRightMap.values().size() > 0) { if (!fieldRightMap.isEmpty() && CollectionUtils.isNotEmpty(fieldRightMap.values())) {
if (!fieldRightMap.containsValue(false)) { if (!fieldRightMap.containsValue(false)) {
ocrIdentifyDetail.setStatus("1");//全部通过 ocrIdentifyDetail.setStatus("1");//全部通过
} else if (fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)) { } else if (fieldRightMap.containsValue(false) && fieldRightMap.containsValue(true)) {
@ -294,22 +292,22 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
JSONObject semanticResponseJson = new JSONObject(); JSONObject semanticResponseJson = new JSONObject();
//将主任务存到redis. //将主任务存到redis.
StringBuffer task_master = new StringBuffer(); StringBuilder taskMaster = new StringBuilder();
for (int i = 0; i < identifyUrlList.size(); i++) { for (int i = 0; i < identifyUrlList.size(); i++) {
taskId = String.format(id + "_" + (i + 1)); taskId = id + "_" + (i + 1);
task_master.append(taskId).append(","); taskMaster.append(taskId).append(",");
} }
redisUtil.set("identify_" + id, task_master.toString()); redisUtil.set("identify_" + id, taskMaster.toString());
//执行子任务. //执行子任务.
for (int i = 0; i < identifyUrlList.size(); i++) { for (int i = 0; i < identifyUrlList.size(); i++) {
identifyUrl = identifyUrlList.get(i); identifyUrl = identifyUrlList.get(i);
taskId = String.format(id + "_" + (i + 1)); taskId = id + "_" + (i + 1);
requestBody.put("taskId", taskId); requestBody.put("taskId", taskId);
requestBody.put("taskLevel", Integer.valueOf(priority)); requestBody.put("taskLevel", Integer.valueOf(priority));
requestBody.put("taskType", "identify"); requestBody.put("taskType", "identify");
requestBody.put("parameter", id + "," + taskId + "," + identifyUrl); requestBody.put("parameter", id + "," + taskId + "," + identifyUrl);
//发送任务请求 到 redis //发送任务请求 到 redis
Result result = pushTask(requestBody); Result<?> result = pushTask(requestBody);
log.info("---------------"); log.info("---------------");
log.info(result.toString()); log.info(result.toString());
/*semanticResponseJson = RestUtil.post(OcrConstant.api_test_identify_url, requestBody); /*semanticResponseJson = RestUtil.post(OcrConstant.api_test_identify_url, requestBody);
@ -323,56 +321,51 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
public void updateOcrIdentifyStatus(String id, String status) { public void updateOcrIdentifyStatus(String id, String status) {
//4.更新主任务状态 //4.更新主任务状态
OcrIdentifyDTO ocrIdentifyDTO = this.findById(id); OcrIdentifyDTO ocrIdentifyDTO = this.findById(id);
OcrRuleCheckDTO ocrRuleCheckVo = ocrIdentifyDTO.getOcrRuleCheckVo(); LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<>();
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 (identifyDetailList != null && identifyDetailList.size() > 0) {
if (identifyDetailList != null && identifyDetailList.size() > 0) { Map<String, OcrResultDTO> fieldRightMap = new LinkedHashMap<>();
Map<String, OcrResultDTO> fieldRightMap = new LinkedHashMap<>(); String tag = null;
String tag = null; boolean ruleValidation = false;
boolean ruleValidation = false; /////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的. for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { 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<OcrResultDTO> resultList = jsonArray.toJavaList(OcrResultDTO.class);
List<OcrResultDTO> resultList = jsonArray.toJavaList(OcrResultDTO.class); for (OcrResultDTO result : resultList) {
for (OcrResultDTO result : resultList) { tag = result.getTag();
tag = result.getTag(); ruleValidation = result.getRuleValidation();
ruleValidation = result.getRuleValidation(); OcrResultDTO 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()) { //失败时就是未获取到结果
//失败时就是未获取到结果 result.setFailureReason(result.getTagName() + "未获取到结果");
result.setFailureReason(result.getTagName() + "未获取到结果"); fieldRightMap.put(tag, result);
fieldRightMap.put(tag, result);
}
} }
} }
} }
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败 }
List<OcrResultDTO> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList()); //如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
List<OcrResultDTO> ocrResultDTOS = fieldRightMap.values().stream().collect(Collectors.toList()); List<OcrResultDTO> errorResults = fieldRightMap.values().stream().filter(f -> !f.getRuleValidation()).collect(Collectors.toList());
List<OcrResultDTO> ocrResultDTOS = new ArrayList<>(fieldRightMap.values());
//TODO 后续考虑需要修正复杂程度. 支持 & + || 一起 //TODO 后续考虑需要修正复杂程度. 支持 & + || 一起
String errorMsg = errorResults.stream().map(OcrResultDTO::getFailureReason).collect(Collectors.joining(";"));
String errorMsg = errorResults.stream().map(e -> e.getFailureReason()).collect(Collectors.joining(";"));
// if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckSplitChar)) { // if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckSplitChar)) {
if (errorResults.size() > 0) { if (errorResults.size() > 0) {
//匹配失败. //匹配失败.
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg); updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
updateWrapper.set(OcrIdentify::getTaskResult, 0); updateWrapper.set(OcrIdentify::getTaskResult, 0);
} else { } else {
//匹配成功. //匹配成功.
updateWrapper.set(OcrIdentify::getTaskResult, 1); updateWrapper.set(OcrIdentify::getTaskResult, 1);
}
String taskResultInfo = JSONArray.toJSONString(ocrResultDTOS);
updateWrapper.set(OcrIdentify::getStatus, "1");
updateWrapper.set(OcrIdentify::getEndTime, new Date());
updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo);
} }
String taskResultInfo = JSONArray.toJSONString(ocrResultDTOS);
updateWrapper.set(OcrIdentify::getStatus, "1");
updateWrapper.set(OcrIdentify::getEndTime, new Date());
updateWrapper.set(OcrIdentify::getTaskResultInfo, taskResultInfo);
} }
super.update(updateWrapper); super.update(updateWrapper);
} }
@ -418,25 +411,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
callbackWly(ocrIdentifyId); callbackWly(ocrIdentifyId);
} }
public static void mapPutIfTrue(Map map, String key, Boolean flag) { public static void mapPutIfTrue(Map<String,Boolean> map, String key, Boolean flag) {
if (map.containsKey(key) && (Boolean) map.get(key).equals(true)) { if (!map.containsKey(key) || !map.get(key).equals(true)) {
} else {
map.put(key, flag); map.put(key, flag);
} }
} }
/** /**
* *
* @param ocrResultDTOList
* @param fieldName
* @param field
* @param inputText
* @param ocrText
* @param ocrPrecisionRate
* @param imgPath
* @param failureReason
* @param ruleValidation
* @param d
* @param ruleValidationValue * @param 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) { 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) {
@ -487,14 +469,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
/** /**
* OcrResult, ocrResultList * OcrResult, ocrResultList
*
* @param ocrResultDTOList
* @param field
* @param inputText
* @param ocrText
* @param ocrPrecisionRate
* @param imgPath
* @param failureReason
*/ */
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) { 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) {
@ -509,7 +483,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
* *
* @param configRuleMap 1/0 map * @param configRuleMap 1/0 map
* @param fieldMap map * @param fieldMap map
* @return
*/ */
public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, String> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) { public Map<String, CheckSemanticModel> getCheckSemanticModelMap(Map<String, String> configRuleMap, Map<String, String> fieldMap, List<JSONObject> sourceJsonObjects) {
Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>(); Map<String, CheckSemanticModel> checkSemanticModelMap = new LinkedHashMap<>();
@ -532,7 +505,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
//判断 规则检查配置 是不是 isrule=1 //判断 规则检查配置 是不是 isrule=1
if (configRuleMap.keySet().contains("isrule") && "1".equals((String) configRuleMap.get("isrule"))) { if (configRuleMap.containsKey("isrule") && "1".equals((String) configRuleMap.get("isrule"))) {
//isrule=1 //isrule=1
for (String field : inputMap.keySet()) { for (String field : inputMap.keySet()) {
fieldName = fieldMap.get(field); fieldName = fieldMap.get(field);
@ -573,11 +546,11 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
/** /**
* *
* *
* @param jsonObject * @param jsonObject
* @return * @return
*/ */
@Override @Override
public Result pushTask(JSONObject jsonObject) { public Result<?> pushTask(JSONObject jsonObject) {
//获取优先级1的任务 //获取优先级1的任务
String taskId = jsonObject.getString("taskId"); String taskId = jsonObject.getString("taskId");
String taskType = jsonObject.getString("taskType"); String taskType = jsonObject.getString("taskType");
@ -597,7 +570,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
if (task_ == null || task_.equals("[]")) { if (task_ == null || task_.equals("[]")) {
//无历史任务 //无历史任务
TaskModel task = new TaskModel(taskId, taskLevel, taskType, "0", parameter); TaskModel task = new TaskModel(taskId, taskLevel, taskType, "0", parameter);
List<TaskModel> jsonObjects = Arrays.asList(task); List<TaskModel> jsonObjects = Collections.singletonList(task);
task_ = JSONObject.toJSONString(jsonObjects); task_ = JSONObject.toJSONString(jsonObjects);
} else { } else {
//有历史任务 //有历史任务
@ -606,7 +579,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
List<TaskModel> taskList = jsonArray.toJavaList(TaskModel.class); List<TaskModel> taskList = jsonArray.toJavaList(TaskModel.class);
List<TaskModel> staskList = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).collect(Collectors.toList()); List<TaskModel> staskList = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).collect(Collectors.toList());
TaskModel task = null; TaskModel task = null;
if (staskList == null || staskList.size() == 0) { if (CollectionUtils.isEmpty(staskList)) {
//该任务不存在, 看看 库表里 该任务是否已执行成功了 //该任务不存在, 看看 库表里 该任务是否已执行成功了
String overTask = (String) redisUtil.get("over_task"); String overTask = (String) redisUtil.get("over_task");
if (org.apache.commons.lang.StringUtils.isNotBlank(overTask) && Arrays.asList(overTask.split(",")).contains(taskId)) { if (org.apache.commons.lang.StringUtils.isNotBlank(overTask) && Arrays.asList(overTask.split(",")).contains(taskId)) {
@ -653,8 +626,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
queryWrapper.notIn(OcrIdentify::getId, identifyIdList); queryWrapper.notIn(OcrIdentify::getId, identifyIdList);
} }
queryWrapper.eq(OcrIdentify::getNoticeStatus, 0); queryWrapper.eq(OcrIdentify::getNoticeStatus, 0);
List<OcrIdentify> list = super.list(queryWrapper); return super.list(queryWrapper);
return list;
} }
@Override @Override
@ -667,9 +639,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
Date startDataCheckTime = new Date(); Date startDataCheckTime = new Date();
Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map Map<String, Boolean> fieldRightMap = new LinkedHashMap<>();//存放 字段判断正确map
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) { 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++; i1++;
String semanticResultJson = ocrIdentifyDetail.getSemanticResult(); String semanticResultJson = ocrIdentifyDetail.getSemanticResult();
String imgPath = ocrIdentifyDetail.getImageUrl(); String imgPath = ocrIdentifyDetail.getImageUrl();
@ -717,122 +686,118 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath); ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
}*/ }*/
//绘制虚线 //============================绘制虚线
if (true) { JSONObject semanticResult2 = semanticResult.getJSONObject("semantic_result");
String fileUrl = "/data/ocrImage/drawDashed" + imgPath.substring(0, i);
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());
//判断新目录是否存在,不存在则新建 if (semanticResult2!=null) {
FileOUtils.folderCreate(fileUrl); List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2);
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length()); if (CollectionUtils.isNotEmpty(resultToPoints)) {
if (semanticResult2!=null) { ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath);
List<List<Point>> resultToPoints = ImageUtils.semanticResultToPoints(semanticResult2); imgPath = outputImagePath;
if (CollectionUtils.isNotEmpty(resultToPoints)) {
ImageUtils.drawDashedRectangleOnImages(file.getAbsolutePath(), resultToPoints, outputImagePath);
imgPath = outputImagePath;
}
} }
} }
//============================
} }
OcrRuleCheckDTO 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;
StringBuffer rMessage = new StringBuffer(); StringBuilder rMessage = new StringBuilder();
//========================== //==========================
checkSemanticFor: for (CheckSemanticModel value : checkSemanticModelMap.values()) { for (CheckSemanticModel value : checkSemanticModelMap.values()) {
String field = value.getField(); String field = value.getField();
String fieldName = value.getFieldName();//校验的字段名称 String fieldName = value.getFieldName();//校验的字段名称
String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断 String ruleInfo = value.getRuleInfo();//是否绝对判断 0-绝对判断1-不绝对判断
String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败 String inputText = value.getInputText();//校验文本 ocr识别的文本如果不包含该内容则算作失败
List<String> fieldNameList = Arrays.asList(fieldName.split(",")); List<String> fieldNameList = Arrays.asList(fieldName.split(","));
text = null; text = null;
boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.getJSONObject("semantic_result").keySet().stream().collect(Collectors.toList())); //boolean b = ArrayOUtils.containsStringList(fieldNameList, new ArrayList<>(semanticResult.getJSONObject("semantic_result").keySet()));
//查看ocr识别返回的字段名称中是否有当前这个字段名称 //查看ocr识别返回的字段名称中是否有当前这个字段名称
if (b) { //TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
//TODO 注意ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确 List<JSONObject> ocrArray = new ArrayList<>();
List<JSONObject> ocrArray = new ArrayList<>(); for (String s : fieldNameList) {
for (String s : fieldNameList) { JSONArray jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s);
JSONArray jsonArray = semanticResult.getJSONObject("semantic_result").getJSONArray(s); if (jsonArray != null && jsonArray.size() > 0) {
if (jsonArray != null && jsonArray.size() > 0) { ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
}
} }
if (ocrArray.size() > 0) { }
ocrArrayFor: if (ocrArray.size() > 0) {
for (int i = 0; i < ocrArray.size(); i++) { for (JSONObject ocrItem : ocrArray) {
JSONObject ocrItem = ocrArray.get(i); text = null;
text = null; text = ocrItem.getString("text");//ocr 识别的文本
text = ocrItem.getString("text");//ocr 识别的文本 probability = ocrItem.getDouble("probability");//置信度
probability = ocrItem.getDouble("probability");//置信度 if ("101".equals(ruleInfo)) {
if ("101".equals(ruleInfo)) { if (StringUtils.isBlank(text) || StringUtils.isBlank(inputText)) {
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.contains(inputText)) {
mapPutIfTrue(fieldRightMap, field, true); mapPutIfTrue(fieldRightMap, field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数不判断", true,ruleInfo); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, "101");
} else { } else {
double v = StrCharUtil.similarityRatio(inputText, text); rMessage.append(value.getFieldName()).append("参数不匹配<br>");
if (text.contains(inputText)) {
mapPutIfTrue(fieldRightMap, field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,"101");
} else {
rMessage.append(value.getFieldName() + "参数不匹配<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() + "参数未获取到结果<br>");
mapPutIfTrue(fieldRightMap, field, false); mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo);
} else if (StringUtils.isBlank(inputText)) { }
//没有输入值. }
} 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, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true, 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);
if (v >= Double.parseDouble(ruleInfo)) {
//准确度 可靠
fieldRightMap.put(field, true); fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "没有输入值不做匹配", true,ruleInfo); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo);
} else if ("0".equals(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 if ("100".equals(ruleInfo)) {
//必定验证参数,必须有值且匹配
double v = StrCharUtil.similarityRatio(inputText, text);
if (text.equals(inputText)) {
fieldRightMap.put(field, true); fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true,ruleInfo); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v, ruleInfo);
} else if (Double.valueOf(ruleInfo) >= 1 && Double.valueOf(ruleInfo) <= 99) { } else {
//在1~99之间根据精准度匹配 rMessage.append(value.getFieldName()).append("参数不匹配<br>");
double v = StrCharUtil.similarityRatio(inputText, text); mapPutIfTrue(fieldRightMap, field, false);
if (v >= Double.valueOf(ruleInfo)) { ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v, ruleInfo);
//准确度 可靠
fieldRightMap.put(field, true);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
} else {
rMessage.append(value.getFieldName() + "参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, 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(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, "", true, v,ruleInfo);
} else {
rMessage.append(value.getFieldName() + "参数不匹配<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, text, probability, imgPath, value.getFieldName() + "参数不匹配", false, v,ruleInfo);
}
} }
} }
} }
} else {
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
mapPutIfTrue(fieldRightMap, field, false);
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo);
} }
} else { } else {
rMessage.append(value.getFieldName() + "参数未获取到结果<br>"); rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false,ruleInfo); mapPutIfTrue(fieldRightMap, field, false);
fieldRightMap.put(field, false); ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, probability, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
} }
/*if (b) {
} else {
rMessage.append(value.getFieldName()).append("参数未获取到结果<br>");
ocrResultAdd(ocrResultDTOList, value.getFieldName(), field, inputText, null, 0d, imgPath, value.getFieldName() + "参数未获取到结果", false, ruleInfo);
fieldRightMap.put(field, false);
}*/
} }
} }
Date overDataCheckTime = new Date(); Date overDataCheckTime = new Date();
@ -842,8 +807,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
//OCR和NlU执行时间总和 //OCR和NlU执行时间总和
double ocrAndNluTimeSum = identifyDetailList.stream().mapToDouble(i -> (i.getOcrTime() == null ? 0 : i.getOcrTime()) + (i.getNluTime() == null ? 0 : i.getNluTime())).sum(); double ocrAndNluTimeSum = identifyDetailList.stream().mapToDouble(i -> (i.getOcrTime() == null ? 0 : i.getOcrTime()) + (i.getNluTime() == null ? 0 : i.getNluTime())).sum();
//执行时间(毫秒) //执行时间(毫秒)
double dataStructuredTime = new BigDecimal(overDataCheckTime.getTime() - startDataCheckTime.getTime()).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); double dataStructuredTime = new BigDecimal(overDataCheckTime.getTime() - startDataCheckTime.getTime()).setScale(2, RoundingMode.HALF_UP).doubleValue();
double executionTime = new BigDecimal(ocrAndNluTimeSum+(dataStructuredTime/1000)).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue(); double executionTime = new BigDecimal(ocrAndNluTimeSum+(dataStructuredTime/1000)).setScale(2, RoundingMode.HALF_UP).doubleValue();
responseBody.put("dataStructuredTime",dataStructuredTime); responseBody.put("dataStructuredTime",dataStructuredTime);
responseBody.put("allExecutionTime",executionTime); responseBody.put("allExecutionTime",executionTime);
@ -859,17 +824,17 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
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);//匹配成功或失败
List<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getOcrPrecisionRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toList()); List<String> haveRateTagList = ocrResultDTOList.stream().filter(o -> o.getTextRate() > 0).map(OcrResultDTO::getTag).collect(Collectors.toList());
//过滤掉0的值 //过滤掉0的值
ocrResultDTOList = ocrResultDTOList.stream().filter(o->haveRateTagList.contains(o.getTag()) && o.getOcrPrecisionRate()>0).collect(Collectors.toList()); ocrResultDTOList = ocrResultDTOList.stream().filter(o->haveRateTagList.contains(o.getTag()) && o.getTextRate()>0).collect(Collectors.toList());
} }
//获取最小 //获取最小
Double min = 0d; double min = 0d;
//获取最大 //获取最大
Double max = 0d; double max = 0d;
if (CollectionUtils.isNotEmpty(ocrResultDTOList)) { if (CollectionUtils.isNotEmpty(ocrResultDTOList)) {
min = ocrResultDTOList.stream().sorted((a, b) -> a.getTextRate().compareTo(b.getTextRate())).findFirst().get().getTextRate(); min = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).min().getAsDouble();
max = ocrResultDTOList.stream().sorted((a, b) -> b.getTextRate().compareTo(a.getTextRate())).findFirst().get().getTextRate(); max = ocrResultDTOList.stream().mapToDouble(OcrResultDTO::getTextRate).max().getAsDouble();
} }
responseBody.put("min",min); responseBody.put("min",min);
responseBody.put("max",max); responseBody.put("max",max);
@ -889,7 +854,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
log.error("该方法正在执行中"); log.error("该方法正在执行中");
} }
List<TaskModel> waitingTaskList = taskList.stream().filter(t -> t.getTaskStatus().equals("0")).collect(Collectors.toList()); List<TaskModel> waitingTaskList = taskList.stream().filter(t -> t.getTaskStatus().equals("0")).collect(Collectors.toList());
if (waitingTaskList != null) { if (CollectionUtils.isNotEmpty(waitingTaskList)) {
while (waitingTaskList.size() > 0) { while (waitingTaskList.size() > 0) {
//取第一个任务 //取第一个任务
TaskModel taskModel = waitingTaskList.get(0); TaskModel taskModel = waitingTaskList.get(0);
@ -910,14 +875,14 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
/** /**
* *
* *
* @param taskId * @param taskId id
* @param status 1 2 * @param status 1 2
*/ */
public void flushTask(String taskId, int status) { public void flushTask(String taskId, int status) {
List<TaskModel> taskList = getTaskList(); List<TaskModel> taskList = getTaskList();
if (taskList != null && taskList.size() > 0) { if (taskList != null && taskList.size() > 0) {
TaskModel taskModel = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).findFirst().get(); TaskModel taskModel = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).findFirst().get();
if (taskModel != null) { if (taskModel!=null) {
int taskLevel = taskModel.getTaskLevel(); int taskLevel = taskModel.getTaskLevel();
String task = (String) redisUtil.get("task_" + taskLevel); String task = (String) redisUtil.get("task_" + taskLevel);
JSONArray taskJsonArray = JSONObject.parseArray(task); JSONArray taskJsonArray = JSONObject.parseArray(task);
@ -971,7 +936,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
String masterTask = (String) redisUtil.get("identify_" + masterTaskId); String masterTask = (String) redisUtil.get("identify_" + masterTaskId);
if (StringUtils.isNotBlank(masterTask)) { if (StringUtils.isNotBlank(masterTask)) {
//主任务中排除当前任务 //主任务中排除当前任务
String collect = Arrays.asList(masterTask.split(",")).stream().filter(t -> !t.equals(task_id)).collect(Collectors.joining(",")); String collect = Arrays.stream(masterTask.split(",")).filter(t -> !t.equals(task_id)).collect(Collectors.joining(","));
if (StringUtils.isBlank(collect)) { if (StringUtils.isBlank(collect)) {
//如果主任务下的子任务已清空删除key //如果主任务下的子任务已清空删除key
redisUtil.del("identify_" + masterTaskId); redisUtil.del("identify_" + masterTaskId);
@ -984,7 +949,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
} }
} }
} else { } else {
Thread.sleep(2000l); Thread.sleep(2000L);
} }
@ -999,9 +964,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
if (!Arrays.asList(overTaskIds.split(",")).contains(taskModel.getTaskId())) { if (!Arrays.asList(overTaskIds.split(",")).contains(taskModel.getTaskId())) {
//该任务未执行过 //该任务未执行过
overTaskIds += "," + taskModel.getTaskId(); overTaskIds += "," + taskModel.getTaskId();
} else {
//该任务已结束过
} }
//该任务已结束过
} }
//存入已执行 redis里 //存入已执行 redis里
redisUtil.set("over_task", overTaskIds); redisUtil.set("over_task", overTaskIds);

@ -2,6 +2,8 @@ package org.jeecg.modules.ocr.utils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -13,10 +15,16 @@ import java.util.List;
public class ArrayOUtils { public class ArrayOUtils {
public static boolean containsStringList(List<String> objects,List<String> objects2){ public static boolean containsStringList(List<String> objects,List<String> objects2){
boolean flag=false; boolean flag=false;
for (String object : objects) { for (String o : objects) {
o2For:for (String o : objects2) { for (String object : objects2) {
if (object.contains(o) || o.contains(object)) { if (o.contains("姓名") || o.contains("医生")) {
return true; flag = Arrays.asList("姓名", "医生", "医生名称").contains(object);
}else if(o.contains("科室")){
flag = Arrays.asList("科室","科室名称").contains(object);
}else if(o.contains("医院")){
flag = Arrays.asList("医院","医院名称").contains(object);
}else{
flag = object.contains(o) || o.contains(object);
} }
} }
} }

@ -35,20 +35,16 @@ public class CallBackWlyUtils {
CallBackWlyResult result = new CallBackWlyResult(); CallBackWlyResult result = new CallBackWlyResult();
List<JSONObject> jsonObjects = new ArrayList<>(); List<JSONObject> jsonObjects = new ArrayList<>();
boolean ruleValidation = false;//失败
//成功率 //成功率
BigDecimal ocrPrecisionRateBigD = new BigDecimal(0); BigDecimal textRateBigd = new BigDecimal(0);
//总明细数量 //总明细数量
Integer detail_detailCount = 0; Integer detail_detailCount = 0;
for (OcrIdentifyDetail identifyDetail : identifyDetails) { for (OcrIdentifyDetail identifyDetail : identifyDetails) {
List<JSONObject> jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class); List<JSONObject> jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class);
if (jsonObjects1 != null) { if (jsonObjects1 != null) {
long ruleValidationCount = jsonObjects.stream().filter(o -> o.getBooleanValue("ruleValidation") == false).count(); //double ocrPrecisionRate = jsonObjects.stream().mapToDouble(o -> o.getDouble("ocrPrecisionRate")).sum();
if (ruleValidationCount == 0) { double textRate = jsonObjects.stream().mapToDouble(o->o.getDouble("textRate")).sum();
ruleValidation = true; textRateBigd = textRateBigd.add(new BigDecimal(textRate));
}
double ocrPrecisionRate = jsonObjects.stream().mapToDouble(o -> o.getDouble("ocrPrecisionRate")).sum();
ocrPrecisionRateBigD = ocrPrecisionRateBigD.add(new BigDecimal(ocrPrecisionRate));
detail_detailCount += jsonObjects1.size(); detail_detailCount += jsonObjects1.size();
} }
jsonObjects.addAll(jsonObjects1); jsonObjects.addAll(jsonObjects1);
@ -57,13 +53,16 @@ public class CallBackWlyUtils {
//组装回调参数 //组装回调参数
double imageTagRetrievePercentage = 0.0d; double imageTagRetrievePercentage = 0.0d;
if (detail_detailCount > 0) { if (detail_detailCount > 0) {
BigDecimal divide = ocrPrecisionRateBigD.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP); BigDecimal divide = textRateBigd.divide(new BigDecimal(detail_detailCount), 2, RoundingMode.HALF_UP);
imageTagRetrievePercentage = divide.doubleValue(); imageTagRetrievePercentage = divide.doubleValue();
} }
if (StringUtils.isNotBlank(ocrIdentify.getTaskResult()) && "1".equals(ocrIdentify.getTaskResult())) {
result.setRuleValidation(ruleValidation); result.setRuleValidation(true);
}else{
result.setRuleValidation(false);
}
result.setImageTagRetrievePercentage(imageTagRetrievePercentage + ""); result.setImageTagRetrievePercentage(imageTagRetrievePercentage + "");
result.setRetrieveReviewCompliance("0"); result.setRetrieveReviewCompliance(imageTagRetrievePercentage+"");
result.setFailureReason(ocrIdentify.getErrorMsg()); result.setFailureReason(ocrIdentify.getErrorMsg());
result.setOcrResult(jsonObjects); result.setOcrResult(jsonObjects);

Loading…
Cancel
Save