master
周文涛 2 years ago
parent 5d0e27a549
commit 575ba02918

@ -91,6 +91,12 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
if (StringUtils.isNotBlank(ocrIdentify.getTaskName())) {
ocrIdentify.setTaskName("*"+ocrIdentify.getTaskName()+"*");
}
if (StringUtils.isNotBlank(ocrIdentify.getIdentifyUrl())) {
ocrIdentify.setIdentifyUrl("*"+ocrIdentify.getIdentifyUrl()+"*");
}
if (StringUtils.isNotBlank(ocrIdentify.getCreateBy())) {
ocrIdentify.setCreateBy("*"+ocrIdentify.getCreateBy()+"*");
}
Date startTime=ocrIdentify.getStartTime();
Date endTime=ocrIdentify.getEndTime();
if (startTime!=null&&endTime!=null) {
@ -102,33 +108,13 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
queryWrapper.between("startTime",startTime,endTime);
queryWrapper.between("endTime",startTime,endTime);
}
Page<OcrIdentify> page = new Page<OcrIdentify>(pageNo, pageSize);
Page<OcrIdentify> page = new Page<>(pageNo, pageSize);
Map<String, OcrRuleCheckVo> ocrRuleCheckMap = ocrRuleCheckService.listToMap(null);
Map<String, OcrMetadataConfigVo> metadataConfigMap = ocrMetadataConfigService.listToMap(null);
Map<String, String> taskNameMap = ocrTaskTypeService.listNameToMap(null);
IPage<OcrIdentify> pageList = ocrIdentifyService.page(page, queryWrapper);
if (pageList != null && pageList.getRecords() != null) {
List<String> idList = pageList.getRecords().stream().map(p -> p.getId()).collect(Collectors.toList());
List<OcrIdentifyDetail> ocrIdentifyDetailList = null;
if (idList.size()>0) {
ocrIdentifyDetailList = ocrIdentifyDetailService.list(new LambdaQueryWrapper<OcrIdentifyDetail>().in(OcrIdentifyDetail::getIdentifyId, idList));
}
List<OcrIdentifyDetail> identifyDetailList = new ArrayList<>();
for (OcrIdentify record : pageList.getRecords()) {
if ("1".equals(record.getStatus()) &&ocrIdentifyDetailList!=null&&ocrIdentifyDetailList.size()>0) {
//判断明细是否识别成功
identifyDetailList = ocrIdentifyDetailList.stream().filter(o -> o.getIdentifyId().equals(record.getId())).collect(Collectors.toList());
if (identifyDetailList.size()>0) {
long errorCount = identifyDetailList.stream().filter(i -> i.getStatus().equals("1")).count();
//errorCount>0,说明有失败的明细
record.setTaskResult(errorCount>0?"0":"1");
}else{
//失败
record.setTaskResult("0");
}
}
OcrRuleCheckVo ocrRuleCheckVo = ocrRuleCheckMap.get(record.getRuleCheck());
if (ocrRuleCheckVo!=null && StringUtils.isNotBlank(ocrRuleCheckVo.getMetadataConfigId())) {
record.setMetadataConfigId(ocrRuleCheckVo.getMetadataConfigId());
@ -337,9 +323,6 @@ public class OcrIdentifyController extends JeecgController<OcrIdentify, IOcrIden
for (OcrIdentify ocrIdentify : ocrIdentifyList) {
AssertUtils.isTrue("1".equals(ocrIdentify.getStatus()),String.format("[任务名称]-%s 当前正在识别中,不可进行通知回调",ocrIdentify.getTaskName()));
}
for (OcrIdentify ocrIdentify : ocrIdentifyList) {
ocrIdentify.setNoticeStatus("1");
}
for (String identifyId : Arrays.asList(ids.split(","))) {
ocrIdentifyService.callbackWly(identifyId);
}

@ -133,7 +133,7 @@ public class OcrIdentify implements Serializable {
private String errorMsg;
/**任务匹配结果*/
@ApiModelProperty(value = "任务匹配结果 0匹配失败,1匹配成功 -1匹配中")
private String taskResult="-1";
private String taskResult;
/*匹配结果信息*/
private String taskResultInfo;
}

@ -2,6 +2,7 @@ package org.jeecg.modules.ocr.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import org.checkerframework.checker.units.qual.A;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.ocr.entity.OcrIdentify;
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
@ -25,7 +26,7 @@ public interface IOcrIdentifyService extends IService<OcrIdentify> {
*/
@Async
public void callbackWly(String ocrIdentifyId);
public void updateTaskResultInfo(String id);
/**
* ocr

@ -289,6 +289,54 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
this.callbackWly(id);
/*System.out.println("已通过一条!");*/
}
@Override
@Async
public void updateTaskResultInfo(String id){
//4.更新主任务状态
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
updateWrapper.eq(OcrIdentify::getId, id);
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
if(true) {
if (identifyDetailList != null && identifyDetailList.size() > 0) {
Map<String, OcrResult> fieldRightMap = new LinkedHashMap<>();
String tag = null;
boolean ruleValidation = false;
/////明细中,如果有字段成功的,则会覆盖其他明细的匹配失败的情况,如果全都是失败的,会获取第一次失败的.
for (OcrIdentifyDetail ocrIdentifyDetail : identifyDetailList) {
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) {
tag = result.getTag();
ruleValidation = result.getRuleValidation();
OcrResult lastResult = fieldRightMap.get(tag);
if (ruleValidation) {
fieldRightMap.put(tag, result);
} else if (lastResult == null || !lastResult.getRuleValidation()) {
fieldRightMap.put(tag, result);
}
}
}
}
//如果明细合并一起,都是成功,则主任务 匹配成功, 否则匹配失败
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);
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);
}
}
}
super.update(updateWrapper);
}
@Override
@Async

Loading…
Cancel
Save