服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-08-07 6c9535734ff0bd5e957620be0247689d6e2ca252
Tiger.Business.MES/Transaction/Position.cs
@@ -17,7 +17,7 @@
    /// <summary>
    /// MES岗位事务
    /// </summary>
    public class Position : MESTransactionBase, IPosition
    public class Position : MESTransactionBase, IPosition, ICloneable
    {
        public IPosition Init(string id, string apiHost, string userCode, string postCode)
        {
@@ -72,6 +72,7 @@
        /// </summary>
        public bool NeedTemporaryStoreDBCommitAction { get; set; } = false;
        protected List<Action> DBCommitList { get; set; } = new();
        protected List<Position> NodeCommitList { get; set; } = new();
        #endregion Propertys & Variables
@@ -329,6 +330,15 @@
            return result;
        }
        public object Clone()
        {
            var newObject = this.MemberwiseClone() as Position;
            newObject.Steps = Steps.Clone();
            newObject.CurWipSNs = CurWipSNs.Clone();
            return newObject;
        }
        /// <summary>
        /// 保存工步的数据库提交操作到数据库
        /// </summary>
@@ -346,15 +356,15 @@
                NeedTemporaryStoreDBCommitAction = false;
                var dbTran = GetCommitDB().UseTran(() =>
               {
                   //在同一个事务中保存所有工步的数据
                   foreach (var action in DBCommitList)
                   {
                {
                    //在同一个事务中保存所有工步的数据
                    foreach (var action in DBCommitList)
                    {
                        action.Invoke();
                   }
               });
               if (dbTran.IsSuccess)
               {
                    }
                });
                if (dbTran.IsSuccess)
                {
                    //保存成功则清空提交操作列表
                    DBCommitList.Clear();
                }
@@ -364,6 +374,42 @@
                    throw dbTran.ErrorException;
                }
            }
            //if (NeedTemporaryStoreDBCommitAction)
            //{
            //    NodeCommitList.Add(this.Clone() as Position);
            //}
            //else
            //{
            //    //保存成功则清空提交操作列表
            //    foreach (var item in NodeCommitList)
            //    {
            //        item?.DoSaveToDB();
            //        item?.Dispose();
            //    }
            //    DoSaveToDB();
            //    NodeCommitList.Clear();
            //}
        }
        protected void DoSaveToDB()
        {
            var dbTran = GetCommitDB().UseTran(() =>
            {
                //在同一个事务中保存所有工步的数据
                foreach (var step in Steps.OrderBy(q => q.Sequence))
                {
                    step.DBSubmitAction.Invoke();
                }
            });
            if (!dbTran.IsSuccess)
            {
                //抛出异常
                throw dbTran.ErrorException;
            }
        }
        /// <summary>