package ink.wgink.service.department.listener.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: DepartmentExcelListener
 * @Description: 部门Excel监听
 * @Author: WangGeng
 * @Date: 2020/4/8 15:13
 * @Version: 1.0
 **/
public abstract class DepartmentExcelListener extends AnalysisEventListener<DepartmentExcel> {

    private static final Logger LOG = LoggerFactory.getLogger(DepartmentExcelListener.class);
    private List<DepartmentExcel> departmentExcels = new ArrayList<>(0);

    @Override
    public void invoke(DepartmentExcel departmentExcel, AnalysisContext analysisContext) {
        departmentExcels.add(departmentExcel);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        try {
            listDepartmentExcel(departmentExcels);
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
        departmentExcels.clear();
    }

    public abstract void listDepartmentExcel(List<DepartmentExcel> departmentExcels) throws Exception;
}
