package com.bluefire.top.util;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.bluefire.top.entity.ExcelMode;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @classname: ExcelModelListener
 * @description TODO
 * @author: liu liu
 * @create: 2020-07-15 15:30
 */
@Slf4j
public class ExcelModelListener extends AnalysisEventListener<ExcelMode> {


    private static final int BATCH_COUNT = 1000;
    List<ExcelMode> list = new ArrayList<ExcelMode>();


    List<String> result=new ArrayList<>();
    private int count=10;
    @Override
    public void invoke(ExcelMode data, AnalysisContext analysisContext) {

        result.add(data.getColumn1());
        list.add(data);
        count ++;
        if (list.size() >= BATCH_COUNT) {

            list.clear();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
      log.info("所有数据解析完成");
    }


    public   List<String> resultData(){
        return result;
    }

}
