botp自定函数设置

package com.kingdee.eas.znw.utils.utilPack;

import java.util.Date;
import java.util.List;
import java.util.Vector;

import sun.util.logging.resources.logging;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.ContextUtils;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.framework.DynamicObjectFactory;
import com.kingdee.bos.kscript.KScriptException;
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.query.util.CompareType;
import com.kingdee.bos.util.BOSObjectType;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.dap.util.ExtendFormulaFunctions;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.eas.znw.lt.baseData.settle.BizGroupEntryCollection;
import com.kingdee.eas.znw.lt.baseData.settle.BizGroupEntryFactory;
import com.kingdee.eas.znw.lt.baseData.settle.BizGroupEntryInfo;
import com.kingdee.eas.znw.lt.baseData.settle.CropSeasonFactory;
import com.kingdee.eas.znw.lt.baseData.settle.CropSeasonInfo;
import com.kingdee.eas.znw.lt.baseData.settle.ProcurementPlan;
import com.kingdee.eas.znw.lt.baseData.settle.ProcurementPlanFactory;
import com.kingdee.eas.znw.lt.baseData.settle.ProcurementPlanInfo;
import com.kingdee.eas.znw.lt.settle.report.DailySettleInfoFactory;
/**
 * 
 * 面向所有实体(所有单据)的自定义公式

通过该方法创建的自定义公式,可以被任何单据的 BOTP 规则引用。

1.在 BOS 创建一个类,继承标准产品的类 com.kingdee.eas.base.dap.util. ExtendFormulaFunctions。可运行的示例代码可以参考本文的 4.3 章节;

2.修改客户端和服务端的 ServiceProviderImpl.xml 文件,该文件在 BOS 和 Server 的路径分

别为:

BOS: %Solution%\runtime\client\deploy\client\ServiceProviderImpl.xml %Solution%\runtime\server\properties\ServiceProviderImpl.xml

EAS Server: server\deploy\fileserver.ear\easWebClient\deploy\client\ServiceProviderImpl.xml server\properties\ServiceProviderImpl.xml

用 xml 编辑器打开该文件,查找关键字“BOTP_EXTENDFUNCIONS”,将蓝色部分改成第

1 步创建的类名:

<!-- BOTP 扩展公用函数--> <configitem name="BOTP_EXTENDFUNCIONS">

<attribute key="providerName" value="BotpCustomFormula"/> <attribute key="providerClassName"

value="com.kingdee.eas.custom.gz.utils.botp.formula.BotpCustomFormula"/> </configitem>
 特别注意的是:传入的参数默认有一个隐藏的参数:(好像是ctx),因此传入一个,时间paramList.size()=2,传入两个参数,实际参数是三个。实际传入的参数索引从1开始,而不是0
 */
public class BillBotpFormula extends ExtendFormulaFunctions {
	//用于存放公式的变量
	private static Vector funcInfos;
	public static final String __BOTgetOVByBosType = "__BOTgetOVByBosType";
	public static final String __BOTgetSettleDate = "__BOTgetSettleDate";
	public static final String __BOTgetBodyInBizGroupOfProcumentPlan = "__BOTgetBodyInBizGroupOfProcumentPlan";

