package com.jwipc.shopping.util;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.jwipc.shopping.model.vo.ExcelShopCartVO;

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

/**
 * 功能描述:
 *
 * @Author: zx
 * @Date: 2023/8/14 0014 18:20
 */
public class EasyExcelListener extends AnalysisEventListener<ExcelShopCartVO> {

    List<ExcelShopCartVO> list = new ArrayList<>();

    @Override
    public void invoke(ExcelShopCartVO s, AnalysisContext analysisContext) {

        if (ExcelShopCartVOValidator.validateData(s)) {
            list.add(s);
        } else {
             throw new RuntimeException("请检查商品价格及数量填写是否有误: 数量: "+s.getQty()+" , 价格:"+s.getProductPrice());
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    public List<ExcelShopCartVO> getDatas() {
        return list;
    }

}
