✨ 新增金蝶付款结果定时回写任务(A103-2/A103-4)并抽取BFI分页通用翻页工具
This commit is contained in:
Vendored
+60
@@ -26,10 +26,15 @@
|
||||
package org.springblade.thirdparty.bfi.util;
|
||||
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.thirdparty.bfi.pojo.dto.BfiBaseDTO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiPageVO;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
/**
|
||||
* 业财融合(BFI)接口通用参数工具类
|
||||
@@ -46,6 +51,11 @@ public class BfiUtil {
|
||||
*/
|
||||
public static final String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
/**
|
||||
* 分页查询默认最大页数保护,防止金蝶侧 lastPage 异常时死循环
|
||||
*/
|
||||
public static final int DEFAULT_MAX_PAGES = 50;
|
||||
|
||||
private BfiUtil() {
|
||||
}
|
||||
|
||||
@@ -79,4 +89,54 @@ public class BfiUtil {
|
||||
param.setTimestamp(timestamp());
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* BFI 分页查询通用翻页,自动翻页汇总全量数据行(默认最大页数保护)
|
||||
* <p>
|
||||
* 适用所有返回 {@link BfiPageVO} 的查询接口
|
||||
* (A103-2 付款申请单查询、A103-4 付款处理查询、A102-4 财务应付单查询、A902-1 客户查询等):
|
||||
* <pre>{@code
|
||||
* List<BfiPayApplyVO> rows = BfiUtil.queryAllPages(pageNo -> {
|
||||
* param.setPageNo(pageNo);
|
||||
* param.setPageSize(pageSize);
|
||||
* return bfiService.queryPayApply(param);
|
||||
* });
|
||||
* }</pre>
|
||||
*
|
||||
* @param pageFetcher 页码 -> 分页结果,lambda 内负责设置页码(必要时含页大小)并调用接口
|
||||
* @param <T> 数据行类型
|
||||
* @return 全量数据行
|
||||
*/
|
||||
public static <T> List<T> queryAllPages(IntFunction<BfiPageVO<T>> pageFetcher) {
|
||||
return queryAllPages(pageFetcher, DEFAULT_MAX_PAGES);
|
||||
}
|
||||
|
||||
/**
|
||||
* BFI 分页查询通用翻页,自动翻页汇总全量数据行
|
||||
* <p>
|
||||
* 终止条件:返回页为空、数据行为空、lastPage=true、数据行不满一页(按返回 pageSize 判断)、超出最大页数保护
|
||||
*
|
||||
* @param pageFetcher 页码 -> 分页结果,lambda 内负责设置页码(必要时含页大小)并调用接口
|
||||
* @param maxPages 最大页数保护
|
||||
* @param <T> 数据行类型
|
||||
* @return 全量数据行
|
||||
*/
|
||||
public static <T> List<T> queryAllPages(IntFunction<BfiPageVO<T>> pageFetcher, int maxPages) {
|
||||
List<T> rows = new ArrayList<>();
|
||||
for (int pageNo = 1; pageNo <= maxPages; pageNo++) {
|
||||
BfiPageVO<T> page = pageFetcher.apply(pageNo);
|
||||
if (page == null || Func.isEmpty(page.getRows())) {
|
||||
break;
|
||||
}
|
||||
rows.addAll(page.getRows());
|
||||
if (Boolean.TRUE.equals(page.getLastPage())) {
|
||||
break;
|
||||
}
|
||||
// 末页数据不满一页时无需继续翻页(pageSize 取返回值,返回为空时依赖 lastPage 与最大页数保护)
|
||||
if (page.getPageSize() != null && page.getRows().size() < page.getPageSize()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user