文档拆分-解决一次批量插入太多PacketTooBigException异常

This commit is contained in:
liyawei
2022-10-10 11:45:51 +08:00
parent de9e2701f1
commit 36d3f0c323
3 changed files with 42 additions and 4 deletions
@@ -3754,7 +3754,26 @@ public class FileSplitItemsEOServiceImpl extends ServiceImpl<FileSplitItemsEOMap
@Override
public int insertForeach(List<SarFileSplitItemsEO> messageList) {
return dao.insertForeach(messageList);
// 解决一次批量插入太多 PacketTooBigException 异常
int total = messageList.size();
int count = 0;
int pageSum = 1;
if(total > 100) {
pageSum = total / 100; // 总页数
if ((total % 100) > 0) {
pageSum += 1;
}
}
List<SarFileSplitItemsEO> subList = new ArrayList<>();
for(int i = 0; i < pageSum; i++) {
int j = i*100+100;
if (i == pageSum -1) {
j = total;
}
subList = messageList.subList(i*100, j);
count += dao.insertForeach(subList);
}
return count;
}
/**
@@ -1784,7 +1784,7 @@ public class FileSplitPdfService {
if(StringUtils.isNotBlank(preName)) {
List<String> nowStartList = fileSpiltService.getNewNowStart(preName);
List<String> subList1 = startDigitList.subList(preNameNum, startDigitList.size()-1);
List<String> subList1 = startDigitList.subList(preNameNum, startDigitList.size());
// 后文有一级以下的标题
for (int i = nowStartList.size() - 1; i >= 1; i--) {
int index1 = subList1.indexOf(nowStartList.get(i));
@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@@ -79,8 +80,26 @@ public class SarFileSplitItemsValEOServiceImpl extends ServiceImpl<SarFileSplitI
@Override
public int insertForeach(List<SarFileSplitItemsValEO> itemValList) {
return dao.insertForeach(itemValList);
// 解决一次批量插入太多 PacketTooBigException 异常
int total = itemValList.size();
int count = 0;
int pageSum = 1;
if(total > 100) {
pageSum = total / 100; // 总页数
if ((total % 100) > 0) {
pageSum += 1;
}
}
List<SarFileSplitItemsValEO> subList = new ArrayList<>();
for(int i = 0; i < pageSum; i++) {
int j = i*100+100;
if (i == pageSum -1) {
j = total;
}
subList = itemValList.subList(i*100, j);
count += dao.insertForeach(subList);
}
return count;
}
}