说明:由于使用决策表体是子表体,因此到不良品处理单字段的携带不能通过配置单据转换字段映射实现,必须通过二开单据转换插件实现,本例以检验单使用决策表体二开文本类型字段携带到不良品处理单表体文本字段为例:
1、检验单使用决策表体二开增加文本类型字段:
2、不良品处理单表体二开增加文本类型字段:
3、二开单据转换插件继承BaseBillConvertServicePlugIn,挂在检验单到不良品处理单单据转换规则插件策略中,注意注册在标准产品单据转换插件之后,在AfterConvert事件中根据不良品处理单分录的源单使用决策分录内码去获取检验单使用决策表体对应的二开字段的值,然后与不良品处理单表体的源单使用决策分录内码进行匹配,将二开字段的值赋值给不良品处理单分录的二开字段;
4、示例代码如下:
using Kingdee.BOS.Core;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.Core.MFG.EnumConst;
using Kingdee.K3.MFG.App.ConvertPlugIn;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.K3.Core.MFG.EntityHelper;
using Kingdee.BOS.Util;
using Kingdee.BOS;
using Kingdee.K3.MFG.App;
namespace Kingdee.K3.MFG.QM.App.BillConvertServicePlugIn
{
public class test : BaseBillConvertServicePlugIn
{
public override void AfterConvert(BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e)
{
base.AfterConvert(e);
ExtendedDataEntity[] headDatas = e.Result.FindByEntityKey(CONST_QM_DefectProcessBill.CONST_FBillHead.ENTITY_FBillHead);
foreach (ExtendedDataEntity headData in headDatas)
{
DynamicObjectCollection dpEntrys =
headData.DataEntity.GetDynamicValue<DynamicObjectCollection>(CONST_QM_DefectProcessBill.CONST_FEntity.ENTITY_ORM_Entity);
List<long> tempSrcDetailIds =
dpEntrys.Where(en => en.GetDynamicValue<long>(CONST_QM_DefectProcessBill.CONST_FEntity.ORM_SourceBillDetailId) > 0)
.Select(en => en.GetDynamicValue<long>(CONST_QM_DefectProcessBill.CONST_FEntity.ORM_SourceBillDetailId)).ToList();
if (tempSrcDetailIds.IsEmpty()) continue;
DynamicObjectCollection result = this.GetSrcPolicyDatas(this.Context, tempSrcDetailIds);
if (result.IsEmpty()) continue;
Dictionary<long, IGrouping<long, DynamicObject>> srcPolicyInfos = result.GroupBy(o => o.GetDynamicValue<long>("FDETAILID")).ToDictionary(d => d.Key);
foreach(DynamicObject entry in dpEntrys)
{
long srcDetailId = entry.GetDynamicValue<long>(CONST_QM_DefectProcessBill.CONST_FEntity.ORM_SourceBillDetailId);
IGrouping<long, DynamicObject> matchInfo = null;
if (srcPolicyInfos.TryGetValue(srcDetailId, out matchInfo))
{
entry.SetDynamicObjectItemValue("Test", matchInfo.FirstOrDefault().GetDynamicValue<string>("FTEST"));
}
}
}
}
private DynamicObjectCollection GetSrcPolicyDatas(Context ctx, List<long> srcDetailIds)
{
StringBuilder sbSql = new StringBuilder();
sbSql.AppendLine(" SELECT TIBPD.FDETAILID, TIBPD.FTEST ");
sbSql.AppendLine(" FROM T_QM_IBPOLICYDETAIL TIBPD ");
sbSql.AppendLine(" INNER JOIN TABLE(fn_StrSplit(@FENTRYIDA, ',',1)) T1 ON TIBPD.FDETAILID=T1.FID ");
List<SqlParam> sqlParam = new List<SqlParam>();
sqlParam.Add(new SqlParam("@FENTRYIDA", KDDbType.udt_inttable, srcDetailIds.Distinct().ToArray()));
return AppServiceContext.DbUtils.ExecuteDynamicObject(ctx, sbSql.ToString(), sqlParam.ToArray());
}
}
}
推荐阅读