java for循环批次处理

for (int from = 0, to = 0, size = orderList.size(); from < size; from = to) {
    to = Math.min(from + query.getBatchSize(), size);
    List<Order> pageList = orderList.subList(from, to);
    for (Order order : pageList) {
        TradeBillSyncSpec tradeBillSyncSpec = setTradeBillSyncSpec.apply(partnerMap, order);
        tradeBillSyncSpecList.add(tradeBillSyncSpec);
        // 返回操作结果
        DealToMiddleGroundUpgradeOrderVo upgradeDataVO = setDealToMiddleGroundUpgradeOrderVo(order);
        upgradeDataVOList.add(upgradeDataVO);
    }
    try {
        //事务内更新
        transactionTemplate.executeWithoutResult(transactionStatus -> {
            tradeBillBatchSync(pageList, tradeBillSyncSpecList, needUpdate);
        });
    } catch (Exception e) {
        log.error("commonDealToMiddleGround 异常:{}", e);
    }
}

 

posted @ 2022-03-03 17:37  八英里  阅读(440)  评论(0编辑  收藏  举报