【星空-开发】二开插件代码调用下推方法原创
74人赞赏了该文章
1,064次浏览
编辑于2024年04月23日 09:45:24
业务场景:BOS中可以在单据的操作列表中配置自动下推服务来实现自动下推单据,但局限于源单只能基于本单,无法实现其他源单下推,此时就需要二开插件来实现,自定义推单
using Kingdee.BOS.App; using Kingdee.BOS.Contracts; using Kingdee.BOS.Core.DynamicForm.Operation; using Kingdee.BOS.Core.List; using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs; using Kingdee.BOS.Core.Metadata.ConvertElement; using Kingdee.BOS.Orm; using Kingdee.BOS.Util; using Kingdee.BOS; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Common.KingDee.Utils.Bill; using Kingdee.BOS.Orm.DataEntity; namespace Demo { public class Demo { //调用示例 public void main() { //销售订单下推发货通知单示例 ConvertOperationResult inspecResult = BillProcess.DoPush(this.Context, "SAL_SaleOrder", "SAL_DELIVERYNOTICE", "销售订单内码", "发货通知单单据类型(可以为空,会取默认)"); DynamicObject[] inspecDataObjects = (from p in inspecResult.TargetDataEntities select p.DataEntity).ToArray();//linq拿到下推的数据包 //循环自定义处理下推数据包 foreach (var inspecData in inspecDataObjects) { xxxxx } } /// <summary> /// 下推方法 /// </summary> /// <param name="ctx">上下文</param> /// <param name="sourceFormId">源单元数据标识</param> /// <param name="targetFormId">目标单元数据标识</param> /// <param name="sourceBillIds">源单fid</param> /// <param name="targetBillTypeId">目标单单据类型</param> /// <returns>返回下推结果</returns> public ConvertOperationResult DoPush(Context ctx, string sourceFormId, string targetFormId, List<long> sourceBillIds, string targetBillTypeId = "") { IConvertService service = ServiceHelper.GetService<IConvertService>(); List<ConvertRuleElement> convertRules = service.GetConvertRules(ctx, sourceFormId, targetFormId); if (convertRules == null || convertRules.Count == 0) { throw new KDBusinessException("", $"未找到{sourceFormId}到{targetFormId}之间,启用的转换规则,无法自动下推!"); } ConvertRuleElement rule = convertRules[0];//默认取第一行 foreach (ConvertRuleElement item in convertRules)//遍历判断是否默认规则,取默认单据转换规则 { if (item.IsDefault) { rule = item; break; } } List<ListSelectedRow> list = new List<ListSelectedRow>(); //取下推数据 默认整单下推 foreach (long sourceBillId in sourceBillIds) { list.Add(new ListSelectedRow(sourceBillId.ToString(), string.Empty, 0, sourceFormId)); } //此参数为自定义的下推参数 Dictionary<string, object> customParams = new Dictionary<string, object>(); PushArgs pushArgs = new PushArgs(rule, list.ToArray()); pushArgs.TargetBillTypeId = targetBillTypeId; pushArgs.TargetOrgId = 0; pushArgs.CustomParams = customParams; PushArgs serviceArgs = pushArgs; ConvertOperationResult convertOperationResult = service.Push(ctx, serviceArgs, OperateOption.Create()); if (ListUtils.IsEmpty(convertOperationResult.TargetDataEntities)) { throw new KDBusinessException("", $"由{sourceFormId}自动下推{targetFormId},没有成功生成数据包,自动下推失败!"); } return convertOperationResult; } } }
更多精彩内容,请查阅如下地址,谢谢
https://vip.kingdee.com/article/518480895951406080?productLineId=1
赞 74
74人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读