管道基础大数据平台系统开发-【后端】-Server
13693261870
2022-11-21 dfa4fd206b390a3afee9769fe1953b692a1eac9a
src/main/java/com/lf/server/helper/PathHelper.java
@@ -65,7 +65,7 @@
            }
            File[] files = file.listFiles();
            if (files.length < SettingData.MAX_FILES) {
            if (null == files || files.length < SettingData.MAX_FILES) {
                return subPath;
            }
@@ -105,18 +105,14 @@
     */
    public String getTempPath() {
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String tempPath = config.getTempPath();
        String path = tempPath + File.separator + tempName;
        String path = config.getTempPath() + File.separator + tempName;
        File file = new File(path);
        if (!file.exists() && !file.isDirectory()) {
            file.mkdirs();
        }
        double ran = Math.random() * 99;
        if (ran > D90) {
            deleteOldPath(tempPath);
        }
        deleteOldPath(config.getTempPath());
        return path;
    }
@@ -134,7 +130,26 @@
            }
        }
        deleteOldPath(config.getTempPath());
        return getTempPath();
    }
    /**
     * 获取临时路径名称
     */
    public String getTempPathName() {
        String tempName = StringHelper.YMDHMS2_FORMAT.format(new Date());
        String path = config.getTempPath() + File.separator + tempName;
        File file = new File(path);
        if (!file.exists() && !file.isDirectory()) {
            file.mkdirs();
        }
        deleteOldPath(config.getTempPath());
        return tempName;
    }
    /**
@@ -142,12 +157,17 @@
     */
    public void deleteOldPath(String tempPath) {
        try {
            double ran = Math.random() * 99;
            if (ran < D90) {
                return;
            }
            File file = new File(tempPath);
            String str = StringHelper.YMD__FORMAT.format(new Date());
            File[] files = file.listFiles();
            for (File f : files) {
                if (f.getPath().indexOf(str) > -1) {
                if (f.getPath().contains(str)) {
                    continue;
                }