EmpUtils 新增根据机构类型获取机构数据方法

This commit is contained in:
thinkgem
2019-10-31 20:34:56 +08:00
parent 6ec4bd8e5a
commit b2a062a93e
4 changed files with 106 additions and 47 deletions

View File

@@ -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)){

View File

@@ -181,9 +181,9 @@ role:
Office: {
#控制类型的类名 : "用来获取控制表名和主键字段名,如果为 NONE则代表是不控制该类型权限",
ctrlTypeClass: "com.jeesite.modules.sys.entity.Office",
#控制数据的类名: "指定一个静态类名,方便 ctrlDataAttrName 得到权限数据,如:当前部门编码、公司编码",
#控制数据的类名: "指定一个静态类名,方便 ctrlDataAttrName 得到权限数据,如:当前机构编码、当前公司编码、当前行业编码等",
ctrlDataClass: "com.jeesite.modules.sys.utils.EmpUtils",
#控制数据的类名下的属性名 : "可看做下的 get 方法EmpUtils.getOffices(),支持返回字符串或字符串数组类型",
#控制数据的类名下的属性名 : "可看做 ctrlDataClass 下的 get 方法EmpUtils.getOfficeCodes(),支持返回字符串或字符串数组类型",
ctrlDataAttrName: "officeCodes",
#控制数据的所有上级编码 : "用于控制数据为树表的情况,为数组时,必须与 ctrlDataAttrName 返回的长度相同,不是树表设置为空",
ctrlDataParentCodesAttrName: "officeParentCodess"

View File

@@ -68,7 +68,7 @@
模板名称=Template name
归属模块=Module
模板内容=Template content
模板内容语法格式=Template content syntax format
语法格式=Content syntax format
# =========== 消息相关字典 ===========