Browse Source

[fix]Job,Label基类中的GetByCode,GetByCodes不再使用缓存

集成Redis
贾荣国 2 years ago
parent
commit
b789f7df11
  1. 39
      be/Modules/Label/src/Win_in.Sfs.Label.Application/Bases/SfsLabelAppServiceWithCodeBase.cs
  2. 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;
} }

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