73.4、单据转换插件,多选辅助基础资料原创
金蝶云社区-林荫大道_找工作身份
林荫大道_找工作
17人赞赏了该文章 7,205次浏览 未经作者许可,禁止转载编辑于2021年09月26日 18:46:25


1、续73.2,采购订单和收料通知单,添加多选辅助资料字段 F_PAEZ_MulAssistantGGB ,


    注意标识、字段名、绑定实体属性一样  


image.png



2、续73.3,添加类  MulBaseConvPlug


image.png



3、添加 public


image.png



4、添加引用 


using System;
using System.Collections.Generic;
using System.ComponentModel;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.App;
using Kingdee.BOS.Core.Metadata.FieldElement;
using System.Linq;



5、添加说明  [Description("多选辅助基础资料插件")]


6、添加继承 : AbstractConvertPlugIn


7、复制固定写法的代码,修改字段标志成 上面多选辅助资料的 F_PAEZ_MulAssistantGGB


using System;
using System.Collections.Generic;
using System.ComponentModel;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.App;
using Kingdee.BOS.Core.Metadata.FieldElement;
using System.Linq;
namespace KingdeeRSS.BOS.Test.ConverPlug
{
    [Description("多选辅助基础资料插件")]
    public class MulBaseConvPlug : AbstractConvertPlugIn
    {
        public override void AfterConvert(AfterConvertEventArgs e)
        {
            // 找到目标单单据关联主实体
            var targetForm = e.TargetBusinessInfo.GetForm();
            if (targetForm.LinkSet == null
                || targetForm.LinkSet.LinkEntitys == null
                || targetForm.LinkSet.LinkEntitys.Count == 0)
            {
                // 目标单未设置关联主实体,无法获取目标单的源单信息,携带不了
                return;
            }
            // 关联主实体
            Entity entity = e.TargetBusinessInfo.GetEntity(
                targetForm.LinkSet.LinkEntitys[0].ParentEntityKey);
            // 关联Link子实体
            Entity linkEntity = e.TargetBusinessInfo.GetEntity(
                targetForm.LinkSet.LinkEntitys[0].Key);
            // 收集全部源单内码
            HashSet<long> srcBillIds = new HashSet<long>();
            // Dictionary(目标单索引, HashSet(源单内码))
            Dictionary<int, HashSet<long>> dctDataIndexToSrcBillId = new Dictionary<int, HashSet<long>>();
            var entryRows = e.Result.FindByEntityKey(entity.Key);
            foreach (var entryRow in entryRows)
            {
                int dataIndex = entryRow.DataEntityIndex;
                if (dctDataIndexToSrcBillId.ContainsKey(dataIndex) == false)
                {
                    dctDataIndexToSrcBillId.Add(dataIndex, new HashSet<long>());
                }
var linkRows = linkEntity.DynamicProperty.GetValue(entryRow.DataEntity) as DynamicObjectCollection;
                foreach (var linkRow in linkRows)
                {
                    long srcBillId = Convert.ToInt64(linkRow["SBillId"]);
                    if (srcBillIds.Contains(srcBillId) == false)
                    {
                        srcBillIds.Add(srcBillId);
                    }
                    // 记录每条目标单,其引用的源单集合
                    if (dctDataIndexToSrcBillId[dataIndex].Contains(srcBillId) == false)
                    {
                        dctDataIndexToSrcBillId[dataIndex].Add(srcBillId);
                    }
                }
            }
            // 读取源单上的多选辅助资料信息
            IViewService viewService = ServiceHelper.GetService<IViewService>();
            // 仅加载源单内码、多选辅助资料内码
            List<SelectorItemInfo> selectItems = new List<SelectorItemInfo>();
            selectItems.Add(new SelectorItemInfo(e.SourceBusinessInfo.GetForm().PkFieldName));
            selectItems.Add(new SelectorItemInfo("F_PAEZ_MulAssistantGGB"));
            string filter = string.Format("{0} IN ({1})",
                            e.SourceBusinessInfo.GetForm().PkFieldName,
                            string.Join(",", srcBillIds));
            var srcObjs = viewService.Load(this.Context,
                        e.SourceBusinessInfo, selectItems,
                        OQLFilter.CreateHeadEntityFilter(filter));
            // 收集源单上全部的辅助资料内码
MulAssistantField sourceFld = e.SourceBusinessInfo.GetField("F_PAEZ_MulAssistantGGB") as MulAssistantField;
            HashSet<string> assIds = new HashSet<string>();
            // Dictionary(源单内码, HashSet(辅助资料内码))
            Dictionary<long, HashSet<string>> dctSrcBillIdToAssIds = new Dictionary<long, HashSet<string>>();
            foreach (var srcObj in srcObjs)
            {
                long srcBillId = Convert.ToInt64(srcObj[0]);
                var srcAssiRows = sourceFld.RefEntityDynamicProperty.GetValue(srcObj) as DynamicObjectCollection;
                foreach (var srcAssiRow in srcAssiRows)
                {
                    string assId = Convert.ToString(sourceFld.RefIDDynamicProperty.GetValue(srcAssiRow));
                    if (assIds.Contains(assId) == false)
                    {
                        assIds.Add(assId);
                    }
                    if (dctSrcBillIdToAssIds.ContainsKey(srcBillId) == false)
                    {
                        dctSrcBillIdToAssIds.Add(srcBillId, new HashSet<string>());
                    }
                    if (dctSrcBillIdToAssIds[srcBillId].Contains(assId) == false)
                    {
                        dctSrcBillIdToAssIds[srcBillId].Add(assId);
                    }
                }
            }
            // 加载辅助资料详情
MulAssistantField targetFld = e.TargetBusinessInfo.GetField("F_PAEZ_MulAssistantGGB") as MulAssistantField;
            var assObjs = viewService.Load(
                this.Context,
                (from p in assIds select (object)p).ToArray(),
                targetFld.RefFormDynamicObjectType);
            // Dictionary(辅助资料内码, 辅助资料数据包)
            Dictionary<string, DynamicObject> dctAssObjs = new Dictionary<string, DynamicObject>();
            foreach (var assObj in assObjs)
            {
                string assId = Convert.ToString(assObj[0]);
                dctAssObjs.Add(assId, assObj);
            }
            // 向目标单填写辅助资料
            var headObjs = e.Result.FindByEntityKey(targetFld.EntityKey);
            foreach (var item in dctDataIndexToSrcBillId)
            {
                int dataIndex = item.Key;
                DynamicObject headObj = headObjs[dataIndex].DataEntity;
        var mulAssiRows = targetFld.RefEntityDynamicProperty.GetValue(headObj) as DynamicObjectCollection;
                foreach (var srcBillId in item.Value)
                {
                    if (dctSrcBillIdToAssIds.ContainsKey(srcBillId) == false) continue;
                    foreach (var assId in dctSrcBillIdToAssIds[srcBillId])
                    {
                        if (dctAssObjs.ContainsKey(assId) == false) continue;
                        DynamicObject newAssiRow = new DynamicObject(targetFld.RefEntityDynamicObjectType);
                        mulAssiRows.Add(newAssiRow);
                        targetFld.RefIDDynamicProperty.SetValue(newAssiRow, assId);
                        targetFld.DynamicProperty.SetValue(newAssiRow, dctAssObjs[assId]);
                    }
                }
            }
        }
    }
}



8、和上一节区别,MulBaseDataField修改类型为 MulAssistantField



9、注册插件,具体操作请参考上一节


10、最终效果,采购订单下推收料通知单,带出多选辅助资料


image.png


类似帖子


单据转换插件 Dave

https://vip.kingdee.com/article/229916094369502720



视频

链接:https://pan.baidu.com/s/1Mc7EBD62o0bjsAAcXslFYA

提取码:KISS



总目录链接

https://vip.kingdee.com/article/6499387201459123


发布于 金蝶云星空BOS开发交流圈 社群

图标赞 17
17人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!