|
|
|
@ -73,7 +73,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSemanticInfo(JSONObject responseBody) {
|
|
|
|
|
String ocrApiCallStatisticsId=null;
|
|
|
|
|
String ocrApiCallStatisticsId = null;
|
|
|
|
|
try {
|
|
|
|
|
ocrApiCallStatisticsId = ocrApiCallStatisticsService.saveLogs("通用识别", "/ocr/ocrApi/identify", 1);
|
|
|
|
|
Thread.sleep(1000l);
|
|
|
|
@ -86,7 +86,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
String imgName = null;//图片名称
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
|
imgName = imgPath.substring(imgPath.lastIndexOf("/") + 1, imgPath.length());
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
log.error("异常,识别图片地址为空");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -98,7 +98,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
OcrIdentifyDetail ocrIdentifyDetail = new OcrIdentifyDetail();
|
|
|
|
|
if (semanticResult != null) {
|
|
|
|
|
long count = ocrIdentifyDetailService.count(new LambdaUpdateWrapper<OcrIdentifyDetail>().eq(OcrIdentifyDetail::getIdentifyId, identifyId).eq(OcrIdentifyDetail::getImageUrl, imgPath));
|
|
|
|
|
if (count>0) {
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
//该图片已识别过
|
|
|
|
|
log.error("该图片已识别过了");
|
|
|
|
|
return;
|
|
|
|
@ -147,27 +147,28 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrArray.addAll(jsonArray.toJavaList(JSONObject.class));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ocrArrayFor:
|
|
|
|
|
for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
ocrArrayFor: for (int i = 0; i < ocrArray.size(); i++) {
|
|
|
|
|
JSONObject ocrItem = ocrArray.get(i);
|
|
|
|
|
text = ocrItem.getString("text");//ocr 识别的文本
|
|
|
|
|
probability = ocrItem.getDouble("probability");//置信度
|
|
|
|
|
if(inputText==null){
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
if (StringUtils.isBlank(text)) {
|
|
|
|
|
//ocr识别参数为空,不通过
|
|
|
|
|
rMessage.append(value.getFieldName() + "参数未获取到结果<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "参数未获取到结果", false);
|
|
|
|
|
} else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) {
|
|
|
|
|
//不必校验,有值就行,通过
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
}else if ("1".equals(ruleInfo) && StringUtils.isNotBlank(text)) {
|
|
|
|
|
// 1 不需要校验,只需要有返回ocr识别值
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
} else {
|
|
|
|
|
if (StringUtils.isBlank(text) || !text.contains(inputText)) {
|
|
|
|
|
//识别结果为空,识别结果 匹配不上 校验文本
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
} else if ("0".equals(ruleInfo)) {
|
|
|
|
|
//必定验证参数,必须有值且匹配
|
|
|
|
|
if (StringUtils.isBlank(inputText) || text.contains(inputText)) {
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
} else {
|
|
|
|
|
rMessage.append(value.getFieldName() + "不匹配<br>");
|
|
|
|
|
mapPutIfTrue(fieldRightMap, field, false);
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, value.getFieldName() + "不匹配", false);
|
|
|
|
|
} else {
|
|
|
|
|
ocrResultAdd(ocrResultList, field, inputText, text, probability, imgPath, "", true);
|
|
|
|
|
fieldRightMap.put(field, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -191,12 +192,9 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
//=========================
|
|
|
|
|
|
|
|
|
|
ocrApiCallStatisticsService.updateLogsEndTime(ocrApiCallStatisticsId,new Date());
|
|
|
|
|
ocrApiCallStatisticsService.updateLogsEndTime(ocrApiCallStatisticsId, new Date());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String semanticResponse = "{\"execution_time\":69.1751720905304,\"img_path\":\"./static/ocrData/custom_2_44.jpg\",\"message\":\"成功\",\"semantic_result\":{\"医院名称\":[{\"area\":[[227,382],[441,388],[440,422],[226,416]],\"end\":7,\"ocrText\":\"开封市眼病医院\",\"probability\":0.9677108957485778,\"start\":0,\"text\":\"开封市眼病医院\"}],\"姓名\":[{\"area\":[[566,668],[691,668],[691,712],[566,712]],\"end\":3,\"ocrText\":\"闫利霞\",\"probability\":0.884488371938783,\"start\":0,\"text\":\"闫利霞\"}],\"时间\":[{\"area\":[[701,400],[874,400],[874,456],[701,456]],\"end\":5,\"ocrText\":\"10:40\",\"probability\":0.9626484940814066,\"start\":0,\"text\":\"10:40\"},{\"area\":[[502,422],[667,424],[667,452],[502,450]],\"end\":11,\"ocrText\":\"2023年05月17日\",\"probability\":0.815085233546764,\"start\":0,\"text\":\"2023年05月17日\"}],\"科室\":[]},\"task_id\":1}";
|
|
|
|
|
public static String semanticUrl = "http://111.202.228.113:7003/semantic";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Async
|
|
|
|
|
public void postSemantic(OcrIdentify ocrIdentify, List<String> identifyUrlList) {
|
|
|
|
@ -222,7 +220,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
requestBody.put("taskId", taskId);
|
|
|
|
|
requestBody.put("taskLevel", Integer.valueOf(priority));
|
|
|
|
|
requestBody.put("taskType", "identify");
|
|
|
|
|
requestBody.put("parameter",id+","+taskId+","+identifyUrl);
|
|
|
|
|
requestBody.put("parameter", id + "," + taskId + "," + identifyUrl);
|
|
|
|
|
//发送任务请求 到 redis
|
|
|
|
|
pushTask(requestBody);
|
|
|
|
|
/*semanticResponseJson = RestUtil.post(OcrConstant.api_test_identify_url, requestBody);
|
|
|
|
@ -232,7 +230,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateOcrIdentifyStatus(String id,String status) {
|
|
|
|
|
public void updateOcrIdentifyStatus(String id, String status) {
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
@ -240,67 +238,67 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "1");
|
|
|
|
|
long time = new Date().getTime();
|
|
|
|
|
//回调 无量云接口
|
|
|
|
|
if(true){
|
|
|
|
|
if (true) {
|
|
|
|
|
OcrIdentify ocrIdentify = super.getById(id);
|
|
|
|
|
if (StringUtils.isBlank(ocrIdentify.getRequestId())) {
|
|
|
|
|
ocrIdentify.setRequestId(time+"");
|
|
|
|
|
ocrIdentify.setRequestId(time + "");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentify.getRequestId())) {
|
|
|
|
|
LambdaQueryWrapper<OcrIdentifyDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
queryWrapper.eq(OcrIdentifyDetail::getIdentifyId,id);
|
|
|
|
|
queryWrapper.eq(OcrIdentifyDetail::getIdentifyId, id);
|
|
|
|
|
queryWrapper.isNotNull(OcrIdentifyDetail::getDataStructured);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetails = ocrIdentifyDetailService.list(queryWrapper);
|
|
|
|
|
if (identifyDetails!=null) {
|
|
|
|
|
List<JSONObject> jsonObjects=new ArrayList<>();
|
|
|
|
|
boolean ruleValidation=false;//失败
|
|
|
|
|
if (identifyDetails != null) {
|
|
|
|
|
List<JSONObject> jsonObjects = new ArrayList<>();
|
|
|
|
|
boolean ruleValidation = false;//失败
|
|
|
|
|
//成功率
|
|
|
|
|
BigDecimal ocrPrecisionRateBigD = new BigDecimal(0);
|
|
|
|
|
//总明细数量
|
|
|
|
|
Integer detail_detailCount=0;
|
|
|
|
|
Integer detail_detailCount = 0;
|
|
|
|
|
for (OcrIdentifyDetail identifyDetail : identifyDetails) {
|
|
|
|
|
List<JSONObject> jsonObjects1 = JSONArray.parseArray(identifyDetail.getDataStructured()).toJavaList(JSONObject.class);
|
|
|
|
|
if (jsonObjects1!=null) {
|
|
|
|
|
long ruleValidationCount = jsonObjects.stream().filter(o -> o.getBooleanValue("ruleValidation")==false).count();
|
|
|
|
|
if (ruleValidationCount==0) {
|
|
|
|
|
ruleValidation=true;
|
|
|
|
|
if (jsonObjects1 != null) {
|
|
|
|
|
long ruleValidationCount = jsonObjects.stream().filter(o -> o.getBooleanValue("ruleValidation") == false).count();
|
|
|
|
|
if (ruleValidationCount == 0) {
|
|
|
|
|
ruleValidation = true;
|
|
|
|
|
}
|
|
|
|
|
double ocrPrecisionRate = jsonObjects.stream().mapToDouble(o -> o.getDouble("ocrPrecisionRate")).sum();
|
|
|
|
|
ocrPrecisionRateBigD=ocrPrecisionRateBigD.add(new BigDecimal(ocrPrecisionRate));
|
|
|
|
|
detail_detailCount+=jsonObjects1.size();
|
|
|
|
|
ocrPrecisionRateBigD = ocrPrecisionRateBigD.add(new BigDecimal(ocrPrecisionRate));
|
|
|
|
|
detail_detailCount += jsonObjects1.size();
|
|
|
|
|
}
|
|
|
|
|
jsonObjects.addAll(jsonObjects1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//组装回调参数
|
|
|
|
|
JSONObject requestBody=new JSONObject();
|
|
|
|
|
requestBody.put("requestId",ocrIdentify.getRequestId());
|
|
|
|
|
requestBody.put("ruleValidation",ruleValidation);
|
|
|
|
|
if (detail_detailCount==0) {
|
|
|
|
|
requestBody.put("imageTagRetrievePercentage",0);
|
|
|
|
|
}else{
|
|
|
|
|
JSONObject requestBody = new JSONObject();
|
|
|
|
|
requestBody.put("requestId", ocrIdentify.getRequestId());
|
|
|
|
|
requestBody.put("ruleValidation", ruleValidation);
|
|
|
|
|
if (detail_detailCount == 0) {
|
|
|
|
|
requestBody.put("imageTagRetrievePercentage", 0);
|
|
|
|
|
} else {
|
|
|
|
|
BigDecimal divide = ocrPrecisionRateBigD.divide(new BigDecimal(detail_detailCount), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
|
requestBody.put("imageTagRetrievePercentage",divide.doubleValue());
|
|
|
|
|
requestBody.put("imageTagRetrievePercentage", divide.doubleValue());
|
|
|
|
|
}
|
|
|
|
|
requestBody.put("retrieveReviewCompliance",0);
|
|
|
|
|
requestBody.put("failureReason","");
|
|
|
|
|
requestBody.put("retrieveReviewCompliance", 0);
|
|
|
|
|
requestBody.put("failureReason", "");
|
|
|
|
|
log.info("请求无量云回调接口");
|
|
|
|
|
JSONObject semanticResponseJson=null;
|
|
|
|
|
JSONObject semanticResponseJson = null;
|
|
|
|
|
try {
|
|
|
|
|
semanticResponseJson = RestUtil.post("https://192.168.1.21:8686/api/task/image/ocr/callback", requestBody);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("请求无量云回调接口失败");
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
} finally {
|
|
|
|
|
log.info("回调返回------------------");
|
|
|
|
|
if (semanticResponseJson!=null) {
|
|
|
|
|
if (semanticResponseJson != null) {
|
|
|
|
|
log.info(semanticResponseJson.toJSONString());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getNoticeStatus,"1");
|
|
|
|
|
}else{
|
|
|
|
|
updateWrapper.set(OcrIdentify::getNoticeStatus, "1");
|
|
|
|
|
} else {
|
|
|
|
|
log.info("回调返回-----:null");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
updateWrapper.set(OcrIdentify::getNoticeStatus,"0");
|
|
|
|
|
} else {
|
|
|
|
|
updateWrapper.set(OcrIdentify::getNoticeStatus, "0");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -403,6 +401,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送任务
|
|
|
|
|
*
|
|
|
|
|
* @param jsonObject
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -411,12 +410,12 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//获取优先级1的任务
|
|
|
|
|
String taskId = jsonObject.getString("taskId");
|
|
|
|
|
String taskType = jsonObject.getString("taskType");
|
|
|
|
|
int taskLevel= jsonObject.getInteger("taskLevel");
|
|
|
|
|
int taskLevel = jsonObject.getInteger("taskLevel");
|
|
|
|
|
String parameter = jsonObject.getString("parameter");
|
|
|
|
|
String task_ = (String) redisUtil.get("task_"+taskLevel);
|
|
|
|
|
String task_ = (String) redisUtil.get("task_" + taskLevel);
|
|
|
|
|
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);
|
|
|
|
|
task_ = JSONObject.toJSONString(jsonObjects);
|
|
|
|
|
} else {
|
|
|
|
@ -426,10 +425,10 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
List<TaskModel> taskList = jsonArray.toJavaList(TaskModel.class);
|
|
|
|
|
List<TaskModel> staskList = taskList.stream().filter(t -> t.getTaskId().equals(taskId)).collect(Collectors.toList());
|
|
|
|
|
TaskModel task = null;
|
|
|
|
|
if (staskList==null || staskList.size()==0) {
|
|
|
|
|
if (staskList == null || staskList.size() == 0) {
|
|
|
|
|
//该任务不存在, 看看 库表里 该任务是否已执行成功了
|
|
|
|
|
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)) {
|
|
|
|
|
//库表里已执行过
|
|
|
|
|
return Result.OK("该任务已执行结束");
|
|
|
|
|
} else {
|
|
|
|
@ -447,7 +446,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//存入redis
|
|
|
|
|
redisUtil.set("task_"+taskLevel, task_);
|
|
|
|
|
redisUtil.set("task_" + taskLevel, task_);
|
|
|
|
|
//执行任务
|
|
|
|
|
executeTask();
|
|
|
|
|
return Result.OK("已追加到任务");
|
|
|
|
@ -537,22 +536,22 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
requestBody.put("task_id", task_id);
|
|
|
|
|
requestBody.put("img_path", image);
|
|
|
|
|
JSONObject semanticResponseJson = RestUtil.post(OcrConstant.api_test_identify_url, requestBody);
|
|
|
|
|
semanticResponseJson.put("identifyId",masterTaskId);
|
|
|
|
|
semanticResponseJson.put("identifyId", masterTaskId);
|
|
|
|
|
this.getSemanticInfo(semanticResponseJson);
|
|
|
|
|
//该子任务已执行,判断主任务是否残留
|
|
|
|
|
String masterTask = (String) redisUtil.get("identify_"+masterTaskId);
|
|
|
|
|
String masterTask = (String) redisUtil.get("identify_" + masterTaskId);
|
|
|
|
|
if (StringUtils.isNotBlank(masterTask)) {
|
|
|
|
|
//主任务中排除当前任务
|
|
|
|
|
String collect = Arrays.asList(masterTask.split(",")).stream().filter(t -> !t.equals(task_id)).collect(Collectors.joining(","));
|
|
|
|
|
if (StringUtils.isBlank(collect)) {
|
|
|
|
|
//如果主任务下的子任务已清空,删除key
|
|
|
|
|
redisUtil.del("identify_"+masterTaskId);
|
|
|
|
|
redisUtil.del("identify_" + masterTaskId);
|
|
|
|
|
//刷新Ocr识别任务状态
|
|
|
|
|
updateOcrIdentifyStatus(masterTaskId,"1");
|
|
|
|
|
log.error("更新任务状态,id:"+masterTaskId);
|
|
|
|
|
}else{
|
|
|
|
|
updateOcrIdentifyStatus(masterTaskId, "1");
|
|
|
|
|
log.error("更新任务状态,id:" + masterTaskId);
|
|
|
|
|
} else {
|
|
|
|
|
//主任务还存在,刷新主任务明细
|
|
|
|
|
redisUtil.set("identify_"+masterTaskId,collect);
|
|
|
|
|
redisUtil.set("identify_" + masterTaskId, collect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|