You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.6 KiB

2 years ago
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Caching;
using Win_in.Sfs.Shared.Application;
using Win_in.Sfs.Wms.Inventory.Application.Contracts;
namespace Win_in.Sfs.Wms.Job.Domain.Acl.LocationCapacity
{
public class LocationCapacityAclService
: AclServiceBase
, ILocationCapacityAclService
{
private readonly ILocationCapacityAppService _appService;
private readonly IDistributedCache<LocationCapacityDTO> _cache;
public LocationCapacityAclService(
ILocationCapacityAppService appService
, IDistributedCache<LocationCapacityDTO> cache
)
{
_appService = appService;
_cache = cache;
}
public virtual async Task<LocationCapacityDTO> GetByLocationCodeAsync(string code)
{
var dto = await _cache.GetOrAddItemAsync(
code,
async () => await GetFromAppServiceAsync(code).ConfigureAwait(false),
CacheMinutes).ConfigureAwait(false);
return dto;
}
private async Task<LocationCapacityDTO> GetFromAppServiceAsync(string code)
{
var item = await _appService.GetByLocationCodeAsync(code).ConfigureAwait(false);
Check.NotNull(item, "库位代码", $"库位容量 {code} 不存在");
return item;
}
public virtual async Task<List<LocationCapacityDTO>> GetByLocationCodesAsync(IEnumerable<string> codes)
{
var dtos = new List<LocationCapacityDTO>();
var notInCacheCodes = new List<string>();
foreach (var code in codes)
{
var dto = await _cache.GetAsync(code).ConfigureAwait(false);
if (dto == null)
{
notInCacheCodes.Add(code);
}
else
{
dtos.Add(dto);
}
}
var notInCacheCodeDtos = await _appService.GetByLocationCodesAsync(notInCacheCodes).ConfigureAwait(false);
foreach (var notInCacheCodeDto in notInCacheCodeDtos)
{
await _cache.SetItemAsync(notInCacheCodeDto.LocationCode, notInCacheCodeDto, CacheMinutes).ConfigureAwait(false);
}
dtos.AddRange(notInCacheCodeDtos);
return dtos;
}
public virtual async Task<List<LocationInfoDTO>> GetUsableListAsync(List<LocationInfoInput> locationInfoInput)
{
return await _appService.GetUsableListAsync(locationInfoInput).ConfigureAwait(false);
}
}
}