package com.jeeplus.test.utils.excel;

import com.alibaba.excel.EasyExcel;
import com.jeeplus.core.excel.EasyExcelUtils;
import com.jeeplus.test.wdt.merchantCompany.service.MerchantCompanyService;
import com.jeeplus.test.wdt.merchantCompany.service.dto.MerchantCompanyDTO;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.MerchantCompanyWrapper;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

public class MerchantCompanyEasyExcel extends EasyExcelUtils <MerchantCompanyDTO> {

    public static MerchantCompanyEasyExcel newInstance() {
        return new MerchantCompanyEasyExcel( );
    }

    public static MerchantCompanyEasyExcel newInstance(MerchantCompanyService service, MerchantCompanyWrapper wrapper) {
        return new MerchantCompanyEasyExcel( service, wrapper );
    }

    public MerchantCompanyEasyExcel() {
        super ( );
    }

    public MerchantCompanyEasyExcel(MerchantCompanyService service, MerchantCompanyWrapper wrapper) {
        super ( service, wrapper );
    }


    /**
     * 功能描述：根据接收的Excel文件来导入Excel,并封装成实体类
     *
     * @param file      上传的文件
     * @param pojoClass Excel实体类
     * @return
     * @author Steel.D
     * @Date 2019-7-31 11:30
     */

    public String importExcel(MultipartFile file, Class <MerchantCompanyDTO> pojoClass) throws IOException {
        if ( file == null ) {
            return "上传文件不能为空!";
        }
        MerchantCompanyExcelListener merchantCompanyExcelListener = new MerchantCompanyExcelListener ( this.getService ( ), this.getWrapper ( ) );
        EasyExcel.read ( file.getInputStream ( ), pojoClass, merchantCompanyExcelListener ).sheet ( ).doRead ( );
        return merchantCompanyExcelListener.getMessage ( );

    }

}
