|
|
|
@ -1,20 +1,48 @@
|
|
|
|
|
package cn.jyjz.xiaoyao.ocr.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import cn.jyjz.xiaoyao.admin.dataobject.User;
|
|
|
|
|
import cn.jyjz.xiaoyao.admin.service.LogService;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.exception.CommonExceptionCodeEnum;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.exception.ServiceException;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.DateUtils;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.StringUtils;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.vo.ResultVo;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.vo.ResultVoUtil;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.vo.UserToken;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.redis.cache.ehcache.EhCacheTask;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.dataDao.OcrCheckDuplicateMapper;
|
|
|
|
|
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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.IOcrPictureDuplicateHisService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.HashCompareUtil;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.ImageClassUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import lombok.extern.log4j.Log4j;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -25,12 +53,83 @@ import java.util.function.Function;
|
|
|
|
|
* @author author
|
|
|
|
|
* @since 2024-03-24
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Service("checkDuplicateService")
|
|
|
|
|
public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateMapper, OcrCheckDuplicate> implements IOcrCheckDuplicateService {
|
|
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(OcrCheckDuplicateServiceImpl.class);
|
|
|
|
|
@Resource
|
|
|
|
|
private OcrCheckDuplicateMapper ocrCheckDuplicateMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private IOcrCheckDuplicateResultService checkDuplicateResultService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private IOcrPictureDuplicateHisService pictureDuplicateHisService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private OcrPictureService pictureService;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private LogService logService;
|
|
|
|
|
|
|
|
|
|
@Value("${image.classifyPath}")
|
|
|
|
|
private String classifyPath;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查重任务接口
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
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());
|
|
|
|
|
ocrCheckDuplicate.setCheckDuplicateNo(checkDuplicateNoStr);
|
|
|
|
|
ocrCheckDuplicate.setTenantId(Long.valueOf(tenantId));
|
|
|
|
|
ocrCheckDuplicate.setCreateBy(sysUser.getUserid());
|
|
|
|
|
ocrCheckDuplicate.setCreateTime(DateUtil.current());
|
|
|
|
|
ocrCheckDuplicate.setPictureCount(ocrPictureList.size());
|
|
|
|
|
ocrCheckDuplicate.setStatus(1);
|
|
|
|
|
ocrCheckDuplicate.setSearchingJson(JSONObject.toJSONString(paraMap));//查重时左侧的筛选条件
|
|
|
|
|
this.save(ocrCheckDuplicate);
|
|
|
|
|
//异步执行图片比对查重功能
|
|
|
|
|
Thread thread = new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
IOcrCheckDuplicateService checkDuplicateService = SpringUtils.getBean("checkDuplicateService");
|
|
|
|
|
Long id = ocrCheckDuplicate.getId();
|
|
|
|
|
OcrCheckDuplicate checkDuplicate = new OcrCheckDuplicate();
|
|
|
|
|
checkDuplicate.setId(id);
|
|
|
|
|
checkDuplicate.setStatus(7); //预留状态
|
|
|
|
|
try {
|
|
|
|
|
//异步调用查重任务
|
|
|
|
|
checkDuplicateService.comparePictureResultSave(ocrPictureList,sysUser,id);
|
|
|
|
|
checkDuplicate.setStatus(2);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("异步执行图片比对异常:",e.getMessage());
|
|
|
|
|
checkDuplicate.setStatus(3);
|
|
|
|
|
}finally {
|
|
|
|
|
checkDuplicateService.updateById(checkDuplicate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
thread.start();
|
|
|
|
|
return ResultVoUtil.success(ocrCheckDuplicate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultVoUtil.error("比对图片不能为空!");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前查重任务执行状态
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public OcrCheckDuplicate getCheckDuplicateStatus(String checkDuplicateNo) {
|
|
|
|
|
|
|
|
|
@ -46,11 +145,16 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
return ocrCheckDuplicate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取最后一次,在执行中的查重编号
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
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.orderByDesc("create_time");
|
|
|
|
|
List<OcrCheckDuplicate> list = ocrCheckDuplicateMapper.selectList(queryWrapper);
|
|
|
|
|
if(CollUtil.isNotEmpty(list)){
|
|
|
|
@ -59,4 +163,231 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 图片比对并存储到查重结果比对表 ocr_check_duplicate_result
|
|
|
|
|
* 1.生成查重任务,插入ocr_check_duplicate,
|
|
|
|
|
* 2.异步执行查重任务比对查重
|
|
|
|
|
* 3.异步查重结果回写 回写orc_check_duplicate_result
|
|
|
|
|
* 4.图片比对历史 ocr_pictrue_duplicate_his 这个表的数据 以图片为维度,该图片与其他图片对比结果的保存
|
|
|
|
|
* 5.回写 orc_check_duplicate_result表 max_similarity字段,字段值是本次查重相似度最高的阈值。
|
|
|
|
|
* 6.回写ocr_picture表,similarity_score字段,字段值是该图片所有历史比对的最高值,如果本次比对的最高阈值小于最高值,则不进行回写。
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void comparePictureResultSave(List<OcrPicture> ocrPictureList,UserToken sysUser,Long checkDuplicateId) throws Exception {
|
|
|
|
|
|
|
|
|
|
List<OcrCheckDuplicateResult> saveList = new ArrayList<>();
|
|
|
|
|
//需要创建任务的图片集合
|
|
|
|
|
List<String> createTaskList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
//图片信息不能为空
|
|
|
|
|
if (null != ocrPictureList && !ocrPictureList.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
//1.开启比对任务
|
|
|
|
|
for (OcrPicture ocrPicture : ocrPictureList) {
|
|
|
|
|
|
|
|
|
|
logService.addLog(103, "AI获取图片相似度接口", sysUser, "sendParams");
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(ocrPicture.getImgHash())) {
|
|
|
|
|
Map<String, String> map = this.getOcrPictureClassifyAndHash(ocrPicture.getLocalpictrueurl());
|
|
|
|
|
if (map != null) {
|
|
|
|
|
ocrPicture.setImgHash(map.get("hash"));
|
|
|
|
|
ocrPicture.setClassificationid(map.get("classId"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//定义比对结果存储结果map
|
|
|
|
|
Map<String, String> resultMap = new HashMap<>();
|
|
|
|
|
//定义比对临时map 防止重复比对
|
|
|
|
|
Map<String, String> compareMap = new HashMap<>();
|
|
|
|
|
//定义当前图片比对的最高阈值
|
|
|
|
|
BigDecimal maxSimilarity = new BigDecimal("0");
|
|
|
|
|
//1.1 开始便利进行比对
|
|
|
|
|
for (OcrPicture ocrPictureNext : ocrPictureList) {
|
|
|
|
|
//排除当前图片,自己跟自己没必要比较
|
|
|
|
|
if (ocrPictureNext.getId().longValue() == ocrPicture.getId().longValue()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
//分类不一致的也不需要进行比对
|
|
|
|
|
//TODO 接口请求判断重复情况
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(ocrPictureNext.getImgHash())) {
|
|
|
|
|
Map<String, String> map = this.getOcrPictureClassifyAndHash(ocrPictureNext.getLocalpictrueurl());
|
|
|
|
|
if (map != null) {
|
|
|
|
|
ocrPictureNext.setImgHash(map.get("hash"));
|
|
|
|
|
ocrPictureNext.setClassificationid(map.get("classId"));
|
|
|
|
|
}
|
|
|
|
|
// this.updateById(ocrPictureNext);
|
|
|
|
|
}
|
|
|
|
|
String resultValue = "";
|
|
|
|
|
String strId = ocrPicture.getId() + ":" + ocrPictureNext.getId();
|
|
|
|
|
String strNextId = ocrPictureNext.getId() + ":" + ocrPicture.getId();
|
|
|
|
|
if (compareMap.containsKey(strId) || compareMap.containsKey(strNextId)) {
|
|
|
|
|
resultValue = resultMap.get(strId) == null ? compareMap.get(strNextId) : compareMap.get(strId);
|
|
|
|
|
} else {
|
|
|
|
|
String img = org.apache.commons.lang3.StringUtils.isBlank(ocrPicture.getImgHash()) ? org.apache.commons.lang3.StringUtils.isBlank(ocrPicture.getLocalpictrueurl()) ? ocrPicture.getImgurl() : ocrPicture.getLocalpictrueurl() : ocrPicture.getImgHash();
|
|
|
|
|
String imgNext = org.apache.commons.lang3.StringUtils.isBlank(ocrPictureNext.getImgHash()) ? org.apache.commons.lang3.StringUtils.isBlank(ocrPictureNext.getLocalpictrueurl()) ? ocrPictureNext.getImgurl() : ocrPictureNext.getLocalpictrueurl() : ocrPictureNext.getImgHash();
|
|
|
|
|
resultValue = HashCompareUtil.cmpHash(img, imgNext);
|
|
|
|
|
resultMap.put(strId, resultValue);
|
|
|
|
|
}
|
|
|
|
|
ocrPictureNext.setResult(resultValue);
|
|
|
|
|
BigDecimal b1 = new BigDecimal(resultValue);
|
|
|
|
|
//比对是否重复图片
|
|
|
|
|
// BigDecimal b2 = new BigDecimal("100");
|
|
|
|
|
// int val = b1.compareTo(b2);
|
|
|
|
|
// if (val == 0) {
|
|
|
|
|
// havePoint = true;
|
|
|
|
|
// }
|
|
|
|
|
//当前阈值大于 最高阈值 进行替换
|
|
|
|
|
if(b1.compareTo(maxSimilarity)==1){
|
|
|
|
|
maxSimilarity = b1;
|
|
|
|
|
}
|
|
|
|
|
resultMap.put(ocrPictureNext.getId().toString(),resultValue);
|
|
|
|
|
}
|
|
|
|
|
//1.2 比对结束组装入库参数
|
|
|
|
|
//定义比对存储对象
|
|
|
|
|
OcrCheckDuplicateResult ocrCheckDuplicateResult = new OcrCheckDuplicateResult();
|
|
|
|
|
ocrCheckDuplicateResult.setPictureId(ocrPicture.getId());
|
|
|
|
|
ocrCheckDuplicateResult.setMaxSimilarity(maxSimilarity.doubleValue());
|
|
|
|
|
ocrCheckDuplicateResult.setCompareResultJson(JSONObject.toJSONString(resultMap));
|
|
|
|
|
ocrCheckDuplicateResult.setCheckDuplicateId(checkDuplicateId);
|
|
|
|
|
saveList.add(ocrCheckDuplicateResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//批量入库
|
|
|
|
|
boolean b = checkDuplicateResultService.saveOrUpdateBatch(saveList);
|
|
|
|
|
if(!b){
|
|
|
|
|
throw new Exception("批量入库比对结果失败!");
|
|
|
|
|
}
|
|
|
|
|
//开始更新图片最高阈值
|
|
|
|
|
this.updatePictureSimilarityScore(saveList);
|
|
|
|
|
//开始更新 图片历史比对数据结果
|
|
|
|
|
this.updateCompareToPictureDuplicateHis(saveList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean removeCheckDuplicate(String checkDuplicateNo, String tenantId) {
|
|
|
|
|
QueryWrapper queryWrapper = new QueryWrapper();
|
|
|
|
|
queryWrapper.eq("tenant_id",tenantId);
|
|
|
|
|
queryWrapper.eq("check_duplicate_no",checkDuplicateNo);
|
|
|
|
|
OcrCheckDuplicate ocrCheckDuplicate = new OcrCheckDuplicate();
|
|
|
|
|
ocrCheckDuplicate.setIsDelete(1);
|
|
|
|
|
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);
|
|
|
|
|
OcrCheckDuplicate ocrCheckDuplicate = ocrCheckDuplicateMapper.selectOne(queryWrapper);
|
|
|
|
|
return ocrCheckDuplicate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新图片最高历史阈值
|
|
|
|
|
* @param saveList
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean updatePictureSimilarityScore(List<OcrCheckDuplicateResult> saveList) throws Exception {
|
|
|
|
|
List<OcrPicture> updateList = new ArrayList<>();
|
|
|
|
|
for (OcrCheckDuplicateResult ocrCheckDuplicateResult : saveList) {
|
|
|
|
|
OcrPicture picture = pictureService.selectDtoById(ocrCheckDuplicateResult.getPictureId());
|
|
|
|
|
OcrPicture ocrPicture = new OcrPicture();
|
|
|
|
|
//如果当前图片没有历史阈值,直接更新上阈值
|
|
|
|
|
if(picture.getSimilarityscore()==null){
|
|
|
|
|
ocrPicture.setId(picture.getId());
|
|
|
|
|
ocrPicture.setSimilarityscore(ocrCheckDuplicateResult.getMaxSimilarity().intValue());
|
|
|
|
|
updateList.add(ocrPicture);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
BigDecimal oldSimilarityScore = new BigDecimal(picture.getSimilarityscore());
|
|
|
|
|
BigDecimal newSimilarityScore = new BigDecimal(ocrCheckDuplicateResult.getMaxSimilarity());
|
|
|
|
|
if(newSimilarityScore.compareTo(oldSimilarityScore)==1){
|
|
|
|
|
ocrPicture.setId(picture.getId());
|
|
|
|
|
ocrPicture.setSimilarityscore(newSimilarityScore.intValue());
|
|
|
|
|
updateList.add(ocrPicture);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(updateList.size()<=0){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!pictureService.updateBatchById(updateList)){
|
|
|
|
|
throw new Exception("更新图片历史最高阈值失败!");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将本次比对的结果增量存储到对应图片里
|
|
|
|
|
* 存储增量比对历史数据 ocr_pictrue_duplicate_his
|
|
|
|
|
*/
|
|
|
|
|
public boolean updateCompareToPictureDuplicateHis(List<OcrCheckDuplicateResult> checkDuplicateResults) throws Exception {
|
|
|
|
|
//定义update集合
|
|
|
|
|
List<OcrPictureDuplicateHis> updateList = new ArrayList<>();
|
|
|
|
|
//定义insert集合
|
|
|
|
|
List<OcrPictureDuplicateHis> insertList = new ArrayList<>();
|
|
|
|
|
//1.循环便利本次比对结果
|
|
|
|
|
for (OcrCheckDuplicateResult checkDuplicateResult : checkDuplicateResults) {
|
|
|
|
|
//查看当前图片历史比对结果
|
|
|
|
|
OcrPictureDuplicateHis pictureDuplicateHis = pictureDuplicateHisService.queryByPictureId(checkDuplicateResult.getPictureId());
|
|
|
|
|
//获取本次对比结果map
|
|
|
|
|
ObjectMapper newObjectMapper = new ObjectMapper();
|
|
|
|
|
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(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));
|
|
|
|
|
}
|
|
|
|
|
pictureDuplicate.setId(pictureDuplicateHis.getId());
|
|
|
|
|
pictureDuplicate.setCheckDuplicateResultHisJson(JSONObject.toJSONString(hisMap));
|
|
|
|
|
pictureDuplicateHisService.updateById(pictureDuplicate);
|
|
|
|
|
updateList.add(pictureDuplicate);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//没有存储过
|
|
|
|
|
hisMap = newMap;
|
|
|
|
|
pictureDuplicate.setPictureId(checkDuplicateResult.getPictureId());
|
|
|
|
|
pictureDuplicate.setCheckDuplicateResultHisJson(JSONObject.toJSONString(hisMap));
|
|
|
|
|
insertList.add(pictureDuplicate);
|
|
|
|
|
}
|
|
|
|
|
if(updateList.size()>0){
|
|
|
|
|
if(!pictureDuplicateHisService.updateBatchById(updateList)){
|
|
|
|
|
throw new Exception("更新图片历史比对失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(insertList.size()>0){
|
|
|
|
|
if(!pictureDuplicateHisService.saveBatch(insertList)){
|
|
|
|
|
throw new Exception("新增图片历史比对失败!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, String> getOcrPictureClassifyAndHash(String img) {
|
|
|
|
|
JSONObject jsonObjectSimi = ImageClassUtil.getClassify(img, "1", classifyPath);
|
|
|
|
|
//返回内容为零,表示成功,否则表示失败
|
|
|
|
|
if (null != jsonObjectSimi && jsonObjectSimi.getString("code").equals("0") && jsonObjectSimi.get("data") != null && jsonObjectSimi.getJSONArray("data").size() > 0) {
|
|
|
|
|
JSONObject data = jsonObjectSimi.getJSONArray("data").getJSONObject(0);
|
|
|
|
|
Map<String, String> map = new HashMap();
|
|
|
|
|
map.put("classId", data.getString("classId"));
|
|
|
|
|
map.put("hash", data.getString("hash"));
|
|
|
|
|
return map;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|