郑勃旭 2 years ago
parent
commit
e09250e52c
  1. 39
      be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs
  2. 12
      be/Modules/Shared/src/Win_in.Sfs.Shared.Host/HostBuilderExtensions.cs
  3. 39
      be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobWithCodeAppServiceBase.cs

39
be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -38,10 +39,12 @@ public class SfsLabelAppServiceWithCodeBase<TEntity, TEntityDto, TRequestDTO, TC
[HttpGet("by-code/{code}")] [HttpGet("by-code/{code}")]
public virtual async Task<TEntityDto> GetByCodeAsync(string code) public virtual async Task<TEntityDto> GetByCodeAsync(string code)
{ {
var dto = await Cache.GetOrAddItemAsync( // var dto = await Cache.GetOrAddItemAsync(
$"{typeof(TEntityDto).Name}:{code}".ToString(), // $"{typeof(TEntityDto).Name}:{code}".ToString(),
async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), // async () => await GetFromRepositoryAsync(code).ConfigureAwait(false),
SfsCacheConst.SeveralMinutes).ConfigureAwait(false); // SfsCacheConst.SeveralMinutes).ConfigureAwait(false);
var dto = await GetFromRepositoryAsync(code).ConfigureAwait(false);
return dto; return dto;
} }
@ -50,18 +53,22 @@ public class SfsLabelAppServiceWithCodeBase<TEntity, TEntityDto, TRequestDTO, TC
[HttpPost("by-codes")] [HttpPost("by-codes")]
public virtual async Task<List<TEntityDto>> GetByCodesAsync(IEnumerable<string> codes) public virtual async Task<List<TEntityDto>> GetByCodesAsync(IEnumerable<string> codes)
{ {
var dtoList = new List<TEntityDto>(); // var dtoList = new List<TEntityDto>();
foreach (var code in codes) // foreach (var code in codes)
{ // {
var dto = await Cache.GetOrAddItemAsync( // var dto = await Cache.GetOrAddItemAsync(
$"{typeof(TEntityDto).Name}:{code}".ToString(), // $"{typeof(TEntityDto).Name}:{code}".ToString(),
async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), // async () => await GetFromRepositoryAsync(code).ConfigureAwait(false),
SfsCacheConst.SeveralMinutes).ConfigureAwait(false); // SfsCacheConst.SeveralMinutes).ConfigureAwait(false);
if (dto != null) // if (dto != null)
{ // {
dtoList.Add(dto); // dtoList.Add(dto);
} // }
} // }
// return dtoList;
var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false);
var dtoList = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(entities);
return dtoList; return dtoList;
} }

12
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"); AddJsonByUrl(cb, $"{configUrl}appsettings.{builder.Environment.EnvironmentName}.json");
if (builder.Environment.IsDevelopment()) if (builder.Environment.IsDevelopment())
{ {
cb.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), "appsettings.json"));
cb.AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(), $"appsettings.{builder.Environment.EnvironmentName}.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) private static void AddJsonByUrl(IConfigurationBuilder configurationBuilder, string url)
{ {
Console.WriteLine($"load config form:{url}"); Console.WriteLine($"load config form:{url}");
var stream = new HttpClient().GetStreamAsync(url).Result; try
configurationBuilder.AddJsonStream(stream); {
var stream = new HttpClient().GetStreamAsync(url).Result;
configurationBuilder.AddJsonStream(stream);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} }
} }

39
be/Modules/Store/src/Win_in.Sfs.Wms.Store.Application/Bases/SfsJobWithCodeAppServiceBase.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -37,10 +38,12 @@ public abstract class SfsJobWithCodeAppServiceBase<TEntity, TEntityDto, TRequest
[HttpGet("by-code/{code}")] [HttpGet("by-code/{code}")]
public virtual async Task<TEntityDto> GetByCodeAsync(string code) public virtual async Task<TEntityDto> GetByCodeAsync(string code)
{ {
var dto = await Cache.GetOrAddItemAsync( // var dto = await Cache.GetOrAddItemAsync(
$"{typeof(TEntityDto).Name}:{code}".ToString(), // $"{typeof(TEntityDto).Name}:{code}".ToString(),
async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), // async () => await GetFromRepositoryAsync(code).ConfigureAwait(false),
SfsCacheConst.SeveralMinutes).ConfigureAwait(false); // SfsCacheConst.SeveralMinutes).ConfigureAwait(false);
var dto = await GetFromRepositoryAsync(code).ConfigureAwait(false);
return dto; return dto;
@ -51,18 +54,22 @@ public abstract class SfsJobWithCodeAppServiceBase<TEntity, TEntityDto, TRequest
public virtual async Task<List<TEntityDto>> GetByCodesAsync(IEnumerable<string> codes) public virtual async Task<List<TEntityDto>> GetByCodesAsync(IEnumerable<string> codes)
{ {
var dtoList = new List<TEntityDto>(); // var dtoList = new List<TEntityDto>();
foreach (var code in codes) // foreach (var code in codes)
{ // {
var dto = await Cache.GetOrAddItemAsync( // var dto = await Cache.GetOrAddItemAsync(
$"{typeof(TEntityDto).Name}:{code}".ToString(), // $"{typeof(TEntityDto).Name}:{code}".ToString(),
async () => await GetFromRepositoryAsync(code).ConfigureAwait(false), // async () => await GetFromRepositoryAsync(code).ConfigureAwait(false),
SfsCacheConst.SeveralMinutes).ConfigureAwait(false); // SfsCacheConst.SeveralMinutes).ConfigureAwait(false);
if (dto != null) // if (dto != null)
{ // {
dtoList.Add(dto); // dtoList.Add(dto);
} // }
} // }
// return dtoList;
var entities = await _repository.GetListAsync(p => codes.Contains(p.Code)).ConfigureAwait(false);
var dtoList = ObjectMapper.Map<List<TEntity>, List<TEntityDto>>(entities);
return dtoList; return dtoList;
} }

Loading…
Cancel
Save