|
|
|
|
@ -224,6 +224,8 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
Map<String, String> compareMap = new HashMap<>();
|
|
|
|
|
//定义当前图片比对的最高阈值
|
|
|
|
|
BigDecimal maxSimilarity = new BigDecimal("0");
|
|
|
|
|
//定义当前图片比对的最低阈值
|
|
|
|
|
Map.Entry<String, String> minEntry = null;
|
|
|
|
|
//1.1 开始便利进行比对
|
|
|
|
|
for (OcrPicture ocrPictureNext : ocrPictureList) {
|
|
|
|
|
//排除当前图片,自己跟自己没必要比较
|
|
|
|
|
@ -287,7 +289,26 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
if (b1.compareTo(maxSimilarity) == 1) {
|
|
|
|
|
maxSimilarity = b1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//对比结果进行限制,取前200条
|
|
|
|
|
if(resultMap.size()>=200){
|
|
|
|
|
//获取最小阈值
|
|
|
|
|
for (Map.Entry<String, String> entry : resultMap.entrySet()) {
|
|
|
|
|
BigDecimal currentValue = new BigDecimal(entry.getValue());
|
|
|
|
|
if (minEntry == null || currentValue.compareTo(new BigDecimal(minEntry.getValue())) < 0) {
|
|
|
|
|
minEntry = entry;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BigDecimal oldMin = new BigDecimal(minEntry.getValue());
|
|
|
|
|
BigDecimal newMin = new BigDecimal(resultValue);
|
|
|
|
|
if(oldMin.compareTo(newMin)==-1){
|
|
|
|
|
resultMap.remove(minEntry.getKey());
|
|
|
|
|
resultMap.put(ocrPictureNext.getId().toString(), resultValue);
|
|
|
|
|
minEntry = new AbstractMap.SimpleEntry<>(ocrPictureNext.getId().toString(), resultValue);
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
resultMap.put(ocrPictureNext.getId().toString(), resultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断相似度是否一样
|
|
|
|
|
BigDecimal allSimilarity = new BigDecimal("100");
|
|
|
|
|
@ -324,9 +345,6 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
List<OcrPicture> pictures = new ArrayList<>();
|
|
|
|
|
pictures.add(ocrPicture);
|
|
|
|
|
try {
|
|
|
|
|
if ("287798960352200777".equals(ocrPicture.getId()) || "287798960268309961".equals(ocrPicture.getId())) {
|
|
|
|
|
System.out.println("adsd");
|
|
|
|
|
}
|
|
|
|
|
this.saveCheckDuplicateData(checkDuplicateId,saveList,pictures,ocrPictureList.get(0).getTenantId().toString(),sysUser);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("比对结果入库异常! error:{}",e.getMessage());
|
|
|
|
|
@ -475,9 +493,22 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
|
|
|
|
|
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));
|
|
|
|
|
//检查如果历史比较结果超出范围,直接重置历史结果,以1000为限制
|
|
|
|
|
if(hisMap.size()>1000){
|
|
|
|
|
hisMap = newMap;
|
|
|
|
|
}else{
|
|
|
|
|
newMap.putAll(hisMap);
|
|
|
|
|
//倒序排序,获取map top200,如果有重复则取新值。
|
|
|
|
|
hisMap = newMap.entrySet()
|
|
|
|
|
.stream()
|
|
|
|
|
.sorted((entry1, entry2) -> new BigDecimal(entry2.getValue().toString()).compareTo(new BigDecimal(entry1.getValue().toString())))
|
|
|
|
|
.limit(200) // 取前200个
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
Map.Entry::getKey,
|
|
|
|
|
Map.Entry::getValue,
|
|
|
|
|
(oldValue, newValue) -> newValue,
|
|
|
|
|
HashMap::new
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
pictureDuplicate.setId(pictureDuplicateHis.getId());
|
|
|
|
|
pictureDuplicate.setCheckDuplicateResultHisJson(JSONObject.toJSONString(hisMap));
|
|
|
|
|
|