package com.lf.server.helper; import com.lf.server.config.PropertiesConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.File; /** * 路径帮助类 * @author WWW */ @Component public class PathHelper { @Autowired private PropertiesConfig config; private static int MAX_FILES = 2000; private static int importPath = 1; private static int exportPath = 1; private static int uploadPath = 1; private static int sharePath = 1; public PropertiesConfig getConfig() { return config; } public static int getImportPath() { return importPath; } public static int getExportPath() { return exportPath; } public static int getUploadPath() { return uploadPath; } public static int getSharePath() { return sharePath; } /** * 初始化 */ public void init() { importPath = getSubPath(config.getImportPath(), importPath); exportPath = getSubPath(config.getExportPath(), exportPath); uploadPath = getSubPath(config.getUploadPath(), uploadPath); sharePath = getSubPath(config.getSharePath(), sharePath); } private static int getSubPath(String parentPath, int subPath) { while (true) { String path = parentPath + File.separator + subPath; File file = new File(path); if (!file.exists() && !file.isDirectory()) { file.mkdirs(); return subPath; } File[] files = file.listFiles(); if (files.length < MAX_FILES) { return subPath; } subPath++; } } /** * 获取导入目录 * * @return */ public String getImportFullPath() { importPath = getSubPath(config.getImportPath(), importPath); return config.getImportPath() + File.separator + importPath; } /** * 获取出图目录 * * @return */ public String getExportFullPath() { exportPath = getSubPath(config.getExportPath(), exportPath); return config.getExportPath() + File.separator + exportPath; } /** * 获取上传目录 * * @return */ public String getUploadFullPath() { uploadPath = getSubPath(config.getUploadPath(), uploadPath); return config.getUploadPath() + File.separator + uploadPath; } /** * 获取共享目录 * * @return */ public String getShareFullPath() { sharePath = getSubPath(config.getSharePath(), sharePath); return config.getSharePath() + File.separator + sharePath; } }