From e25dc0d8fad5a2362bf75cf5ca9f26a0fe6c674c Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 26 三月 2026 11:28:15 +0800
Subject: [PATCH] feat(WMS): 增强日志配置与添加事务处理支持
---
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