From b789f7df1164979838d08af5842e3758d42d7050 Mon Sep 17 00:00:00 2001 From: "rongguo.jia" Date: Fri, 14 Apr 2023 09:34:26 +0800 Subject: [PATCH] =?UTF-8?q?[fix]Job,Label=E5=9F=BA=E7=B1=BB=E4=B8=AD?= =?UTF-8?q?=E7=9A=84GetByCode,GetByCodes=E4=B8=8D=E5=86=8D=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Bases/SfsLabelAppServiceWithCodeBase.cs | 39 +++++++++++-------- .../Bases/SfsJobWithCodeAppServiceBase.cs | 39 +++++++++++-------- 2 files changed, 46 insertions(+), 32 deletions(-) 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 312404b9c..033bb43b3 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 @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -38,10 +39,12 @@ public class SfsLabelAppServiceWithCodeBase GetByCodeAsync(string code) { - var dto = await Cache.GetOrAddItemAsync( - $"{typeof(TEntityDto).Name}:{code}".ToString(), - async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), - SfsCacheConst.SeveralMinutes).ConfigureAwait(false); + // var dto = await Cache.GetOrAddItemAsync( + // $"{typeof(TEntityDto).Name}:{code}".ToString(), + // async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), + // SfsCacheConst.SeveralMinutes).ConfigureAwait(false); + + var dto = await GetFromRepositoryAsync(code).ConfigureAwait(false); return dto; } @@ -50,18 +53,22 @@ public class SfsLabelAppServiceWithCodeBase> GetByCodesAsync(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); - } - } + // 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; + + var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false); + var dtoList = ObjectMapper.Map, List>(entities); return dtoList; } 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 d1493e856..6102ed5d2 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 @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; @@ -37,10 +38,12 @@ public abstract class SfsJobWithCodeAppServiceBase GetByCodeAsync(string code) { - var dto = await Cache.GetOrAddItemAsync( - $"{typeof(TEntityDto).Name}:{code}".ToString(), - async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), - SfsCacheConst.SeveralMinutes).ConfigureAwait(false); + // var dto = await Cache.GetOrAddItemAsync( + // $"{typeof(TEntityDto).Name}:{code}".ToString(), + // async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), + // SfsCacheConst.SeveralMinutes).ConfigureAwait(false); + + var dto = await GetFromRepositoryAsync(code).ConfigureAwait(false); return dto; @@ -51,18 +54,22 @@ public abstract class SfsJobWithCodeAppServiceBase> GetByCodesAsync(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); - } - } + // 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; + + var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false); + var dtoList = ObjectMapper.Map, List>(entities); return dtoList; }