wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
package com.vci.client.common;
 
import java.util.LinkedHashMap;
 
 
/**
 * 统一数据状态处类
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author xchao
 * @time 2013-3-19
 * @version 1.0
 */
public class DataStatusUtils {
    private static ThreadLocal<DataStatusUtils> threadLocal = new ThreadLocal<DataStatusUtils>();
    
    public static DataStatusUtils getRMDataStatusUtils(){
        return getDataStatusUtils("rm", "RMIPRm");
    }
    
    public static DataStatusUtils getCodeDataStatusUtils(){
        return getDataStatusUtils("code", "RMIPCode");
    }
 
    private static DataStatusUtils getDataStatusUtils(String type, String il18FileName){
        DataStatusUtils utils = threadLocal.get();
        if(utils == null){
            utils = new DataStatusUtils(type, il18FileName);
            threadLocal.set(utils);
        }
        return utils;
    }
    
    /**
     * 类别,RM\CODE
     */
    private String type = "";
    private String il18nName = "";
    private DataStatusUtils(String type, String il18nName){
        this.type = type;
        this.il18nName = il18nName;
        initStatus();
    }
    
    private Integer[] supportStatus = new Integer[]{};
    // key:状态值 value:状态名称
    private LinkedHashMap<Integer, String> statusToNameMap = new LinkedHashMap<Integer, String>();
    // key:状态名称 value状态值
    private LinkedHashMap<String, Integer> nameToStatusMap = new LinkedHashMap<String, Integer>();
    
    private void initStatus(){
        reInitStatus();
    }
    
    public void reInitStatus(){
        // 从 指定名称的国际化文件取出状态总数
        String[] statuss = ConfigUtils.getI18nString("rmip.code.status.support", il18nName).split(",");
        supportStatus = new Integer[statuss.length];
        for (int i = 0; i < statuss.length; i++) {
            supportStatus[i] = Integer.valueOf(statuss[i]);
        }
        statusToNameMap.clear();
        nameToStatusMap.clear();
        for(int i = 0; i < supportStatus.length; i++){
            Integer status = supportStatus[i];
            // key format e.g
            //rmip.code.status.0
            //rmip.code.status.1
            String key = "rmip." + getType() + ".status." + status;
            String value = ConfigUtils.getI18nString(key, il18nName);
            statusToNameMap.put(status, value);
            nameToStatusMap.put(value, status);
        }
    }
 
    /**
     * 状态值(值范围:getSupportStatus()),返回对应状态的国际化名称
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2013-3-20
     * @param statusValue 状态值
     * @return
     */
    public String getStatusNameByValue(Integer statusValue){
        String res = String.valueOf(statusValue);
        if(statusToNameMap.containsKey(statusValue)){
            res = statusToNameMap.get(statusValue);
        }
        return res;
    }
    /**
     * 根据状态的国际化名称,返回状态值(值范围:getSupportStatus())
     * <p>Description: </p>
     * 
     * @author xchao
     * @time 2013-3-20
     * @param statusName 状态名称
     * @return
     */
    public Integer getStatusValueByName(String statusName){
        Integer res = 0;
        if(nameToStatusMap.containsKey(statusName)){
            res = nameToStatusMap.get(statusName);
        }
        return res;
    }
    
    
    public String getType() {
        return type;
    }
 
    public void setType(String type) {
        this.type = type;
    }
 
    public Integer[] getSupportStatus() {
        return supportStatus;
    }
 
    public void setSupportStatus(Integer[] supportStatus) {
        this.supportStatus = supportStatus;
    }
 
    public LinkedHashMap<Integer, String> getStatusToNameMap() {
        return statusToNameMap;
    }
 
    public void setStatusToNameMap(LinkedHashMap<Integer, String> statusToNameMap) {
        this.statusToNameMap = statusToNameMap;
    }
 
    public LinkedHashMap<String, Integer> getNameToStatusMap() {
        return nameToStatusMap;
    }
 
    public void setNameToStatusMap(LinkedHashMap<String, Integer> nameToStatusMap) {
        this.nameToStatusMap = nameToStatusMap;
    }
 
}