From 4d5b4319ebfb155b199ec641ec377b220f9fa837 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 08 四月 2026 00:55:31 +0800
Subject: [PATCH] fix(wms): 优化组盘库存逻辑与数据库连接配置
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs | 41 ++++++++++++++++++++++++++++++++++++++---
1 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index 1d708bf..a3e0f16 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;
@@ -11,6 +9,10 @@
using Newtonsoft.Json;
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;
@@ -35,6 +37,34 @@
config.Sources.Clear();
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
});
+
+builder.Host.UseSerilog((context, services, loggerConfiguration) =>
+{
+ loggerConfiguration
+ .ReadFrom.Configuration(context.Configuration)
+ .ReadFrom.Services(services)
+ //.Enrich.FromLogContext()
+ .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
+ .WriteTo.File(
+ //new JsonFormatter(renderMessage: true),
+ "logs/serilog-.log",
+ outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}",
+ rollingInterval: RollingInterval.Day,
+ retainedFileCountLimit: 30,
+ // 姣忎釜鏃ュ織鏂囦欢鏈�澶уぇ灏忥紙瀛楄妭锛夛紝姝ゅ璁剧疆涓�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();
// App.ExpDateTime = DateTime.Parse("2025-03-31 00:00:00"); // 璁剧疆杩囨湡鏃堕棿
@@ -50,7 +80,8 @@
builder.Services.AddSqlsugarSetup(); // SqlSugar 鏁版嵁搴撻厤缃�
builder.Services.AddDbSetup(); // Db 鏁版嵁搴撻厤缃�
builder.Services.AddInitializationHostServiceSetup(); // 搴旂敤绋嬪簭鍒濆鍖栨湇鍔℃敞鍐�
-builder.Services.AddHostedService<AutoOutboundTaskBackgroundService>();
+builder.Services.AddHostedService<AutoOutboundTaskBackgroundService>(); // 鍚姩鑷姩鍑哄簱浠诲姟鍚庡彴鏈嶅姟
+builder.Services.AddHostedService<StockMonitorBackgroundService>(); // 鍚姩搴撳瓨鐩戞帶鍚庡彴鏈嶅姟
// builder.Services.AddHostedService<PermissionDataHostService>(); // 鏉冮檺鏁版嵁鏈嶅姟
builder.Services.AddAutoMapperSetup();
@@ -68,6 +99,8 @@
options.Filters.Add(typeof(ApiAuthorizeFilter));
options.Filters.Add(typeof(ActionExecuteFilter));
});
+
+builder.Services.AddSignalR();
builder.Services.AddScoped<HttpClientHelper>();
@@ -144,4 +177,6 @@
app.MapControllers();
+app.MapHub<WIDESEA_WMSServer.Hubs.StockHub>("/stockHub");
+
app.Run();
--
Gitblit v1.9.3