业务流程.二开案例.合并下推上查时仅显示发生关系的行

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

业务流程.二开案例.合并下推上查时仅显示发生关系的行

【场景】合并下推上查时仅显示发生关系的行 【数据准备】 ![image.webp](/download/01007acfa62d928b40748f88c229c382ed15.webp) 【逻辑】 单据转换计算过程中就会把关联关系计算好,不会因为调整分录数据而修改关联关系; (因为计算过程中还会有很多拼接字段,如源单编号,自定义公式拼接等,这些字段平台不会再重新计算) ![image.webp](/download/010049eedfc08c14463b8fd0bacecff55e76.webp) 【思路扩展】 如何判断当前分录数据真实发生关系的源行? 依赖于控制字段的分配置 ![image.webp](/download/0100e90acb7a69e04b069ea16d12a5aebbdb.webp) 【方案一】保存时把没有发生关系的lk数据删除,通过保存服务插件,把lk中分配值为0的行去掉 优点:直接解除关系,上游没发送分配的行也无法下查到该单据,数据更为简单 缺点:需要有控制字段才能实现,且需要自行评估单据上哪些字段需要重新计算,避免因为关联关系和转换时的关系不一致而出现的数据不对称问题 【方案二】第三方上查 案例:采购订单仅上查发生关系的采购申请单行(表单和列表都需要实现) ![image.webp](/download/0100f0f358718b494d1987b4655e44493896.webp) ```csharp using Kingdee.BOS; using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.List.PlugIn; using Kingdee.BOS.Core.List.PlugIn.Args; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.ConvertElement; using Kingdee.BOS.Core.Metadata.EntityElement; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DynamicFormPlugIn.BillConvert { [Kingdee.BOS.Util.HotUpdate] [System.ComponentModel.Description("干预上查的树节点 表单插件")] public class AdjustTrackResultBillPlugIn : AbstractBillPlugIn { public override void OnShowConvertOpForm(ShowConvertOpFormEventArgs e) { /* * 标记上查时需要替换关系,替换的关系是采购申请单到采购订单 */ if (e.ConvertOperation == Kingdee.BOS.Core.DynamicForm.FormOperationEnum.TrackUp) { ReplaceRelation rel = new ReplaceRelation("PUR_Requisition", "PUR_Requisition"); rel.SourceLinkId = new List<string>(); rel.SourceLinkId.Add("1"); e.ReplaceRelations.Add(rel); } } public override void OnShowTrackResult(ShowTrackResultEventArgs e) { /* * 将上查的节点替换为真实发生关系数据的节点 */ if (e.TrackOperation == Kingdee.BOS.Core.DynamicForm.FormOperationEnum.TrackUp) { //if (!string.Equals(e.TargetFormKey, this.View.BillBusinessInfo.GetForm().Id, StringComparison.OrdinalIgnoreCase)) // return; List<int> entityIds = new List<int>(); var linkParentEntity = AdjustTrackResultHelper.GetLinkParentEntiy(this.View.BillBusinessInfo); var entityObjs = this.Model.GetEntityDataObject(linkParentEntity); foreach(var entityObj in entityObjs) { int entityId = ObjectUtils.Object2Int(entityObj[0]); if (entityId == 0) continue; entityIds.Add(entityId); } var result = AdjustTrackResultHelper.GetTrackResult(this.Context, "PUR_Requisition", this.View.BillBusinessInfo, entityIds); e.TrackResult = result; } } } public static class AdjustTrackResultHelper { public static object GetTrackResult(Context ctx, string srcFormId, BusinessInfo tgtBusinessInfo, List<int> tgtEntityIds) { FormMetadata srcMetaData = Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load(ctx, srcFormId) as FormMetadata; if (srcMetaData == null) return null; var srcEntityIds = GetRealSrcEntityIds(ctx, tgtBusinessInfo, tgtEntityIds); if (srcEntityIds == null) return null; var trackResult = Kingdee.BOS.BusinessEntity.BillTrack.BillNode.Create(srcFormId, srcMetaData.BusinessInfo.GetForm().Name); var srcEntiyList = srcEntityIds.Select(x => x.ToString()).ToList(); trackResult.AddLinkCopyData(srcEntiyList); return trackResult; } /// <summary> /// 获取link实体的关联实体 /// </summary> /// <param name="businessInfo"></param> /// <returns></returns> public static Entity GetLinkParentEntiy(BusinessInfo businessInfo) { var linkEntity = GetLinkEntity(businessInfo); if (linkEntity == null) return null; var linkParentEntity = businessInfo.GetEntity(linkEntity.ParentEntityKey); return linkParentEntity; } /// <summary> /// 获取link实体 /// </summary> /// <param name="businessInfo"></param> /// <returns></returns> public static LinkEntity GetLinkEntity(BusinessInfo businessInfo) { var billForm = businessInfo.GetForm(); if (billForm.LinkSet == null || billForm.LinkSet.LinkEntitys.Count == 0) return null; return billForm.LinkSet.LinkEntitys[0]; } /// <summary> /// 依赖控制字段获取实际发生关系的行 /// </summary> /// <param name="ctx"></param> /// <param name="businessInfo"></param> /// <param name="tgtEntityIds"></param> /// <returns></returns> public static List<int> GetRealSrcEntityIds(Context ctx, BusinessInfo businessInfo, List<int> tgtEntityIds) { var linkEntity = GetLinkEntity(businessInfo); if (linkEntity.WriteBackFieldKeys == null || linkEntity.WriteBackFieldKeys.Count <= 0) return null; var linkParentEntity = GetLinkParentEntiy(businessInfo); //控制字段非0 string filter = string.Format(" lk.{0} <> 0", linkEntity.WriteBackFieldKeys[0]); string sql = string.Format( @"SELECT lk.FSID FROM {0} Entity LEFT JOIN {1} Lk ON Entity.{2} = Lk.{2} WHERE Entity.{2} IN ({3}) AND {4} ", linkParentEntity.TableName, linkEntity.TableName, linkParentEntity.EntryPkFieldName, string.Join(",", tgtEntityIds), filter); List<int> result = new List<int>(); using (var reader = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(ctx, sql)) { while(reader.Read()) { int sentryId = Convert.ToInt32(reader["FSID"]); if (sentryId == 0) continue; result.Add(sentryId); } } return result; } } } ``` 【效果】 ![20231201 2047.webp](/download/0100d40627ba836a48abba6c9029144c5da1.webp)

业务流程.二开案例.合并下推上查时仅显示发生关系的行

【场景】合并下推上查时仅显示发生关系的行【数据准备】![image.webp](/download/01007acfa62d928b40748f88c229c382ed15.webp)【逻辑】单据...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息