From 9fc76c281c7ec211f8450801eebd1bc9acd25c0d Mon Sep 17 00:00:00 2001 From: "boxu.zheng" Date: Mon, 22 Jul 2024 09:41:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20post=20getbycodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bases/SfsAuthCrudAppServiceBase.cs | 20 +++++++++++++++++++ .../SfsBaseDataWithCodeAppServiceBase.cs | 20 +++++++++++++++++++ .../Balances/BalanceAppService.cs | 2 +- .../Bases/SfsLabelAppServiceWithCodeBase.cs | 7 +++++++ .../ISfsGetByCodeAppService.cs | 2 ++ .../Bases/SfsJobWithCodeAppServiceBase.cs | 7 +++++++ 6 files changed, 57 insertions(+), 1 deletion(-) diff --git a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Bases/SfsAuthCrudAppServiceBase.cs b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Bases/SfsAuthCrudAppServiceBase.cs index 51fde7a8f..443f160c3 100644 --- a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Bases/SfsAuthCrudAppServiceBase.cs +++ b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Bases/SfsAuthCrudAppServiceBase.cs @@ -76,6 +76,26 @@ public abstract class SfsBaseDataWithCodeAppServiceBase> GetByCodesWithPostAsync(IEnumerable codes) + { + + var dtoList = new List(); + foreach (var code in codes) + { + var dto = await Cache.GetOrAddItemAsync( + $"{typeof(TEntityDto).Name}:{code}".ToString(), + async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), + SfsCacheConst.SeveralMinutes).ConfigureAwait(false); + if (dto != null) + { + dtoList.Add(dto); + } + } + return dtoList; + } + private async Task GetFromRepositoryAsync(string code) { // var entity = await _repository.FindAsync(p => p.Code == code); diff --git a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Bases/SfsBaseDataWithCodeAppServiceBase.cs b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Bases/SfsBaseDataWithCodeAppServiceBase.cs index 7e3d24536..2ead84aaf 100644 --- a/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Bases/SfsBaseDataWithCodeAppServiceBase.cs +++ b/be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Bases/SfsBaseDataWithCodeAppServiceBase.cs @@ -67,6 +67,26 @@ public abstract class SfsBaseDataWithCodeAppServiceBase> GetByCodesWithPostAsync(IEnumerable codes) + { + + var dtoList = new List(); + foreach (var code in codes) + { + var dto = await Cache.GetOrAddItemAsync( + $"{typeof(TEntityDto).Name}:{code}".ToString(), + async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), + SfsCacheConst.SeveralMinutes).ConfigureAwait(false); + if (dto != null) + { + dtoList.Add(dto); + } + } + return dtoList; + } + protected virtual async Task GetFromRepositoryAsync(string code) { // var entity = await _repository.FindAsync(p => p.Code == code); diff --git a/be/Modules/Inventory/src/Win_in.Sfs.Wms.Inventory.Application/Balances/BalanceAppService.cs b/be/Modules/Inventory/src/Win_in.Sfs.Wms.Inventory.Application/Balances/BalanceAppService.cs index 597e5b0c4..6d8bcabee 100644 --- a/be/Modules/Inventory/src/Win_in.Sfs.Wms.Inventory.Application/Balances/BalanceAppService.cs +++ b/be/Modules/Inventory/src/Win_in.Sfs.Wms.Inventory.Application/Balances/BalanceAppService.cs @@ -961,7 +961,7 @@ public class BalanceAppService if (list.Count > 0) { var itemCodes = list.Select(t => t.ItemCode).Distinct(); - var itemBasicDtos = await _itemBasicAppService.GetByCodesAsync(itemCodes).ConfigureAwait(false); + var itemBasicDtos = await _itemBasicAppService.GetByCodesWithPostAsync(itemCodes).ConfigureAwait(false); if (itemBasicDtos.Count > 0) { list.ForEach(item => diff --git a/be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs b/be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs index 033bb43b3..ab15537f7 100644 --- a/be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs +++ b/be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs @@ -72,6 +72,13 @@ public class SfsLabelAppServiceWithCodeBase> GetByCodesWithPostAsync(IEnumerable codes) + { + var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false); + var dtoList = ObjectMapper.Map, List>(entities); + return dtoList; + } + private async Task GetFromRepositoryAsync(string code) { // var entity = await _repository.FindAsync(p => p.Code == code); diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application.Contracts/ISfsGetByCodeAppService.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Application.Contracts/ISfsGetByCodeAppService.cs index 8b79a9924..00a28540e 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application.Contracts/ISfsGetByCodeAppService.cs +++ b/be/Modules/Shared/src/Win_in.Sfs.Shared.Application.Contracts/ISfsGetByCodeAppService.cs @@ -20,4 +20,6 @@ public interface ISfsGetByCodeAppService /// /// Task> GetByCodesAsync(IEnumerable codes); + + Task> GetByCodesWithPostAsync(IEnumerable codes); } diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobWithCodeAppServiceBase.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobWithCodeAppServiceBase.cs index 6102ed5d2..6c7059fdf 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobWithCodeAppServiceBase.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobWithCodeAppServiceBase.cs @@ -73,6 +73,13 @@ public abstract class SfsJobWithCodeAppServiceBase> GetByCodesWithPostAsync(IEnumerable codes) + { + var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false); + var dtoList = ObjectMapper.Map, List>(entities); + return dtoList; + } + protected virtual async Task GetFromRepositoryAsync(string code) { // var entity = await _repository.FindAsync(p => p.Code == code);