package cn.iocoder.yudao.module.member.controller.admin.excelImport.vo;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;

import java.util.List;
import java.util.function.Consumer;


/**
 * 读取excel数据
 */
public class RechargeExcelListener extends AnalysisEventListener<RechargeExcel> {

    /**临时存储正常数据集合,最大存储100*/
    private List<RechargeExcel> successDataList = Lists.newArrayListWithExpectedSize(300);

    /**自定义消费者函数接口用于自定义监听器中数据组装*/
    private final Consumer<List<RechargeExcel>> successConsumer;

    public RechargeExcelListener(Consumer<List<RechargeExcel>> successConsumer) {
        this.successConsumer = successConsumer;
    }

    @Override
    public void invoke(RechargeExcel rechargeExcel, AnalysisContext analysisContext) {
        successDataList.add(rechargeExcel);
        System.out.println("数据："+rechargeExcel);
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        if (CollectionUtils.isNotEmpty(successDataList)) {
            successConsumer.accept(successDataList);
        }
    }
}

