
package com.lideeyunji.tool.framework.excel;

import com.lideeyunji.tool.framework.excel.model.ExcelTitleModel;
import com.lideeyunji.tool.framework.excel.model.MoreSheetConfig;
import com.lideeyunji.tool.framework.excel.read.ExcelImportUtils;
import com.lideeyunji.tool.framework.excel.write.ExcelExportUtils;
import org.apache.commons.collections4.map.LinkedMap;

import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class lideeYunJiExcelUtils {


    /**
     * 导出 Excel-单个 sheet
     * @param response
     * @param sheetName
     * @param headMap
     * @param dataList
     */
    public static void exportExcel(HttpServletResponse response, String sheetName, LinkedMap<String, ExcelTitleModel> headMap, List<Map<String, Object>> dataList) {
        MoreSheetConfig moreSheetConfig=new MoreSheetConfig();
        moreSheetConfig.setSheetName(sheetName);
        moreSheetConfig.setHeadMap(headMap);
        moreSheetConfig.setDataList(dataList);

        List<MoreSheetConfig> sheetConfigList=new ArrayList<>();
        sheetConfigList.add(moreSheetConfig);
        ExcelExportUtils.exportExcel(response,sheetName,sheetConfigList);
    }

    /**
     * 多个 sheet
     * @param response
     * @param sheetName
     */
    public static void exportExcel(HttpServletResponse response, String sheetName, List<MoreSheetConfig> sheetConfigList) {
        ExcelExportUtils.exportExcel(response,sheetName,sheetConfigList);
    }

    /**
     * 导入Excel
     * @param inputStream
     * @param headerCou 表头所在的行数
     * @return
     */
    public static List<Map<String, Object>> importExcel(InputStream inputStream, Integer headerCou, Map<String, String> fieldNameAndCodeMap){
        return ExcelImportUtils.importExcel(inputStream,headerCou,fieldNameAndCodeMap);
    }

    /**
     * 导入Excel
     * @param inputStream
     * @param headerCou 表头所在的行数
     * @return
     */
    public static List<Map<String, Object>> importExcel(InputStream inputStream, Integer headerCou,Integer sheet, Map<String, String> fieldNameAndCodeMap){
        return ExcelImportUtils.importExcel(inputStream,headerCou,fieldNameAndCodeMap,sheet);
    }
}