业务流.常见问题.单据删除后重新操作导致的异常问题

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

业务流.常见问题.单据删除后重新操作导致的异常问题

【问题】单据删除后重新操作导致的异常问题 ![image.webp](/download/010003bb3fde05e2431a8d6a9e4879b5cf8d.webp) ![image.webp](/download/0100bba933d68c11425ea0e30cc9d96b3666.webp) 【场景1】 使用数据包接口做单据操作,其中数据包是脏的(非最新的数据包),数据使用包接口平台不会做任何校验,容易导致数据异常 (0)系统中的标准单据和列表的提交、审核、反审核、删除操作,均使用单据单据内码,在操作是会通过数据库取对应单据数据,验证单据是否存在 ![20240207 1107.webp](/download/01004f593d1bbf2a4b5cb38aeec20db1046b.webp) (1)使用传入的数据包,平台不做校验 异常场景的演示代码 ```csharp using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using System.Collections.Concurrent; using System.Collections.Generic; namespace DynamicFormPlugIn.Test { [Kingdee.BOS.Util.HotUpdate] public class TestFormPlugIn_UnAudit : AbstractBillPlugIn { public StepManager manager; public override void OnInitializeService(InitializeServiceEventArgs e) { manager = new StepManager(this.Context); } public override void BarItemClick(BarItemClickEventArgs e) { if (string.Equals("tb_StepDo", e.BarItemKey, System.StringComparison.OrdinalIgnoreCase)) { manager.Do(); } } } public class StepManager { private List<IStep> stepList = new List<IStep>(); public ConcurrentDictionary<object, object> Options = new ConcurrentDictionary<object, object>(); public readonly Kingdee.BOS.Context Context; private int stepIdx = 0; public StepManager(Kingdee.BOS.Context ctx) { Context = ctx; Init(); } public void Init() { Options["BillId"] = 107452; string formId = "PUR_PurchaseOrder"; Options["FormId"] = formId; var businessInfo = (Kingdee.BOS.ServiceHelper.MetaDataServiceHelper.Load(Context, formId) as Kingdee.BOS.Core.Metadata.FormMetadata).BusinessInfo; Options["BusinessInfo"] = businessInfo; stepList = new List<IStep>() { new LoadBill(this), new UnAuditById(this), new DeleteById(this), new UnAuditByDataObj(this), //new SaveByDataObj(this), }; } public void Do() { if (stepIdx < stepList.Count) { stepList[stepIdx].Do(); ++stepIdx; } } } public abstract class IStep { public readonly StepManager Manager; public Kingdee.BOS.Context Context { get { return Manager.Context; } } public IStep(StepManager manager){ Manager = manager; } public abstract void Do(); } public class LoadBill : IStep { public LoadBill(StepManager manager) : base(manager) { } public override void Do() { object billId = Manager.Options["BillId"]; var businessInfo = Manager.Options["BusinessInfo"] as Kingdee.BOS.Core.Metadata.BusinessInfo; var billObjs = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Load(Context, new object[] { billId }, businessInfo.GetDynamicObjectType()); if (billObjs != null && billObjs.Length > 0) { Manager.Options["BillObj"] = billObjs[0]; } } } public class UnAuditById : IStep { public UnAuditById(StepManager manager) : base(manager) { } public override void Do() { object billId = Manager.Options["BillId"]; var businessInfo = Manager.Options["BusinessInfo"] as Kingdee.BOS.Core.Metadata.BusinessInfo; var result = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.UnAudit(Context, businessInfo, new object[] { billId }, null); Manager.Options["UnAuditById_Result"] = result; } } public class DeleteById: IStep { public DeleteById(StepManager manager) : base(manager) { } public override void Do() { object billId = Manager.Options["BillId"]; var businessInfo = Manager.Options["BusinessInfo"] as Kingdee.BOS.Core.Metadata.BusinessInfo; var result = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Delete(Context, businessInfo, new object[] { billId }, null); Manager.Options["DeleteById_Result"] = result; } } public class UnAuditByDataObj : IStep { public UnAuditByDataObj(StepManager manager) : base(manager) { } public override void Do() { object billId = Manager.Options["BillId"]; var billObj = Manager.Options["BillObj"] as Kingdee.BOS.Orm.DataEntity.DynamicObject; var businessInfo = Manager.Options["BusinessInfo"] as Kingdee.BOS.Core.Metadata.BusinessInfo; var result = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.UnAudit(Context, businessInfo, new Kingdee.BOS.Orm.DataEntity.DynamicObject[] { billObj }, null); Manager.Options["UnAuditByDataObj_Result"] = result; } } public class SaveByDataObj : IStep { public SaveByDataObj(StepManager manager) : base(manager) { } public override void Do() { object billId = Manager.Options["BillId"]; var billObj = Manager.Options["BillObj"] as Kingdee.BOS.Orm.DataEntity.DynamicObject; var businessInfo = Manager.Options["BusinessInfo"] as Kingdee.BOS.Core.Metadata.BusinessInfo; var result = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Save(Context, businessInfo, new Kingdee.BOS.Orm.DataEntity.DynamicObject[] { billObj }, null); Manager.Options["SaveByDataObj_Result"] = result; } } } ``` (2)此问题的核心是传入的数据是假数据,非并发问题。 平台层面:可以在操作上增加一个通用校验器,验证单据是否存在处理(仅能验证单据是否存在); 二开层面:使用数据包操作的通常都是业务上需要做连续操作,为了避免每次使用内码获取数据包的性能损耗问题,因此只会获取一次,而后调用提交审核、反审核删除之类的逻辑; 这类二开场景最好是在获取单据数据包前引入系统的网控,等连续操作完成后解除网控; 避免在这段操作中间有人获取了数据包操作,导致数据库的数据包和提交的数据包不匹配的问题 备注:后续版本平台会记录传入数据包操作的场景 ![20240207 1445.webp](/download/01002a9d0a7aeb7a4266993ae550a2c187de.webp) ![20240207 1450.webp](/download/01004d643250477b4e79b2b0c42c9da3a883.webp) ```python import clr clr.AddReference("mscorlib") clr.AddReference("System.Data") #本次引用 clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.App.Core") from System import * from System.Collections.Generic import * from System.Data import * ##本次引用 from Kingdee.BOS.Core.DynamicForm.PlugIn import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * from Kingdee.BOS.Core.Metadata.FormValidationElement import * from Kingdee.BOS.App.Core.Validation import * from Kingdee.BOS.Core.Validation import * def OnAddValidators(e): billExistValidation = BillExistValidation(); validator = billExistValidation.CreateValidator(); validatorName = validator.GetType().Name; exists = False; for idx in range(len(e.Validators)): curValidator = e.Validators[idx]; if curValidator == None or curValidator.GetType().Name != validatorName: continue; exists = True; break; if(exists == False): e.Validators.Add(validator); ```

楼主能否提供一个kettle连接云星空查询单据并写到本地sql server的完整的ktr项目文件,谢谢


非常好,插件同时提供dll与python,这样更亲民了。

业务流.常见问题.单据删除后重新操作导致的异常问题

【问题】单据删除后重新操作导致的异常问题![image.webp](/download/010003bb3fde05e2431a8d6a9e4879b5cf8d.webp)![image.webp](/download/...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息