From 8e42d0c1b7ae36cff2e7c69999117911a4b6f300 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 26 三月 2026 17:31:06 +0800
Subject: [PATCH] feat(WCS): 完善 WIDESEAWCS_Tasks 模块代码注释

---
 Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs |  105 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 72 insertions(+), 33 deletions(-)

diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
index a7cb7e0..f50aea3 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Server/Program.cs
@@ -1,8 +1,7 @@
-using System.Reflection;
-using System.Text;
-using Autofac;
+锘縰sing Autofac;
 using Autofac.Core;
 using Autofac.Extensions.DependencyInjection;
+using Magicodes.ExporterAndImporter.Excel.Utility.TemplateExport;
 using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Mvc.Controllers;
 using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
@@ -11,6 +10,12 @@
 using Newtonsoft.Json;
 using Newtonsoft.Json.Converters;
 using Newtonsoft.Json.Serialization;
+using Serilog;
+using Serilog.Events;
+using System.IO;
+using System.Reflection;
+using System.Text;
+using WIDESEA_Core;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.Authorization;
 using WIDESEAWCS_Core.BaseServices;
@@ -23,56 +28,87 @@
 using WIDESEAWCS_QuartzJob;
 using WIDESEAWCS_QuartzJob.QuartzExtensions;
 using WIDESEAWCS_QuartzJob.Seed;
+using WIDESEAWCS_RedisService.Extensions;
 using WIDESEAWCS_Server.Filter;
 using WIDESEAWCS_Server.HostedService;
+using WIDESEAWCS_Tasks.SocketServer;
 using WIDESEAWCS_WCSServer.Filter;
 
 var builder = WebApplication.CreateBuilder(args);
-// 1、配置服务容器
+// 绗�1閮ㄥ垎锛氫富鏈轰笌鍩虹璁炬柦閰嶇疆
+
+// 浣跨敤 Serilog 浣滀负缁熶竴鏃ュ織鎻愪緵绋嬪簭锛堟浛鎹㈤粯璁� Logging Providers锛�
+builder.Logging.ClearProviders();
+builder.Host.UseSerilog((context, services, loggerConfiguration) =>
+{
+    // 閰嶇疆Serilog鏃ュ織璁板綍鍣�
+    loggerConfiguration
+        .ReadFrom.Configuration(context.Configuration) // 浠庡簲鐢ㄧ▼搴忛厤缃腑璇诲彇Serilog鐩稿叧璁剧疆锛堝appsettings.json锛�
+        .ReadFrom.Services(services)  // 浠庝緷璧栨敞鍏ュ鍣ㄤ腑璇诲彇鏈嶅姟閰嶇疆锛屽厑璁稿湪閰嶇疆涓娇鐢ㄥ凡娉ㄥ唽鐨勬湇鍔�
+        .Enrich.FromLogContext()  // 鍚敤鏃ュ織涓婁笅鏂囷紝鍙互鍦ㄦ棩蹇椾腑鍖呭惈濡傝姹侷D銆佺敤鎴稩D绛夊姩鎬佸睘鎬�
+
+        // 璁剧疆Microsoft鍛藉悕绌洪棿鐨勬棩蹇楃骇鍒负Information
+        // 杩欐牱鍙互鍑忓皯Microsoft妗嗘灦鏈韩鐨勮缁嗘棩蹇楋紝閬垮厤杩囧鐨凞ebug鏃ュ織
+        .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
+        .WriteTo.Console()  // 娣诲姞鎺у埗鍙拌緭鍑烘帴鏀跺櫒锛屾棩蹇楀皢鏄剧ず鍦ㄦ帶鍒跺彴绐楀彛涓�
+                            // 娣诲姞鏂囦欢杈撳嚭鎺ユ敹鍣紝灏嗘棩蹇楀啓鍏ユ枃浠剁郴缁�
+        .WriteTo.File(
+            /*Path.Combine(AppContext.BaseDirectory, "Logs", "serilog-.log"),*/  // 鎸囧畾鏃ュ織鏂囦欢鐨勫畬鏁磋矾寰勶細搴旂敤绋嬪簭鐩綍 + "Log"鏂囦欢澶� + "serilog-鏃ユ湡.log"
+            "logs/serilog-.log",
+            rollingInterval: RollingInterval.Day,  // 璁剧疆鏃ュ織鏂囦欢鎸夊ぉ婊氬姩锛屾瘡澶╃敓鎴愪竴涓柊鐨勬棩蹇楁枃浠�  U1od4UGVsIKZG39S5Yak
+            retainedFileCountLimit: 30,  // 鏈�澶氫繚鐣欐渶杩�30澶╃殑鏃ュ織鏂囦欢锛岃秴杩�30澶╃殑鏂囦欢浼氳嚜鍔ㄥ垹闄�
+            shared: true)  // 鍏佽澶氫釜杩涚▼鍚屾椂鍐欏叆鍚屼竴涓棩蹇楁枃浠讹紝閫傜敤浜庡瀹炰緥閮ㄧ讲鍦烘櫙
+        .WriteTo.Seq(
+                 serverUrl: "http://localhost:5341",
+                 apiKey: "U1od4UGVsIKZG39S5Yak", // 濡係eq闇�瑕丄piKey鍒欓厤缃湡瀹炲瘑閽�
+                 batchPostingLimit: 1000, // 鎵归噺鍙戦�佹暟閲�
+                 period: TimeSpan.FromSeconds(2) // 鍙戦�侀棿闅�
+             );
+});
 
 builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()).ConfigureContainer<ContainerBuilder>(builder =>
 {
-    builder.RegisterModule(new AutofacModuleRegister());//带有接口层的服务注入
+    // 娉ㄥ唽搴旂敤灞� Autofac 妯″潡锛堜粨鍌ㄣ�佹湇鍔°�丄OP 绛夛級
+    builder.RegisterModule(new AutofacModuleRegister());
     builder.RegisterModule(new QuartzJobAutofacModuleRegister());
-    builder.RegisterModule<AutofacPropertityModuleReg>();//
+    builder.RegisterModule<AutofacPropertityModuleReg>();
 }).ConfigureAppConfiguration((hostingContext, config) =>
 {
+    // 浣跨敤缁熶竴閰嶇疆鍏ュ彛骞跺彧淇濈暀 appsettings.json
     hostingContext.Configuration.ConfigureApplication();
     config.Sources.Clear();
     config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false);
 });
 builder.ConfigureApplication();
 
