package cn.com.victorysoft.business.util;

import lombok.SneakyThrows;
import org.springframework.util.ResourceUtils;

import java.io.File;

public class PathUtils {
    @SneakyThrows
    public static String getRootPath() {
        String path = ResourceUtils.getURL("classpath:").getPath();
        if(path.startsWith("file:")) {
            path = path.substring(path.indexOf("/"));
        }
        path = path.substring(0, path.lastIndexOf("/"));
        path = path.substring(0, path.lastIndexOf("/"));
        path = path.substring(0, path.lastIndexOf("/"));
        path = path.substring(0, path.lastIndexOf("/"));
        return path;
    }

    /**
     * 获取导出路径
     */
    public static String getExportPath() {
        String rootPath = getRootPath();
        String exportPath = rootPath + "/export";
        File file = new File(exportPath);
        if (!file.exists()) {
            file.mkdir();
        }
        return exportPath;
    }
}
