package com.kingdee.eas.framework;import com.kingdee.bos.BOSException;import com.kingdee.bos.Context;import com.kingdee.bos.ctrl.extendcontrols.ext.FilterInfoProducerFactory;import com.kingdee.bos.ctrl.extendcontrols.ext.OrgUnitFilterInfoProducer;import com.kingdee.bos.dao.AbstractObjectValue;import com.kingdee.bos.dao.IObjectPK;import com.kingdee.bos.dao.ormapping.ObjectUuidPK;import com.kingdee.bos.metadata.IMetaDataLoader;import com.kingdee.bos.metadata.MetaDataLoaderFactory;import com.kingdee.bos.metadata.entity.EntityObjectInfo;import com.kingdee.bos.metadata.entity.FilterInfo;import com.kingdee.bos.metadata.entity.FilterItemCollection;import com.kingdee.bos.metadata.entity.FilterItemInfo;import com.kingdee.bos.metadata.entity.PropertyInfo;import com.kingdee.bos.metadata.query.util.CompareType;import com.kingdee.bos.util.BOSObjectType;import com.kingdee.bos.util.BOSUuid;import com.kingdee.eas.base.codingrule.CodingRuleException;import com.kingdee.eas.base.codingrule.CodingRuleManagerFactory;import com.kingdee.eas.base.codingrule.ICodingRuleManager;import com.kingdee.eas.base.codingrule.RuleStatus;import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;import com.kingdee.eas.basedata.org.CostCenterOrgUnitInfo;import com.kingdee.eas.basedata.org.CtrlUnitInfo;import com.kingdee.eas.basedata.org.FullOrgUnitInfo;import com.kingdee.eas.basedata.org.HROrgUnitInfo;import com.kingdee.eas.basedata.org.INewOrgUnitFacade;import com.kingdee.eas.basedata.org.IOrgSwitchFacade;import com.kingdee.eas.basedata.org.NewOrgUnitFacadeFactory;import com.kingdee.eas.basedata.org.OrgSwitchFacadeFactory;import com.kingdee.eas.basedata.org.OrgType;import com.kingdee.eas.basedata.org.OrgUnitInfo;import com.kingdee.eas.basedata.org.ProfitCenterOrgUnitInfo;import com.kingdee.eas.basedata.org.PurchaseOrgUnitInfo;import com.kingdee.eas.basedata.org.QualityOrgUnitInfo;import com.kingdee.eas.basedata.org.SaleOrgUnitInfo;import com.kingdee.eas.basedata.org.StorageOrgUnitInfo;import com.kingdee.eas.basedata.org.TransportOrgUnitInfo;import com.kingdee.eas.basedata.org.service.OrgCommonUtils;import com.kingdee.eas.common.EASBizException;import com.kingdee.eas.common.client.SysContext;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;public class FrameWorkUtils{ public static final String strDataBase_Assistant = "com.kingdee.eas.basedata.assistant"; public static final String strDataBase_Master = "com.kingdee.eas.basedata.master"; public static final String CURRENT_COMPANY = "CurCompanyId"; public static final String CURRENT_COMPANYINFO = "CompanyInfo"; public static IMetaDataLoader createMetaDataLoader() { return MetaDataLoaderFactory.getRemoteMetaDataLoader(); } public static String getPropertyAlias(ObjectBaseInfo dataBaseInfo, String propertyName) { IMetaDataLoader loader = MetaDataLoaderFactory.getRemoteMetaDataLoader(); EntityObjectInfo entity = null; entity = loader.getEntity(dataBaseInfo.getBOSType()); PropertyInfo property = null; property = entity.getPropertyByName(propertyName); if (property == null) { return ""; } return property.getAlias(); } public static String getClassAlias(CoreBaseInfo dataBaseInfo) { IMetaDataLoader loader = MetaDataLoaderFactory.getRemoteMetaDataLoader(); EntityObjectInfo entity = null; if (dataBaseInfo == null) { return ""; } entity = loader.getEntity(dataBaseInfo.getBOSType()); String name = entity.getAlias(); if (name == null) { name = entity.getName(); } return name; } public static String getEntityExtendProperty(ObjectBaseInfo info) { String extendProperty = null; IMetaDataLoader loader = MetaDataLoaderFactory.getRemoteMetaDataLoader(); extendProperty = loader.getEntity(info.getBOSType()).getExtendedProperty("OrgType"); return extendProperty; } public static String getCodeRuleClient(BillBaseInfo billInfo) throws CodingRuleException, EASBizException, BOSException { String companyID = billInfo.getCompany().getId().toString(); return getCodeRuleClient(billInfo, companyID); } public static String getCodeRuleClient(CoreBillBaseInfo coreBillInfo, String companyID) throws CodingRuleException, EASBizException, BOSException { String sysNumber = null; ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory.getRemoteInstance(); if (iCodingRuleManager.isExist(coreBillInfo, companyID)) { if (iCodingRuleManager.isAddView(coreBillInfo, companyID)) { sysNumber = iCodingRuleManager.getNumber(coreBillInfo, companyID); } } return sysNumber; } public static String getCodeRuleClient(CoreBaseInfo info, String companyID) throws CodingRuleException, EASBizException, BOSException { String sysNumber = null; ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory.getRemoteInstance(); if (iCodingRuleManager.isExist(info, companyID)) { if (iCodingRuleManager.isAddView(info, companyID)) { sysNumber = iCodingRuleManager.getNumber(info, companyID); } } return sysNumber; } public static String getCodeRuleServer(Context ctx, CoreBaseInfo info, String companyID) throws CodingRuleException, EASBizException, BOSException { String sysNumber = null; ICodingRuleManager iCodingRuleManager = CodingRuleManagerFactory.getLocalInstance(ctx); RuleStatus rStatus = iCodingRuleManager.getRuleStatus(info, companyID); if ((rStatus != null) && (rStatus.isExist()) && (!rStatus.isAddView())) { sysNumber = iCodingRuleManager.getNumber(info, companyID); } return sysNumber; } public static FilterInfo getF7FilterInfoByAuthorizedOrg(OrgType orgType, String orgFieldName) { return getF7FilterInfoByAuthorizedOrg(orgType, orgFieldName, false); } public static FilterInfo getF7FilterInfoByAuthorizedOrg(OrgType orgType, String orgFieldName, boolean includeNull) { OrgUnitFilterInfoProducer oufip = (OrgUnitFilterInfoProducer)FilterInfoProducerFactory.getOrgUnitFilterInfoProducer(orgType); FilterInfo filterInfo = oufip.getFilterInfo(); FilterItemCollection filterItems = filterInfo.getFilterItems(); int i = 0; for (int num = filterItems.size(); i < num; i++) { filterItems.get(i).setPropertyName(orgFieldName); } if (includeNull) { FilterInfo filter = new FilterInfo(); filter.getFilterItems().add(new FilterItemInfo(orgFieldName, null, CompareType.EQUALS)); try { filter.mergeFilter(filterInfo, "OR"); } catch (BOSException e) { return filterInfo; } return filter; } return filterInfo; } public static void switchOrg(Context ctx, String orgID) throws Exception { if (ctx == null) { ctx = new Context(); } IOrgSwitchFacade iswitch = OrgSwitchFacadeFactory.getRemoteInstance(); HashMap map = iswitch.getSwitchOrgs(orgID); Iterator iter = OrgType.getEnumList().iterator(); while (iter.hasNext()) { OrgType orgType = (OrgType)iter.next(); OrgUnitInfo orgUnitInfo = (OrgUnitInfo)map.get(orgType); if (OrgCommonUtils.isBasicOrgType(orgType)) { setCurrentOrgUnit(ctx, orgType, orgUnitInfo); } } FullOrgUnitInfo ouInfo = (FullOrgUnitInfo)map.get("CurOU"); setCurrentOrgUnit(ctx, ouInfo); } public static void setCurrentTransportUnit(Context ctx, TransportOrgUnitInfo tou) { setCurrentOrgUnit(ctx, OrgType.Transport, tou); } public static CtrlUnitInfo getCurrentCtrlUnit(Context ctx) { return (CtrlUnitInfo)getCurrentOrgUnit(ctx, OrgType.ControlUnit); } public static void setCurrentCtrlUnit(Context ctx, CtrlUnitInfo cu) { setCurrentOrgUnit(ctx, OrgType.ControlUnit, cu); } public static CompanyOrgUnitInfo getCurrentFIUnit(Context ctx) { return (CompanyOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.Company); } public static void setCurrentFIUnit(Context ctx, CompanyOrgUnitInfo company) { setCurrentOrgUnit(ctx, OrgType.Company, company); } public static AdminOrgUnitInfo getCurrentAdminUnit(Context ctx) { return (AdminOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.Admin); } public static void setCurrentAdminUnit(Context ctx, AdminOrgUnitInfo adminUnit) { setCurrentOrgUnit(ctx, OrgType.Admin, adminUnit); } public static ProfitCenterOrgUnitInfo getCurrentProfitUnit(Context ctx) { return (ProfitCenterOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.ProfitCenter); } public static void setCurrentProfitUnit(Context ctx, ProfitCenterOrgUnitInfo profitCenter) { setCurrentOrgUnit(ctx, OrgType.ProfitCenter, profitCenter); } public static CostCenterOrgUnitInfo getCurrentCostUnit(Context ctx) { return (CostCenterOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.CostCenter); } public static void setCurrentCostUnit(Context ctx, CostCenterOrgUnitInfo costCenter) { setCurrentOrgUnit(ctx, OrgType.CostCenter, costCenter); } public static SaleOrgUnitInfo getCurrentSaleUnit(Context ctx) { return (SaleOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.Sale); } public static void setCurrentSaleUnit(Context ctx, SaleOrgUnitInfo saleUnit) { setCurrentOrgUnit(ctx, OrgType.Sale, saleUnit); } public static QualityOrgUnitInfo getCurrentQualityUnit(Context ctx) { return (QualityOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.Quality); } public static void setCurrentQualityOrgUnitUnit(Context ctx, QualityOrgUnitInfo qualityUnit) { setCurrentOrgUnit(ctx, OrgType.Quality, qualityUnit); } public static StorageOrgUnitInfo getCurrentStorageUnit(Context ctx) { return (StorageOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.Storage); } public static void setCurrentStorageUnit(Context ctx, StorageOrgUnitInfo storageUnit) { setCurrentOrgUnit(ctx, OrgType.Storage, storageUnit); } public static PurchaseOrgUnitInfo getCurrentPurchaseUnit(Context ctx) { return (PurchaseOrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.Purchase); } public static void setCurrentPurchaseUnit(Context ctx, PurchaseOrgUnitInfo purchaseUnit) { setCurrentOrgUnit(ctx, OrgType.Purchase, purchaseUnit); } public static OrgUnitInfo getCurrentOrgUnit(Context ctx, OrgType orgType) { return (OrgUnitInfo)ctx.get(orgType); } public static void setCurrentOrgUnit(Context ctx, OrgType orgType, OrgUnitInfo orgUnit) { ctx.put(orgType, orgUnit); if (orgType.equals(OrgType.Company)) { ctx.put("CompanyInfo", orgUnit); if ((orgUnit != null) && (orgUnit.getId() != null)) { ctx.put("CurCompanyId", orgUnit.getId().toString()); } } } public static OrgUnitInfo getCurrentOrgUnit(Context ctx) { return (OrgUnitInfo)ctx.get("CurOU"); } public static void setCurrentOrgUnit(Context ctx, OrgUnitInfo orgUnit) { ctx.put("CurOU", orgUnit); } public static HROrgUnitInfo getCurrentHRUnit(Context ctx) { return (HROrgUnitInfo)getCurrentOrgUnit(ctx, OrgType.HRO); } public static void setCurrentHRUnit(Context ctx, HROrgUnitInfo hroInfo) { setCurrentOrgUnit(ctx, OrgType.HRO, hroInfo); } public static void checkIsOUSealUp(Context ctx, BOSObjectType type, Context mainOrgContext) throws Exception { int orgTypeValue = 0; String ouID = null; OrgUnitInfo org = null; if (ctx == null) { orgTypeValue = getOrgTypeExtendedPropertyies(ctx, type); if (orgTypeValue < 0) { return; } org = getCurrentOrgUnit(mainOrgContext, OrgType.getEnum(orgTypeValue)); ouID = org != null ? org.getId().toString() : null; if (ouID == null) { throw new FrameWorkException(FrameWorkException.ORGNOTEQUAL); } NewOrgUnitFacadeFactory.getRemoteInstance().checkIsOUSealUp(ouID, orgTypeValue); } else { orgTypeValue = getOrgTypeExtendedPropertyies(ctx, type); if (orgTypeValue < 0) { return; } org = getCurrentOrgUnit(ctx, OrgType.getEnum(orgTypeValue)); ouID = org != null ? org.getId().toString() : null; if (ouID == null) { throw new FrameWorkException(FrameWorkException.ORGNOTEQUAL); } NewOrgUnitFacadeFactory.getLocalInstance(ctx).checkIsOUSealUp(ouID, orgTypeValue); } } public static void checkIsOUSealUp(Context ctx, BOSObjectType type, SysContext sysContext) throws Exception { int orgTypeValue = 0; String ouID = null; OrgUnitInfo org = null; if (ctx == null) { orgTypeValue = getOrgTypeExtendedPropertyies(ctx, type); if (orgTypeValue < 0) { return; } org = sysContext.getCurrentOrgUnit(OrgType.getEnum(orgTypeValue)); ouID = org != null ? org.getId().toString() : null; if (ouID == null) { throw new FrameWorkException(FrameWorkException.ORGNOTEQUAL); } NewOrgUnitFacadeFactory.getRemoteInstance().checkIsOUSealUp(ouID, orgTypeValue); } else { orgTypeValue = getOrgTypeExtendedPropertyies(ctx, type); if (orgTypeValue < 0) { return; } org = getCurrentOrgUnit(ctx, OrgType.getEnum(orgTypeValue)); ouID = org != null ? org.getId().toString() : null; if (ouID == null) { throw new FrameWorkException(FrameWorkException.ORGNOTEQUAL); } NewOrgUnitFacadeFactory.getLocalInstance(ctx).checkIsOUSealUp(ouID, orgTypeValue); } } public static EntityObjectInfo getEntity(Context ctx, BOSObjectType type) throws Exception { IMetaDataLoader loader = null; EntityObjectInfo entity = null; if (ctx == null) { loader = MetaDataLoaderFactory.getRemoteMetaDataLoader(); } else { loader = MetaDataLoaderFactory.getMetaDataLoader(ctx); } entity = loader.getEntity(type); return entity; } public static int getOrgTypeExtendedPropertyies(Context ctx, BOSObjectType type) throws Exception { int orgTypeValue = 0; EntityObjectInfo entity = null; entity = getEntity(ctx, type); String orgTypeStr = (String)entity.getExtendedProperties().get("OrgType"); if (orgTypeStr == null) { orgTypeStr = "NONE"; } OrgType orgType = OrgCommonUtils.getOrgType(orgTypeStr); if (orgType != null) { orgTypeValue = orgType.getValue(); } return orgTypeValue; } public static String getOrgPropertyNameByCoreBillBaseInfo(CoreBillBaseInfo vo) throws Exception { String orgPropertyName = null; if (vo != null) { orgPropertyName = vo.getBizOrgPropertyName(); } return orgPropertyName; } public static IObjectPK getOrgPKByCoreBillBaseInfo(CoreBillBaseInfo vo) throws Exception { String orgPropertyName = null; orgPropertyName = getOrgPropertyNameByCoreBillBaseInfo(vo); orgPropertyName = getOrgPropertyNameByCoreBillBaseInfo(vo); if (orgPropertyName == null) { return null; } if (vo != null) { AbstractObjectValue abstractObjectValue = vo; if (abstractObjectValue.containsKey(orgPropertyName)) { Object orgValue = abstractObjectValue.get(orgPropertyName); if (orgValue == null) { return null; } OrgUnitInfo orgUnitInfo = (OrgUnitInfo)orgValue; if (orgUnitInfo.getId() == null) { return null; } return new ObjectUuidPK(orgUnitInfo.getId()); } } return null; }}