|
@@ -1,14 +1,11 @@
|
|
|
package com.jiayue.ipfcst.spare2.util;
|
|
|
|
|
|
+import com.jiayue.ipfcst.common.data.util.CommonDataUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
-import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.net.URLDecoder;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.LinkOption;
|
|
|
import java.nio.file.Path;
|
|
@@ -25,11 +22,19 @@ import java.util.Date;
|
|
|
* @version 3.0
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-public class FileUtil {
|
|
|
+public class FileUtil extends CommonDataUtil {
|
|
|
|
|
|
- public final static String FILEPATH = FileUtil.getFileUploadPath() + File.separator + "new";
|
|
|
- public final static String BAKPATH = FileUtil.getFileUploadPath() + File.separator + "bak";
|
|
|
- public final static String ERRPATH = FileUtil.getFileUploadPath() + File.separator + "err";
|
|
|
+ private static final String imageFileSuffix = "txt";
|
|
|
+
|
|
|
+ public static <T> String imageFileName(Class<T> clazz) {
|
|
|
+ String name = clazz.getSimpleName() + "." + imageFileSuffix;
|
|
|
+ String full = getImageFilePath() + File.separator + name;
|
|
|
+ File imageFile = new File(full);
|
|
|
+ if (!imageFile.exists()) {
|
|
|
+ log.error("ImageFile : {} dosen`t exist", name);
|
|
|
+ }
|
|
|
+ return name;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 移动本地文件
|
|
@@ -114,129 +119,4 @@ public class FileUtil {
|
|
|
}
|
|
|
return new Date().getTime();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取项目根路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getResourceBasePath() {
|
|
|
- // 获取跟目录
|
|
|
- File path = null;
|
|
|
- try {
|
|
|
- path = new File(ResourceUtils.getURL("classpath:").getPath());
|
|
|
-
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- // nothing to do
|
|
|
- }
|
|
|
- if (path == null || !path.exists()) {
|
|
|
- path = new File("");
|
|
|
- }
|
|
|
-
|
|
|
- String pathStr = path.getAbsolutePath();
|
|
|
- try {
|
|
|
- pathStr = URLDecoder.decode(pathStr, "UTF-8");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- // 如果是在eclipse中运行,则和target同级目录,如果是jar部署到服务器,则默认和jar包同级
|
|
|
-// pathStr = pathStr.replace("\\target\\classes", "");
|
|
|
-
|
|
|
- return pathStr;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取上报文件目录相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getFileUploadPath() {
|
|
|
- return createUploadAllDir("uploadFile");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取下载文件目录相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getDownloadFilePath() {
|
|
|
- return createUploadAllDir("downloadFile");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取日志目录相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getLogsPath() {
|
|
|
- return createUploadAllDir("logs");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取系统脚本相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getBinPath() {
|
|
|
- return createUploadAllDir("bin");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * json数据存储相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getJsonPath() {
|
|
|
- return createUploadAllDir("json");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 存储接入数据
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getDataPath() {
|
|
|
- return createUploadAllDir("data");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private static String createUploadAllDir(String dir) {
|
|
|
- String path = "";
|
|
|
- if (System.getProperties().getProperty("file.separator").equals("\\")) {
|
|
|
- path = new File(getResourceBasePath()).getParentFile().getParentFile().getParentFile().getAbsolutePath() + File.separator + dir;
|
|
|
- } else {
|
|
|
- path = "/home/syjy/ipfcstSingle/" + dir;
|
|
|
- }
|
|
|
- try {
|
|
|
- path = URLDecoder.decode(path, "UTF-8");
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- File file = new File(path);
|
|
|
- if (!file.exists()) {
|
|
|
- boolean b = file.mkdirs();
|
|
|
- if (!b)
|
|
|
- log.error("目录创建失败" + path);
|
|
|
- }
|
|
|
- return path;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取环境数导据出文件目录相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getEnvironmentalDataFile() {
|
|
|
- return createUploadAllDir("environmentalDataFile");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取临时文件目录相对路径
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getTempFilePath() {
|
|
|
- return createUploadAllDir("tempFile");
|
|
|
- }
|
|
|
}
|