管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-08 e7b3a5e891287b1291d2ac38f7c83d5d73bc7906
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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 propertiesConfig;
 
    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 void init() {
        importPath = getSubPath(propertiesConfig.getImportPath(), importPath);
        exportPath = getSubPath(propertiesConfig.getExportPath(), exportPath);
        uploadPath = getSubPath(propertiesConfig.getUploadPath(), uploadPath);
        sharePath = getSubPath(propertiesConfig.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 getImportPath() {
        importPath = getSubPath(propertiesConfig.getImportPath(), importPath);
 
        return propertiesConfig.getImportPath() + File.separator + importPath;
    }
 
    /**
     * 获取出图目录
     *
     * @return
     */
    public String getExportPath() {
        exportPath = getSubPath(propertiesConfig.getExportPath(), exportPath);
 
        return propertiesConfig.getExportPath() + File.separator + exportPath;
    }
 
    /**
     * 获取上传目录
     *
     * @return
     */
    public String getUploadPath() {
        uploadPath = getSubPath(propertiesConfig.getUploadPath(), uploadPath);
 
        return propertiesConfig.getUploadPath() + File.separator + uploadPath;
    }
 
    /**
     * 获取共享目录
     *
     * @return
     */
    public String getSharePath() {
        sharePath = getSubPath(propertiesConfig.getSharePath(), sharePath);
 
        return propertiesConfig.getSharePath() + File.separator + sharePath;
    }
}