|
|
|
@ -1,11 +1,24 @@
|
|
|
|
|
package org.jeecg.modules.ocr.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
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.service.IOcrIdentifyDetailService;
|
|
|
|
|
import org.jeecg.modules.ocr.service.IOcrIdentifyService;
|
|
|
|
|
import org.jeecg.modules.ocr.service.IOcrRuleCheckDetailService;
|
|
|
|
|
import org.jeecg.modules.ocr.service.IOcrRuleCheckService;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description: ocr识别
|
|
|
|
|
* @Author: jeecg-boot
|
|
|
|
@ -14,5 +27,82 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrIdentify> implements IOcrIdentifyService {
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrRuleCheckService ocrRuleCheckService;
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrIdentifyDetailService ocrIdentifyDetailService;
|
|
|
|
|
@Resource
|
|
|
|
|
IOcrRuleCheckDetailService ocrRuleCheckDetailService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OcrIdentifyVo findById(String id){
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo=baseMapper.findById(id);
|
|
|
|
|
if (StringUtils.isNotBlank(ocrIdentifyVo.getSourceJson())) {
|
|
|
|
|
ocrIdentifyVo.setSourceJsonObject(JSONObject.parseObject(ocrIdentifyVo.getSourceJson()));
|
|
|
|
|
}
|
|
|
|
|
//规则检查配置信息
|
|
|
|
|
String ruleCheck = ocrIdentifyVo.getRuleCheck();
|
|
|
|
|
if (StringUtils.isNotBlank(ruleCheck)) {
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheck = ocrRuleCheckService.findById(ocrIdentifyVo.getRuleCheck());
|
|
|
|
|
ocrIdentifyVo.setOcrRuleCheckVo(ocrRuleCheck);
|
|
|
|
|
}
|
|
|
|
|
return ocrIdentifyVo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSemanticInfo(JSONObject responseBody) {
|
|
|
|
|
log.debug("打印 ocr 结果:"+responseBody.toString());
|
|
|
|
|
String identifyId = responseBody.getString("identifyId");//任务id
|
|
|
|
|
String imgPath = responseBody.getString("img_path");//图片路径
|
|
|
|
|
String imgName = null;//图片名称
|
|
|
|
|
if (StringUtils.isNotBlank(imgPath)) {
|
|
|
|
|
imgName = imgPath.substring(imgPath.lastIndexOf("/"),imgPath.length());
|
|
|
|
|
}
|
|
|
|
|
String message = responseBody.getString("message");//描述
|
|
|
|
|
String taskStatus = responseBody.getString("taskStatus");//任务是否完成
|
|
|
|
|
Double executionTime = responseBody.getDouble("execution_time");//执行时长(秒)
|
|
|
|
|
JSONObject semanticResult = responseBody.getJSONObject("semantic_result");//语义化结果
|
|
|
|
|
// 入库记录
|
|
|
|
|
OcrIdentifyDetail ocrIdentifyDetail = new OcrIdentifyDetail();
|
|
|
|
|
if (semanticResult!=null) {
|
|
|
|
|
ocrIdentifyDetail.setIdentifyId(identifyId);
|
|
|
|
|
ocrIdentifyDetail.setImageName(imgName);
|
|
|
|
|
ocrIdentifyDetail.setImageUrl(imgPath);
|
|
|
|
|
ocrIdentifyDetail.setStatus(taskStatus);
|
|
|
|
|
ocrIdentifyDetail.setMessage(message);
|
|
|
|
|
ocrIdentifyDetail.setExecutionTime(executionTime);
|
|
|
|
|
ocrIdentifyDetail.setSemanticResult(semanticResult.toJSONString());
|
|
|
|
|
ocrIdentifyDetailService.save(ocrIdentifyDetail);
|
|
|
|
|
}
|
|
|
|
|
//===================
|
|
|
|
|
String ocrIdentifyDetailId = ocrIdentifyDetail.getId();//明细id
|
|
|
|
|
// 进行数据化 结构
|
|
|
|
|
if (semanticResult!=null) {
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(identifyId);
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
|
|
|
|
|
// field,1/0
|
|
|
|
|
Map<String, String> configRuleMap = ocrRuleCheckVo.getConfigRuleMap();
|
|
|
|
|
// field,fieldname
|
|
|
|
|
Map<String, String> fieldMap = ocrRuleCheckVo.getFieldMap();
|
|
|
|
|
//对参数做匹配
|
|
|
|
|
|
|
|
|
|
JSONObject sourceJsonObject = ocrIdentifyVo.getSourceJsonObject();
|
|
|
|
|
//将 语义化结果 返回的 key 转换成 字段
|
|
|
|
|
for (String field : sourceJsonObject.keySet()) {
|
|
|
|
|
String fieldName = sourceJsonObject.getString(field);
|
|
|
|
|
semanticResultFor: for (String s : semanticResult.keySet()) {
|
|
|
|
|
if (fieldName.contains(s)) {
|
|
|
|
|
break semanticResultFor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (String s : semanticResult.keySet()) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//=========================
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|