From 4fc1be40676b5f9928da3a83bdb1c215d0584ae9 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 06 四月 2026 11:15:13 +0800
Subject: [PATCH] Merge branch 'dev' of http://115.159.85.185:8098/r/SuZhouGuanHong/ShanMeiXinNengYuan into dev
---
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