如何实现在物料反查的结果加入BOM关系属性字段
【应用场景】
根据业务需要,物料反查需要显示对应BOM关系属性字段,如BOM用量。
【注意事项】
1.扩展【物料BOM关系反查】单据,单据体上新增自定义字段来表示关系属性,演示内容以FBomNumber(BOM用量)为例,其他关系属性逻辑类似。
2.关系属性表:T_PLM_CFG_RELATION。
【案例演示】
物料反查显示出对应BOM的用量。
【实现步骤】
<1>编写表单插件和服务插件,代码如下。
using Kingdee.BOS; using Kingdee.BOS.App.Core.Utils; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; using Kingdee.K3.PLM.Business.PlugIn; using Kingdee.K3.PLM.CFG.Common.BusinessEntity.Base; using Kingdee.K3.PLM.CFG.Common.BusinessEntity.Entity; using Kingdee.K3.PLM.CFG.Common.BusinessEntity.Manager; using Kingdee.K3.PLM.Common.Core.BOSBridge; using Kingdee.K3.PLM.Common.Core.Common; using Kingdee.K3.PLM.Common.Core.ServiceHelper; using Kingdee.K3.PLM.Common.Core.Utility; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; namespace Kingdee.K3.PLM.STD.Business.PlugIn { [HotUpdate] [Description("物料反查BOM用量插件")] public class MatReverseNumberForm : AbstractPLMDynamicFormPlugIn { /// <summary> /// 当前物料id /// </summary> long _currentId = 0; /// <summary> /// 当前物料业务类型 /// </summary> long _categoryId = 0; /// <summary> /// BOM业务类型 /// </summary> List<long> bomcategory = new List<long>(); /// <summary> /// 是否初始化 /// </summary> bool _init = false; public override void PreOpenForm(PreOpenFormEventArgs e) { _currentId = Convert.ToInt64(e.OpenParameter.GetCustomParameter("plm_param_SourceObjectId")); base.PreOpenForm(e); } public override void OnLoad(EventArgs e) { var d = DomainObjectManager.Instance(PLMContext, (long)StandardCategoryType.Material).Get(PLMContext, _currentId); if (d != null) { _categoryId = Convert.ToInt64(d["CategoryId_Id"]); } if (CategoryContract.Instance.IsMaterialCategory(_categoryId)) { bomcategory.Add((long)StandardCategoryType.BOM);//支持反查bom所有业务类型 bomcategory.Add((long)StandardCategoryType.DBOM); } else if (CategoryContract.Instance.IsVirtualMaterialCategory(_categoryId)) { bomcategory.Add((long)StandardCategoryType.DBOM); } _init = true; } public override void CustomEvents(CustomEventsArgs e) { if (_init) { Dictionary<string, decimal> dicRelationBomNumbers = GetRelationBomNumberBySlaveId(PLMContext, bomcategory, _currentId); if (dicRelationBomNumbers.Count > 0) { var dicKeys = dicRelationBomNumbers.Keys; var relationDatas = this.View.Model.DataObject["RelationsOperationLogs"].GetAsType<DynamicObjectCollection>(); int rowIndex = 0; foreach (var relation in relationDatas) { var bomCode = relation.GetDynamicObjectItemValue<string>("RelationObjectCode"); if (!string.IsNullOrWhiteSpace(bomCode) && dicKeys.Contains(bomCode)) { relation["BomNumber"] = dicRelationBomNumbers[bomCode];//BOM用量 } this.View.UpdateView("FBomNumber", rowIndex); rowIndex++; } } } _init = false; base.CustomEvents(e); } /// <summary> /// 根据物料或者对应的BOM编码、用量 /// </summary> /// <param name="ctx"></param> /// <param name="categoryId">BOM业务类型</param> /// <param name="slaveId">物料id</param> /// <returns></returns> public Dictionary<string, decimal> GetRelationBomNumberBySlaveId(PLMContext ctx, List<long> categoryId, long slaveId) { string filter = string.Empty; string orderby = string.Empty; if (categoryId != null && categoryId.Count > 0) // 过滤业务类型 { string categoryfilter = string.Empty; foreach (var item in categoryId) { if (string.IsNullOrEmpty(categoryfilter)) categoryfilter = string.Format("((B.FCATEGORYID >= {0}) AND (B.FCATEGORYID < {1}))", item, CategoryModel.GetNextSiblingID(item)); else categoryfilter = categoryfilter + "OR" + string.Format("((B.FCATEGORYID >= {0}) AND (B.FCATEGORYID < {1}))", item, CategoryModel.GetNextSiblingID(item)); } filter = string.Format("INNER JOIN T_PLM_PDM_BASE B ON (({0}) AND R.FID = B.FID) ", categoryfilter); orderby = " ORDER BY B.FCATEGORYID"; } var isChangeObject = false; if (ctx is PLMBasketContext && ((PLMBasketContext)ctx).GetBasket("_ReverseDyn_") != null) { var dyn = (DynamicObject)((PLMBasketContext)ctx).GetBasket("_ReverseDyn_"); isChangeObject = dyn.GetDynamicObjectItemValue<bool>("IsChangeObject"); } string filter1 = !isChangeObject ? " AND FISCHANGEOBJECT='0' " : string.Empty; string sql = string.Format("SELECT DISTINCT FCODE,R.FID,R.BOMNUMBER FROM T_PLM_CFG_RELATION R {0} WHERE R.FSLAVERELATION = @id " + filter1 + orderby, filter); var p = PLMDBUtils.Instance.GetAParameter("@id", KDDbType.Int64, slaveId); return PLMDBUtils.Instance.ExecuteDataSet(ctx, sql, p).Rows.Cast<System.Data.DataRow>().ToDictionary(m => m["FCODE"].ToString(), n => Convert.ToDecimal(n["BOMNUMBER"])); } } }
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE扩展【物料BOM关系反查】,注册表单插件,保存元数据,开发完毕。
【功能验证】
<1>登录业务站点,打开物料反查界面,即可通过VS调试观察到最新的服务插件执行顺序。
【参考资料】
【汇总】星空PLM二开指南(持续更新)https://vip.kingdee.com/article/329914697153905408?productLineId=1&isKnowledge=2
【合辑】金蝶云.星空 PLM知识合辑(持续更新) https://vip.kingdee.com/article/329662872047302912?productLineId=1&isKnowledge=2
金蝶云星空PLM表结构(V8.0) https://vip.kingdee.com/article/350294658524016128?productLineId=1
二次开发扩展程序开发之插件模式 https://vip.kingdee.com/article/83591896433330944?productLineId=1
PLM云 -- 基于BOS平台的二次开发扩展https://vip.kingdee.com/article/10875?productLineId=1
PLM云 -- 基于配置系统的二次开发扩展(对象属性扩展)https://vip.kingdee.com/article/10887?productLineId=1
PLM云 -- 基于标准业务系统的二次开发扩展 https://vip.kingdee.com/article/10901?productLineId=1
金蝶云星空BOS二次开发指南https://vip.kingdee.com/article/94751030918525696?productLineId=1&isKnowledge=2
金蝶云星空数据字典V7.6 https://open.kingdee.com/K3Cloud/WenKu/DocumentView.aspx?docId=102613
如何实现在物料反查的结果加入BOM关系属性字段
本文2024-09-23 03:03:06发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-156348.html