erp服务优化

This commit is contained in:
tongfei
2024-01-15 15:32:24 +08:00
parent 329f0f2978
commit 5e61f1f6a4
2 changed files with 25 additions and 34 deletions

View File

@@ -4531,11 +4531,10 @@
<param name="id"></param> <param name="id"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForMaterialPagedList(System.String)"> <member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForMaterialPagedList">
<summary> <summary>
erp:基础数据-物料-分页查询 erp:基础数据-物料-分页查询
</summary> </summary>
<param name="cache_key"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForMaterialById(System.Int32)"> <member name="M:WMS.Web.Domain.Services.Public.ErpService.BillQueryForMaterialById(System.Int32)">

View File

@@ -40,17 +40,19 @@ namespace WMS.Web.Domain.Services.Public
private ILogger<ErpService> _logger; private ILogger<ErpService> _logger;
private ERPGWSoapClient _client; private ERPGWSoapClient _client;
private readonly IMemoryCache _memoryCache; private readonly IMemoryCache _memoryCache;
private readonly ISingleDataService _singleDataService;
private readonly ILoginRepositories _loginRepositories;
private readonly IBasicsRepositories _basicsRepositories; private readonly IBasicsRepositories _basicsRepositories;
public readonly string cache_materail_key = "erp_materials_list";
public readonly string cache_org_key = "erp_org_list";
public readonly string cache_supplier_key = "erp_supplier_list";
public readonly string cache_customer_key = "erp_customer_list";
public readonly string cache_stock_key = "erp_stock_list";
public readonly string cache_substock_key = "erp_substock_list";
public ErpService( public ErpService(
IMapper mapper, IMapper mapper,
IOptions<ErpOptions> erpOptions, IOptions<ErpOptions> erpOptions,
IOptions<AppOptions> appOptions, IOptions<AppOptions> appOptions,
ILogger<ErpService> logger, ILogger<ErpService> logger,
IMemoryCache memoryCache, IMemoryCache memoryCache, IBasicsRepositories basicsRepositories)
ISingleDataService singleDataService,
ILoginRepositories loginRepositories, IBasicsRepositories basicsRepositories)
{ {
this._basicsRepositories = basicsRepositories; this._basicsRepositories = basicsRepositories;
this._erpOptions = erpOptions?.Value; this._erpOptions = erpOptions?.Value;
@@ -58,8 +60,6 @@ namespace WMS.Web.Domain.Services.Public
this._mapper = mapper; this._mapper = mapper;
this._logger = logger; this._logger = logger;
this._memoryCache = memoryCache; this._memoryCache = memoryCache;
this._singleDataService = singleDataService;
this._loginRepositories = loginRepositories;
} }
/// <summary> /// <summary>
@@ -798,11 +798,10 @@ namespace WMS.Web.Domain.Services.Public
try try
{ {
//1.获取缓存中的物料数据; //1.获取缓存中的物料数据;
var cache_key = "erp_materials_list"; var materials = _memoryCache.Get<List<ErpMaterialDto>>(cache_materail_key);
var materials = _memoryCache.Get<List<ErpMaterialDto>>(cache_key);
if (materials == null || materials.Count == 0) if (materials == null || materials.Count == 0)
{ {
return await this.BillQueryForMaterialPagedList(cache_key); return await this.BillQueryForMaterialPagedList();
} }
else else
{ {
@@ -825,9 +824,8 @@ namespace WMS.Web.Domain.Services.Public
/// <returns></returns> /// <returns></returns>
public async Task<Result<ErpMaterialDto>> BillQueryForMaterial(int id) public async Task<Result<ErpMaterialDto>> BillQueryForMaterial(int id)
{ {
//1.获取缓存中的物料数据 //1.获取缓存中的物料数据
var cache_key = "erp_materials_list"; var materials = _memoryCache.Get<List<ErpMaterialDto>>(cache_materail_key);
var materials = _memoryCache.Get<List<ErpMaterialDto>>(cache_key);
if (materials == null || materials.Count == 0) if (materials == null || materials.Count == 0)
return Result<ErpMaterialDto>.ReSuccess(null); return Result<ErpMaterialDto>.ReSuccess(null);
//2.通过ID取当前物料列表中的 //2.通过ID取当前物料列表中的
@@ -840,7 +838,7 @@ namespace WMS.Web.Domain.Services.Public
{ {
//把取到的数据放集合中并重新给缓存 //把取到的数据放集合中并重新给缓存
materials.Add(mater); materials.Add(mater);
_memoryCache.Set(cache_key, materials, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12))); _memoryCache.Set(cache_materail_key, materials, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
return Result<ErpMaterialDto>.ReSuccess(mater); return Result<ErpMaterialDto>.ReSuccess(mater);
} }
else else
@@ -853,9 +851,8 @@ namespace WMS.Web.Domain.Services.Public
/// <summary> /// <summary>
/// erp:基础数据-物料-分页查询 /// erp:基础数据-物料-分页查询
/// </summary> /// </summary>
/// <param name="cache_key"></param>
/// <returns></returns> /// <returns></returns>
private async Task<ResultList<ErpMaterialDto>> BillQueryForMaterialPagedList(string cache_key) private async Task<ResultList<ErpMaterialDto>> BillQueryForMaterialPagedList()
{ {
//2.先登录金蝶-拿到token //2.先登录金蝶-拿到token
var token_result = await this.Init(); var token_result = await this.Init();
@@ -914,7 +911,7 @@ namespace WMS.Web.Domain.Services.Public
var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
_logger.LogInformation($"物料拉取-结束时间:{endTime}"); _logger.LogInformation($"物料拉取-结束时间:{endTime}");
//5.物料集合进行缓存 //5.物料集合进行缓存
_memoryCache.Set(cache_key, erp_materials_list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(7))); _memoryCache.Set(cache_materail_key, erp_materials_list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
_logger.LogInformation($"物料拉取-总条数:{erp_materials_list.Count}"); _logger.LogInformation($"物料拉取-总条数:{erp_materials_list.Count}");
return ResultList<ErpMaterialDto>.ReSuccess(erp_materials_list); return ResultList<ErpMaterialDto>.ReSuccess(erp_materials_list);
} }
@@ -986,8 +983,7 @@ namespace WMS.Web.Domain.Services.Public
try try
{ {
//1.获取缓存中的组织数据; //1.获取缓存中的组织数据;
var cache_key = "erp_org_list"; var orgs = _memoryCache.Get<List<ErpOrgDto>>(cache_org_key);
var orgs = _memoryCache.Get<List<ErpOrgDto>>(cache_key);
if (orgs == null || orgs.Count == 0) if (orgs == null || orgs.Count == 0)
{ {
@@ -1029,7 +1025,7 @@ namespace WMS.Web.Domain.Services.Public
} }
//5.组织集合进行缓存 //5.组织集合进行缓存
_memoryCache.Set(cache_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12))); _memoryCache.Set(cache_org_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
_logger.LogInformation($"组织拉取-总条数:{list.Count}"); _logger.LogInformation($"组织拉取-总条数:{list.Count}");
return ResultList<ErpOrgDto>.ReSuccess(list); return ResultList<ErpOrgDto>.ReSuccess(list);
@@ -1055,8 +1051,7 @@ namespace WMS.Web.Domain.Services.Public
try try
{ {
//1.获取缓存中的供应商数据; //1.获取缓存中的供应商数据;
var cache_key = "erp_supplier_list"; var suppliers = _memoryCache.Get<List<ErpSupplierDto>>(cache_supplier_key);
var suppliers = _memoryCache.Get<List<ErpSupplierDto>>(cache_key);
if (suppliers == null || suppliers.Count == 0) if (suppliers == null || suppliers.Count == 0)
{ {
@@ -1098,7 +1093,7 @@ namespace WMS.Web.Domain.Services.Public
} }
//5.供应商集合进行缓存 //5.供应商集合进行缓存
_memoryCache.Set(cache_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12))); _memoryCache.Set(cache_supplier_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
_logger.LogInformation($"供应商拉取-总条数:{list.Count}"); _logger.LogInformation($"供应商拉取-总条数:{list.Count}");
return ResultList<ErpSupplierDto>.ReSuccess(list); return ResultList<ErpSupplierDto>.ReSuccess(list);
@@ -1123,8 +1118,7 @@ namespace WMS.Web.Domain.Services.Public
try try
{ {
//1.获取缓存中的供应商数据; //1.获取缓存中的供应商数据;
var cache_key = "erp_customer_list"; var customers = _memoryCache.Get<List<ErpCustomerDto>>(cache_customer_key);
var customers = _memoryCache.Get<List<ErpCustomerDto>>(cache_key);
if (customers == null || customers.Count == 0) if (customers == null || customers.Count == 0)
{ {
@@ -1177,7 +1171,7 @@ namespace WMS.Web.Domain.Services.Public
var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
_logger.LogInformation($"供应商拉取-结束时间:{endTime}"); _logger.LogInformation($"供应商拉取-结束时间:{endTime}");
//5.供应商集合进行缓存 //5.供应商集合进行缓存
_memoryCache.Set(cache_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12))); _memoryCache.Set(cache_customer_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
_logger.LogInformation($"供应商拉取-总条数:{list.Count}"); _logger.LogInformation($"供应商拉取-总条数:{list.Count}");
return ResultList<ErpCustomerDto>.ReSuccess(list); return ResultList<ErpCustomerDto>.ReSuccess(list);
@@ -1202,8 +1196,7 @@ namespace WMS.Web.Domain.Services.Public
try try
{ {
//1.获取缓存中的仓库数据; //1.获取缓存中的仓库数据;
var cache_key = "erp_supplier_list"; var stocks = _memoryCache.Get<List<ErpStockDto>>(cache_stock_key);
var stocks = _memoryCache.Get<List<ErpStockDto>>(cache_key);
if (stocks == null || stocks.Count == 0) if (stocks == null || stocks.Count == 0)
{ {
//2.先登录金蝶-拿到token //2.先登录金蝶-拿到token
@@ -1240,7 +1233,7 @@ namespace WMS.Web.Domain.Services.Public
} }
//5.供应商集合进行缓存 //5.供应商集合进行缓存
_memoryCache.Set(cache_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12))); _memoryCache.Set(cache_stock_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
_logger.LogInformation($"仓库拉取-总条数:{list.Count}"); _logger.LogInformation($"仓库拉取-总条数:{list.Count}");
return ResultList<ErpStockDto>.ReSuccess(list); return ResultList<ErpStockDto>.ReSuccess(list);
} }
@@ -1265,8 +1258,7 @@ namespace WMS.Web.Domain.Services.Public
try try
{ {
//1.获取缓存中的仓库数据; //1.获取缓存中的仓库数据;
var cache_key = "erp_substock_list"; var stocks = _memoryCache.Get<List<Erp_SubStockDto>>(cache_substock_key);
var stocks = _memoryCache.Get<List<Erp_SubStockDto>>(cache_key);
if (stocks == null || stocks.Count == 0) if (stocks == null || stocks.Count == 0)
{ {
var token_result = await this.Init(); var token_result = await this.Init();
@@ -1297,7 +1289,7 @@ namespace WMS.Web.Domain.Services.Public
} }
//5.供应商集合进行缓存 只有查询全部的时候才缓存 //5.供应商集合进行缓存 只有查询全部的时候才缓存
_memoryCache.Set(cache_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromHours(12))); _memoryCache.Set(cache_substock_key, list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromDays(3)));
_logger.LogInformation($"子仓库拉取-总条数:{list.Count}"); _logger.LogInformation($"子仓库拉取-总条数:{list.Count}");
return ResultList<Erp_SubStockDto>.ReSuccess(list); return ResultList<Erp_SubStockDto>.ReSuccess(list);
} }