package com.zcxk.rmcp.web.excel.download.adapter;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.zcxk.rmcp.web.excel.download.AbstractDownloadExcelAdapter;

import java.io.InputStream;

/**
 * @author linqingwei
 * @date 2021-07-27 17:00
 */
public class InstallMeterExcelFillAdapter extends AbstractDownloadExcelAdapter {
    @Override
    public AbstractDownloadExcelAdapter fillData() {
        data.setTemplatePath("excel/installMeterTemplate.xlsx");

        InputStream in = this.getClass().getClassLoader().getResourceAsStream(data.getTemplatePath());
        ExcelWriter excelWriter = EasyExcel.write(data.getFilePath()).withTemplate(in).build();

        //填充设备数据
        WriteSheet deviceSheet = EasyExcel.writerSheet("安装计划").build();
        excelWriter.fill(data.getInstallMeterDataList(), deviceSheet);

        // 千万别忘记关闭流
        excelWriter.finish();
        return this;
    }
}
