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;
|
}
|
}
|