From b698a2085fd090e90abedb1e91266ec496574b29 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 16 四月 2026 23:31:35 +0800
Subject: [PATCH] 1

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs
index 6a89499..da3bb86 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs
@@ -36,6 +36,51 @@
 
         public ISqlSugarClient Db => BaseDal.Db;
 
+        protected async Task<WebResponseContent> ExecuteWithinTransactionAsync(Func<Task<WebResponseContent>> operation)
+        {
+            var db = Db as SqlSugarClient;
+            if (db == null)
+            {
+                return WebResponseContent.Instance.Error("Database context does not support transactions");
+            }
+
+            var ownsTransaction = db.Ado.Transaction == null;
+            try
+            {
+                if (ownsTransaction)
+                {
+                    db.BeginTran();
+                }
+
+                var result = await operation();
+                if (result?.Status == true)
+                {
+                    if (ownsTransaction)
+                    {
+                        db.CommitTran();
+                    }
+
+                    return result;
+                }
+
+                if (ownsTransaction)
+                {
+                    db.RollbackTran();
+                }
+
+                return result ?? WebResponseContent.Instance.Error("Transaction failed");
+            }
+            catch
+            {
+                if (ownsTransaction)
+                {
+                    db.RollbackTran();
+                }
+
+                throw;
+            }
+        }
+
         private PropertyInfo[] _propertyInfo { get; set; } = null;
         public PropertyInfo[] TProperties
         {

--
Gitblit v1.9.3