From 71ac49b66fff075cf85c8fc0caae3177ef055c34 Mon Sep 17 00:00:00 2001 From: zhaoxinyu <89237069@qq.com> Date: Tue, 9 Apr 2024 13:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductionReturnRequestController .cs | 9 +- .../Stores/CustomerReturnNoteController.cs | 6 +- .../Boms/BomManager.cs | 5 ++ .../Caches/Cache.cs | 49 ++++++++++- .../CustomerProductionReturnNoteAppService.cs | 12 +++ ...erProductionReturnNoteAutoMapperProfile.cs | 31 ++++++- ...ustomerProductionReturnNoteEventHandler.cs | 86 ++++++++++--------- 7 files changed, 148 insertions(+), 50 deletions(-) diff --git a/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Jobs/ProductionReturnRequestController .cs b/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Jobs/ProductionReturnRequestController .cs index 62dda4056..0a665f45f 100644 --- a/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Jobs/ProductionReturnRequestController .cs +++ b/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Jobs/ProductionReturnRequestController .cs @@ -23,6 +23,7 @@ public class ProductionReturnRequestController : AbpController { private readonly IProductionReturnJobAppService _productionReturnJobAppService; private readonly IProductionReturnRequestAppService _productionReturnRequestAppService; + private readonly ICustomerProductionReturnNoteAppService _customerReturnAppService; private readonly IUserWorkGroupAppService _userWorkGroupAppService; @@ -38,9 +39,11 @@ public class ProductionReturnRequestController : AbpController IProductionReturnJobAppService productionReturnJobAppService , IUserWorkGroupAppService userWorkGroupAppService , ILocationAppService locationApp - , IProductionReturnRequestAppService productionReturnRequestAppService + , IProductionReturnRequestAppService productionReturnRequestAppService, + ICustomerProductionReturnNoteAppService customerReturnAppService ) { + _customerReturnAppService = customerReturnAppService; _productionReturnRequestAppService = productionReturnRequestAppService; _userWorkGroupAppService = userWorkGroupAppService; this._productionReturnJobAppService = productionReturnJobAppService; @@ -62,9 +65,9 @@ public class ProductionReturnRequestController : AbpController [HttpPost("")] - public virtual async Task CreateAsync(ProductionReturnRequestEditInput input) + public virtual async Task CreateAsync(CustomerProductionReturnNoteEditInput input) { - return await _productionReturnRequestAppService.CreateAsync(input).ConfigureAwait(false); + return await _customerReturnAppService.CreateAsync(input).ConfigureAwait(false); } diff --git a/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Stores/CustomerReturnNoteController.cs b/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Stores/CustomerReturnNoteController.cs index 6519ade22..a7ecf3b67 100644 --- a/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Stores/CustomerReturnNoteController.cs +++ b/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Stores/CustomerReturnNoteController.cs @@ -12,14 +12,14 @@ namespace Win_in.Sfs.Wms.Pda.Controllers.Stores; [Route($"{PdaHostConst.ROOT_ROUTE}store/return-from-customer")] public class CustomerReturnNoteController : AbpController { - private readonly ICustomerReturnNoteAppService _customerReturnNoteAppService; + private readonly ICustomerProductionReturnNoteAppService _customerReturnNoteAppService; /// /// /// /// public CustomerReturnNoteController( - ICustomerReturnNoteAppService customerReturnNoteAppService) + ICustomerProductionReturnNoteAppService customerReturnNoteAppService) { _customerReturnNoteAppService = customerReturnNoteAppService; } @@ -30,7 +30,7 @@ public class CustomerReturnNoteController : AbpController /// /// [HttpPost("")] - public virtual async Task CreateAsync(CustomerReturnNoteEditInput input) + public virtual async Task CreateAsync(CustomerProductionReturnNoteEditInput input) { return await _customerReturnNoteAppService.CreateAsync(input).ConfigureAwait(false); } diff --git a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Boms/BomManager.cs b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Boms/BomManager.cs index a0f2f3978..c3f7120bd 100644 --- a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Boms/BomManager.cs +++ b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Boms/BomManager.cs @@ -324,6 +324,11 @@ public class BomManager : DomainService, IBomManager private async Task> GetComponentsByProduct(string product) { List list=new List(); + if (Cache.Boms.Count == 0) + { + InitBomComponent(); + } + list=Cache.Boms.Count > 0 ? Cache.Boms.Where(p => p.Product == product).ToList() : await _repository.GetListAsync(p => p.Product == product).ConfigureAwait(false); List components = new List(); diff --git a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Caches/Cache.cs b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Caches/Cache.cs index 718bb501c..0d3bb63ea 100644 --- a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Caches/Cache.cs +++ b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Domain/Caches/Cache.cs @@ -8,6 +8,53 @@ using Win_in.Sfs.Basedata.Domain; namespace Win_in.Sfs.Basedata.Caches; public static class Cache { - public static List Boms = new List(); + public static List Boms = new List(); + public static async void BomsLifeCycle(int lifetime) + { + var reassigner = new Reassigner(DateTime.Now,new TimeSpan(0,5,0)); + await reassigner.RunAsync(() => { + Boms.Clear(); + }).ConfigureAwait(false); + } } +public class Reassigner +{ + private readonly TimeSpan _interval; + private DateTime _lasttime; + public Reassigner(DateTime lasttime, TimeSpan interval) + { + _lasttime = lasttime; + _interval = interval; + } + + public async Task RunAsync(Action p_action) + { + while (true) + { + // 获取当前时间 + var currentTime = DateTime.Now; + // 计算上次重新赋值到现在的时间间隔 + var elapsed = currentTime - _lasttime; + // 检查时间间隔是否满足条件 + if (elapsed >= _interval) + { + p_action(); + // 重新赋值 + //_value = await GetValueAsync(); + // 更新最后更新时间 + _lasttime = currentTime; + } + + // 等待下一刻钟 + await Task.Delay(_interval); + } + } + +} + + + + + + diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/CustomerProductionReturnNotes/CustomerProductionReturnNoteAppService.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/CustomerProductionReturnNotes/CustomerProductionReturnNoteAppService.cs index 5a239fbf0..241a8f532 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/CustomerProductionReturnNotes/CustomerProductionReturnNoteAppService.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Notes/CustomerProductionReturnNotes/CustomerProductionReturnNoteAppService.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Win_in.Sfs.Shared.Domain.Shared; using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; using Win_in.Sfs.Wms.Store.Domain.Shared; @@ -37,6 +38,17 @@ public class CustomerProductionReturnNoteAppService : public override async Task CreateAsync(CustomerProductionReturnNoteEditInput input) { var entity = ObjectMapper.Map(input); + foreach (var itm in entity.Details) + { + itm.FromLocationCode = "HOLD"; + itm.FromStatus = EnumInventoryStatus.OK; + itm.ToStatus=EnumInventoryStatus.OK; + + + } + + + await _CustomerProductionReturnNoteManager.CreateAsync(entity).ConfigureAwait(false); var dto = ObjectMapper.Map(entity); return dto; diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/AutoMapperProfiles/Notes/CustomerProductionReturnNoteAutoMapperProfile.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/AutoMapperProfiles/Notes/CustomerProductionReturnNoteAutoMapperProfile.cs index ae68caa23..eaa70bea5 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/AutoMapperProfiles/Notes/CustomerProductionReturnNoteAutoMapperProfile.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/AutoMapperProfiles/Notes/CustomerProductionReturnNoteAutoMapperProfile.cs @@ -1,6 +1,7 @@ using AutoMapper; using Volo.Abp.AutoMapper; using Win_in.Sfs.Wms.Inventory.Application.Contracts; +using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; namespace Win_in.Sfs.Wms.Store.Event; @@ -10,14 +11,38 @@ public partial class StoreEventAutoMapperProfile : Profile private void CustomerProductionReturnNoteAutoMapperProfile() { CreateMap() + .Ignore(x => x.Worker) + .Ignore(x => x.TransType) + .Ignore(x => x.DocNumber) + .Ignore(x => x.JobNumber) + .Ignore(x => x.ExtraProperties) + .Ignore(x => x.TransSubType) + ; - .ForMember(x => x.DocNumber, y => y.MapFrom(t => t.Number)) - .Ignore(x => x.JobNumber) + CreateMap() + .ForMember(x => x.PackingCode, y => y.MapFrom(d => d.ToPackingCode)) + .ForMember(x => x.ContainerCode, y => y.MapFrom(d => d.ToContainerCode)) + .ForMember(x => x.Lot, y => y.MapFrom(d => d.ToLot)) + .ForMember(x => x.Status, y => y.MapFrom(d => d.ToStatus)) + .ForMember(x => x.LocationCode, y => y.MapFrom(d => d.ToLocationCode)) + .ForMember(x => x.LocationArea, y => y.MapFrom(d => d.ToLocationArea)) + .ForMember(x => x.LocationGroup, y => y.MapFrom(d => d.ToLocationGroup)) + .ForMember(x => x.LocationErpCode, y => y.MapFrom(d => d.ToLocationErpCode)) + .ForMember(x => x.WarehouseCode, y => y.MapFrom(d => d.ToWarehouseCode)) .Ignore(x => x.Worker) - .Ignore(x => x.TransType) .Ignore(x => x.ExtraProperties) + .Ignore(x => x.DocNumber) + .Ignore(x => x.JobNumber) + .Ignore(x => x.ManageType) + .Ignore(x => x.TransType) .Ignore(x => x.TransSubType) + .Ignore(x => x.TransInOut) + ; + + CreateMap() + .ReverseMap(); + CreateMap(); } } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/CustomerProductionReturnNoteEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/CustomerProductionReturnNoteEventHandler.cs index bc62f87a8..81bea4400 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/CustomerProductionReturnNoteEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Transactions/CustomerProductionReturnNoteEventHandler.cs @@ -8,6 +8,7 @@ using Win_in.Sfs.Shared.Event; using Win_in.Sfs.Wms.Inventory.Application.Contracts; using Win_in.Sfs.Wms.Store.Application.Contracts; using Win_in.Sfs.Wms.Store.Domain; +using Win_in.Sfs.Wms.Store.Domain.Shared; using Win_in.Sfs.Wms.Store.Event.Transaction; namespace Win_in.Sfs.Wms.Store.Event.Transactions; @@ -17,78 +18,83 @@ public class CustomerProductionReturnNoteEventHandler , ILocalEventHandler> , ILocalEventHandler>> - - - { private const EnumTransType TransType = EnumTransType.CustomerReturn; - - private readonly IProductionReturnRequestAppService _productionReturnRequestApp; - - public CustomerProductionReturnNoteEventHandler(IProductionReturnRequestAppService productionReturnRequestApp) - { - this._productionReturnRequestApp = productionReturnRequestApp; - } + private const EnumTransInOut TransInOut = EnumTransInOut.In; [UnitOfWork] public virtual async Task HandleEventAsync(SfsCreatedEntityEventData eventData) { var entity = eventData.Entity; - await AddTransactionsAsync(entity).ConfigureAwait(false); - if (!string.IsNullOrEmpty(entity.ProductionReturnRequestNumber)) - { - await _productionReturnRequestApp.CompleteByNumberAsync(entity.ProductionReturnRequestNumber).ConfigureAwait(false); - } + await AddTransactionsAsync(entity).ConfigureAwait(false); } private async Task AddTransactionsAsync(CustomerProductionReturnNote CustomerProductionReturnNote) { - var inboundTransactions = new List(); + ////如果WMS管理客户寄售库,生成库存转移 + //if (await SettingManager.IsTrueAsync(StoreSettings.Common.EnableCustomerLocation).ConfigureAwait(false)) + //{ - inboundTransactions.AddRange(BuildTransferLogs(CustomerProductionReturnNote)); + // var transferLogs = BuildTransferLogs(CustomerProductionReturnNote); + // await TransferLogAppService.AddManyAsync(transferLogs).ConfigureAwait(false); - await TransferLogAppService.AddManyAsync(inboundTransactions).ConfigureAwait(false); + //} + //else //如果WMS不管理客户寄售库,生成入库 + //{ - } + var transactions = BuildTransactions(CustomerProductionReturnNote); + await TransactionAppService.AddManyAsync(transactions).ConfigureAwait(false); + //} - [UnitOfWork] - public virtual async Task HandleEventAsync(SfsCreatedEntityEventData> eventData) - { - var entities = eventData.Entity; - await AddTransactionsAsync(entities).ConfigureAwait(false); } - private async Task AddTransactionsAsync(List CustomerProductionReturnNotes) + /// + /// 构造 库存转移日志实体 + /// + /// + /// + private List BuildTransferLogs(CustomerProductionReturnNote CustomerProductionReturnNote) { - var inboundTransactions = new List(); + var transferLogCreateInputs = new List(); - //如果要做库存事务汇总,可以修改此处 - foreach (var CustomerProductionReturnNote in CustomerProductionReturnNotes) + foreach (var detail in CustomerProductionReturnNote.Details.Where(detail => detail.Qty != 0)) { - inboundTransactions.AddRange(BuildTransferLogs(CustomerProductionReturnNote)); + var transferLog = ObjectMapper.Map(detail); + transferLog.TransType = TransType; + transferLog.Worker = CustomerProductionReturnNote.Worker; + transferLog.DocNumber = CustomerProductionReturnNote.Number; + transferLog.JobNumber = CustomerProductionReturnNote.JobNumber; + transferLogCreateInputs.Add(transferLog); } - await TransferLogAppService.AddManyAsync(inboundTransactions).ConfigureAwait(false); + return transferLogCreateInputs; } - private List BuildTransferLogs(CustomerProductionReturnNote CustomerProductionReturnNote) + private List BuildTransactions(CustomerProductionReturnNote CustomerProductionReturnNote) { - var transferLogs = new List(); - foreach (var detail in CustomerProductionReturnNote.Details.Where(detail => detail.Qty != 0)) + var transactions = new List(); + + foreach (var detail in CustomerProductionReturnNote.Details) { - var transferLog = ObjectMapper.Map(detail); + var transaction = ObjectMapper.Map(detail); - transferLog.TransType = TransType; + transaction.TransType = TransType; + transaction.TransInOut = TransInOut; - transferLog.Worker = CustomerProductionReturnNote.Worker; - transferLog.DocNumber = CustomerProductionReturnNote.Number; - transferLog.JobNumber = CustomerProductionReturnNote.JobNumber; + transaction.Worker = CustomerProductionReturnNote.Worker; + transaction.DocNumber = CustomerProductionReturnNote.Number; + transaction.JobNumber = CustomerProductionReturnNote.JobNumber; + transaction.Status = EnumInventoryStatus.OK; - transferLogs.Add(transferLog); + transactions.Add(transaction); } - return transferLogs; + return transactions; } + public Task HandleEventAsync(SfsCreatedEntityEventData> eventData) + { + throw new System.NotImplementedException(); + } }