优化
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Dto.Erp;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Domain.Services.Public;
|
||||
|
||||
|
||||
@@ -1097,6 +1097,11 @@
|
||||
对应金蝶,物料信息
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Erp.ErpMaterialDto.OrgId">
|
||||
<summary>
|
||||
组织ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Core.Dto.Erp.ErpMaterialDto.MaterialId">
|
||||
<summary>
|
||||
物料ID
|
||||
|
||||
@@ -1271,6 +1271,61 @@
|
||||
创建
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Entitys.Materials">
|
||||
<summary>
|
||||
物料
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.Id">
|
||||
<summary>
|
||||
ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.OrgId">
|
||||
<summary>
|
||||
组织编码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.MaterialId">
|
||||
<summary>
|
||||
物料ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.MaterialName">
|
||||
<summary>
|
||||
物料名称
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.MaterialNumber">
|
||||
<summary>
|
||||
物料编码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.Specifications">
|
||||
<summary>
|
||||
物料规格型号
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.BaseUnitId">
|
||||
<summary>
|
||||
基本单位
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.BaseUnitName">
|
||||
<summary>
|
||||
基本单位名称
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.BaseUnitNumber">
|
||||
<summary>
|
||||
基本单位编码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:WMS.Web.Domain.Entitys.Materials.BarCode">
|
||||
<summary>
|
||||
条码
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Entitys.MoveBoxRecord">
|
||||
<summary>
|
||||
wms移箱记录
|
||||
@@ -2637,6 +2692,40 @@
|
||||
员工ID
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:WMS.Web.Domain.Infrastructure.IMaterialsRepositories">
|
||||
<summary>
|
||||
物料仓储接口
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IMaterialsRepositories.AddRange(System.Collections.Generic.List{WMS.Web.Domain.Entitys.Materials},System.Boolean)">
|
||||
<summary>
|
||||
物料添加
|
||||
</summary>
|
||||
<param name="entitys"></param>
|
||||
<param name="isTransaction"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IMaterialsRepositories.GetEntityList(System.Nullable{System.Int32})">
|
||||
<summary>
|
||||
列表
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IMaterialsRepositories.Get(System.Int32)">
|
||||
<summary>
|
||||
物料
|
||||
</summary>
|
||||
<param name="mid"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IMaterialsRepositories.Get(System.String,System.Int32)">
|
||||
<summary>
|
||||
物料
|
||||
</summary>
|
||||
<param name="code"></param>
|
||||
<param name="orgId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WMS.Web.Domain.Infrastructure.IMoveBoxRecordRepositories.AddRange(System.Collections.Generic.List{WMS.Web.Domain.Entitys.MoveBoxRecord},System.Boolean)">
|
||||
批量添加
|
||||
</member>
|
||||
|
||||
@@ -9,6 +9,11 @@ namespace WMS.Web.Core.Dto.Erp
|
||||
/// </summary>
|
||||
public class ErpMaterialDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织ID
|
||||
/// </summary>
|
||||
public int OrgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料ID
|
||||
/// </summary>
|
||||
|
||||
63
src/WMS.Web.Domain/Entitys/Materials.cs
Normal file
63
src/WMS.Web.Domain/Entitys/Materials.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
using WMS.Web.Core;
|
||||
|
||||
namespace WMS.Web.Domain.Entitys
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
[Table("t_wms_materials")]
|
||||
public class Materials : EntityBase
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
public override int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组织编码
|
||||
/// </summary>
|
||||
public int OrgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料ID
|
||||
/// </summary>
|
||||
public int MaterialId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 物料名称
|
||||
/// </summary>
|
||||
public string MaterialName { get; set; }
|
||||
/// <summary>
|
||||
/// 物料编码
|
||||
/// </summary>
|
||||
public string MaterialNumber { get; set; }
|
||||
/// <summary>
|
||||
/// 物料规格型号
|
||||
/// </summary>
|
||||
public string Specifications { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 基本单位
|
||||
/// </summary>
|
||||
public int BaseUnitId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 基本单位名称
|
||||
/// </summary>
|
||||
public string BaseUnitName { get; set; }
|
||||
/// <summary>
|
||||
/// 基本单位编码
|
||||
/// </summary>
|
||||
public string BaseUnitNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 条码
|
||||
/// </summary>
|
||||
public string BarCode { get; set; }
|
||||
}
|
||||
}
|
||||
43
src/WMS.Web.Domain/Infrastructure/IMaterialsRepositories.cs
Normal file
43
src/WMS.Web.Domain/Infrastructure/IMaterialsRepositories.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
|
||||
namespace WMS.Web.Domain.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料仓储接口
|
||||
/// </summary>
|
||||
public interface IMaterialsRepositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> AddRange(List<Materials> entitys, bool isTransaction = true);
|
||||
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<List<Materials>> GetEntityList(int? orgId = null);
|
||||
|
||||
/// <summary>
|
||||
/// 物料
|
||||
/// </summary>
|
||||
/// <param name="mid"></param>
|
||||
/// <returns></returns>
|
||||
Task<Materials> Get(int mid);
|
||||
|
||||
/// <summary>
|
||||
/// 物料
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="orgId"></param>
|
||||
/// <returns></returns>
|
||||
Task<Materials> Get(string code, int orgId);
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ namespace WMS.Web.Domain.Services.Public
|
||||
public static Task Sync(IServiceProvider serviceProvider)
|
||||
{
|
||||
var sercice = serviceProvider.GetRequiredService<IErpService>();
|
||||
Task.Run(() =>
|
||||
{
|
||||
//异步-同步下物料数据
|
||||
sercice.BillQueryForMaterial().GetAwaiter().GetResult();
|
||||
});
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// //异步-同步下物料数据
|
||||
// sercice.BillQueryForMaterial().GetAwaiter().GetResult();
|
||||
//});
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -369,10 +369,17 @@ namespace WMS.Web.Repositories.Configuration
|
||||
ent.ToTable("t_wms_box_mark_billno");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
//物料
|
||||
builder.Entity<Materials>(ent =>
|
||||
{
|
||||
ent.ToTable("t_wms_materials");
|
||||
ent.HasKey(x => x.Id);
|
||||
});
|
||||
|
||||
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
public DbSet<Materials> Materials { get; set; }
|
||||
public DbSet<BoxMarkBillNo> BoxMarkBillNo { get; set; }
|
||||
public DbSet<BoxMark> BoxMark { get; set; }
|
||||
public DbSet<FileDownManager> FileDownManager { get; set; }
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
||||
services.AddTransient<IErpOpsSyncDateRepositories, ErpOpsSyncDateRepositories>();
|
||||
services.AddTransient<IInStockTaskBoxRepositories, InStockTaskBoxRepositories>();
|
||||
services.AddTransient<IBoxMarkRepositories, BoxMarkRepositories>();
|
||||
services.AddTransient<IMaterialsRepositories, MaterialsRepositories>();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
111
src/WMS.Web.Repositories/MaterialsRepositories.cs
Normal file
111
src/WMS.Web.Repositories/MaterialsRepositories.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WMS.Web.Core.Help;
|
||||
using WMS.Web.Domain.Entitys;
|
||||
using WMS.Web.Domain.Infrastructure;
|
||||
using WMS.Web.Domain.IService.Public;
|
||||
using WMS.Web.Repositories.Configuration;
|
||||
|
||||
namespace WMS.Web.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// 物料仓储
|
||||
/// </summary>
|
||||
public class MaterialsRepositories : IMaterialsRepositories
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly RepositoryDbContext _context;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public MaterialsRepositories(RepositoryDbContext context, IServiceProvider serviceProvider,
|
||||
IMapper mapper)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加
|
||||
/// </summary>
|
||||
/// <param name="entitys"></param>
|
||||
/// <param name="isTransaction"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> AddRange(List<Materials> entitys, bool isTransaction = true)
|
||||
{
|
||||
IDbContextTransaction _transaction = null;
|
||||
if (isTransaction)
|
||||
_transaction = _context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
if (entitys != null && entitys.Count != 0)
|
||||
{
|
||||
await _context.Materials.AddRangeAsync(entitys);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
if (_transaction != null)
|
||||
_transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (_transaction != null)
|
||||
_transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取集合
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<Materials>> GetEntityList(int? orgId = null)
|
||||
{
|
||||
var query = _context.Materials.Where(x => 1 == 1);
|
||||
if (orgId.HasValue)
|
||||
query = query.Where(x => x.OrgId == orgId.Value);
|
||||
|
||||
var res = await query.ToListAsync();
|
||||
|
||||
return res.Clone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Materials> Get(int mid)
|
||||
{
|
||||
var query = _context.Materials.Where(x => 1 == 1);
|
||||
|
||||
query = query.Where(x => x.MaterialId == mid);
|
||||
|
||||
var res = await query.FirstOrDefaultAsync();
|
||||
|
||||
return res.Clone();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Materials> Get(string code,int orgId)
|
||||
{
|
||||
var query = _context.Materials.Where(x => x.MaterialNumber==code && x.OrgId==orgId);
|
||||
|
||||
var res = await query.FirstOrDefaultAsync();
|
||||
|
||||
return res.Clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user