package cn.autoform.web.client.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import cn.autoform.web.client.bean.Organization; /** * 组织机构数据处理 * @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(); System.err.println(organization.getName()); 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(); 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 OrgCode * @param list * @param OrgName * @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(orgName.size()>0){ return null; } getOrgName(orgCode, organization.getChildren(), orgName); } return null; } /** * 依据组织机构code数组查询对应的name并格式化为,分隔的形式 * @param map * @param orgCodes * @return */ public static String stringFormat(Map map, String[] orgCodes) { StringBuffer ids = new StringBuffer(); List strList = new ArrayList(); for(String str : orgCodes) { strList.add(map.get(str).toString()); } if(strList.size()==0||strList==null){ return null; } else { for (int i = 0; i < strList.size(); i++) { if (i != 0) { ids.append(","); } ids.append(strList.get(i).toString()); } } return ids.toString(); } /** * 依据组织机构code查询name * @param OrgCode * @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 OrgCode * @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 OrgCode * @param list * @param organization * @return */ public static String getParentOrg(String id, List list, Organization organization){ if(list != null) for(Organization org:list) { if(org.getId().equals(id)) { organization.setName(org.getName()); organization.setCode(org.getCode()); } getParentOrg(id, org.getChildren(), organization); } return null; } }