|
|
|
@ -19,10 +19,7 @@ import cn.jyjz.xiaoyao.ocr.dataobject.OcrCheckDuplicate;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.dataobject.OcrCheckDuplicateResult;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.dataobject.OcrPicture;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.dataobject.OcrPictureDuplicateHis;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.IOcrCheckDuplicateResultService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.IOcrCheckDuplicateService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.IOcrPictureDuplicateHisService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.*;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.HashCompareUtil;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.ImageClassUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
@ -33,6 +30,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import lombok.extern.log4j.Log4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -71,23 +69,25 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
@Resource
|
|
|
|
|
private LogService logService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private OcrTaskchildPictureService taskchildPictureService;
|
|
|
|
|
|
|
|
|
|
@Value("${image.classifyPath}")
|
|
|
|
|
private String classifyPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查重任务接口
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ResultVo duplicateCheck(List<OcrPicture> ocrPictureList, String tenantId, UserToken sysUser, HttpServletRequest req,Map<String, Object> paraMap) {
|
|
|
|
|
public ResultVo duplicateCheck(List<OcrPicture> ocrPictureList, String tenantId, UserToken sysUser, HttpServletRequest req, Map<String, Object> paraMap) {
|
|
|
|
|
|
|
|
|
|
if (null != ocrPictureList && !ocrPictureList.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
//生成查重任务插入表ocr_check_duplicate
|
|
|
|
|
OcrCheckDuplicate ocrCheckDuplicate = new OcrCheckDuplicate();
|
|
|
|
|
// 生成查重任务编号,规则用户id+当前年月日时分秒
|
|
|
|
|
String checkDuplicateNoStr = sysUser.getUserid()+"-"+ DateUtils.parseDateToStr("yyyyMMddHHmmss",new Date());
|
|
|
|
|
String checkDuplicateNoStr = sysUser.getUserid() + "-" + DateUtils.parseDateToStr("yyyyMMddHHmmss", new Date());
|
|
|
|
|
ocrCheckDuplicate.setCheckDuplicateNo(checkDuplicateNoStr);
|
|
|
|
|
ocrCheckDuplicate.setTenantId(Long.valueOf(tenantId));
|
|
|
|
|
ocrCheckDuplicate.setCreateBy(sysUser.getUserid());
|
|
|
|
@ -107,12 +107,12 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
checkDuplicate.setStatus(7); //预留状态
|
|
|
|
|
try {
|
|
|
|
|
//异步调用查重任务
|
|
|
|
|
checkDuplicateService.comparePictureResultSave(ocrPictureList,sysUser,id);
|
|
|
|
|
checkDuplicateService.comparePictureResultSave(ocrPictureList, sysUser, id);
|
|
|
|
|
checkDuplicate.setStatus(2);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("异步执行图片比对异常:",e.getMessage());
|
|
|
|
|
logger.error("异步执行图片比对异常:", e.getMessage());
|
|
|
|
|
checkDuplicate.setStatus(3);
|
|
|
|
|
}finally {
|
|
|
|
|
} finally {
|
|
|
|
|
checkDuplicateService.updateById(checkDuplicate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -126,19 +126,18 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前查重任务执行状态
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public OcrCheckDuplicate getCheckDuplicateStatus(String checkDuplicateNo) {
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isBlank(checkDuplicateNo)){
|
|
|
|
|
if (StringUtils.isBlank(checkDuplicateNo)) {
|
|
|
|
|
throw new ServiceException(CommonExceptionCodeEnum.PARAM_NOTVALID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QueryWrapper<OcrCheckDuplicate> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("check_duplicate_no",checkDuplicateNo);
|
|
|
|
|
queryWrapper.eq("check_duplicate_no", checkDuplicateNo);
|
|
|
|
|
|
|
|
|
|
OcrCheckDuplicate ocrCheckDuplicate = ocrCheckDuplicateMapper.selectOne(queryWrapper);
|
|
|
|
|
|
|
|
|
@ -152,14 +151,14 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
public String getLastCheckNo(String tenantId) {
|
|
|
|
|
|
|
|
|
|
QueryWrapper<OcrCheckDuplicate> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
queryWrapper.eq("tenant_id",tenantId);
|
|
|
|
|
queryWrapper.eq("status","1");
|
|
|
|
|
queryWrapper.eq("is_delete",0);
|
|
|
|
|
queryWrapper.eq("tenant_id", tenantId);
|
|
|
|
|
queryWrapper.eq("status", "1");
|
|
|
|
|
queryWrapper.eq("is_delete", 0);
|
|
|
|
|
queryWrapper.orderByDesc("create_time");
|
|
|
|
|
List<OcrCheckDuplicate> list = ocrCheckDuplicateMapper.selectList(queryWrapper);
|
|
|
|
|
if(CollUtil.isNotEmpty(list)){
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
return list.get(0).getCheckDuplicateNo();
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -175,7 +174,7 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void comparePictureResultSave(List<OcrPicture> ocrPictureList,UserToken sysUser,Long checkDuplicateId) throws Exception {
|
|
|
|
|
public void comparePictureResultSave(List<OcrPicture> ocrPictureList, UserToken sysUser, Long checkDuplicateId) throws Exception {
|
|
|
|
|
|
|
|
|
|
List<OcrCheckDuplicateResult> saveList = new ArrayList<>();
|
|
|
|
|
//需要创建任务的图片集合
|
|
|
|
@ -237,10 +236,10 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
// havePoint = true;
|
|
|
|
|
// }
|
|
|
|
|
//当前阈值大于 最高阈值 进行替换
|
|
|
|
|
if(b1.compareTo(maxSimilarity)==1){
|
|
|
|
|
if (b1.compareTo(maxSimilarity) == 1) {
|
|
|
|
|
maxSimilarity = b1;
|
|
|
|
|
}
|
|
|
|
|
resultMap.put(ocrPictureNext.getId().toString(),resultValue);
|
|
|
|
|
resultMap.put(ocrPictureNext.getId().toString(), resultValue);
|
|
|
|
|
}
|
|
|
|
|
//1.2 比对结束组装入库参数
|
|
|
|
|
//定义比对存储对象
|
|
|
|
@ -250,11 +249,16 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
ocrCheckDuplicateResult.setCompareResultJson(JSONObject.toJSONString(resultMap));
|
|
|
|
|
ocrCheckDuplicateResult.setCheckDuplicateId(checkDuplicateId);
|
|
|
|
|
saveList.add(ocrCheckDuplicateResult);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (CollectionUtils.isNotEmpty(ocrPictureList)) {
|
|
|
|
|
taskchildPictureService.createTask(ocrPictureList, ocrPictureList.get(0).getTenantId().toString(), sysUser);
|
|
|
|
|
}
|
|
|
|
|
//批量入库
|
|
|
|
|
boolean b = checkDuplicateResultService.saveOrUpdateBatch(saveList);
|
|
|
|
|
if(!b){
|
|
|
|
|
if (!b) {
|
|
|
|
|
throw new Exception("批量入库比对结果失败!");
|
|
|
|
|
}
|
|
|
|
|
//开始更新图片最高阈值
|
|
|
|
@ -266,24 +270,25 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean removeCheckDuplicate(String checkDuplicateNo, String tenantId) {
|
|
|
|
|
QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
|
|
queryWrapper.eq("tenant_id",tenantId);
|
|
|
|
|
queryWrapper.eq("check_duplicate_no",checkDuplicateNo);
|
|
|
|
|
queryWrapper.eq("tenant_id", tenantId);
|
|
|
|
|
queryWrapper.eq("check_duplicate_no", checkDuplicateNo);
|
|
|
|
|
OcrCheckDuplicate ocrCheckDuplicate = new OcrCheckDuplicate();
|
|
|
|
|
ocrCheckDuplicate.setIsDelete(1);
|
|
|
|
|
return baseMapper.update(ocrCheckDuplicate,queryWrapper)>0;
|
|
|
|
|
return baseMapper.update(ocrCheckDuplicate, queryWrapper) > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public OcrCheckDuplicate queryByCheckDuplicateNo(String checkDuplicateNo, Long tenantId) {
|
|
|
|
|
QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
|
|
queryWrapper.eq("tenant_id",tenantId);
|
|
|
|
|
queryWrapper.eq("check_duplicate_no",checkDuplicateNo);
|
|
|
|
|
queryWrapper.eq("tenant_id", tenantId);
|
|
|
|
|
queryWrapper.eq("check_duplicate_no", checkDuplicateNo);
|
|
|
|
|
OcrCheckDuplicate ocrCheckDuplicate = ocrCheckDuplicateMapper.selectOne(queryWrapper);
|
|
|
|
|
return ocrCheckDuplicate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新图片最高历史阈值
|
|
|
|
|
*
|
|
|
|
|
* @param saveList
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -293,7 +298,7 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
OcrPicture picture = pictureService.selectDtoById(ocrCheckDuplicateResult.getPictureId());
|
|
|
|
|
OcrPicture ocrPicture = new OcrPicture();
|
|
|
|
|
//如果当前图片没有历史阈值,直接更新上阈值
|
|
|
|
|
if(picture.getSimilarityscore()==null){
|
|
|
|
|
if (picture.getSimilarityscore() == null) {
|
|
|
|
|
ocrPicture.setId(picture.getId());
|
|
|
|
|
ocrPicture.setSimilarityscore(ocrCheckDuplicateResult.getMaxSimilarity().intValue());
|
|
|
|
|
updateList.add(ocrPicture);
|
|
|
|
@ -301,17 +306,17 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
}
|
|
|
|
|
BigDecimal oldSimilarityScore = new BigDecimal(picture.getSimilarityscore());
|
|
|
|
|
BigDecimal newSimilarityScore = new BigDecimal(ocrCheckDuplicateResult.getMaxSimilarity());
|
|
|
|
|
if(newSimilarityScore.compareTo(oldSimilarityScore)==1){
|
|
|
|
|
if (newSimilarityScore.compareTo(oldSimilarityScore) == 1) {
|
|
|
|
|
ocrPicture.setId(picture.getId());
|
|
|
|
|
ocrPicture.setSimilarityscore(newSimilarityScore.intValue());
|
|
|
|
|
updateList.add(ocrPicture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(updateList.size()<=0){
|
|
|
|
|
if (updateList.size() <= 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!pictureService.updateBatchById(updateList)){
|
|
|
|
|
if (!pictureService.updateBatchById(updateList)) {
|
|
|
|
|
throw new Exception("更新图片历史最高阈值失败!");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -333,20 +338,20 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
OcrPictureDuplicateHis pictureDuplicateHis = pictureDuplicateHisService.queryByPictureId(checkDuplicateResult.getPictureId());
|
|
|
|
|
//获取本次对比结果map
|
|
|
|
|
ObjectMapper newObjectMapper = new ObjectMapper();
|
|
|
|
|
Map<String,Object> newMap = newObjectMapper.readValue(checkDuplicateResult.getCompareResultJson(), HashMap.class);
|
|
|
|
|
Map<String, Object> newMap = newObjectMapper.readValue(checkDuplicateResult.getCompareResultJson(), HashMap.class);
|
|
|
|
|
//创建当前用于存储的历史map
|
|
|
|
|
Map<String, Object> hisMap = new HashMap<>();
|
|
|
|
|
//定义处理对象
|
|
|
|
|
OcrPictureDuplicateHis pictureDuplicate = new OcrPictureDuplicateHis();
|
|
|
|
|
|
|
|
|
|
if(pictureDuplicateHis!=null){
|
|
|
|
|
if (pictureDuplicateHis != null) {
|
|
|
|
|
//检查当前是否存在 历史
|
|
|
|
|
if(StringUtils.isNotBlank(pictureDuplicateHis.getCheckDuplicateResultHisJson())){
|
|
|
|
|
if (StringUtils.isNotBlank(pictureDuplicateHis.getCheckDuplicateResultHisJson())) {
|
|
|
|
|
ObjectMapper hisObjectMapper = new ObjectMapper();
|
|
|
|
|
hisMap = hisObjectMapper.readValue(pictureDuplicateHis.getCheckDuplicateResultHisJson(), HashMap.class);
|
|
|
|
|
for (String key : newMap.keySet()) {
|
|
|
|
|
//开始变更旧map
|
|
|
|
|
hisMap.put(key,newMap.get(key));
|
|
|
|
|
hisMap.put(key, newMap.get(key));
|
|
|
|
|
}
|
|
|
|
|
pictureDuplicate.setId(pictureDuplicateHis.getId());
|
|
|
|
|
pictureDuplicate.setCheckDuplicateResultHisJson(JSONObject.toJSONString(hisMap));
|
|
|
|
@ -361,14 +366,14 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
pictureDuplicate.setCheckDuplicateResultHisJson(JSONObject.toJSONString(hisMap));
|
|
|
|
|
insertList.add(pictureDuplicate);
|
|
|
|
|
}
|
|
|
|
|
if(updateList.size()>0){
|
|
|
|
|
if(!pictureDuplicateHisService.updateBatchById(updateList)){
|
|
|
|
|
if (updateList.size() > 0) {
|
|
|
|
|
if (!pictureDuplicateHisService.updateBatchById(updateList)) {
|
|
|
|
|
throw new Exception("更新图片历史比对失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(insertList.size()>0){
|
|
|
|
|
if(!pictureDuplicateHisService.saveBatch(insertList)){
|
|
|
|
|
if (insertList.size() > 0) {
|
|
|
|
|
if (!pictureDuplicateHisService.saveBatch(insertList)) {
|
|
|
|
|
throw new Exception("新增图片历史比对失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|