	static
	{
		//加载类时定义自定义公式
		funcInfos = new Vector();
		//FuncInfo()的第一个参数是公式名,第二个参数是公式所在的分类(可随便取名),
		//第三个参数是公式的描述信息(在 BOTP 公式平台显示)
		funcInfos.add(new FuncInfo(__BOTgetOVByBosType, "自定义公式", "通过业务单元的 BosType 和编码获取对应的值对象(F7)\n__BOTgetOVByBosType(String number, String bosType),返回值为 IObjectValue。 \nDeveloped by GZ Kingdee Development Dept.."));
		funcInfos.add(new FuncInfo(__BOTgetSettleDate, "自定义公式", "通过组织id获取当前的日结日期\n__BOTgetOVByBosType(BOSUuid companyId),返回值为 Date。"));
		funcInfos.add(new FuncInfo(__BOTgetBodyInBizGroupOfProcumentPlan, "自定义公式", "通过购销计划id获取所属业务群中指定类型的主体\n__BOTgetBodyInBizGroupOfProcumentPlan(String procumentPlanId,String bodyType)\nprocumentPlanId购销计划id,bodyType主体类型\n返回值指定bodyType的主体返回类型为CompanyOrgUnitInfo (bodyType =TradeBody<贸易主体>,FinanceBody<金融主体> ,TransferBody<物流主体>)。"));
	}
	/**
	 * 运行时 BOTP 公式平台加载自定义公式时,就是从该返回值里取公式的名称的
	 * @date since 2007-9-6
	 * @return 所有自定义公式的名称
	 */
	public String[] getAllFuncNames()
	{
		String as[] = new String[funcInfos.size()];
		for(int i = 0; i < funcInfos.size(); i++)
			as[i] = ((FuncInfo)funcInfos.get(i)).funcName;
		return as;
	}
	/**
	 * 运行时 BOTP 公式平台加载自定义公式时,就是从该返回值里取公式的分类的(看运
	行时的界面就很好理解)
	 * @date since 2007-9-6
	 * @param s
	 * @return
	 */
	public String getFuncCategory(String s)
	{
		if(s == null)
			return null;
		for(int i = 0; i < funcInfos.size(); i++)
			if(s.equals(((FuncInfo)funcInfos.get(i)).funcName))
				return ((FuncInfo)funcInfos.get(i)).funcCategory;
		return null;
	}
	/**
	 * 获取公式的描述
	 * @date since 2007-9-6
	 * @param s
	 * @return
	 */
	public String getFuncDesc(String s)
	{
		if(s == null)
			return null;
		for(int i = 0; i < funcInfos.size(); i++)
			if(s.equals(((FuncInfo)funcInfos.get(i)).funcName))
				return ((FuncInfo)funcInfos.get(i)).funcDesc;
		return null;
	}
	public boolean existFunction(String s)
	{
		if(s == null)
			return false;
		for(int i = 0; i < funcInfos.size(); i++)
			if(s.equals(((FuncInfo)funcInfos.get(i)).funcName))
				return true;
		return false;
	}
	/**
	 * 运行公式时调用此方法,公式的具体逻辑就写在这里
	 * @date since 2007-9-6
	 * @param func 公式名称
	 * @param paramList 公式的参数
	 * @return 公式结果
	 * @throws KScriptException
	 */
	public Object evalFunction(String func, List paramList) throws KScriptException
	{
		//判断用户是选了哪个公式
		if(func != null && func.equals(__BOTgetOVByBosType))
		{
			//这里可以写满足各式各样需求的代码
			if(paramList != null && paramList.size() == 3)
			{
				String number = (String) paramList.get(1);
				String bosType = (String) paramList.get(2);
				try 
				{
					return 
					DynamicObjectFactory.getLocalInstance(ContextUtils.getContextFromSession()).getValue(BOSObjectType.create(bosType), "where number='" + number + "'");
				} 
				catch (BOSException e) 
				{
					e.printStackTrace();
				}
			}
			else
				return null;
		}else if(func != null && func.equals(__BOTgetSettleDate)){
			if(paramList != null && paramList.size() ==2){
				BOSUuid companyId=(BOSUuid) paramList.get(1);
				Date settleDate=null;
				try {
					settleDate=DailySettleInfoFactory.getLocalInstance(ContextUtils.getContextFromSession()).getStartSettleDate(companyId.toString());
				} catch (EASBizException e) {
					e.printStackTrace();
				} catch (BOSException e) {
					e.printStackTrace();
				}
				return settleDate;
			}else
				return null;
		}else if(func!=null&&func.equals(__BOTgetBodyInBizGroupOfProcumentPlan)){
			if(paramList!=null&¶mList.size()== 3){
				BOSUuid procumentPlanId= (BOSUuid)paramList.get(1);
				String bodyType = (String)paramList.get(2);
				return getBodyInBizGroup(procumentPlanId, bodyType);
			}else{
				return null;
			}
		}

		return null;
	}
	
	
	/**
	 *获取购销计划所属业务群中的主题 
	 * @param procumentPlanId
	 * @param bodyType
	 * @return
	 */
	public CompanyOrgUnitInfo getBodyInBizGroup(BOSUuid procumentPlanId, String bodyType) {
		try {
			ProcurementPlanInfo procurementPlan  = ProcurementPlanFactory.getLocalInstance(ContextUtils.getContextFromSession()).getProcurementPlanInfo(new ObjectUuidPK(procumentPlanId));
			EntityViewInfo view = new EntityViewInfo();
			SelectorItemCollection coll = new SelectorItemCollection();
			coll.add("*");
			coll.add("parent.*");
			view.setSelector(coll);
			FilterInfo filter = new FilterInfo();
			filter.getFilterItems().add(new FilterItemInfo("parent.id", procurementPlan.getBizGroup().getId(), CompareType.EQUALS));
			filter.getFilterItems().add(new FilterItemInfo("parent.isEnable", 1, CompareType.EQUALS));
			view.setFilter(filter);
			BizGroupEntryCollection entryCollection = BizGroupEntryFactory.getLocalInstance(ContextUtils.getContextFromSession()).getBizGroupEntryCollection(view);
			for(int i = 0,size = entryCollection.size();i<size;i++ ){
				BizGroupEntryInfo bizGroupEntryInfo = entryCollection.get(i);
				if(bizGroupEntryInfo.isIsStorageOrg()&&"TradeBody".equalsIgnoreCase(bodyType)){//TradeBbody 贸易主体
					return bizGroupEntryInfo.getCompany();
				}else if(bizGroupEntryInfo.isIsFinanceOrg()&&"FinanceBody".equalsIgnoreCase(bodyType)){//Financebody 金融主体
					return bizGroupEntryInfo.getCompany();
				}else if(bizGroupEntryInfo.isIsTransferOrg()&&"TransferBody".equalsIgnoreCase(bodyType)){//Transferbody:物流主体
					return bizGroupEntryInfo.getCompany();
				}
			}
		} catch (EASBizException e) {
			e.printStackTrace();
		} catch (BOSException e) {
			e.printStackTrace();
		}
		return null;
	}
}
class FuncInfo {
	public void setFuncName(String name)
	{
		funcName = name;
	}
	public void setFuncDesc(String desc)

	{
		funcDesc = desc;
	}
	public void setFuncCatetory(String category)
	{
		funcCategory = category;
	}
	String funcName;
	String funcCategory;
	String funcDesc;
	public FuncInfo(String name, String category, String desc)
	{
		super();
		funcName = name;
		funcCategory = category;
		funcDesc = desc;
	}
	public FuncInfo()
	{
		super();
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值