liurunyu
2024-10-21 a408f749e77f3c13834770727dc2e1e6aafe062c
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.dy.pipIrrWebFile.fm;
 
import java.util.ArrayList;
import java.util.List;
 
public class DyFileSvConf {
    
    public static class Group{
        public List<Vo> list ;
        public Group(){
            this.list = new ArrayList<Vo>() ;
        }
        public void add(Vo vo)throws Exception{
            if(vo == null){
                throw new Exception("出错,预加入集合Vo为空了!") ;
            }
            if(list.size() > 0){
                for(Vo lvo : list){
                    lvo.checkEqual(vo) ;
                }
                this.list.add(vo) ;
            }else{
                this.list.add(vo) ;
            }
        }
        public void check() throws Exception{
            Integer startV = 0 ;
            doCheck(startV) ;
        }
        private void doCheck(Integer startV) throws Exception{
            boolean find = false ;
            for(Vo vo : list){
                if(vo.hashStart.intValue() == startV.intValue()){
                    startV = vo.hashEnd + 1;
                    find = true ;
                    break ;
                }
            }
            if(!find){
                throw new Exception("严重错误,未发现哈希值为" + startV + "文件服务器!") ;
            }
            if(startV.intValue() <= 65535){
                doCheck(startV) ;
            }
        }
    }
    
    public static class Vo{
        public String id ;//id或名称
        public String fileSysAbsolutePath; //文件名称的哈希值对应的文件最终存储绝对路径中的根目录,在配置文件中配置
        public String fileSysRelativePath; //文件名称的哈希值对应的文件最终存储相对路径的目录,在配置文件中配置
        public String restUrl;//文件系统路径
        public String webUrl ;//下载文档的web路径
        public String webDownloadPath ;//下载文档的Controller的相对路径
        public Integer hashStart ;//哈希值启始值(包含)
        public Integer hashEnd ;//哈希值截止值(包含)
    
        public Vo(){}
        public Vo(String id,
                String fileSysAbsolutePath,
                String fileSysBasePath,
                String restUrl,
                String webUrl,
                String webDownloadPath,
                Integer hashStart,
                Integer hashEnd)throws Exception{
            this.id = id ;
            this.fileSysAbsolutePath = fileSysAbsolutePath ;
            this.fileSysRelativePath = fileSysBasePath ;
            this.restUrl = restUrl ;
            this.webUrl = webUrl ;
            this.webDownloadPath = webDownloadPath ;
            this.hashStart = hashStart ;
            this.hashEnd = hashEnd ;
            if(this.id == null || this.id.trim().equals("")){
                throw new Exception("出错,id为空了!") ;
            }else{
                this.id = this.id.trim() ;
            }
            if(this.fileSysAbsolutePath == null || this.fileSysAbsolutePath.trim().equals("")){
                throw new Exception("出错,fileSysAbsolutePath为空了!") ;
            }else{
                this.fileSysAbsolutePath = this.fileSysAbsolutePath.trim() ;
                this.fileSysAbsolutePath = this.fileSysAbsolutePath.replaceAll("\\\\", "/") ;
                if(!this.fileSysAbsolutePath.endsWith("/")){
                    this.fileSysAbsolutePath = this.fileSysAbsolutePath + "/" ;
                }
            }
            if(this.fileSysRelativePath == null || this.fileSysRelativePath.trim().equals("")){
                throw new Exception("出错,fileSysBasePath为空了!") ;
            }else{
                this.fileSysRelativePath = this.fileSysRelativePath.trim() ;
            }
            if(this.webUrl == null || this.webUrl.trim().equals("")){
                throw new Exception("出错,webUrl为空了!") ;
            }else{
                this.webUrl = this.webUrl.trim() ;
                if(!this.webUrl.endsWith("/") && !this.webUrl.endsWith("\\")){
                    this.webUrl += "/" ;
                }
            }
            if(this.webDownloadPath == null || this.webDownloadPath.trim().equals("")){
                throw new Exception("出错,webDownloadPath!") ;
            }
 
            if(this.hashStart == null){
                throw new Exception("出错,hashStart为空了!") ;
            }else if(this.hashStart.intValue() < 0){
                throw new Exception("出错,hashStart小于0了!") ;
            }else if(this.hashStart.intValue() > 65535){
                throw new Exception("出错,hashStart大于65535了!") ;
            }
            if(this.hashEnd == null){
                throw new Exception("出错,hashEnd为空了!") ;
            }else if(this.hashEnd.intValue() < 0){
                throw new Exception("出错,hashEnd小于0了!") ;
            }else if(this.hashEnd.intValue() > 65535){
                throw new Exception("出错,hashEnd大于65535了!") ;
            }
            if(this.hashEnd < this.hashStart){
                throw new Exception("出错,hashEnd小于hashStart了!") ;
            }
        }
        public String toString(){
            return "id=" + id + "\n" 
                    + "fileSysAbsolutePath=" + fileSysAbsolutePath + "\n"
                    + "fileSysBasePath=" + fileSysRelativePath + "\n"
                    + "restUrl=" + restUrl + "\n"
                    + "webUrl=" + webUrl + "\n" 
                    + "webDownloadPath=" + webDownloadPath + "\n"
                    + "hashStart=" + hashStart + "\n" 
                    + "hashEnd=" + hashEnd ;
        }
 
        
        private boolean checkEqual(Vo vo)throws Exception{
            if(this.id.equalsIgnoreCase(vo.id)){
                throw new Exception("出错,id有重复!") ;
            }
            if(this.hashStart.intValue() == vo.hashStart.intValue()){
                throw new Exception("出错,hashStart有重复!") ;
            }
            if(this.hashEnd.intValue() == vo.hashEnd.intValue()){
                throw new Exception("出错,hashEnd有重复!") ;
            }
            if(this.hashStart.intValue() == vo.hashEnd.intValue()){
                throw new Exception("出错,hashStart与hashEnd有重复!") ;
            }
            if(this.hashEnd.intValue() == vo.hashStart.intValue()){
                throw new Exception("出错,hashEnd与hashStart有重复!") ;
            }
            return true ;
        }
    }
}