package com.rongwei.sfcommon.sys.service.impl;


import com.rongwei.sfcommon.sys.service.EasyExcelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * easyexcel 导出
 *
 * @author 往事，优雅而已
 * @date 2019-07-27
 */
@Service
public class EasyExcelWriteImpl implements EasyExcelService {
    private static final Logger logger = LoggerFactory.getLogger(EasyExcelWriteImpl.class);


    /**
     * 获取模板、或附件路径
     * <p>
     * type=1 无模板直从项目同目录下fileExport中文件
     * type=2 有模板，直接从本系统模板库下载
     *
     * @param type
     */
    @Override
    public InputStream getFilePath(Integer type, String fileName) {

        InputStream inputStream = null;
        // type=2 有模板，直接从本系统模板库下载
        if (type.equals(2)) {
            inputStream = this.getClass().getResourceAsStream("/fileitem/" + fileName);
            return inputStream;
        }

        // 文件路径
        String classpath;
        try {
            String filePath = ("/fileExport/" + fileName);
            logger.info("filePath:" + filePath);
            inputStream = new FileInputStream(filePath);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return inputStream;
    }


}
