|
|
|
|
@ -18,6 +18,7 @@ import org.jeecg.modules.ocr.mapper.OcrIdentifyMapper;
|
|
|
|
|
import org.jeecg.modules.ocr.model.*;
|
|
|
|
|
import org.jeecg.modules.ocr.service.*;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.ArrayOUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.ImageUtils;
|
|
|
|
|
import org.jeecg.modules.ocr.utils.StrCharUtil;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrIdentifyVo;
|
|
|
|
|
import org.jeecg.modules.ocr.vo.OcrRuleCheckVo;
|
|
|
|
|
@ -28,6 +29,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@ -101,6 +103,24 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
ocrIdentifyDetail.setIdentifyId(identifyId);
|
|
|
|
|
ocrIdentifyDetail.setImageName(imgName);
|
|
|
|
|
ocrIdentifyDetail.setImageUrl(imgPath);
|
|
|
|
|
//压缩图片
|
|
|
|
|
File file = new File(imgPath);
|
|
|
|
|
//当原图片存在时.
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
int maxWidth = 800;// 压缩后图片的最大宽度
|
|
|
|
|
int maxHeight = 600;// 压缩后图片的最大高度
|
|
|
|
|
int i = imgPath.lastIndexOf("/");
|
|
|
|
|
String fileUrl = "/data/thumbnail" + imgPath.substring(0, i);
|
|
|
|
|
//判断新目录是否存在,不存在则新建
|
|
|
|
|
ImageUtils.folderCreate(fileUrl);
|
|
|
|
|
String outputImagePath = fileUrl + imgPath.substring(i + 1, imgPath.length());
|
|
|
|
|
File thumbnailFile = new File(outputImagePath);
|
|
|
|
|
//如果上次生成过缩率图,就不生成了
|
|
|
|
|
if (!thumbnailFile.exists()) {
|
|
|
|
|
ImageUtils.compressImage(file.getAbsolutePath(), outputImagePath, maxWidth, maxHeight);
|
|
|
|
|
}
|
|
|
|
|
ocrIdentifyDetail.setThumbnailImageUrl(outputImagePath);
|
|
|
|
|
}
|
|
|
|
|
//ocrIdentifyDetail.setStatus(taskStatus);
|
|
|
|
|
ocrIdentifyDetail.setStatus("");
|
|
|
|
|
ocrIdentifyDetail.setMessage(message);
|
|
|
|
|
@ -243,7 +263,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//4.更新主任务状态
|
|
|
|
|
OcrIdentifyVo ocrIdentifyVo = this.findById(id);
|
|
|
|
|
OcrRuleCheckVo ocrRuleCheckVo = ocrIdentifyVo.getOcrRuleCheckVo();
|
|
|
|
|
Map<String, Map<String, String>> configRuleTypeMap = ocrRuleCheckVo.getConfigRuleTypeMap();
|
|
|
|
|
LambdaUpdateWrapper<OcrIdentify> updateWrapper = new LambdaUpdateWrapper<OcrIdentify>();
|
|
|
|
|
updateWrapper.eq(OcrIdentify::getId, id);
|
|
|
|
|
List<OcrIdentifyDetail> identifyDetailList = ocrIdentifyDetailService.listByIdentifyId(id);
|
|
|
|
|
@ -265,6 +284,8 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
if (ruleValidation) {
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
} else if (lastResult == null || !lastResult.getRuleValidation()) {
|
|
|
|
|
//失败时就是未获取到结果
|
|
|
|
|
result.setFailureReason(result.getTagName()+"未获取到结果");
|
|
|
|
|
fieldRightMap.put(tag, result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -286,19 +307,6 @@ public class OcrIdentifyServiceImpl extends ServiceImpl<OcrIdentifyMapper, OcrId
|
|
|
|
|
//匹配成功.
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
}
|
|
|
|
|
/*}else if (configRuleTypeMap.containsKey(OcrConstant.ruleCheckOrChar)){
|
|
|
|
|
Map<String, String> fieldMap = configRuleTypeMap.get(OcrConstant.ruleCheckSplitChar);
|
|
|
|
|
//获取成功的字段.
|
|
|
|
|
List<String> successFields = ocrResults.stream().filter(o -> o.getRuleValidation()).map(c->c.getTag()).collect(Collectors.toList());
|
|
|
|
|
updateWrapper.set(OcrIdentify::getErrorMsg, errorMsg);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 0);
|
|
|
|
|
fieldMapFor: for (String s : fieldMap.keySet()) {
|
|
|
|
|
if (successFields.contains(s)) {
|
|
|
|
|
updateWrapper.set(OcrIdentify::getTaskResult, 1);
|
|
|
|
|
break fieldMapFor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
String taskResultInfo = JSONArray.toJSONString(ocrResults);
|
|
|
|
|
updateWrapper.set(OcrIdentify::getStatus,"1");
|
|
|
|
|
updateWrapper.set(OcrIdentify::getEndTime,new Date());
|
|
|
|
|
|