package com.kingdee.shr.custom.service; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.kingdee.bos.BOSException; import com.kingdee.bos.Context; import com.kingdee.bos.bsf.service.app.IHRMsfService; import com.kingdee.bos.metadata.entity.EntityViewInfo; import com.kingdee.bos.metadata.entity.FilterInfo; import com.kingdee.bos.metadata.entity.FilterItemInfo; import com.kingdee.bos.metadata.entity.SelectorItemCollection; import com.kingdee.bos.metadata.entity.SorterItemCollection; import com.kingdee.bos.metadata.entity.SorterItemInfo; import com.kingdee.bos.metadata.query.util.CompareType; import com.kingdee.eas.basedata.org.AdminOrgUnitCollection; import com.kingdee.eas.basedata.org.AdminOrgUnitFactory; import com.kingdee.eas.basedata.org.AdminOrgUnitInfo; import com.kingdee.eas.basedata.org.IAdminOrgUnit; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.util.app.DbUtil; import com.kingdee.jdbc.rowset.IRowSet; import com.kingdee.util.StringUtils; public class GetAdminInfoService implements IHRMsfService { private static final Logger logger = LoggerFactory.getLogger(GetAdminInfoService.class); /** * 组织下属组织 * @param ctx * @param adminOrgId * @return * @throws BOSException * @throws SQLException */ public Object process(Context ctx, Map param) throws EASBizException, BOSException { String orgId = StringUtils.cnulls(param.get("orgId")); String checkType = StringUtils.cnulls(param.get("checkType")); if(StringUtils.equals("1", orgId)){ orgId = GetOrgUtils.getRootOrg(ctx); } if(StringUtils.isEmpty(orgId) ){ logger.error("查询到orgId为空"); return new ArrayList(); } return getSubOrgAndPerson(ctx, orgId,checkType); } /** * 获取直接下级组织,并且获取组织下的成员的数量 * checkType 为1,则只查询直接下级的成员数量, * 否则,所有下级的成员数量 * @param ctx * @param orgId * @return * @throws BOSException * @throws EASBizException */ private List getSubOrgAndPerson(Context ctx,String orgId,String checkType) throws BOSException, EASBizException { List maplist = new ArrayList(); IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx); EntityViewInfo view = new EntityViewInfo(); SelectorItemCollection sic =new SelectorItemCollection(); sic.add("id"); sic.add("longNumber"); sic.add("name"); FilterInfo filter = new FilterInfo(); filter.getFilterItems().add(new FilterItemInfo("parent.id", orgId ,CompareType.EQUALS)); //是否封存, filter.getFilterItems().add(new FilterItemInfo("isSealUp", false ,CompareType.EQUALS)); SorterItemCollection sc = new SorterItemCollection(); sc.add(new SorterItemInfo("number")); view.setFilter(filter); view.setSelector(sic); view.setSorter(sc); AdminOrgUnitCollection col = iAdminOrgUnit.getAdminOrgUnitCollection(view); HashMap admPersonMap = getDirectSubCol(ctx); for(int i =0; i < col.size(); i++) { AdminOrgUnitInfo adminInfo = col.get(i); Map map = new HashMap(); map.put("id", adminInfo.getId().toString()); map.put("name", adminInfo.getName().toString()); String adminId = adminInfo.getId().toString(); if(admPersonMap.containsKey(adminId)) { map.put("count",admPersonMap.get(adminId)); }else { map.put("count",0); } int totalCount = GetOrgUtils.getPersonCount (ctx, adminInfo.getId().toString(),"0"); map.put("totalCount",totalCount); maplist.add(map); } return maplist; } //获取所有的组织与组织的直接人数 public HashMap getDirectSubCol(Context ctx) throws BOSException { HashMap admPersonMap = new HashMap (); try { String filterStr = " and admOrg.fisSealUp <> 1 "; String pinSql = GetOrgUtils.pinPersonSql( "adminPerson",filterStr); IRowSet rs = DbUtil.executeQuery(ctx, pinSql); while(rs.next()) { int pcount = rs.getInt("pcount"); String depId = StringUtils.cnulls(rs.getString("depId")); admPersonMap.put(depId, pcount); } } catch (SQLException e) { e.printStackTrace(); } return admPersonMap; } }