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_TaskInfoService/TaskService.cs | 189 ++++++++++++---------
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs | 27 ++
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json | 31 +++
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs | 192 +++++++++++++-------
Code/WMS/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs | 45 +++++
Code/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_MenuService.cs | 26 ++
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj | 7
7 files changed, 357 insertions(+), 160 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
{
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
index a4c4868..5a531aa 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -1,4 +1,5 @@
-锘縰sing WIDESEA_Common.StockEnum;
+锘縰sing SqlSugar;
+using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_DTO.Stock;
using WIDESEA_IStockService;
@@ -51,6 +52,51 @@
}
/// <summary>
+ /// 鍦ㄤ簨鍔′腑鎵ц鎿嶄綔
+ /// </summary>
+ private async Task<WebResponseContent> ExecuteWithinTransactionAsync(Func<Task<WebResponseContent>> operation)
+ {
+ var db = StockInfoService.Repository.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;
+ }
+ }
+
+ /// <summary>
/// 缁勭洏
/// </summary>
public async Task<WebResponseContent> GroupPalletAsync(StockDTO stock)
@@ -72,28 +118,29 @@
Status = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
}).ToList();
- var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
- var result = false;
- if (existingStock != null)
+ return await ExecuteWithinTransactionAsync(async () =>
{
- details.ForEach(d => d.StockId = existingStock.Id);
- result = await StockInfoDetailService.Repository.AddDataAsync(details) > 0;
- if (result) return content.OK("缁勭洏鎴愬姛");
- return content.Error("缁勭洏澶辫触");
- }
+ var existingStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
+ var result = false;
+ if (existingStock != null)
+ {
+ details.ForEach(d => d.StockId = existingStock.Id);
+ result = await StockInfoDetailService.Repository.AddDataAsync(details) > 0;
+ return result ? content.OK("缁勭洏鎴愬姛") : content.Error("缁勭洏澶辫触");
+ }
- var entity = new Dt_StockInfo
- {
- PalletCode = stock.TargetPalletNo,
- WarehouseId = 1,
- StockStatus = 1,
- Creater = "system",
- Details = details
- };
+ var entity = new Dt_StockInfo
+ {
+ PalletCode = stock.TargetPalletNo,
+ WarehouseId = 1,
+ StockStatus = 1,
+ Creater = "system",
+ Details = details
+ };
- result = StockInfoService.Repository.AddData(entity, x => x.Details);
- if (result) return content.OK("缁勭洏鎴愬姛");
- return content.Error("缁勭洏澶辫触");
+ result = StockInfoService.Repository.AddData(entity, x => x.Details);
+ return result ? content.OK("缁勭洏鎴愬姛") : content.Error("缁勭洏澶辫触");
+ });
}
/// <summary>
@@ -101,7 +148,6 @@
/// </summary>
public async Task<WebResponseContent> ChangePalletAsync(StockDTO stock)
{
-
WebResponseContent content = new WebResponseContent();
if (stock == null ||
string.IsNullOrWhiteSpace(stock.TargetPalletNo) ||
@@ -111,44 +157,47 @@
return content.Error("婧愭墭鐩樺彿涓庣洰鏍囨墭鐩樺彿鐩稿悓");
}
- var sourceStock = await StockInfoService.Repository.QueryDataNavFirstAsync(s => s.PalletCode == stock.SourcePalletNo);
- if (sourceStock == null) return content.Error("婧愭墭鐩樹笉瀛樺湪");
-
- var targetStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
- if (targetStock == null)
+ return await ExecuteWithinTransactionAsync(async () =>
{
- var newStock = new Dt_StockInfo
+ var sourceStock = await StockInfoService.Repository.QueryDataNavFirstAsync(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStock == null) return content.Error("婧愭墭鐩樹笉瀛樺湪");
+
+ var targetStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.TargetPalletNo);
+ if (targetStock == null)
{
- PalletCode = stock.TargetPalletNo,
- WarehouseId = sourceStock.WarehouseId,
- StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
- Creater = "system",
- };
+ var newStock = new Dt_StockInfo
+ {
+ PalletCode = stock.TargetPalletNo,
+ WarehouseId = sourceStock.WarehouseId,
+ StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
+ Creater = "system",
+ };
- var newId = StockInfoService.Repository.AddData(newStock);
- if (newId <= 0) return content.Error("鎹㈢洏澶辫触");
+ var newId = StockInfoService.Repository.AddData(newStock);
+ if (newId <= 0) return content.Error("鎹㈢洏澶辫触");
- targetStock = newStock;
- targetStock.Id = newId;
- }
+ targetStock = newStock;
+ targetStock.Id = newId;
+ }
- var serialNumbers = stock.Details.Select(d => d.Channel).Distinct().ToList();
- if (!serialNumbers.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴忓垪鍙�");
+ var serialNumbers = stock.Details.Select(d => d.Channel).Distinct().ToList();
+ if (!serialNumbers.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴忓垪鍙�");
- var detailEntities = StockInfoDetailService.Repository.QueryData(
- d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.InboundOrderRowNo));
- if (!detailEntities.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴撳瓨鏄庣粏");
+ var detailEntities = StockInfoDetailService.Repository.QueryData(
+ d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.InboundOrderRowNo));
+ if (!detailEntities.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴撳瓨鏄庣粏");
- if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎹㈢洏")) <= 0)
- return content.Error("鎹㈢洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+ if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎹㈢洏")) <= 0)
+ return content.Error("鎹㈢洏鍘嗗彶璁板綍淇濆瓨澶辫触");
- if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock, targetStock }, "鎹㈢洏")) <= 0)
- return content.Error("鎹㈢洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+ if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock, targetStock }, "鎹㈢洏")) <= 0)
+ return content.Error("鎹㈢洏鍘嗗彶璁板綍淇濆瓨澶辫触");
- detailEntities.ForEach(d => d.StockId = targetStock.Id);
- var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
- if (!result) return content.Error("鎹㈢洏澶辫触");
- return content.OK("鎹㈢洏鎴愬姛");
+ detailEntities.ForEach(d => d.StockId = targetStock.Id);
+ var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
+ if (!result) return content.Error("鎹㈢洏澶辫触");
+ return content.OK("鎹㈢洏鎴愬姛");
+ });
}
/// <summary>
@@ -160,31 +209,34 @@
if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
return content.Error("婧愭墭鐩樺彿涓嶈兘涓虹┖");
- var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
- if (sourceStock == null) return content.Error("婧愭墭鐩樹笉瀛樺湪");
-
- var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
- if (!serialNumbers.Any())
+ return await ExecuteWithinTransactionAsync(async () =>
{
- serialNumbers = sourceStock.Details
- .Where(x => stock.Details.Any(d => d.Channel == x.InboundOrderRowNo))
- .Select(x => x.SerialNumber)
- .ToList();
- }
+ var sourceStock = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStock == null) return content.Error("婧愭墭鐩樹笉瀛樺湪");
- var detailEntities = StockInfoDetailService.Repository.QueryData(
- d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
- if (!detailEntities.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴撳瓨鏄庣粏");
+ var serialNumbers = stock.Details.Select(d => d.CellBarcode).Distinct().ToList();
+ if (!serialNumbers.Any())
+ {
+ serialNumbers = sourceStock.Details
+ .Where(x => stock.Details.Any(d => d.Channel == x.InboundOrderRowNo))
+ .Select(x => x.SerialNumber)
+ .ToList();
+ }
- if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎷嗙洏")) <= 0)
- return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+ var detailEntities = StockInfoDetailService.Repository.QueryData(
+ d => d.StockId == sourceStock.Id && serialNumbers.Contains(d.SerialNumber));
+ if (!detailEntities.Any()) return content.Error("鏈壘鍒版湁鏁堢殑搴撳瓨鏄庣粏");
- if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "鎷嗙洏")) <= 0)
- return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+ if (await StockInfoDetail_HtyService.Repository.AddDataAsync(CreateDetailHistory(detailEntities, "鎷嗙洏")) <= 0)
+ return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
- var result = await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities);
- if (!result) return content.Error("鎷嗙洏澶辫触");
- return content.OK("鎷嗙洏鎴愬姛");
+ if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "鎷嗙洏")) <= 0)
+ return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
+
+ var result = await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities);
+ if (!result) return content.Error("鎷嗙洏澶辫触");
+ return content.OK("鎷嗙洏鎴愬姛");
+ });
}
/// <summary>
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_MenuService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_MenuService.cs
index 838e81c..b044afa 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_MenuService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_SystemService/Sys_MenuService.cs
@@ -309,6 +309,30 @@
}
}
+ public object x_GetTreeItem(int menuId)
+ {
+ var sysMenu = BaseDal.QueryData(x => x.MenuId == menuId)
+ .Select(
+ p => new
+ {
+ p.MenuId,
+ p.ParentId,
+ p.MenuName,
+ p.Url,
+ p.Auth,
+ p.OrderNo,
+ p.Icon,
+ p.Enable,
+ // 2022.03.26澧炵Щ鍔ㄧ鍔犺彍鍗曠被鍨�
+ MenuType = p.MenuType,
+ p.CreateDate,
+ p.Creater,
+ p.TableName,
+ p.ModifyDate
+ }).FirstOrDefault();
+ return sysMenu;
+ }
+
/// <summary>
/// 缂栬緫鑿滃崟鏃讹紝鑾峰彇鑿滃崟淇℃伅
/// </summary>
@@ -316,7 +340,7 @@
/// <returns></returns>
public object GetTreeItem(int menuId)
{
- return GetTreeItem(menuId);
+ return x_GetTreeItem(menuId);
}
/// <summary>
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index 550c291..20dc592 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -172,18 +172,23 @@
var locationInfo = await _locationInfoService.GetLocationInfo(task.Roadway);
if (locationInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
- locationInfo.LocationStatus = LocationStatusEnum.FreeLock.GetHashCode();
- task.CurrentAddress = task.SourceAddress;
- task.NextAddress = locationInfo.LocationCode;
- task.TargetAddress = locationInfo.LocationCode;
- task.TaskStatus = TaskInStatusEnum.Line_InFinish.GetHashCode();
+ return await ExecuteWithinTransactionAsync(async () =>
+ {
+ locationInfo.LocationStatus = LocationStatusEnum.FreeLock.GetHashCode();
+ task.CurrentAddress = task.SourceAddress;
+ task.NextAddress = locationInfo.LocationCode;
+ task.TargetAddress = locationInfo.LocationCode;
+ task.TaskStatus = TaskInStatusEnum.Line_InFinish.GetHashCode();
- var updateResult = await BaseDal.UpdateDataAsync(task);
- var locationResult = await _locationInfoService.UpdateLocationInfoAsync(locationInfo);
+ var updateTaskResult = await BaseDal.UpdateDataAsync(task);
+ var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(locationInfo);
+ if (!updateTaskResult || !updateLocationResult)
+ {
+ return WebResponseContent.Instance.Error("浠诲姟鏇存柊澶辫触");
+ }
- return WebResponseContent.Instance.OK(
- updateResult && locationResult ? "浠诲姟鏇存柊鎴愬姛" : "浠诲姟鏇存柊澶辫触",
- locationInfo.LocationCode);
+ return WebResponseContent.Instance.OK("浠诲姟鏇存柊鎴愬姛", locationInfo.LocationCode);
+ });
}
catch (Exception ex)
{
@@ -205,23 +210,28 @@
if (location == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
- stockInfo.LocationCode = location.LocationCode;
- stockInfo.LocationId = location.Id;
- stockInfo.OutboundDate = task.Roadway switch
+ if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴斿簱瀛樹俊鎭�");
+
+ return await ExecuteWithinTransactionAsync(async () =>
{
- var r when r.Contains("GW") => DateTime.Now.AddHours(2),
- var r when r.Contains("CW") => DateTime.Now.AddHours(1),
- _ => DateTime.Now
- };
- stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode();
+ stockInfo.LocationCode = location.LocationCode;
+ stockInfo.LocationId = location.Id;
+ stockInfo.OutboundDate = task.Roadway switch
+ {
+ var r when r.Contains("GW") => DateTime.Now.AddHours(2),
+ var r when r.Contains("CW") => DateTime.Now.AddHours(1),
+ _ => DateTime.Now
+ };
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode();
- location.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
+ location.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
- var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
- var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
- if (!updateLocationResult || !updateStockResult)
- return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
- return await CompleteTaskAsync(task);
+ var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
+ var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
+ if (!updateLocationResult || !updateStockResult)
+ return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+ return await CompleteTaskAsync(task);
+ });
}
catch (Exception ex)
{
@@ -242,18 +252,23 @@
var location = await _locationInfoService.GetLocationInfo(task.Roadway, task.SourceAddress);
if (location == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴旂殑璐т綅");
- var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
- stockInfo.LocationId = 0;
- stockInfo.LocationCode = null;
- stockInfo.OutboundDate = DateTime.Now;
+ var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
+ if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴斿簱瀛樹俊鎭�");
- location.LocationStatus = LocationStatusEnum.Free.GetHashCode();
+ return await ExecuteWithinTransactionAsync(async () =>
+ {
+ stockInfo.LocationId = 0;
+ stockInfo.LocationCode = null;
+ stockInfo.OutboundDate = DateTime.Now;
- var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
- var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
- if (!updateLocationResult || !updateStockResult)
- return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
- return await CompleteTaskAsync(task);
+ location.LocationStatus = LocationStatusEnum.Free.GetHashCode();
+
+ var updateLocationResult = await _locationInfoService.UpdateLocationInfoAsync(location);
+ var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
+ if (!updateLocationResult || !updateStockResult)
+ return WebResponseContent.Instance.Error("浠诲姟瀹屾垚澶辫触");
+ return await CompleteTaskAsync(task);
+ });
}
catch (Exception ex)
{
@@ -282,21 +297,24 @@
var stockInfo = await _stockInfoService.GetStockInfoAsync(taskDto.PalletCode);
if (stockInfo == null) return WebResponseContent.Instance.Error("鏈壘鍒板搴斿簱瀛樹俊鎭�");
- stockInfo.LocationCode = targetLocation.LocationCode;
- stockInfo.LocationId = targetLocation.Id;
- stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode();
+ return await ExecuteWithinTransactionAsync(async () =>
+ {
+ stockInfo.LocationCode = targetLocation.LocationCode;
+ stockInfo.LocationId = targetLocation.Id;
+ stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.GetHashCode();
- sourceLocation.LocationStatus = LocationStatusEnum.Free.GetHashCode();
- targetLocation.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
+ sourceLocation.LocationStatus = LocationStatusEnum.Free.GetHashCode();
+ targetLocation.LocationStatus = LocationStatusEnum.InStock.GetHashCode();
- var updateSourceResult = await _locationInfoService.UpdateLocationInfoAsync(sourceLocation);
- var updateTargetResult = await _locationInfoService.UpdateLocationInfoAsync(targetLocation);
- var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
+ var updateSourceResult = await _locationInfoService.UpdateLocationInfoAsync(sourceLocation);
+ var updateTargetResult = await _locationInfoService.UpdateLocationInfoAsync(targetLocation);
+ var updateStockResult = await _stockInfoService.UpdateStockAsync(stockInfo);
- if (!updateSourceResult || !updateTargetResult || !updateStockResult)
- return WebResponseContent.Instance.Error("绉诲簱浠诲姟瀹屾垚澶辫触");
+ if (!updateSourceResult || !updateTargetResult || !updateStockResult)
+ return WebResponseContent.Instance.Error("绉诲簱浠诲姟瀹屾垚澶辫触");
- return await CompleteTaskAsync(task);
+ return await CompleteTaskAsync(task);
+ });
}
catch (Exception ex)
{
@@ -549,45 +567,54 @@
taskList.Add(task);
}
- var addResult = await BaseDal.AddDataAsync(taskList) > 0;
- if (!addResult)
+ var transactionResult = await ExecuteWithinTransactionAsync(async () =>
{
- return WebResponseContent.Instance.Error($"鎵归噺鍒涘缓浠诲姟澶辫触锛屽叡 {taskList.Count} 涓换鍔�");
- }
-
- // 浠诲姟鍒涘缓鎴愬姛鍚庯紝鍚屾閿佸畾搴撳瓨鍜岃揣浣嶇姸鎬侊紝閬垮厤閲嶅鍒嗛厤
- var stocksToUpdate = stocksToProcess
- .Select(s =>
+ var addResult = await BaseDal.AddDataAsync(taskList) > 0;
+ if (!addResult)
{
- s.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.GetHashCode();
- return s;
- })
- .ToList();
-
- var updateStockResult = await _stockInfoService.Repository.UpdateDataAsync(stocksToUpdate);
- if (!updateStockResult)
- {
- return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓鎴愬姛锛屼絾搴撳瓨鐘舵�佹洿鏂板け璐ワ紝鍏� {stocksToUpdate.Count} 鏉�");
- }
-
- var locationsToUpdate = stocksToProcess
- .Where(s => s.LocationDetails != null)
- .GroupBy(s => s.LocationDetails.Id)
- .Select(g =>
- {
- var location = g.First().LocationDetails;
- location.LocationStatus = LocationStatusEnum.InStockLock.GetHashCode();
- return location;
- })
- .ToList();
-
- if (locationsToUpdate.Any())
- {
- var updateLocationResult = await _locationInfoService.Repository.UpdateDataAsync(locationsToUpdate);
- if (!updateLocationResult)
- {
- return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓鎴愬姛锛屼絾璐т綅鐘舵�佹洿鏂板け璐ワ紝鍏� {locationsToUpdate.Count} 鏉�");
+ return WebResponseContent.Instance.Error($"鎵归噺鍒涘缓浠诲姟澶辫触锛屽叡 {taskList.Count} 涓换鍔�");
}
+
+ // 浠诲姟鍒涘缓鎴愬姛鍚庯紝鍚屾閿佸畾搴撳瓨鍜岃揣浣嶇姸鎬侊紝閬垮厤閲嶅鍒嗛厤
+ var stocksToUpdate = stocksToProcess
+ .Select(s =>
+ {
+ s.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.GetHashCode();
+ return s;
+ })
+ .ToList();
+
+ var updateStockResult = await _stockInfoService.Repository.UpdateDataAsync(stocksToUpdate);
+ if (!updateStockResult)
+ {
+ return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓鎴愬姛锛屼絾搴撳瓨鐘舵�佹洿鏂板け璐ワ紝鍏� {stocksToUpdate.Count} 鏉�");
+ }
+
+ var locationsToUpdate = stocksToProcess
+ .Where(s => s.LocationDetails != null)
+ .GroupBy(s => s.LocationDetails.Id)
+ .Select(g =>
+ {
+ var location = g.First().LocationDetails;
+ location.LocationStatus = LocationStatusEnum.InStockLock.GetHashCode();
+ return location;
+ })
+ .ToList();
+
+ if (locationsToUpdate.Any())
+ {
+ var updateLocationResult = await _locationInfoService.Repository.UpdateDataAsync(locationsToUpdate);
+ if (!updateLocationResult)
+ {
+ return WebResponseContent.Instance.Error($"浠诲姟鍒涘缓鎴愬姛锛屼絾璐т綅鐘舵�佹洿鏂板け璐ワ紝鍏� {locationsToUpdate.Count} 鏉�");
+ }
+ }
+
+ return WebResponseContent.Instance.OK();
+ });
+ if (!transactionResult.Status)
+ {
+ return transactionResult;
}
// 6. 閫氱煡 WCS锛堝紓姝ワ紝涓嶅奖鍝嶄富娴佺▼锛�
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index 8ea1382..e5332e1 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
@@ -1,5 +1,3 @@
-using System.Reflection;
-using System.Text;
using Autofac;
using Autofac.Core;
using Autofac.Extensions.DependencyInjection;
@@ -12,6 +10,9 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using Serilog;
+using Serilog.Formatting.Json;
+using System.Reflection;
+using System.Text;
using WIDESEA_Core;
using WIDESEA_Core.Authorization;
using WIDESEA_Core.BaseServices;
@@ -42,13 +43,27 @@
loggerConfiguration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
- .Enrich.FromLogContext()
- .WriteTo.Console()
+ //.Enrich.FromLogContext()
+ .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File(
- "logs/serilog-.log.txt",
+ //new JsonFormatter(renderMessage: true),
+ "logs/serilog-.log",
+ outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30,
- shared: true);
+ // 姣忎釜鏃ュ織鏂囦欢鏈�澶уぇ灏忥紙瀛楄妭锛夛紝姝ゅ璁剧疆涓�10MB
+ fileSizeLimitBytes: 10 * 1024 * 1024,
+ shared: true
+ )
+ // 6. 鍙�夛細杈撳嚭鍒癝eq鏃ュ織鏈嶅姟鍣紙缁撴瀯鍖栨棩蹇楁湇鍔″櫒锛�
+ // 闇�瑕佸畨瑁� Serilog.Sinks.Seq NuGet鍖咃紝骞剁‘淇漇eq鏈嶅姟鍦� http://localhost:5341 杩愯
+ // 濡備笉闇�瑕丼eq鏃ュ織锛屾敞閲婃帀涓嬫柟浠g爜鍗冲彲
+ .WriteTo.Seq(
+ serverUrl: "http://localhost:5341",
+ apiKey: "CWVa8UWQ9CdUp9GWXCPL", // 濡係eq闇�瑕丄piKey鍒欓厤缃湡瀹炲瘑閽�
+ batchPostingLimit: 1000, // 鎵归噺鍙戦�佹暟閲�
+ period: TimeSpan.FromSeconds(2) // 鍙戦�侀棿闅�
+ );
});
builder.ConfigureApplication();
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj
index 9700c4e..5f95ade 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_WMSServer.csproj
@@ -50,7 +50,8 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
- <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
+ <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
+ <PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.7.3" />
</ItemGroup>
@@ -88,4 +89,8 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
+
+ <ItemGroup>
+ <Folder Include="logs\" />
+ </ItemGroup>
</Project>
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json
index feb1181..c628c08 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/appsettings.json
@@ -1,10 +1,31 @@
{
"urls": "http://*:9291", //web鏈嶅姟绔彛锛屽鏋滅敤IIS閮ㄧ讲锛屾妸杩欎釜鍘绘帀
+ "Serilog": {
+ "MinimumLevel": {
+ "Default": "Information",
+ "Override": {
+ "Microsoft": "Information",
+ "Microsoft.AspNetCore": "Warning",
+ "Microsoft.AspNetCore.Routing": "Warning",
+ "Microsoft.AspNetCore.Mvc": "Warning",
+ "Microsoft.AspNetCore.Mvc.Infrastructure": "Warning",
+ "Microsoft.AspNetCore.Mvc.Filters": "Warning",
+ "Microsoft.AspNetCore.Mvc.ModelBinding": "Warning",
+ "Microsoft.EntityFrameworkCore": "Warning"
+ }
+ }
+ },
"Logging": {
"LogLevel": {
"Default": "Information",
+ "Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
- "Microsoft.AspNetCore.DataProtection": "Warning"
+ "Microsoft.AspNetCore.DataProtection": "Warning",
+ "Microsoft.AspNetCore.Routing": "Warning",
+ "Microsoft.AspNetCore.Mvc": "Warning",
+ "Microsoft.AspNetCore.Mvc.Infrastructure": "Warning",
+ "Microsoft.AspNetCore.Mvc.Filters": "Warning",
+ "Microsoft.AspNetCore.Mvc.ModelBinding": "Warning"
}
},
"dics": "inOrderType,outOrderType,inboundState,createType,enableEnum,enableStatusEnum,locationStatusEnum,locationTypeEnum,taskTypeEnum,taskStatusEnum,outboundStatusEnum,orderDetailStatusEnum,stockStatusEmun,stockChangeType,outStockStatus,receiveOrderTypeEnum,authorityScope,authorityScopes,locationChangeType,warehouses,suppliers,taskType,receiveStatus,purchaseType,purchaseOrderStatus,printStatus",
@@ -25,6 +46,14 @@
// 娉ㄦ剰锛宧ttp://127.0.0.1:1818 鍜� http://localhost:1818 鏄笉涓�鏍风殑
"IPs": "http://127.0.0.1:8080,http://localhost:8080,http://127.0.0.1:8081,http://localhost:8081"
},
+
+ "LocalLogConfig": {
+ "LogLevel": "DEBUG", //鏃ュ織绾у埆 DEBUG,INFO,WARN,ERROR,FATAL
+ "LogFileSize": 10, //鍗曚釜鏃ュ織鏂囦欢澶у皬锛屽崟浣峂B
+ "LogFileCount": 300, //鏃ュ織鏂囦欢鏁伴噺
+ "EnableConsoleOutput": false, //鏄惁杈撳嚭鍒版帶鍒跺彴
+ "EnableFloderByLevel": true //鏄惁鎸夋棩蹇楃骇鍒敓鎴愪笉鍚岀殑鏂囦欢澶�
+ },
"LogAopEnable": false,
"PrintSql": false, //鎵撳嵃SQL璇彞
"ApiName": "WIDESEA",
--
Gitblit v1.9.3