package com.bocloud.ims.booter.utils;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExcelReader {

    private static Logger logger = LoggerFactory.getLogger(ExcelReader.class);

    public List<Map<String, String>> getFlavor(InputStream inputStream) {
        try {
            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
            HSSFSheet sheet = workbook.getSheetAt(0);
            List<Map<String, String>> listMap = new ArrayList<>();
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                Map<String, String> map = new HashMap<>();
                HSSFRow row = sheet.getRow(i);
                String name = row.getCell(0).getStringCellValue();
//                String regionId = row.getCell(1).getStringCellValue();
                map.put("name", name);
//                map.put("regionId", regionId);
                listMap.add(map);
            }
            return listMap;
        } catch (IOException e) {
            logger.info("规格信息转换失败" + e.getMessage());
            return null;
        }

    }

//    public static void main(String[] args) {
//        try {
//            File file = new File("D:\\price.xls");
//            InputStream inputStream= new FileInputStream(file);
//            List<AzureResourcePrice> prices = getPrices(inputStream);
//            System.out.println("args = [" + args + "]");
//
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
//    }

}
