业务流.常见问题.取消事务导致的数据异常问题

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

业务流.常见问题.取消事务导致的数据异常问题

【常见问题】 单据下查提示单据不存在,且打开上机操作日志仅有调用下推操作的记录,没有下游单据保存、删除的记录。 ![image.webp](/download/01004098cd6a8b794880bfc3ceabbac99179.webp) ![image.webp](/download/0100892411b499b6448c82131baa063df4e1.webp) 【原因】因取消事务导致的数据不一致性问题; 操作事务被取消,操作中的执行顺序:BeginOperationTransaction->创建源单关联关系->反写源单并保存源单->保存当前单据数据包->调用操作上的服务(如自动下推)->EndOperationTransaction 在执行过程中如果出现异常,不会回滚保存的关联关系数据 【案例演示】采购申请单到采购订单保存,采购订单保存因反写异常中断事务,但是关联关系保存成功 (0)采购申请单增加复选框字段,用作反写规则,设置超额控制 ![image.webp](/download/01008a3d7c2d6aa74554bbe33a35f7398641.webp) ![image.webp](/download/0100a70056d9d37849d58fe96087554ff7b0.webp) (1)采购订单,表单插件或者服务插件,增加取消事务的逻辑 ![image.webp](/download/0100283c992a124b469eba7237356be5465a.webp) ```csharp using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using System; namespace DynamicFormPlugIn.Operation { [Kingdee.BOS.Util.HotUpdate] [System.ComponentModel.Description("操作服务插件,取消事务")] public class OperationServicePlugIn_CancelTransaction : AbstractOperationServicePlugIn { public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e) { //是否启用事务,设置为false 不启用 e.SupportTransaction = false; } } [Kingdee.BOS.Util.HotUpdate] [System.ComponentModel.Description("表单插件,取消事务")] public class FormPlugIn_CancelTransaction : AbstractBillPlugIn { public override void BeforeDoOperation(BeforeDoOperationEventArgs e) { if (string.Equals(e.Operation.FormOperation.Operation, "Save", StringComparison.OrdinalIgnoreCase)) { //是否忽略事务,设置为true 代表忽略 e.Option.SetVariableValue("IgnoreTransaction", true); } } } } ``` (2)运行效果 ![image.webp](/download/0100d6422576e5e940cb934de43f0ea0ada0.webp) ![20240222 1527.webp](/download/0100b238ff7d7a7c4bbe90319e0b8af01161.webp) 【说明】强烈不建议外部使用取消事务的逻辑,容易导致数据不一致的问题; 如果强制要使用该参数,需要按以下逻辑记录 (0)上机操作日志中增加记录,标记对应单据的操作为取消事务的逻辑,以及取消标记的代码地址 (1)操作失败时写上机操作日志,标记操作失败,以便排查数据不一致的原因 ![image.webp](/download/0100a3362e287a62409faf585119683243f3.webp) ![image.webp](/download/010007b065a8320f4cd2a35704e9028d8737.webp) ```csharp using Kingdee.BOS.Core.Bill.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Log; using Kingdee.BOS.Util; using System; using System.Collections.Generic; namespace DynamicFormPlugIn.Operation { [Kingdee.BOS.Util.HotUpdate] [System.ComponentModel.Description("操作服务插件,登记是否取消事务了")] public class OperationServicePlugIn_LogCancelTransaction : AbstractOperationServicePlugIn { public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e) { if (e.SupportTransaction == false) { List<LogObject> lstLogObject = new List<LogObject>(); var subSysId = this.Option.GetVariableValue("BOS_Operation_OpenParameter_SubSystemId", string.Empty); var logObj = new LogObject() { Description = "当前操作事务被取消", OperateName = this.FormOperation.OperationName, ObjectTypeId = this.BusinessInfo.GetForm().Id, SubSystemId = subSysId.IsNullOrEmptyOrWhiteSpace() ? this.BusinessInfo.GetForm().SubsysId : subSysId, Environment = OperatingEnvironment.BizOperate, }; lstLogObject.Add(logObj); Kingdee.BOS.ServiceHelper.LogServiceHelper.BatchWriteLog(this.Context, lstLogObject); } } } } ``` ```python import clr clr.AddReference("mscorlib") clr.AddReference("System.Data") #本次引用 clr.AddReference("Kingdee.BOS") clr.AddReference("Kingdee.BOS.Core") clr.AddReference("Kingdee.BOS.ServiceHelper") 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.Log import * from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Util import * def OnPrepareOperationServiceOption(e): if e.SupportTransaction == True: return; lstLogObject = List[LogObject](); logObj = LogObject(); logObj.Description = '当前操作事务被取消py'; logObj.OperateName = this.FormOperation.OperationName; logObj.ObjectTypeId = this.BusinessInfo.GetForm().Id; logObj.SubSystemId = this.BusinessInfo.GetForm().SubsysId; logObj.Environment = OperatingEnvironment.BizOperate; lstLogObject.Add(logObj); LogServiceHelper.BatchWriteLog(this.Context, lstLogObject); ```

业务流.常见问题.取消事务导致的数据异常问题

【常见问题】单据下查提示单据不存在,且打开上机操作日志仅有调用下推操作的记录,没有下游单据保存、删除的记录。![image.webp](/downloa...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息