业务流.二开案例.调整下游单据的link实体实现关联和反写
【场景】调整下游单据的link实体实现关联和反写
【二开案例】
(0)定义下游单据的关联实体配置,用作id存储关联关系的存放表
![image.webp](/download/010076a99dd78bbb4f62b9f9a072b3ecbe86.webp)
(1)定义转换规则
转换规则是必须的,因为关联关系中需要记录转换规则id
![image.webp](/download/01001d3d6d18854b45e3bb2dce25ec5dab52.webp)
(2)插件代码,实现调整link并重新保存实现关联和反写
![image.webp](/download/010024a23d1a45ce4f30b62c23ca51b75b4f.webp)
```csharp
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
namespace DynamicFormPlugIn.WriteBack
{
[Kingdee.BOS.Util.HotUpdate]
public class FormSamplePlugIn_ChangeLink : AbstractBillPlugIn
{
public override void BarItemClick(BarItemClickEventArgs e)
{
if (!string.Equals(e.BarItemKey, "BHR_tbButton", StringComparison.OrdinalIgnoreCase))
{
return;
}
ChangeLink();
}
private readonly string EntityKey = "FEntity";
private readonly string FieldKey = "F_BHR_LinkInfo";
private void ChangeLink()
{
Entity entity = this.View.BillBusinessInfo.GetEntity(EntityKey);
DynamicObjectCollection objColl = this.Model.GetEntityDataObject(entity);
if (objColl == null)
return;
bool hasChange = false;
foreach(var entityRowObj in objColl)
{
string linkInfo = ObjectUtils.Object2String(entityRowObj[FieldKey]);
if (linkInfo.IsNullOrEmptyOrWhiteSpace())
continue;
hasChange = true;
string[] info = linkInfo.Split(',');
string srcBillNo = info[0];//源单编号
int seq = ObjectUtils.Object2Int(info[1]);//分录序号行
ChangeRowLink(entityRowObj, srcBillNo, seq);
entityRowObj[FieldKey] = string.Empty;
}
//将更新的link信息保存到数据库,并计算单据的反写值
if (hasChange)
{
//如果没有界面就调用BusinessDataServiceHelper.Save
this.View.Model.Save();
this.View.ShowMessage("根据自定义信息重新关联完成");
}
}
private void ChangeRowLink(DynamicObject rowObj, string srcbillNo, int seq)
{
const string srcFormId = "kc0c27c005bcc4df9a8172dff6c36f5c4";//关联源单实体
const string srcEntityKey = "FEntity";//关联的源单实体
const string srcBillNoKey = "FBillNo";
FormMetadata metaData = Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load(this.Context, srcFormId) as FormMetadata;
if (metaData == null)
return;
Field field = metaData.BusinessInfo.GetField(srcBillNoKey);
Entity srcEntity = metaData.BusinessInfo.GetEntity(srcEntityKey);
if (field == null || srcEntity == null)
return;
string entityIdKey = string.Concat(srcEntity.Key, "_", srcEntity.EntryPkFieldName);
string seqKey = string.Concat(srcEntity.Key, "_", srcEntity.SeqFieldKey);
//<1>根据单据编号和序号,获取到需要关联的单据内码 和 分录内码
QueryBuilderParemeter query = new QueryBuilderParemeter();
query.BusinessInfo = metaData.BusinessInfo;
List<SelectorItemInfo> selectItems = new List<SelectorItemInfo>();
selectItems.Add(new SelectorItemInfo(metaData.BusinessInfo.GetForm().PkFieldName));
selectItems.Add(new SelectorItemInfo(field.Key));
selectItems.Add(new SelectorItemInfo(entityIdKey));
selectItems.Add(new SelectorItemInfo(seqKey));
query.SelectItems = selectItems;
query.FilterClauseWihtKey = string.Format("{0} = '{1}' and {2} = {3}", srcBillNoKey, srcbillNo, seqKey, seq);
var objs = Kingdee.BOS.ServiceHelper.QueryServiceHelper.GetDynamicObjectCollection(this.Context, query);
if (objs == null || objs.Count <= 0)
return;
long srcBillId = ObjectUtils.Object2Int(objs[0][metaData.BusinessInfo.GetForm().PkFieldName]);
long srcEntityId = ObjectUtils.Object2Int(objs[0][entityIdKey]);
DynamicObjectCollection linkObjColl = rowObj["FEntity_Link"] as DynamicObjectCollection;
if (linkObjColl == null)
return;
//清除历史的关联信息
linkObjColl.Clear();
//todo 仅绑定源单分录,link中还存在控制字段逻辑,针对合并的反写,建议按照下推的数据逻辑调整link的携带量
DynamicObject linkObj = new DynamicObject(linkObjColl.DynamicCollectionItemPropertyType);
linkObjColl.Add(linkObj);
linkObj["SBillId"] = srcBillId;
linkObj["Sid"] = srcEntityId;
linkObj["RuleId"] = "2b40874f-d498-426f-9e45-537b59ea4e28";//转换规则id
var td = Kingdee.BOS.ServiceHelper.BusinessFlowServiceHelper.LoadTableDefine(this.Context, srcFormId, srcEntityKey);//转换规则id
linkObj["STableName"] = td.TableNumber;
}
}
}
```
【效果】
![20231012 1720.webp](/download/0100a43064158c484267b60f946f12cdb8d7.webp)
【补充说明】
(0)link数据包结构
![image.webp](/download/0100bf6e075120e24de189567b43e737463e.webp)
字段含义参考
[WebAPI保存接口实现上下游关联](https://wenku.my7c.com/article/171055?productLineId=1)
(1)建议link数据包的处理与直接下推保存的保持一致,以确保数据逻辑和标准下推一致
(2)业务流程图id参考
[业务流程.案例.Api关联业务流程图](https://wenku.my7c.com/article/372766828033884160?productLineId=1)
(3)源单编号和源单类型是单据转换中填入的,按照本案例的场景需要自行处理,填入数据包的值
业务流.二开案例.调整下游单据的link实体实现关联和反写
【场景】调整下游单据的link实体实现关联和反写【二开案例】(0)定义下游单据的关联实体配置,用作id存储关联关系的存放表![image.webp](/do...
点击下载文档
本文2024-09-16 18:17:02发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-21135.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章