From ea9632d8b54cf00231ef166d7ae7b6d6e004f474 Mon Sep 17 00:00:00 2001 From: "rongguo.jia" Date: Fri, 14 Apr 2023 09:33:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[fix]=E4=B8=BA=E8=BF=9C=E7=A8=8B=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?try,catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Win_in.Sfs.Shared.Host/HostBuilderExtensions.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/HostBuilderExtensions.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/HostBuilderExtensions.cs index 5319f16a2..189e69c1d 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/HostBuilderExtensions.cs +++ b/be/Modules/Shared/src/Win_in.Sfs.Shared.Host/HostBuilderExtensions.cs @@ -45,6 +45,7 @@ public static class HostBuilderExtensions AddJsonByUrl(cb, $"{configUrl}appsettings.{builder.Environment.EnvironmentName}.json"); if (builder.Environment.IsDevelopment()) { + cb.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json")); cb.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{builder.Environment.EnvironmentName}.json")); } }); @@ -79,7 +80,14 @@ public static class HostBuilderExtensions private static void AddJsonByUrl(IConfigurationBuilder configurationBuilder, string url) { Console.WriteLine($"load config form:{url}"); - var stream = new HttpClient().GetStreamAsync(url).Result; - configurationBuilder.AddJsonStream(stream); + try + { + var stream = new HttpClient().GetStreamAsync(url).Result; + configurationBuilder.AddJsonStream(stream); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } } } From b789f7df1164979838d08af5842e3758d42d7050 Mon Sep 17 00:00:00 2001 From: "rongguo.jia" Date: Fri, 14 Apr 2023 09:34:26 +0800 Subject: [PATCH 2/2] =?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; }