From dedeb77685c258bc7851c7c4da40eb1315127cb8 Mon Sep 17 00:00:00 2001
From: hwh <332078369@qq.com>
Date: 星期二, 25 六月 2024 14:06:29 +0800
Subject: [PATCH] Merge branch 'hwh'

---
 Wms/Wms/Startup.cs |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/Wms/Wms/Startup.cs b/Wms/Wms/Startup.cs
index 93f1405..fb30816 100644
--- a/Wms/Wms/Startup.cs
+++ b/Wms/Wms/Startup.cs
@@ -14,6 +14,14 @@
 using Wms.Tools;
 using WMS.Entity.Context;
 using WMS.IBLL.IDataServer;
+using Serilog;
+using Autofac.Core;
+using Utility;
+using Utility.Extension;
+using Microsoft.Extensions.Options;
+using Microsoft.AspNetCore.Http;
+using SqlSugar;
+using Utility.Job;
 
 namespace Wms
 {
@@ -37,7 +45,9 @@
             services.AddHostedService<DailyTaskService>(provider =>
             new DailyTaskService(url,url2));
 
-            services.AddControllers()
+            services.AddControllers(options => {
+                options.Filters.Add<RequestAuditLogFilter>();
+            })
                 .AddJsonOptions(options =>
                     {
                         //不使用驼峰样式的key
@@ -100,9 +110,15 @@
             #endregion
 
             //读取配置文件配置的接口交互的相关配置
-            services.Configure<ApiUrlConfig>(Configuration.GetSection("ApiUrlConfig"));
+            services.Configure<ApiUrlConfig>(Configuration.GetSection("ApiUrlConfig")); 
             //数据库配置
             BaseDbConfig.ConnectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;
+            //验签配置文件
+            SignConfig.ERPAppKey = Configuration.GetSection("SignConfig:ERPAppKey").Value;  
+            SignConfig.MESAppKey = Configuration.GetSection("SignConfig:MESAppKey").Value;  
+            SignConfig.LIMSAppKey = Configuration.GetSection("SignConfig:LIMSAppKey").Value;  
+            SignConfig.FuMaAppKey = Configuration.GetSection("SignConfig:FuMaAppKey").Value;
+            SignConfig.Minutes = double.Parse(Configuration.GetSection("SignConfig:Minutes").Value);
 
 
             #region AutoMapper注入
@@ -110,6 +126,15 @@
             services.AddAutoMapper(typeof(AutoMapperProfile)); // automapper依赖
             #endregion
 
+            //注册serilog
+            services.AddConfigSerilog();
+            services.AddScoped<ApiResponseActionFilter>();
+            services.AddScoped<UnitOfWorkAttribute>();
+            services.AddSingleton<ISqlSugarClient>(DataContext.Db); // 单例注册
+            services.AddTransient<IUnitOfWork, SqlSugarUnitOfWork>(); // 事务与工作单元注册
+
+            services.AddHostedService<HostedService>();
+            services.AddSingleton<SchedulerCenter>();
         }
         public void ConfigureContainer(ContainerBuilder builder)
         {
@@ -133,7 +158,12 @@
                     c.RoutePrefix = string.Empty;
                 });
             }
+            //全局返回规范
+            //app.UseApiResponse();//弃用 改用Filter [ServiceFilter(typeof(ApiResponseActionFilter))]
+            app.UseExceptionMiddleware();
 
+            //使用Serilog记录请求日志
+            app.UseSerilogRequestLogging();
             //app.UseHttpsRedirection();
 
             app.UseRouting();
@@ -141,7 +171,6 @@
             app.UseAuthentication();
             app.UseAuthorization();
             app.UseCors("MyCors");//跨域
-
 
             app.UseEndpoints(endpoints =>
             {

--
Gitblit v1.8.0