liurunyu
2024-04-23 1300e2434cb457e7d4d06ea66d90a04492f6c4e9
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
package com.dy.pmsOther.dyFm;
 
import com.dy.common.util.MurmurHash ;
 
public class RestHashDeal {
    
 
    /**
     * 文件名称计算转换
     * @param fileName
     * @param rvo
     * @return
     * @throws Exception
     */
    public FileRestVo fileTransRest(String fileName, FileRestVo rvo) throws Exception{
        if(fileName != null 
                && !fileName.trim().equals("") 
                && rvo != null){
            if(DyFmListener.dyFileGroup == null 
                    || DyFmListener.dyFileGroup.list == null 
                    || DyFmListener.dyFileGroup.list.size() == 0){
                throw new Exception("严重错误,文件服务器restful未配置!") ;
            }else{
                DyFileSvConf.Vo confVo = null ;
                Integer hash = null ;
                if(DyFmListener.dyFileGroup.list.size() == 1){
                    confVo = DyFmListener.dyFileGroup.list.get(0) ;
                }else{
                    hash = new MurmurHash().hash16_plus(fileName) ;
                    for(DyFileSvConf.Vo lvo : DyFmListener.dyFileGroup.list){
                        if(hash >= lvo.hashStart.intValue() 
                                && hash <= lvo.hashEnd.intValue()){
                            confVo = lvo ;
                            break ;
                        }
                    }
                }
                if(confVo != null){
                    rvo.fileSysId = confVo.id;
                    rvo.fileNameHash = hash;
                    rvo.fileSysAbsolutePath = confVo.fileSysAbsolutePath;
                    rvo.fileSysRelativePath = confVo.fileSysRelativePath;
                    rvo.fileSysRestUrl = confVo.restUrl;
                    rvo.fileWebUrl = confVo.webUrl ;
                    rvo.fileWebDownloadUrl = confVo.webDownloadUrl ;
                }
            }
        }
        return rvo ;
    }
 
    
    /**
     * 哈希值计算转换
     * @param hashcode
     * @param rvo
     * @return
     * @throws Exception
     */
    public FileRestVo fileTransRest(Integer hashcode, FileRestVo rvo) throws Exception{
        if(hashcode != null
                && rvo != null){
            if(DyFmListener.dyFileGroup == null 
                    || DyFmListener.dyFileGroup.list == null 
                    || DyFmListener.dyFileGroup.list.size() == 0){
                throw new Exception("严重错误,文件服务器restful未配置!") ;
            }else{
                DyFileSvConf.Vo confVo = null ;
                Integer hash = hashcode ;
                if(DyFmListener.dyFileGroup.list.size() == 1){
                    confVo = DyFmListener.dyFileGroup.list.get(0) ;
                }else{
                    for(DyFileSvConf.Vo lvo : DyFmListener.dyFileGroup.list){
                        if(hash >= lvo.hashStart.intValue() 
                                && hash <= lvo.hashEnd.intValue()){
                            confVo = lvo ;
                            break ;
                        }
                    }
                }
                if(confVo != null){
                    rvo.fileSysId = confVo.id;
                    rvo.fileNameHash = hash;
                    rvo.fileSysAbsolutePath = confVo.fileSysAbsolutePath;
                    rvo.fileSysRelativePath = confVo.fileSysRelativePath;
                    rvo.fileSysRestUrl = confVo.restUrl;
                    rvo.fileWebUrl = confVo.webUrl ;
                    rvo.fileWebDownloadUrl = confVo.webDownloadUrl ;
                }
            }
        }
        return rvo ;
    }
 
}