Commit 260f4e35 authored by liangyb's avatar liangyb

#20240719 评标工具-项目解析结构化数据保存数据失败

parent ae0fc601
......@@ -2,14 +2,12 @@ package com.gx.obe.server.management.struct_new.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gx.obe.server.common.utils.CollectionUtils;
import com.gx.obe.server.common.utils.ExceptionUtil;
import com.gx.obe.server.common.utils.IDUtils;
import com.gx.obe.server.common.utils.StringUtils;
import com.gx.obe.server.common.utils.*;
import com.gx.obe.server.management.struct_new.dao.*;
import com.gx.obe.server.management.struct_new.entity.*;
import com.gx.obe.server.management.struct_new.service.ObeEvaluationContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -177,6 +175,27 @@ public class ObeEvaluationContentServiceImpl extends ServiceImpl<ObeEvaluationCo
return obeEvaluationContentMapper.selectList(queryWrapper);
}
/**
* 捕获重复ID的异常,重新生成UUID并重试插入
* @param templateTableList tableList
* @param attempt 尝试次数
*/
private void dataIntegrityViolationHandle(List<ObeTemplateTable> templateTableList, int attempt) throws RuntimeException{
if (attempt > 3) {
// 如果重试次数超过3次,抛出异常或其他处理方式
throw new RuntimeException("Failed to insert data after multiple attempts");
}
try{
int inserted = obeTemplateTableMapper.insertByBatch(templateTableList);
ExceptionUtil.equal(inserted, templateTableList.size());
}catch (DataIntegrityViolationException ex){
// 捕获重复ID的异常,重新生成UUID并重试插入
for (ObeTemplateTable data : templateTableList) {
data.setId(UuidUtils.getUUID());
}
dataIntegrityViolationHandle(templateTableList, attempt + 1);
}
}
/**
* @param structDateInfo
* @Description: 保存结构化信息数据
......@@ -187,7 +206,7 @@ public class ObeEvaluationContentServiceImpl extends ServiceImpl<ObeEvaluationCo
public boolean saveStructDateInfo(StructDateInfo structDateInfo) {
List<ObeTemplateTable> templateTableList = structDateInfo.getTemplateTableList();
if (CollectionUtils.isNotNull(templateTableList))
ExceptionUtil.equal(obeTemplateTableMapper.insertByBatch(templateTableList), templateTableList.size());
dataIntegrityViolationHandle(templateTableList, 1);
List<ObeModelData> modelDataList = structDateInfo.getModelDataList();
if (CollectionUtils.isNotNull(modelDataList))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment