package com.jkcredit.invoice.util;


/**
 * @description:
 * @author: sunzhaoning
 * @create: 2019-05-30 16:32
 * @version: V1.0
 **/
public class ReadExcelUtil {


    /*public static <T> List<T> readExcel(MultipartFile file,Class<?> clazz){
        //将本地文件上传到服务器/static/upload/excel
        String filePath = null;
        try {
            filePath = FileHandleUtil.upload(file.getInputStream(), "excel/", file.getOriginalFilename());
        } catch (IOException e) {
            e.printStackTrace();
        }
        //设置读取格式
        ImportParams params = new ImportParams();
        params.setTitleRows(1);
        params.setHeadRows(1);
        params.setKeyIndex(1);
        //读取文件  path.getAbsolutePath()获取当前服务器路径
        List<T> list = ExcelImportUtil.importExcel(
                new File(CommonConstants.BASE_PATH +"/static"+filePath),
                clazz , params);
        //删除文件
        FileHandleUtil.delete(filePath);
        return list;
    }

    public static <T> List<T> readNumExcel(MultipartFile file,Class<?> clazz){
        //将本地文件上传到服务器/static/upload/excel
        String filePath = null;
        try {
            filePath = FileHandleUtil.upload(file.getInputStream(), "excel/", file.getOriginalFilename());
        } catch (IOException e) {
            e.printStackTrace();
        }
        //设置读取格式
        ImportParams params = new ImportParams();
        params.setTitleRows(1);
        params.setHeadRows(1);
        //读取文件  path.getAbsolutePath()获取当前服务器路径
        List<T> list = ExcelImportUtil.importExcel(
                new File(CommonConstants.BASE_PATH +"/static"+filePath),
                clazz , params);
        //删除文件
        FileHandleUtil.delete(filePath);
        return list;
    }

    public static <T> List<T> readBillExcel(MultipartFile file,Class<?> clazz) throws Exception{
        ImportParams params = new ImportParams();
        params.setTitleRows(0);
        params.setHeadRows(1);
        InputStream inputStream = file.getInputStream();
        List<T> list = ExcelImportUtil.importExcel(inputStream, clazz, params);
        return list;
    }

    public static Long bigDecimalToLong(BigDecimal fee){
        return fee.multiply(new BigDecimal(100)).setScale(2,BigDecimal.ROUND_HALF_UP).longValue();
    }

    public static BigDecimal longToBigDecimal(Long fee){
        return new BigDecimal(fee).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
    }

    public static void main(String[] args) {
        System.out.println(bigDecimalToLong(new BigDecimal(123)));
        System.out.println(longToBigDecimal(1011L));
    }

    public static <T> List<T> readTempExcel(MultipartFile file,Class<?> clazz){
        //将本地文件上传到服务器/static/upload/excel
        String filePath = null;
        try {
            filePath = FileHandleUtil.upload(file.getInputStream(), "excel/", file.getOriginalFilename());
        } catch (IOException e) {
            e.printStackTrace();
        }
        //设置读取格式
        ImportParams params = new ImportParams();
        //读取文件  path.getAbsolutePath()获取当前服务器路径
        List<T> list = ExcelImportUtil.importExcel(
                new File(CommonConstants.BASE_PATH +"/static"+filePath),
                clazz , params);
        //删除文件
        FileHandleUtil.delete(filePath);
        return list;
    }*/
}
