feat: 修改PageUtil
This commit is contained in:
parent
7b9814c909
commit
d91c1e5178
@ -0,0 +1,43 @@
|
||||
package cn.axzo.foundation.util;
|
||||
|
||||
import cn.axzo.foundation.page.IPageReq;
|
||||
import cn.axzo.foundation.page.PageResp;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class PageUtils {
|
||||
|
||||
/**
|
||||
* 将所有的数据通过page接口写入到list. 并返回
|
||||
* function中需要参数为新的pageNum, 默认从第一页开始加载. 直到返回的记录行数小于 预期的行数
|
||||
*/
|
||||
public static <T> List<T> drainAll(Function<Integer, PageResp<T>> function) {
|
||||
return drainAll(function, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将所有的数据通过page接口写入到list. 并返回
|
||||
* function中需要参数为新的pageNum, 默认从第一页开始加载. 直到返回的记录行数小于 预期的行数
|
||||
* breaker可以自行决定何时中断,允许为空,为空表示会拉取所有
|
||||
*/
|
||||
public static <T> List<T> drainAll(Function<Integer, PageResp<T>> function, Function<List<T>, Boolean> breaker) {
|
||||
List<T> totalData = Lists.newArrayList();
|
||||
int pageNum = IPageReq.DEFAULT_PAGE_NUMBER;
|
||||
while (true) {
|
||||
PageResp<T> result = function.apply(pageNum);
|
||||
totalData.addAll(result.getData());
|
||||
|
||||
if (result.getData().size() < result.getSize()) {
|
||||
break;
|
||||
}
|
||||
if (breaker != null && BooleanUtils.isTrue(breaker.apply(totalData))) {
|
||||
break;
|
||||
}
|
||||
pageNum += 1;
|
||||
}
|
||||
return totalData;
|
||||
}
|
||||
}
|
||||
@ -3,11 +3,10 @@ package cn.axzo.foundation.dao.support.converter;
|
||||
import cn.axzo.foundation.dao.support.mysql.MybatisPlusConverterUtils;
|
||||
import cn.axzo.foundation.page.IPageReq;
|
||||
import cn.axzo.foundation.page.PageResp;
|
||||
import cn.axzo.foundation.util.PageUtils;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -88,7 +87,10 @@ public class PageConverter {
|
||||
/**
|
||||
* 将所有的数据通过page接口写入到list. 并返回
|
||||
* function中需要参数为新的pageNum, 默认从第一页开始加载. 直到返回的记录行数小于 预期的行数
|
||||
*
|
||||
* 建议使用PageUtils.drainAll
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> List<T> drainAll(Function<Integer, PageResp<T>> function) {
|
||||
return drainAll(function, null);
|
||||
}
|
||||
@ -97,24 +99,11 @@ public class PageConverter {
|
||||
* 将所有的数据通过page接口写入到list. 并返回
|
||||
* function中需要参数为新的pageNum, 默认从第一页开始加载. 直到返回的记录行数小于 预期的行数
|
||||
* breaker可以自行决定何时中断,允许为空,为空表示会拉取所有
|
||||
*
|
||||
* 建议使用PageUtils.drainAll
|
||||
*/
|
||||
@Deprecated
|
||||
public static <T> List<T> drainAll(Function<Integer, PageResp<T>> function, Function<List<T>, Boolean> breaker) {
|
||||
List<T> totalData = Lists.newArrayList();
|
||||
int pageNum = IPageReq.DEFAULT_PAGE_NUMBER;
|
||||
while (true) {
|
||||
PageResp<T> result = function.apply(pageNum);
|
||||
totalData.addAll(result.getData());
|
||||
|
||||
if (result.getData().size() < result.getSize()) {
|
||||
break;
|
||||
}
|
||||
if (breaker != null && BooleanUtils.isTrue(breaker.apply(totalData))) {
|
||||
break;
|
||||
}
|
||||
pageNum += 1;
|
||||
}
|
||||
return totalData;
|
||||
return PageUtils.drainAll(function, breaker);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user