林豪 左 2 年之前
父節點
當前提交
328414a015

+ 3 - 10
ServiceCenter/SqlSugars/SqlSugarHelper.cs

@@ -92,28 +92,21 @@ namespace ServiceCenter.SqlSugars
         /// </summary>
         /// <param name="act"></param>
         /// <exception cref="Exception"></exception>
-        public static bool Do(Action<SqlSugarHelper> act)
+        public static void Do(Action<SqlSugarHelper> act)
         {
-            if (_Db == null)
-            {
-                Console.WriteLine("请调用[SqlSugarHelper.SetDb]方法设置设置数据库连接");
-                return false;
-            }
-
+            if (_Db == null) throw new Exception("请调用[SqlSugarHelper.SetDb]方法设置设置数据库连接");
             var db = new SqlSugarHelper();
-
             try
             {
                 db.Connect.BeginTran();//开始事务
                 act(db);//执行委托
                 db.Connect.CommitTran();//提交事务
-                return true;
             }
             catch (Exception ex)
             {
                 db.Connect.RollbackTran();//回滚事务
                 //Console.WriteLine($"事务回滚记录:{ex.Message}:{ex.StackTrace}");
-                return false;
+                throw new Exception(ex.Message);
             }
         }
     }

+ 35 - 1
WCS.WorkEngineering/WebApi/Models/AGV/Request/AgvCallbackRequest.cs

@@ -1,4 +1,6 @@
-namespace WCS.WorkEngineering.WebApi.Models.AGV.Request
+using WCS.Service;
+
+namespace WCS.WorkEngineering.WebApi.Models.AGV.Request
 {
     public class AgvCallbackRequest
     {
@@ -111,5 +113,37 @@
         /// 设备编号
         /// </summary>
         public string eqpCode { get; set; }
+
+        /// <summary>
+        /// 执行堆垛机任务 单例锁
+        /// </summary>
+        /// <param name="act"></param>
+        public void EX(Action<AgvCallbackRequest> act)
+        {
+            var key = $"WCS:Lock:{act.}";
+
+            try
+            {
+                if (ProtocolProxy.YG150Redis.Get(key) != null) throw new WarnException($"[{Entity.CODE}]--触发并发管控");
+                ProtocolProxy.YG150Redis.Set(key, Entity.CODE);
+                act(this);
+            }
+            catch (DoException ex)
+            {
+                ex.DoExceptionEX(Entity);
+            }
+            catch (WarnException ex)
+            {
+                ex.WarnExceptionEX(Entity);
+            }
+            catch (Exception ex)
+            {
+                ex.ExceptionEx(Entity);
+            }
+            finally
+            {
+                ProtocolProxy.YG150Redis.Del(key);
+            }
+        }
     }
 }