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 _cache; public LocationCapacityAclService( ILocationCapacityAppService appService , IDistributedCache cache ) { _appService = appService; _cache = cache; } public virtual async Task GetByLocationCodeAsync(string code) { var dto = await _cache.GetOrAddItemAsync( code, async () => await GetFromAppServiceAsync(code).ConfigureAwait(false), CacheMinutes).ConfigureAwait(false); return dto; } private async Task GetFromAppServiceAsync(string code) { var item = await _appService.GetByLocationCodeAsync(code).ConfigureAwait(false); Check.NotNull(item, "库位代码", $"库位容量 {code} 不存在"); return item; } public virtual async Task> GetByLocationCodesAsync(IEnumerable codes) { var dtos = new List(); var notInCacheCodes = new List(); 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> GetUsableListAsync(List locationInfoInput) { return await _appService.GetUsableListAsync(locationInfoInput).ConfigureAwait(false); } } }