解决方法:
public class BachUtil {
/**
* 批量保护数量
*/
public static final Integer OPEN_BACH_PROTECT = 996;
/**
* 批次数量
*/
public static final Integer NUMBER_BACH_PROTECT = 996;
/**
* 批量中包含有关联查询,可能因为数据过长出现数据查询的的问题,
* 这里进行分批处理
* @param list
* 需要处理的list
* @param bach
* 批量处理的函数
* @param <T>
* 元素类型
*/
public static <T> void protectBach(List<T> list, Consumer<List<T>> bach){
if (isEmpty(list)){return;}
if (list.size() > OPEN_BACH_PROTECT) {
for (int i = 0; i < list.size(); i += NUMBER_BACH_PROTECT) {
int lastIndex = Math.min(i + NUMBER_BACH_PROTECT, list.size());
bach.accept(list.subList(i, lastIndex));
}
}else