物料信息程序启动后就拉取

This commit is contained in:
tongfei
2024-01-15 15:11:39 +08:00
parent 56fca1bcbf
commit 329f0f2978
2 changed files with 24 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Web;
@@ -7,6 +9,8 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WMS.Web.Core.Dto.Erp;
using WMS.Web.Domain.IService.Public;
namespace WMS.Web.Api
{
@@ -14,7 +18,25 @@ namespace WMS.Web.Api
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
var host= CreateHostBuilder(args).Build();
//to do you want
Task.Run(() =>
{
//<2F>첽-ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
using (var scope = host.Services.CreateScope())
{
var sercice = scope.ServiceProvider.GetRequiredService<IErpService>();
sercice.BillQueryForMaterial().GetAwaiter().GetResult();
var cache = scope.ServiceProvider.GetRequiredService<IMemoryCache>();
var cache_key = "erp_materials_list";
var materials = cache.Get<List<ErpMaterialDto>>(cache_key);
Console.WriteLine("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>룺" + materials.Count);
}
});
host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>

View File

@@ -914,7 +914,7 @@ namespace WMS.Web.Domain.Services.Public
var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
_logger.LogInformation($"物料拉取-结束时间:{endTime}");
//5.物料集合进行缓存
_memoryCache.Set(cache_key, erp_materials_list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12)));
_memoryCache.Set(cache_key, erp_materials_list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(7)));
_logger.LogInformation($"物料拉取-总条数:{erp_materials_list.Count}");
return ResultList<ErpMaterialDto>.ReSuccess(erp_materials_list);
}