-// 2、配置服务
-builder.Services.AddSingleton(new AppSettings(builder.Configuration));//注册
-builder.Services.AddAllOptionRegister();//读取配置文件
+// 绗�2閮ㄥ垎锛氭湇鍔℃敞鍐�
+builder.Services.AddSingleton(new AppSettings(builder.Configuration)); // 娉ㄥ唽閰嶇疆璁块棶瀵硅薄
+builder.Services.AddAllOptionRegister(); // 娉ㄥ唽 Options 缁戝畾
 
+builder.Services.AddMemoryCacheSetup(); // 鍐呭瓨缂撳瓨
+builder.Services.AddRedisSetup(builder.Configuration); // Redis 缂撳瓨
+builder.Services.AddHostedService<ApiRouteCacheWarmupHostedService>(); // API璺敱缂撳瓨棰勭儹锛圧edis灏辩华鍚庡姞杞斤級
+builder.Services.AddSqlsugarSetup(); // SqlSugar 鏁版嵁搴撻厤缃�
+builder.Services.AddInitializationHostServiceSetup(); // 搴旂敤鍒濆鍖栫浉鍏冲悗鍙版湇鍔�
+builder.Services.AddHostedService<SeedDataHostedService>(); // 鍚姩鏃剁瀛愭暟鎹垵濮嬪寲
 
-builder.Services.AddMemoryCacheSetup();//缓存
-builder.Services.AddSqlsugarSetup();//SqlSugar 启动服务
-builder.Services.AddInitializationHostServiceSetup();//应用初始化服务注入
-builder.Services.AddHostedService<SeedDataHostedService>();//初始化数据库
+builder.Services.AddDbSetup(); // 鏁版嵁搴撳熀纭�閰嶇疆
 
