From 6beaccff985159015a9cc849bea66f5304d40fc2 Mon Sep 17 00:00:00 2001
From: 晚什么安 <2902889775@qq.com>
Date: 星期三, 08 四月 2026 17:37:32 +0800
Subject: [PATCH] !1 Update README.md
---
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