本文介绍了在金蝶BOS系统中,仓位数据的使用方式及多种插件实现方法。首先,通过BOS配置实现物料默认仓库仓位的设置,但此方法只能指定默认值,无法应对复杂逻辑。其次,通过二开插件,包括表单插件结合值集组合方式、表单插件结合非值集组合方式,以及单据转换插件的两种组合方式,详细说明了如何在不同场景下动态设置仓位值。这些方法涉及查询数据库、构造数据包、清空并赋值仓位字段等步骤,确保在不同业务场景下能灵活设置仓位。
仓位的使用方式 :【仓位数据查询-学习笔记】
值集组合方式
非组合值方式
插件
表单插件
单据转换插件
服务端插件
一、BOS配置实现
【仓库设置默认仓位】
物料设置默认仓库仓位,物料值更新配置服务"携带相关基础资料到指定列",对仓位进行赋值
局限性:只能指定默认值,无法运用复杂的判断逻辑,不同场景赋值不同的仓库仓位
二、二开插件
1、表单插件 + 值集组合方式
说明:需知道仓位的组合内码 SELECT * FROM T_BAS_FLEXVALUESDETAIL
RelatedFlexGroupField stockLocField = this.View.BusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; DynamicObject dyRow = this.View.Model.GetEntityDataObject(stockLocField.Entity)[e.Row]; // 清空仓位 stockLocField.DynamicProperty.SetValue(dyRow, null); stockLocField.RefIDDynamicProperty.SetValue(dyRow, 0); var stockLoc = BusinessDataServiceHelper.LoadFromCache(this.View.Context, new object[] { "100009" }, stockLocField.RefFormDynamicObjectType); stockLocField.DynamicProperty.SetValue(dyRow, stockLoc[0]); stockLocField.RefIDDynamicProperty.SetValue(dyRow, 100009); this.View.UpdateView("FStockLocId", e.Row);
2、表单插件 + 非值集组合方式
说明:
仓库的仓位值集下没有设置对应仓位值,可以选择任意的仓位值
此时并未生成仓位内码,需要构造仓位字段的数据包,给单据的数据包赋值,然后单据保存之后会自动生成内码
保存时,可以看到仓位的数据包包含两个FLEXVALUESY,即仓位值数据包,可以理解为模拟页面选择仓位值维度
RelatedFlexGroupField stockLocField = this.View.BusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; DyxnamicObject dyRow = this.View.Model.GetEntityDataObject(stockLocField.Entity)[e.Row]; // 清空仓位(标准单据单据体配置有实体服务规则,仓库改变会清空仓位,这里需要把这个设置取消,否则插件赋值后,又被实体服务规则清空,导致没有赋值效果) stockLocField.DynamicProperty.SetValue(dyRow, null); stockLocField.RefIDDynamicProperty.SetValue(dyRow, 0); Dictionary<string, long> dctFlexItemIds = new Dictionary<string, long>(); dctFlexItemIds.Add("FF100001", 100002); // 仓位值集Key - 仓位值内码 dctFlexItemIds.Add("FF100002", 100023); // 仓位值集Key - 仓位值内码 // 新建仓位值属性数据包,用来存储各维度值 DynamicObject stockLocObj = new DynamicObject(stockLocField.RefFormDynamicObjectType); foreach (var flexItem in dctFlexItemIds) { Field fldFlex = stockLocField.RelateFlexBusinessInfo.GetField(flexItem.Key); BaseDataField fldBDTypeFlex = fldFlex as BaseDataField; IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); DynamicObject[] flexItemObjs = viewService.LoadFromCache(this.Context, new object[] { flexItem.Value }, fldBDTypeFlex.RefFormDynamicObjectType); fldBDTypeFlex.RefIDDynamicProperty.SetValue(stockLocObj, flexItem.Value); fldBDTypeFlex.DynamicProperty.SetValue(stockLocObj, flexItemObjs[0]); } stockLocField.DynamicProperty.SetValue(dyRow, stockLocObj); var obj = SaveFlexObject(this.Context, stockLocObj); long flexDataId = Convert.ToInt64(obj[0]); stockLocField.RefIDDynamicProperty.SetValue(dyRow, flexDataId); this.View.UpdateView("FStockLocId", e.Row); public static DynamicObject SaveFlexObject(Context ctx, DynamicObject flexData) { var seqReader = new SequenceReader(ctx); var businessDataService = new BusinessDataService(); seqReader.AutoSetPrimaryKey(new[] { flexData }, flexData.DynamicObjectType); return businessDataService.Save(ctx, new[] { flexData })[0]; }
3、单据转换插件 + 值集组合方式
单据转换中采用表达服务策略对仓位的赋值无效
说明:需知道仓位的组合内码 SELECT * FROM T_BAS_FLEXVALUESDETAIL
public override void AfterConvert(BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e) { IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); var dataObjs = e.Result.FindByEntityKey("FBillHead"); foreach (var obj in dataObjs) { DynamicObjectCollection entrys = obj.DataEntity["BillEntry"] as DynamicObjectCollection; RelatedFlexGroupField stockLocField = e.TargetBusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; foreach (DynamicObject entry in entrys) { var stockLoc = BusinessDataServiceHelper.LoadFromCache(this.Context, new object[] { "100009" }, stockLocField.RefFormDynamicObjectType); stockLocField.DynamicProperty.SetValue(entry, stockLoc[0]); stockLocField.RefIDDynamicProperty.SetValue(entry, 100009); } } }
4、单据转换插件 + 非值集组合方式
说明:类似于2中表单插件 + 非值集组合方式的处理方式
public override void AfterConvert(BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e) { IViewService viewService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); var dataObjs = e.Result.FindByEntityKey("FBillHead"); foreach (var obj in dataObjs) { DynamicObjectCollection entrys = obj.DataEntity["BillEntry"] as DynamicObjectCollection; RelatedFlexGroupField stockLocField = e.TargetBusinessInfo.GetField("FStockLocId") as RelatedFlexGroupField; foreach (DynamicObject entry in entrys) { Dictionary<string, long> dctFlexItemIds = new Dictionary<string, long>(); dctFlexItemIds.Add("FF100001", 100002); // 仓位值集Key - 仓位值内码 dctFlexItemIds.Add("FF100002", 100023); // 仓位值集Key - 仓位值内码 DynamicObject stockLocObj = new DynamicObject(stockLocField.RefFormDynamicObjectType); foreach (var flexItem in dctFlexItemIds) { Field fldFlex = stockLocField.RelateFlexBusinessInfo.GetField(flexItem.Key); BaseDataField fldBDTypeFlex = fldFlex as BaseDataField; IViewService viewService1 = Kingdee.BOS.Contracts.ServiceFactory.GetService<IViewService>(this.Context); DynamicObject[] flexItemObjs = viewService1.LoadFromCache(this.Context, new object[] { flexItem.Value }, fldBDTypeFlex.RefFormDynamicObjectType); fldBDTypeFlex.RefIDDynamicProperty.SetValue(stockLocObj, flexItem.Value); fldBDTypeFlex.DynamicProperty.SetValue(stockLocObj, flexItemObjs[0]); } stockLocField.DynamicProperty.SetValue(entry, stockLocObj); var obj = SaveFlexObject(this.Context, stockLocObj); long flexDataId = Convert.ToInt64(obj[0]); stockLocField.RefIDDynamicProperty.SetValue(entry, flexDataId); } } } public static DynamicObject SaveFlexObject(Context ctx, DynamicObject flexData) { var seqReader = new SequenceReader(ctx); var businessDataService = new BusinessDataService(); seqReader.AutoSetPrimaryKey(new[] { flexData }, flexData.DynamicObjectType); return businessDataService.Save(ctx, new[] { flexData })[0]; }
参考:
推荐阅读