-builder.Services.AddDbSetup();//Db 启动服务
-
-builder.Services.AddScoped<QuartzJobCreateDataTabel>();//任务调度 注入创建QuartzJob数据库表类
-builder.Services.AddHostedService<QuartzJobDataTableHostedService>();//任务调度 映射QuartzJob数据库表
+builder.Services.AddScoped<QuartzJobCreateDataTabel>(); // Quartz 浠诲姟琛ㄥ垱寤烘湇鍔�
+builder.Services.AddHostedService<QuartzJobDataTableHostedService>(); // Quartz 浠诲姟琛ㄥ垵濮嬪寲鍚庡彴鏈嶅姟
 
 builder.Services.AddWebSocketSetup();
-
-builder.Services.AddAutoMapperSetup();
-
+builder.Services.AddMapsterSetup(); // Mapster 瀵硅薄鏄犲皠閰嶇疆
 builder.Services.AddCorsSetup();
-
 builder.Services.AddMiniProfilerSetup();
-
 builder.Services.AddSwaggerSetup();
-
-builder.Services.AddJobSetup();//任务调度 注入反射获取依赖对象
+builder.Services.AddJobSetup(); // Quartz Job 璋冨害閰嶇疆
 
 builder.Services.AddHttpContextSetup();
 
-builder.Services.AddHostedService<QuartzJobHostedService>();//任务调度 启动服务
+builder.Services.AddHostedService<QuartzJobHostedService>(); // Quartz 鍚姩鎵樼鏈嶅姟
+builder.Services.AddSingleton<TcpSocketServer>();
+builder.Services.AddHostedService<SocketServerHostedService>();
 
 builder.Services.AddMvc(options =>
 {
@@ -81,9 +117,11 @@
     options.Filters.Add(typeof(CustomAuthorizeFilter));
 });
 
+builder.Services.AddScoped<HttpClientHelper>();
+
 builder.Services.AddAuthorizationSetup();
 
-builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration);//IPLimit限流 启动服务
+builder.Services.AddIpPolicyRateLimitSetup(builder.Configuration); // IP 闄愭祦閰嶇疆
 
 builder.Services.AddScoped<UseServiceDIAttribute>();
 
@@ -93,7 +131,7 @@
 
 builder.Services.AddControllers(o =>
 {
-    o.Filters.Add(typeof(GlobalExceptionsFilter));//全局异常
+    o.Filters.Add(typeof(GlobalExceptionsFilter)); // 鍏ㄥ眬寮傚父杩囨护鍣�
 })
 .AddNewtonsoftJson(options =>
 {
@@ -105,26 +143,26 @@
     options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
     options.SerializerSettings.Converters.Add(new StringEnumConverter());
 });
-// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
 builder.Services.AddEndpointsApiExplorer();
 
+// 浣跨敤 DI 婵�娲� Controller锛岀‘淇濆睘鎬ф敞鍏�/瀹瑰櫒琛屼负涓�鑷�
 builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
 
 
 var app = builder.Build();
 
-// 3、配置中间件
-app.UseMiniProfiler();//性能分析器
-app.ConfigureApplication();//配置文件
-app.UseApplicationSetup();//启动配置
+// 绗�3閮ㄥ垎锛欻TTP 绠¢亾閰嶇疆
+app.UseMiniProfiler(); // 鎬ц兘鍒嗘瀽闈㈡澘
+app.ConfigureApplication(); // 搴旂敤鍏ㄥ眬鍒濆鍖�
+app.UseApplicationSetup(); // 鍏叡涓棿浠跺垵濮嬪寲
 
 app.UseAllServicesMiddle(builder.Services);
 
 app.UseSession();
 
 app.UseSwaggerAuthorized();
-app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html") ?? throw new Exception("未找到WIDESEAWCS_Server.index.html文件"));
+app.UseSwaggerMiddle(() => Assembly.GetExecutingAssembly().GetManifestResourceStream("WIDESEAWCS_Server.index.html") ?? throw new Exception("鏈壘鍒� WIDESEAWCS_Server.index.html 璧勬簮鏂囦欢"));
 
 app.UseIpLimitMiddle();
 app.UseApiLogMiddleware();
@@ -153,3 +191,4 @@
 app.MapControllers();
 
 app.Run();
+

--
Gitblit v1.9.3