优化
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using ERP;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
@@ -42,13 +43,17 @@ namespace WMS.Web.Domain.Services.Public
|
||||
private ERPGWSoapClient _client;
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
private readonly IBasicsRepositories _basicsRepositories;
|
||||
private readonly IMaterialsRepositories _materialsRepositories;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
public ErpService(
|
||||
IMapper mapper,
|
||||
IOptions<ErpOptions> erpOptions,
|
||||
IOptions<AppOptions> appOptions,
|
||||
ILogger<ErpService> logger,
|
||||
IOptions<AppOptions> appOptions, IServiceProvider serviceProvider,
|
||||
ILogger<ErpService> logger, IMaterialsRepositories materialsRepositories,
|
||||
IMemoryCache memoryCache, IBasicsRepositories basicsRepositories)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
this._materialsRepositories = materialsRepositories;
|
||||
this._basicsRepositories = basicsRepositories;
|
||||
this._erpOptions = erpOptions?.Value;
|
||||
this._appOptions = appOptions?.Value;
|
||||
@@ -808,14 +813,43 @@ namespace WMS.Web.Domain.Services.Public
|
||||
var materials = _memoryCache.Get<List<ErpMaterialDto>>(_erpOptions.cache_materail_key);
|
||||
if (materials == null || materials.Count == 0)
|
||||
{
|
||||
return await this.BillQueryForMaterialPagedList();
|
||||
var mats= await _materialsRepositories.GetEntityList(100008);
|
||||
if (mats == null || mats.Count == 0)
|
||||
return await this.BillQueryForMaterialPagedList();
|
||||
else
|
||||
{
|
||||
var beginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
_logger.LogInformation($"物料拉取-开始时间:{beginTime}");
|
||||
var erp_materials_list = new List<ErpMaterialDto>();
|
||||
//4.5.拼装
|
||||
foreach (var item in mats)
|
||||
{
|
||||
var lis = new ErpMaterialDto();
|
||||
lis.MaterialId = item.MaterialId;
|
||||
lis.MaterialName = item.MaterialName;
|
||||
lis.MaterialNumber = item.MaterialNumber;
|
||||
lis.Specifications = item.Specifications;
|
||||
lis.BaseUnitId = item.BaseUnitId;
|
||||
lis.BaseUnitName = item.BaseUnitName;
|
||||
lis.BaseUnitNumber = item.BaseUnitNumber;
|
||||
lis.BarCode = item.BarCode;
|
||||
lis.OrgId = item.OrgId;
|
||||
erp_materials_list.Add(lis);
|
||||
}
|
||||
_memoryCache.Set(_erpOptions.cache_materail_key, erp_materials_list, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(DateTimeUtil.GetTotalMinutesTimeSpan())));
|
||||
var endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
_logger.LogInformation($"物料拉取-结束时间:{endTime}");
|
||||
_logger.LogInformation($"物料拉取-总条数:{erp_materials_list.Count}");
|
||||
return ResultList<ErpMaterialDto>.ReSuccess(erp_materials_list);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResultList<ErpMaterialDto>.ReSuccess(materials);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return ResultList<ErpMaterialDto>.ReFailure(ResultCodes.ErpMaterialError);
|
||||
@@ -840,13 +874,28 @@ namespace WMS.Web.Domain.Services.Public
|
||||
if (mater == null)
|
||||
{
|
||||
//2.1没有的话:去金蝶取
|
||||
mater = await this.BillQueryForMaterialById(id);
|
||||
if (mater != null)
|
||||
//mater = await this.BillQueryForMaterialById(id);
|
||||
var ent = await _materialsRepositories.Get(id);
|
||||
if (ent != null)
|
||||
{
|
||||
//把取到的数据放集合中并重新给缓存
|
||||
materials.Add(mater);
|
||||
_memoryCache.Set(_erpOptions.cache_materail_key, materials, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(DateTimeUtil.GetTotalMinutesTimeSpan())));
|
||||
return Result<ErpMaterialDto>.ReSuccess(mater);
|
||||
var linshi_mat= await _materialsRepositories.Get(ent.MaterialNumber, 100008);
|
||||
if (linshi_mat != null)
|
||||
{
|
||||
mater = new ErpMaterialDto();
|
||||
mater.MaterialId = ent.MaterialId;
|
||||
mater.MaterialName = linshi_mat.MaterialName;
|
||||
mater.MaterialNumber = linshi_mat.MaterialNumber;
|
||||
mater.Specifications = linshi_mat.Specifications;
|
||||
mater.BaseUnitId = linshi_mat.BaseUnitId;
|
||||
mater.BaseUnitName = linshi_mat.BaseUnitName;
|
||||
mater.BaseUnitNumber = linshi_mat.BaseUnitNumber;
|
||||
mater.BarCode = linshi_mat.BarCode;
|
||||
mater.OrgId = linshi_mat.OrgId;
|
||||
//把取到的数据放集合中并重新给缓存
|
||||
materials.Add(mater);
|
||||
_memoryCache.Set(_erpOptions.cache_materail_key, materials, new MemoryCacheEntryOptions().SetAbsoluteExpiration(TimeSpan.FromMinutes(DateTimeUtil.GetTotalMinutesTimeSpan())));
|
||||
return Result<ErpMaterialDto>.ReSuccess(mater);
|
||||
}
|
||||
}
|
||||
else
|
||||
return Result<ErpMaterialDto>.ReSuccess(null);
|
||||
|
||||
Reference in New Issue
Block a user