package com.changhong.epc.rely.api.tool; import com.changhong.epc.rely.api.bean.Organization; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 组织机构数据处理 * @author liush * */ public class OrgUtil { /** * 格式化组织机构树(去掉user position) * @param list */ public static void organizationFormat(List list) { if(list != null) for(Organization organization:list) { if(organization.getUsers() != null) organization.getUsers().clear(); if(organization.getPositions() != null) organization.getPositions().clear(); organizationFormat(organization.getChildren()); } } /** * 转换数组为集合 * @param strArrays * @return */ public static List getCodeList(String[] strArrays) { List strList = new ArrayList(); for(String str : strArrays) { strList.add(str); } return strList; } /** * 获取组织机构code对应的name生成Map * @param strCodeList * @param organizationList * @return */ public static Map getMap(List strCodeList, List organizationList) { Map map = new HashMap<>(); if(ObjectUtil.empty(strCodeList)){ return map; } for(String str : strCodeList) { List getNameList = new ArrayList<>(); getOrgName(str, organizationList, getNameList); if(getNameList.size() == 1) { for(String strValue : getNameList) { map.put(str, strValue); } } else { map.put(str, getNameList.toString()); } } return map; } /** * 依据组织机构code获取对应的name * @param list * @return */ public static String getOrgName(String orgCode, List list ,List orgName){ if(list != null) for(Organization organization:list) { if(organization.getCode().equals(orgCode)) { orgName.add(organization.getName()); } if(ObjectUtil.notEmpty(orgName)){ return null; } getOrgName(orgCode, organization.getChildren(), orgName); } return null; } /** * 依据组织机构code数组查询对应的name并格式化为,分隔的形式 * @param map * @param orgCodes * @return */ public static String stringFormat(Map map, String[] orgCodes) { StringBuilder ids = new StringBuilder(); List strList = new ArrayList<>(); for(String str : orgCodes) { strList.add(map.get(str)); } if(ObjectUtil.empty(strList)){ return null; } else { for (int i = 0; i < strList.size(); i++) { if (i != 0) { ids.append(","); } ids.append(strList.get(i)); } } return ids.toString(); } /** * 依据组织机构code查询name * @param list * @param organization * @return */ public static String getOrg(String orgCode, List list, Organization organization){ if(list != null) for(Organization org:list) { if(org.getCode().equals(orgCode)) { organization.setName(org.getName()); } getOrg(orgCode, org.getChildren(), organization); } return null; } /** * 依据组织机构code查询父机构code * @param list * @param organization * @return */ public static String getParentId(String orgCode, List list, Organization organization){ if(list != null) for(Organization org:list) { if(org.getCode().equals(orgCode)) { // System.err.println(org); organization.setId(org.getParentId()); } getParentId(orgCode, org.getChildren(), organization); } return null; } /** * 依据组织机构id查询code和name * @param list * @param organization * @return */ public static String getParentOrg(String id, List list, Organization organization){ if(list != null) for(Organization org:list) { // System.out.println("org"+org.getId()+"id"+id); if(org.getId().equals(id)) { organization.setName(org.getName()); organization.setCode(org.getCode()); } getParentOrg(id, org.getChildren(), organization); } return null; } }