|
|
|
@ -1,35 +1,29 @@
|
|
|
|
|
package org.jeecg.modules.ocr.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.checkerframework.checker.units.qual.C;
|
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
|
|
import org.jeecg.common.constant.OcrConstant;
|
|
|
|
|
import org.jeecg.common.util.RedisUtil;
|
|
|
|
|
import org.jeecg.common.util.RestUtil;
|
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentify;
|
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrIdentifyDetail;
|
|
|
|
|
import org.jeecg.modules.ocr.entity.OcrRuleCheck;
|
|
|
|
|
import org.jeecg.modules.ocr.mapper.OcrIdentifyMapper;
|
|
|
|
|
import org.jeecg.modules.ocr.model.CheckSemanticModel;
|
|
|
|
|
import org.jeecg.modules.ocr.model.OcrResult;
|
|
|
|
|
import org.jeecg.modules.ocr.model.SourceImage;
|
|
|
|
|
import org.jeecg.modules.ocr.model.TaskModel;
|
|
|
|
|
import org.jeecg.modules.ocr.service.*;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.ArrayCUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.ArrayOUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.*;
|
|
|
|
@ -77,12 +71,12 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
public void getSemanticInfo(JSONObject responseBody) {
|
|
|
|
|
try {
|
|
|
|
|
ocrApiCallStatisticsService.saveLogs("通用识别", "/ocr/ocrApi/identify", 1);
|
|
|
|
|
Thread.sleep(10000l);
|
|
|
|
|
Thread.sleep(1000l);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
log.debug("打印 ocr 结果:" + responseBody.toString());
|
|
|
|
|
String identifyId = responseBody.getString("task_id");//任务id
|
|
|
|
|
String identifyId = responseBody.getString("identifyId");//任务id
|
|
|
|
|
String imgPath = responseBody.getString("img_path");//图片路径
|
|
|
|
|
String imgName = null;//图片名称
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
@ -131,7 +125,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
List<String> fieldNameList = Arrays.asList(fieldName.split(","));
|
|
|
|
|
boolean b = ArrayCUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList()));
|
|
|
|
|
boolean b = ArrayOUtils.containsStringList(fieldNameList, semanticResult.keySet().stream().collect(Collectors.toList()));
|
|
|
|
|
//查看ocr识别返回的字段名称中是否有当前这个字段名称
|
|
|
|
|
if (b) {
|
|
|
|
|
//TODO 注意,ocr 识别返回的 字段是多个结果(数组),有一个值匹配上即为正确
|
|
|
|
@ -229,6 +223,7 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime, new Date());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus, "1");
|
|
|
|
|
super.update(updateWrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void mapPutIfTrue(Map map, String key, Boolean flag) {
|
|
|
|
@ -457,17 +452,19 @@ 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);
|
|
|
|
|
this.getSemanticInfo(semanticResponseJson);
|
|
|
|
|
//该子任务已执行,判断主任务是否残留
|
|
|
|
|
String masterTask = (String) redisUtil.get(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(","));
|
|
|
|
|
String collect = Arrays.asList(masterTask.split(",")).stream().filter(t -> !t.equals(task_id)).collect(Collectors.joining(","));
|
|
|
|
|
if (StringUtils.isBlank(collect)) {
|
|
|
|
|
//如果主任务下的子任务已清空,删除key
|
|
|
|
|
redisUtil.removeAll(masterTaskId);
|
|
|
|
|
redisUtil.del(masterTaskId);
|
|
|
|
|
//刷新Ocr识别任务状态
|
|
|
|
|
updateOcrIdentifyStatus(masterTaskId,"1");
|
|
|
|
|
log.debug("更新任务状态,id:"+masterTaskId);
|
|
|
|
|
}else{
|
|
|
|
|
//主任务还存在,刷新主任务明细
|
|
|
|
|
redisUtil.set(masterTaskId,collect);
|
|
|
|
|