From 06e0e3b7d61e95902a6129de2490461cd0693e1d Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期三, 15 十月 2025 15:06:40 +0800
Subject: [PATCH] 新增异步方法并优化服务调用逻辑在多个数据库文件中进行了二进制文件的修改、删除和新增操作,可能涉及数据库内容的更新或重建。在 HttpsClient.cs文件中新增了 PostNotLimitAsync方法,用于发送支持 JSON 格式的异步 HTTP POST 请求,并记录请求和响应参数。在 AgingInOrOutInputService.cs文件中,将 HttpsClient.PostAsync替换为PostNotLimitAsync,以利用新方法的功能特性。同时删除了不再需要的注释代码。
---
Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs | 64 ++++++++++++++++++++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
index 7dc8b26..4bcf385 100644
--- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
+++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Program.cs
@@ -19,6 +19,14 @@
using WIDESEA_Core.Core;
using Swashbuckle.AspNetCore.SwaggerGen;
using Microsoft.OpenApi.Models;
+using WIDESEA_StorageTaskServices;
+using Autofac.Core;
+using WIDESEA_Cache;
+using SimpleRedis;
+using WIDESEA_DTO.WMS;
+using static NewLife.Remoting.ApiHttpClient;
+using NewLife.Windows;
+using WIDESEA_Core.Enums;
var builder = WebApplication.CreateBuilder(args);
@@ -109,8 +117,43 @@
}
});
+builder.Services.AddHostedService<MyBackgroundService>();
+
+//缓存设置配置转实体
+builder.Services.AddConfigurableOptions<CacheSettingsOptions>();
+//禁止在主机启动时通过 App.GetOptions<TOptions> 获取选项,如需获取配置选项理应通过 App.GetConfig<TOptions>("配置节点", true)。
+var cacheSettings = AppSettings.Configuration.GetSection("CacheSettings").Get<CacheSettingsOptions>();
+//如果有redis连接字符串
+if (cacheSettings.UseRedis)
+{
+ var connectionString =
+ $"server={cacheSettings.RedisSettings.Address};db={cacheSettings.RedisSettings.Db}";
+ //注入redis
+ builder.Services.AddSimpleRedis(connectionString);
+ builder.Services.AddScoped<ISimpleCacheService, RedisCacheService>();
+}
+else
+{
+ builder.Services.AddScoped<ISimpleCacheService, MemoryCacheService>();
+}
+
var app = builder.Build();
+
+// 验证 Redis 服务是否成功注册
+using (var scope = app.Services.CreateScope())
+{
+ var services = scope.ServiceProvider;
+ var redisService = services.GetService<ISimpleCacheService>();
+ if (redisService == null)
+ {
+ WIDESEA_Core.Helper.ConsoleHelper.WriteErrorLine("Redis 服务未成功注册");
+ }
+ else
+ {
+ WIDESEA_Core.Helper.ConsoleHelper.WriteSuccessLine("Redis 服务已成功注册");
+ }
+}
// 3、配置中间件
app.UseMiniProfiler();//性能分析器
@@ -148,5 +191,26 @@
app.MapControllers();
+//通过 App.GetOptions<TOptions> 获取选项
+var cacheSettingsb = App.GetOptions<CacheSettingsOptions>();
+//如果需要清除缓存
+if (cacheSettingsb.UseRedis && cacheSettingsb.RedisSettings.ClearRedis)
+{
+ var redis = app.Services.CreateScope().ServiceProvider.GetService<ISimpleCacheService>(); //获取redis服务
+ // 删除redis的key
+ redis.DelByPattern(CacheConst.Cache_Prefix);
+
+ WIDESEA_Core.Helper.ConsoleHelper.WriteInfoLine("正在缓存库存信息");
+ var stockInfoList = await SqlSugarHelper.DbWMS.Queryable<DtStockInfo>()
+ .Where(x => x.LocationInfo.LocationStatus == (int)LocationEnum.InStock).IncludesAllFirstLayer().ToListAsync();
+ // 缓存库存信息
+ foreach (var item in stockInfoList)
+ {
+ item.StockInfoDetails = new List<DtStockInfoDetail>() { { item.StockInfoDetails[0] } };
+ redis.HashAdd(CacheConst.Cache_DtStockInfo, item.PalletCode, item);
+ }
+ WIDESEA_Core.Helper.ConsoleHelper.WriteInfoLine("缓存库存信息完成");
+}
+
app.Run();
--
Gitblit v1.9.3