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;

public class DeviceExcelFillAdapter extends AbstractDownloadExcelAdapter {


    @Override
    public AbstractDownloadExcelAdapter fillData() {
        data.setTemplatePath("excel/deviceTemplate_V2.1.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.getDeviceImportDataList(), deviceSheet);

        //填充产品（设备类型）数据

        WriteSheet productSheet = EasyExcel.writerSheet("设备型号").build();
        excelWriter.fill(data.getProductDataList(), productSheet);

        //填充公司数据
        WriteSheet orgSheet = EasyExcel.writerSheet("公司").build();
        excelWriter.fill(data.getOrgDataList(), orgSheet);

        //填充小区数据
        WriteSheet communitySheet = EasyExcel.writerSheet("小区").build();
        excelWriter.fill(data.getCommunityDataList(), communitySheet);

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





}
