@@ -24,7 +24,7 @@ import com.jeesite.modules.sys.service.OfficeService;
*/
public class EmpUtils {
// 部门 和公司缓存常量
// 机构 和公司缓存常量
public static final String CACHE_OFFICE_ALL_LIST = " officeAllList " ;
public static final String CACHE_COMPANY_ALL_LIST = " companyAllList " ;
public static final String CACHE_COMPANY_OFFICE_LIST = " employeeOfficeList " ;
@@ -91,7 +91,8 @@ public class EmpUtils {
}
/**
* 获取当前附属部门 对象列表
* 获取当前附属机构 对象列表
* @author ThinkGem
*/
public static List < EmployeeOffice > getEmployeeOfficeList ( ) {
List < EmployeeOffice > list = UserUtils . getCache ( CACHE_COMPANY_OFFICE_LIST ) ;
@@ -103,37 +104,9 @@ public class EmpUtils {
}
/**
* 获取所有部门编码,包括附属部门(数据权限用)
* @return
* @author ThinkGem
*/
public static String [ ] getOfficeCodes ( ) {
List < String > list = ListUtils . newArrayList ( ) ;
list . add ( getOffice ( ) . getOfficeCode ( ) ) ;
getEmployeeOfficeList ( ) . forEach ( e - > {
list . add ( e . getOfficeCode ( ) ) ;
} ) ;
return list . toArray ( new String [ list . size ( ) ] ) ;
}
/**
* 获取所有部门编码,包括附属部门(数据权限用)
* @return
* @author ThinkGem
*/
public static String [ ] getOfficeParentCodess ( ) {
List < String > list = ListUtils . newArrayList ( ) ;
list . add ( getOffice ( ) . getParentCodes ( ) ) ;
getEmployeeOfficeList ( ) . forEach ( e - > {
list . add ( e . getParentCodes ( ) ) ;
} ) ;
return list . toArray ( new String [ list . size ( ) ] ) ;
}
/**
* 获取部门对象
* 根据机构编码获取机构对象
* @param officeCode
* @return
* @author ThinkGem
*/
public static Office getOffice ( String officeCode ) {
List < Office > officeList = getOfficeAllList ( ) ;
@@ -146,15 +119,16 @@ public class EmpUtils {
}
/**
* 获取当前员工附属部门
* 获取当前员工机构
* @author ThinkGem
*/
public static Office getOffice ( ) {
return getEmployee ( ) . getOffice ( ) ;
}
/**
* 获取所有的机构
* @return
* 获取当前员工 所有的机构
* @author ThinkGem
*/
public static List < Office > getOfficeAllList ( ) {
@SuppressWarnings ( " unchecked " )
@@ -169,16 +143,93 @@ public class EmpUtils {
}
/**
* 获取当前公司对象
* 获取当前员工所有机构编码,包括附属机构(数据权限用)
* @author ThinkGem
*/
public static Company getCompany ( ) {
return getEmployee ( ) . getCompany ( ) ;
public static String [ ] getOfficeCodes ( ) {
List < String > list = ListUtils . newArrayList ( ) ;
list . add ( getOffice ( ) . getOfficeCode ( ) ) ;
getEmployeeOfficeList ( ) . forEach ( e - > {
list . add ( e . getOfficeCode ( ) ) ;
} ) ;
return list . toArray ( new String [ list . size ( ) ] ) ;
}
/**
* 获取公司对象
* 根据机构类型,获取当前员工所有机构编码,包括附属机构(数据权限用)
* @author ThinkGem
*/
public static String [ ] getOfficeCodesByType ( String type ) {
List < String > list = ListUtils . newArrayList ( ) ;
Office office = getOffice ( ) ;
if ( type . equals ( office . getOfficeType ( ) ) ) {
list . add ( office . getOfficeCode ( ) ) ;
} else {
Office parent = getOffice ( ) . getParentByType ( type ) ;
if ( parent ! = null ) {
list . add ( parent . getOfficeCode ( ) ) ;
}
}
getEmployeeOfficeList ( ) . forEach ( e - > {
Office office2 = getOffice ( e . getOfficeCode ( ) ) ;
if ( type . equals ( office2 . getOfficeType ( ) ) ) {
list . add ( office2 . getOfficeCode ( ) ) ;
} else {
Office parent2 = office2 . getParentByType ( type ) ;
if ( parent2 ! = null ) {
list . add ( parent2 . getOfficeCode ( ) ) ;
}
}
} ) ;
return list . toArray ( new String [ list . size ( ) ] ) ;
}
/**
* 获取当前员工所有上级机构编码,包括附属机构(数据权限用)
* @author ThinkGem
*/
public static String [ ] getOfficeParentCodess ( ) {
List < String > list = ListUtils . newArrayList ( ) ;
list . add ( getOffice ( ) . getParentCodes ( ) ) ;
getEmployeeOfficeList ( ) . forEach ( e - > {
list . add ( e . getParentCodes ( ) ) ;
} ) ;
return list . toArray ( new String [ list . size ( ) ] ) ;
}
/**
* 根据机构类型,获取当前员工所有机构编码,包括附属机构(数据权限用)
* @author ThinkGem
*/
public static String [ ] getOfficeParentCodessByType ( String type ) {
List < String > list = ListUtils . newArrayList ( ) ;
Office office = getOffice ( ) ;
if ( type . equals ( office . getOfficeType ( ) ) ) {
list . add ( office . getParentCodes ( ) ) ;
} else {
Office parent = getOffice ( ) . getParentByType ( type ) ;
if ( parent ! = null ) {
list . add ( parent . getParentCodes ( ) ) ;
}
}
getEmployeeOfficeList ( ) . forEach ( e - > {
Office office2 = getOffice ( e . getOfficeCode ( ) ) ;
if ( type . equals ( office2 . getOfficeType ( ) ) ) {
list . add ( office2 . getParentCodes ( ) ) ;
} else {
Office parent2 = office2 . getParentByType ( type ) ;
if ( parent2 ! = null ) {
list . add ( parent2 . getParentCodes ( ) ) ;
}
}
} ) ;
return list . toArray ( new String [ list . size ( ) ] ) ;
}
/**
* 根据公司编码获取公司对象
* @param companyCode
* @return
* @author ThinkGem
*/
public static Company getCompany ( String companyCode ) {
List < Company > companyList = getCompanyAllList ( ) ;
@@ -191,8 +242,16 @@ public class EmpUtils {
}
/**
* 获取所有的公司
* @return
* 获取当前员工公司对象
* @author ThinkGem
*/
public static Company getCompany ( ) {
return getEmployee ( ) . getCompany ( ) ;
}
/**
* 获取当前员工所有的公司
* @author ThinkGem
*/
public static List < Company > getCompanyAllList ( ) {
@SuppressWarnings ( " unchecked " )
@@ -208,7 +267,7 @@ public class EmpUtils {
/**
* 清除指定用户缓存, 不包括改用的SESSION缓存
* @param user
* @author ThinkGem
*/
public static void removeCache ( String key ) {
if ( StringUtils . inString ( key , CACHE_OFFICE_ALL_LIST , CACHE_COMPANY_ALL_LIST ) ) {