liuxiaolong
2019-05-06 71af9c46c24b562acc00a71ec6c97c04eb048d9c
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package com.cloud.common.utils;
 
import com.cloud.common.constants.GlobalDict;
import com.cloud.model.sys.GloDict;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
 
/**
 * 机构类型工具类
 * @author lp
 * @date 2018-08-05
 */
public class OrgTypeUtil {
    /**
     * 处理业务
     */
    public static final String BUSINESS_TYPE = "1";
 
    /**
     * 不处理业务
     */
    public static final String NO_BUSINESS_TYPE = "0";
 
    /**
     * 组织机构节点最大值,目前为学校
     */
    public static final Integer ORG_MAX_INDEX = 500;
 
    /**
     * 组织机构下部门类型最大值
     */
    public static final Integer SCHOOL_MAX_INDEX = 900;
 
    /**
     * 获得所有组织机构的类型的value
     * @return List String
     */
    public static List<String> getAllOrgValues() {
        List<GloDict> all = getBusinessOrgType();
        List<String> orgValues = new ArrayList<String>();
        for (GloDict dict : all) {
            orgValues.add(dict.getValue());
        }
        return orgValues;
    }
 
    /**
     * 查询所有处理业务的类型
     * @return
     */
    public static List<GloDict> getBusinessType() {
        return getByParams(null, null, false, true);
    }
 
    /**
     * 查询所有处理业务的机构
     * @return
     */
    public static List<GloDict> getBusinessOrgType() {
        return getByParams(null, null, true, true);
    }
 
    /**
     * 根据Key得到组织机构对象
     *
     * @param key
     */
    public static GloDict getByKey(String key) {
        return GlobalDict.ORG_TYPE_MAP.get(key);
    }
 
    /**
     * 根据Value 得到对象
     * @param value
     * @return
     */
    public static GloDict getByValue(String value) {
        for (Map.Entry<String, GloDict> entry : GlobalDict.ORG_TYPE_MAP.entrySet()) {
            GloDict dict = entry.getValue();
            if (dict.getValue().equals(value)) {
                return dict;
            }
        }
        return null;
    }
 
    /**
     * 得到所有的公司类型,总部,分部
     * @return
     */
    public static List<GloDict> getAllCompanylType() {
        List<GloDict> schools = new ArrayList<GloDict>();
        schools.add(getByKey(GlobalDict.ROOT_SCHOOL));
        schools.add(getByKey(GlobalDict.SCHOOL));
        return schools;
    }
 
    /**
     * 得到所有公司类型的String数组
     * @return String[]
     */
    public static String[] getAllChoolValuesArray() {
        List<GloDict> schools = getAllCompanylType();
        String[] result = new String[schools.size()];
        for (int i = 0; i < schools.size(); i++) {
            result[i] = schools.get(i).getValue();
        }
        return result;
    }
 
    /**
     * 判断某个机构是否属于业务处理
     * @param dict
     * @return
     */
    public static boolean isBusiness(GloDict dict) {
        return BUSINESS_TYPE.equals(dict.getScope());
    }
 
    /**
     * 判断某个字典是否是组织机构
     * @param dict
     * @return
     */
    public static boolean isCompany(GloDict dict) {
        if (dict == null || dict.getValue() == null) {
            return false;
        }
        return Integer.parseInt(dict.getValue()) <= ORG_MAX_INDEX ;
    }
 
    /**
     * 获得最大的组织机构类型值
     */
    public static Integer maxOrgValue() {
        return ORG_MAX_INDEX;
    }
 
    /**
     * 组织机构下部门类型最大值
     */
    public static Integer maxSchoolValue() {
        return SCHOOL_MAX_INDEX;
    }
 
 
    /**
     * 获得所有业务相关的机构
     *
     * @author lp
     * @param currentOfiicesType 范围内的机构权限 ,所有小于该范围,并且和业务相关的机构类型
     * @param compareFlag 操作符,SystemConstans常量中获取
     * @param isOnlyOrg 是否只查机构
     * @param isOnlyBusiness 是否查询处理业务的组织机构 true 是 ; false 否 return
     */
    public static List<GloDict> getByParams(Integer currentOfiicesType, String compareFlag,
                                     boolean isOnlyOrg, boolean isOnlyBusiness) {
        List<GloDict> result = new ArrayList<GloDict>();
        for (Map.Entry<String, GloDict> entry : GlobalDict.ORG_TYPE_MAP.entrySet()) {
            GloDict dict = entry.getValue();
            if (isOnlyBusiness) {
                if (BUSINESS_TYPE.equals(dict.getScope())) {
                    byOrgTypeProcess(currentOfiicesType, compareFlag, isOnlyOrg, result, dict);
                }
            } else {
                byOrgTypeProcess(currentOfiicesType, compareFlag, isOnlyOrg, result, dict);
            }
        }
 
        return result;
    }
 
