From c3413e5c44f3f6418ae53fe951aa8d6b7318f325 Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Sat, 2 Mar 2024 19:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WMS.Web.Api/Program.cs | 1 + src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml | 5 + src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml | 89 ++++++++++++++ .../Dto/Erp/Material/ErpMaterialDto.cs | 5 + src/WMS.Web.Domain/Entitys/Materials.cs | 63 ++++++++++ .../Infrastructure/IMaterialsRepositories.cs | 43 +++++++ .../Services/Public/ErpBaseDataSync.cs | 10 +- .../Services/Public/ErpService.cs | 69 +++++++++-- .../Configuration/RepositoryDbContext.cs | 7 ++ .../AppBuilderExtensions.cs | 1 + .../MaterialsRepositories.cs | 111 ++++++++++++++++++ 11 files changed, 389 insertions(+), 15 deletions(-) create mode 100644 src/WMS.Web.Domain/Entitys/Materials.cs create mode 100644 src/WMS.Web.Domain/Infrastructure/IMaterialsRepositories.cs create mode 100644 src/WMS.Web.Repositories/MaterialsRepositories.cs diff --git a/src/WMS.Web.Api/Program.cs b/src/WMS.Web.Api/Program.cs index 2b6dd864..47e34314 100644 --- a/src/WMS.Web.Api/Program.cs +++ b/src/WMS.Web.Api/Program.cs @@ -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; diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index 66ebbbf3..26c984fc 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -1097,6 +1097,11 @@ 对应金蝶,物料信息 + + + 组织ID + + 物料ID diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index d3f6d424..c394d788 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -1271,6 +1271,61 @@ 创建 + + + 物料 + + + + + ID + + + + + 组织编码 + + + + + 物料ID + + + + + 物料名称 + + + + + 物料编码 + + + + + 物料规格型号 + + + + + 基本单位 + + + + + 基本单位名称 + + + + + 基本单位编码 + + + + + 条码 + + wms移箱记录 @@ -2637,6 +2692,40 @@ 员工ID + + + 物料仓储接口 + + + + + 物料添加 + + + + + + + + 列表 + + + + + + 物料 + + + + + + + 物料 + + + + + 批量添加 diff --git a/src/WMS.Web.Core/Dto/Erp/Material/ErpMaterialDto.cs b/src/WMS.Web.Core/Dto/Erp/Material/ErpMaterialDto.cs index a3d5ddeb..55510f39 100644 --- a/src/WMS.Web.Core/Dto/Erp/Material/ErpMaterialDto.cs +++ b/src/WMS.Web.Core/Dto/Erp/Material/ErpMaterialDto.cs @@ -9,6 +9,11 @@ namespace WMS.Web.Core.Dto.Erp /// public class ErpMaterialDto { + /// + /// 组织ID + /// + public int OrgId { get; set; } + /// /// 物料ID /// diff --git a/src/WMS.Web.Domain/Entitys/Materials.cs b/src/WMS.Web.Domain/Entitys/Materials.cs new file mode 100644 index 00000000..3000d83e --- /dev/null +++ b/src/WMS.Web.Domain/Entitys/Materials.cs @@ -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 +{ + /// + /// 物料 + /// + [Serializable] + [Table("t_wms_materials")] + public class Materials : EntityBase + { + /// + /// ID + /// + public override int Id { get; set; } + + /// + /// 组织编码 + /// + public int OrgId { get; set; } + + /// + /// 物料ID + /// + public int MaterialId { get; set; } + + /// + /// 物料名称 + /// + public string MaterialName { get; set; } + /// + /// 物料编码 + /// + public string MaterialNumber { get; set; } + /// + /// 物料规格型号 + /// + public string Specifications { get; set; } + + /// + /// 基本单位 + /// + public int BaseUnitId { get; set; } + + /// + /// 基本单位名称 + /// + public string BaseUnitName { get; set; } + /// + /// 基本单位编码 + /// + public string BaseUnitNumber { get; set; } + + /// + /// 条码 + /// + public string BarCode { get; set; } + } +} diff --git a/src/WMS.Web.Domain/Infrastructure/IMaterialsRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IMaterialsRepositories.cs new file mode 100644 index 00000000..a26e1a87 --- /dev/null +++ b/src/WMS.Web.Domain/Infrastructure/IMaterialsRepositories.cs @@ -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 +{ + /// + /// 物料仓储接口 + /// + public interface IMaterialsRepositories + { + /// + /// 物料添加 + /// + /// + /// + /// + Task AddRange(List entitys, bool isTransaction = true); + + /// + /// 列表 + /// + /// + Task> GetEntityList(int? orgId = null); + + /// + /// 物料 + /// + /// + /// + Task Get(int mid); + + /// + /// 物料 + /// + /// + /// + /// + Task Get(string code, int orgId); + } +} diff --git a/src/WMS.Web.Domain/Services/Public/ErpBaseDataSync.cs b/src/WMS.Web.Domain/Services/Public/ErpBaseDataSync.cs index 01640077..4f84caf1 100644 --- a/src/WMS.Web.Domain/Services/Public/ErpBaseDataSync.cs +++ b/src/WMS.Web.Domain/Services/Public/ErpBaseDataSync.cs @@ -15,11 +15,11 @@ namespace WMS.Web.Domain.Services.Public public static Task Sync(IServiceProvider serviceProvider) { var sercice = serviceProvider.GetRequiredService(); - Task.Run(() => - { - //异步-同步下物料数据 - sercice.BillQueryForMaterial().GetAwaiter().GetResult(); - }); + //Task.Run(() => + //{ + // //异步-同步下物料数据 + // sercice.BillQueryForMaterial().GetAwaiter().GetResult(); + //}); Task.Run(() => { diff --git a/src/WMS.Web.Domain/Services/Public/ErpService.cs b/src/WMS.Web.Domain/Services/Public/ErpService.cs index d3c9faac..7db7decf 100644 --- a/src/WMS.Web.Domain/Services/Public/ErpService.cs +++ b/src/WMS.Web.Domain/Services/Public/ErpService.cs @@ -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, - IOptions appOptions, - ILogger logger, + IOptions appOptions, IServiceProvider serviceProvider, + ILogger 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>(_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(); + //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.ReSuccess(erp_materials_list); + } + } else { return ResultList.ReSuccess(materials); } } - catch (Exception) + catch (Exception ex) { return ResultList.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.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.ReSuccess(mater); + } } else return Result.ReSuccess(null); diff --git a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs index f3fe4704..cfcfac1c 100644 --- a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs +++ b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs @@ -369,10 +369,17 @@ namespace WMS.Web.Repositories.Configuration ent.ToTable("t_wms_box_mark_billno"); ent.HasKey(x => x.Id); }); + //物料 + builder.Entity(ent => + { + ent.ToTable("t_wms_materials"); + ent.HasKey(x => x.Id); + }); base.OnModelCreating(builder); } + public DbSet Materials { get; set; } public DbSet BoxMarkBillNo { get; set; } public DbSet BoxMark { get; set; } public DbSet FileDownManager { get; set; } diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs index befee5a7..37f9847a 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilderExtensions.cs @@ -78,6 +78,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/src/WMS.Web.Repositories/MaterialsRepositories.cs b/src/WMS.Web.Repositories/MaterialsRepositories.cs new file mode 100644 index 00000000..9964dd70 --- /dev/null +++ b/src/WMS.Web.Repositories/MaterialsRepositories.cs @@ -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 +{ + /// + /// 物料仓储 + /// + 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; + } + + /// + /// 批量添加 + /// + /// + /// + /// + public async Task AddRange(List 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; + } + } + + /// + /// 获取集合 + /// + /// + /// + public async Task> 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(); + } + + /// + /// 获取 + /// + /// + /// + public async Task 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(); + } + + /// + /// 获取 + /// + /// + /// + public async Task 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(); + } + } +}