BOS开发再服务端调用BOTP生成目标单据,记录下
(自用备忘)
@Override
protected void _audit(Context ctx, IObjectValue model) throws BOSException {
try {
this._submit(ctx, model);
} catch (EASBizException e) {
e.printStackTrace();
}
String pKString = this.getpkBysql(ctx, model);
this.test1Totest2ByBOTP(ctx,model,pKString);
}
/**
* 开始执行转换规则
* @param ctx
* 服务器上下文
* @param model
* IObkjectValue类型,通过这个接口可以获得一些单据中控件的值
* @param Pk
* 通过向数据库查询得到的源单据主键
* @throws BOSException
*/
private void test1Totest2ByBOTP(Context ctx,IObjectValue model,String Pk) throws BOSException{
//Test01Collection t1Coll = this.getTest01Collection(ctx);
Test01Info t1Info=null;
try {
System.err.println((IObjectPK)new ObjectStringPK(Pk));
t1Info = this.getTest01Info(ctx, (IObjectPK)new ObjectStringPK(Pk));//通过主键获取原单据实体
} catch (EASBizException e1) {
e1.printStackTrace();
}
IBTPManager botManager = BTPManagerFactory.getLocalInstance(ctx);//获取转换规则管理器
IBOTMapping botMapping = BOTMappingFactory.getLocalInstance(ctx);//获取转换规则接口
EntityViewInfo ev = this.getEntityViewInfo("name", "test1Totest2"); //设置转换规则的过滤条件
BOTMappingCollection bopMappingColl = null;
try {
bopMappingColl = botMapping.getBOTMappingCollection(ev); //获取转换规则的集合,其实就只有一个。
} catch (BOSException e) {
e.printStackTrace();
}
//构建idList的参数,原始对象的id
String[] idList = new String[1];
idList[0] = t1Info.getId().toString(); //将原单据值对象的ID放到一个数组中(后面方法用得到)
Test02Info t2Info = new Test02Info();
List list = new ArrayList(); //(后面方法用得到)
SelectorItemCollection selector = null; //(后面方法用得到)
BTPTransformResult result = null;
try {
result = botManager.transformForBotp(idList,
new String[1],list,selector,
t2Info.getBOSType().toString(),
new ObjectUuidPK(bopMappingColl.get(0).getId().toString()),
t1Info.getBOSType().toString());
if(result!=null){
}
} catch (BTPException e) {
e.printStackTrace();
}
Test02Collection t2Coll = (Test02Collection)result.getBills();
// BOTRelationCollection botRelColl = result.getBOTRelationCollection();
t2Info = (Test02Info)t2Coll.getObject(0);
}
/**
* 使用类似于JDBC(可能是封装了JDBC)的方法向数据库查询原单据的字符串类型的主键
*
* @param ctx
* 服务器上下文
* @param model
* @return
* 原单据主键
*/
private String getpkBysql(Context ctx,IObjectValue model){
StringBuffer sql = new StringBuffer();
sql.append("select FID from T_CUS_Test01 where FNumber = '"+model.get("number")+"'");
IRowSet row = null;;
try {
row = com.kingdee.eas.util.app.DbUtil.executeQuery(ctx, sql.toString());
} catch (BOSException e1) {
e1.printStackTrace();
}
String pKString = null;
try {
while(row.next()){
pKString = row.getString("FID");
}
} catch (SQLException e) {
e.printStackTrace();
}
return pKString;
}
/**
* 设置过滤条件
* @param filter1
* 要查询的属性名字
* @param filter2
* 属性名字的过滤条件
* @return
*/
private EntityViewInfo getEntityViewInfo(String filter1,String filter2){
EntityViewInfo ev0 = new EntityViewInfo();
FilterInfo filter = new FilterInfo();
filter.getFilterItems().add(new FilterItemInfo("name","test1Totest2"));
ev0.setFilter(filter);
return ev0;
}