    /**
     * 根据传入的机构类型 value 对返回值进行处理
     *
     * @param currentOrgType 传入的officeType
     * @param compareFlag 比较符号
     * @param isOnlyOrg 是否只查机构
     * @param result 接入的返回值
     * @param dict 字典对象
     */
    private static void byOrgTypeProcess(Integer currentOrgType, String compareFlag,
                                         boolean isOnlyOrg, List<GloDict> result, GloDict dict) {
        // 当currentOfiicesType 有值得时候,根据比较符号进行筛选
        if (currentOrgType != null) {
            switch (compareFlag) {
                case GlobalDict.GT:
                    if (Integer.parseInt(dict.getValue()) > currentOrgType) {
                        isOnlyOrgProcess(isOnlyOrg, result, dict);
                    }
                    break;
                case GlobalDict.LT:
                    if (Integer.parseInt(dict.getValue()) < currentOrgType) {
                        isOnlyOrgProcess(isOnlyOrg, result, dict);
                    }
                    break;
                case GlobalDict.EQ:
                    if (Integer.parseInt(dict.getValue()) == currentOrgType) {
                        isOnlyOrgProcess(isOnlyOrg, result, dict);
                    }
                    break;
                case GlobalDict.GT_EQ:
                    if (Integer.parseInt(dict.getValue()) >= currentOrgType) {
                        isOnlyOrgProcess(isOnlyOrg, result, dict);
                    }
                    break;
                case GlobalDict.LT_EQ:
                    if (Integer.parseInt(dict.getValue()) <= currentOrgType) {
                        isOnlyOrgProcess(isOnlyOrg, result, dict);
                    }
                    break;
                default:
                    throw new RuntimeException("获取机构类型,参数 compare_flag 传参 错误!");
 
            }
        } else {
            isOnlyOrgProcess(isOnlyOrg, result, dict);
        }
    }
 
    /**
     * 对是否只 获取到 组织机构 进行处理
     *
     * @param isOnlyOrg 是否只查询组织机构
     * @param result 返回值对象
     * @param dict 字典对象
     */
    private static void isOnlyOrgProcess(boolean isOnlyOrg, List<GloDict> result, GloDict dict) {
        if (isOnlyOrg) {
            if (Integer.parseInt(dict.getValue()) <= ORG_MAX_INDEX) {
                result.add(dict);
            }
        } else {
            result.add(dict);
        }
    }
 
    /**
     * 查询所有的机构类型的value,返货List数组
     *
     * @return List Integer
     */
    public static List<Integer> getOrgTreeValues() {
        List<Integer> result = new ArrayList<Integer>();
        for (Map.Entry<String, GloDict> entry : GlobalDict.ORG_TYPE_MAP.entrySet()) {
            GloDict dict = entry.getValue();
            if (Integer.parseInt(dict.getValue()) <= maxOrgValue()) {
                result.add(Integer.parseInt(dict.getValue()));
            }
        }
        return result;
    }
 
    /**
     * 获取学校所有部门类型,年级班级部门等500-900之间
     */
    public static List<Integer> getSchoolChildTypeValues() {
        List<Integer> result = new ArrayList<Integer>();
        for (Map.Entry<String, GloDict> entry : GlobalDict.ORG_TYPE_MAP.entrySet()) {
            GloDict dict = entry.getValue();
            if (Integer.parseInt(dict.getValue()) > maxOrgValue()
                    && (Integer.parseInt(dict.getValue()) < maxSchoolValue())) {
                result.add(Integer.parseInt(dict.getValue()));
            }
        }
        return result;
    }
 
    /**
     * 获取机构类型,合并学校(总部分部)
     */
    public static List<GloDict> getOrgTypeMergeSchool() {
        List<GloDict> types = getBusinessOrgType();
        List<GloDict> result = new ArrayList<GloDict>();
        for (GloDict d : types) {
            if (d.getLable().equals(GlobalDict.SCHOOL)) {
                d.setDescription(getByKey(GlobalDict.SCHOOL).getValue() + ","
                        + getByKey(GlobalDict.SCHOOL_DISTRICT).getValue());
            } else {
                d.setDescription(d.getValue());
            }
            if (!d.getLable().equals(GlobalDict.SCHOOL_DISTRICT)) {
                result.add(d);
            }
        }
        return result;
    }
}