From 559bb7b4be83575cc5fedee98484647243c96f89 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 08 四月 2026 15:57:44 +0800
Subject: [PATCH] feat: 空托盘出库完整流程 + 输送线调度优化 + S7Simulator 协议同步增强
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs | 83 +++++++++++++++++++++++++++++------------
1 files changed, 59 insertions(+), 24 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index 815fd7b..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;
@@ -27,31 +29,60 @@
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()).ConfigureContainer<ContainerBuilder>(builder =>
{
- builder.RegisterModule<AutofacModuleRegister>();//锟斤拷锟叫接口诧拷姆锟斤拷锟阶拷锟�
- builder.RegisterModule<AutofacPropertityModuleReg>();//
+ builder.RegisterModule<AutofacModuleRegister>(); // 娉ㄥ唽鎺ュ彛渚濊禆娉ㄥ叆
+ builder.RegisterModule<AutofacPropertityModuleReg>(); // 娉ㄥ唽灞炴�ф敞鍏�
}).ConfigureAppConfiguration((hostingContext, config) =>
{
hostingContext.Configuration.ConfigureApplication();
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");//锟斤拷锟斤拷时锟斤拷
+// App.ExpDateTime = DateTime.Parse("2025-03-31 00:00:00"); // 璁剧疆杩囨湡鏃堕棿
-// 2锟斤拷锟斤拷锟矫凤拷锟斤拷
-builder.Services.AddSingleton(new AppSettings(builder.Configuration));//注锟斤拷
-builder.Services.AddAllOptionRegister();//锟斤拷取锟斤拷锟斤拷锟侥硷拷
+// 2. 閰嶇疆鏈嶅姟
+builder.Services.AddSingleton(new AppSettings(builder.Configuration)); // 娉ㄥ唽閰嶇疆
+builder.Services.AddAllOptionRegister(); // 鑾峰彇閰嶇疆鏂囦欢
builder.Services.AddSingleton<RoundRobinService>();
builder.Services.Configure<AutoOutboundTaskOptions>(
builder.Configuration.GetSection("AutoOutboundTask"));
-builder.Services.AddMemoryCacheSetup();//锟斤拷锟斤拷
+builder.Services.AddMemoryCacheSetup(); // 缂撳瓨鏈嶅姟
builder.Services.AddWebSocketSetup();
-builder.Services.AddSqlsugarSetup();//SqlSugar 锟斤拷锟斤拷锟斤拷锟斤拷
-builder.Services.AddDbSetup();//Db 锟斤拷锟斤拷锟斤拷锟斤拷
-builder.Services.AddInitializationHostServiceSetup();//应锟矫筹拷始锟斤拷锟斤拷锟斤拷注锟斤拷
-builder.Services.AddHostedService<AutoOutboundTaskBackgroundService>();
-//builder.Services.AddHostedService<PermissionDataHostService>();//锟斤拷锟斤拷权锟斤拷
+builder.Services.AddSqlsugarSetup(); // SqlSugar 鏁版嵁搴撻厤缃�
+builder.Services.AddDbSetup(); // Db 鏁版嵁搴撻厤缃�
+builder.Services.AddInitializationHostServiceSetup(); // 搴旂敤绋嬪簭鍒濆鍖栨湇鍔℃敞鍐�
+builder.Services.AddHostedService<AutoOutboundTaskBackgroundService>(); // 鍚姩鑷姩鍑哄簱浠诲姟鍚庡彴鏈嶅姟
+builder.Services.AddHostedService<StockMonitorBackgroundService>(); // 鍚姩搴撳瓨鐩戞帶鍚庡彴鏈嶅姟
+// builder.Services.AddHostedService<PermissionDataHostService>(); // 鏉冮檺鏁版嵁鏈嶅姟
builder.Services.AddAutoMapperSetup();
builder.Services.AddCorsSetup();
@@ -69,11 +100,13 @@
options.Filters.Add(typeof(ActionExecuteFilter));
});
+builder.Services.AddSignalR();
+
builder.Services.AddScoped<HttpClientHelper>();
builder.Services.AddAuthorizationSetup();
-builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration);//IPLimit锟斤拷锟斤拷 锟斤拷锟斤拷锟斤拷锟斤拷
+builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration); // IP闄愭祦 涓棿浠舵敞鍐�
builder.Services.AddScoped<UseServiceDIAttribute>();
@@ -83,7 +116,7 @@
builder.Services.AddControllers(o =>
{
- o.Filters.Add(typeof(GlobalExceptionsFilter));//全锟斤拷锟届常
+ o.Filters.Add(typeof(GlobalExceptionsFilter)); // 鍏ㄥ眬寮傚父澶勭悊
})
.AddNewtonsoftJson(options =>
{
@@ -104,20 +137,20 @@
var app = builder.Build();
-// 3锟斤拷锟斤拷锟斤拷锟叫硷拷锟�
-app.UseMiniProfiler();//锟斤拷锟杰凤拷锟斤拷锟斤拷
-app.ConfigureApplication();//锟斤拷锟斤拷锟侥硷拷
-app.UseApplicationSetup();//锟斤拷锟斤拷锟斤拷锟斤拷
+// 3. 閰嶇疆涓棿浠�
+app.UseMiniProfiler(); // 鎬ц兘鍒嗘瀽
+app.ConfigureApplication(); // 搴旂敤閰嶇疆
+app.UseApplicationSetup(); // 搴旂敤鍚姩
app.UseAllServicesMiddle(builder.Services);
app.UseSession();
app.UseSwaggerAuthorized();
-app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEA_WMSServer.index.html") ?? throw new Exception("WIDESEA_WMSServer.index.html锟侥硷拷"));
+app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEA_WMSServer.index.html") ?? throw new Exception("WIDESEA_WMSServer.index.html鏂囦欢涓嶅瓨鍦�"));
app.UseIpLimitMiddle();
app.UseApiLogMiddleware();
-//todo
-//app.UseRecordAccessLogsMiddle();
+// todo
+// app.UseRecordAccessLogsMiddle();
DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
@@ -144,4 +177,6 @@
app.MapControllers();
+app.MapHub<WIDESEA_WMSServer.Hubs.StockHub>("/stockHub");
+
app.Run();
--
Gitblit v1.9.3