package ink.wgink.service.user.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: UserExcelListener
 * @Description: 用户Excel监听器
 * @Author: WangGeng
 * @Date: 2020/1/6 11:06 下午
 * @Version: 1.0
 **/
public abstract class UserExcelListener extends AnalysisEventListener<UserExcel> {

    private static final Logger LOG = LoggerFactory.getLogger(UserExcelListener.class);
    private List<UserExcel> userExcels = new ArrayList<>(0);

    @Override
    public void invoke(UserExcel userExcel, AnalysisContext analysisContext) {
        userExcels.add(userExcel);
    }

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

    /**
     * 获取用户列表
     *
     * @param userExcels
     */
    public abstract void listUserExcel(List<UserExcel> userExcels) throws Exception;

}
