fix: 解决查重入库数据量过大,导致事务崩溃问题

pull/79/head
shuliYao 1 year ago
parent d96a911c3f
commit d76ba019c2

@ -41,7 +41,8 @@ public class OcrCheckDuplicateResult implements Serializable {
@ApiModelProperty(value = "图片id")
private Long pictureId;
@ApiModelProperty(value = "当前图片与任务包其他图片比对结果")
@ApiModelProperty(value = "当前图片与任务包其他图片比对结果 (废弃,入库导致数据量过大)")
@TableField(exist = false)
private String compareResultJson;
@ApiModelProperty(value = "查重任务id")

@ -178,8 +178,8 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
* 6.ocr_picturesimilarity_score
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void comparePictureResultSave(List<OcrPicture> ocrPictureList, UserToken sysUser, Long checkDuplicateId) throws Exception {
// @Transactional(rollbackFor = Exception.class)
public void comparePictureResultSave(List<OcrPicture> ocrPictureList, UserToken sysUser, Long checkDuplicateId){
List<OcrCheckDuplicateResult> saveList = new ArrayList<>();
//需要创建任务的图片集合
@ -291,33 +291,57 @@ public class OcrCheckDuplicateServiceImpl extends ServiceImpl<OcrCheckDuplicateM
if(similarityGroupOrderMap.get(ocrPicture.getId().toString())!=null){
ocrCheckDuplicateResult.setSimilarityGroupOrder(similarityGroupOrderMap.get(ocrPicture.getId().toString()));
}
//1.3开启入库操作,不能进行批量入库,会导致内存被拉崩
saveList.add(ocrCheckDuplicateResult);
logger.info("查重任务:{},结束创建任务",checkDuplicateId);
//批量入库
logger.info("查重任务:{},开启批量入库任务",checkDuplicateId);
List<OcrPicture> pictures = new ArrayList<>();
pictures.add(ocrPicture);
try {
this.saveCheckDuplicateData(checkDuplicateId,saveList,pictures,ocrPictureList.get(0).getTenantId().toString(),sysUser);
} catch (Exception e) {
logger.error("比对结果入库异常! error:{}",e.getMessage());
}
saveList = new ArrayList<>();
}
}
}
/**
*
* @return
*/
@Transactional(rollbackFor = Exception.class)
public boolean saveCheckDuplicateData(Long checkDuplicateId,List<OcrCheckDuplicateResult> saveList,List<OcrPicture> ocrPictureList, String tenantId,UserToken sysUser) throws Exception {
//1.批量入库
logger.debug("查重任务:{},开启批量入库任务",checkDuplicateId);
boolean b = checkDuplicateResultService.saveOrUpdateBatch(saveList);
if (!b) {
logger.error("入库比对结果失败,{}",checkDuplicateId);
throw new Exception("批量入库比对结果失败!");
}
logger.info("查重任务:{},结束批量入库任务",checkDuplicateId);
//开始更新图片最高阈值
logger.info("查重任务:{},更新最高阈值",checkDuplicateId);
this.updatePictureSimilarityScore(saveList);
logger.info("查重任务:{},结束更新最高阈值",checkDuplicateId);
//开始更新 图片历史比对数据结果
//2.开始更新图片最高阈值
logger.debug("查重任务:{},更新最高阈值",checkDuplicateId);
b = this.updatePictureSimilarityScore(saveList);
if (!b) {
logger.error("更新最高阈值,{}",checkDuplicateId);
throw new Exception("更新最高阈值失败!");
}
//3.开始更新 图片历史比对数据结果
logger.info("查重任务:{},更新图片历史比对结果",checkDuplicateId);
this.updateCompareToPictureDuplicateHis(saveList);
logger.info("查重任务:{},结束图片历史比对结果",checkDuplicateId);
saveList = new ArrayList<>();
b = this.updateCompareToPictureDuplicateHis(saveList);
if (!b) {
logger.error("更新图片历史比对结果失败,{}",checkDuplicateId);
throw new Exception("更新图片历史比对结果失败!");
}
//结果执行
//4.开始更新 图片历史比对数据结果
logger.info("查重任务:{},开启创建任务",checkDuplicateId);
if (CollectionUtils.isNotEmpty(ocrPictureList)) {
ocrTaskchildPictureService.createTask(ocrPictureList, ocrPictureList.get(0).getTenantId().toString(), sysUser);
}
return true;
}
}
@Override
public Boolean removeCheckDuplicate(String checkDuplicateNo, String tenantId) {

Loading…
Cancel
Save