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.
 
 
 
 
 
 

103 lines
3.6 KiB

using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Caching;
using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Shared.Application;
using Win_in.Sfs.Shared.Domain.Shared;
namespace Win_in.Sfs.Wms.Job.Domain.Acl.Location
{
public class LocationAclService
: AclServiceBase
, ILocationAclService
{
private readonly ILocationAppService _appService;
private readonly IDistributedCache<LocationDTO> _cache;
public LocationAclService(
ILocationAppService appService
, IDistributedCache<LocationDTO> cache
)
{
_appService = appService;
_cache = cache;
}
public virtual async Task<LocationDTO> GetByCodeAsync(string code)
{
var dto = await _cache.GetOrAddItemAsync(
code,
async () => await GetFromAppServiceAsync(code).ConfigureAwait(false),
CacheMinutes).ConfigureAwait(false);
return dto;
}
private async Task<LocationDTO> GetFromAppServiceAsync(string code)
{
var item = await _appService.GetByCodeAsync(code).ConfigureAwait(false);
Check.NotNull(item, "库位代码", $"库位 {code} 不存在");
return item;
}
public virtual async Task<List<LocationDTO>> GetByCodesAsync(IEnumerable<string> codes)
{
var dtos = new List<LocationDTO>();
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.GetByCodesAsync(notInCacheCodes).ConfigureAwait(false);
foreach (var notInCacheCodeDto in notInCacheCodeDtos)
{
await _cache.SetItemAsync(notInCacheCodeDto.Code, notInCacheCodeDto, CacheMinutes).ConfigureAwait(false);
}
dtos.AddRange(notInCacheCodeDtos);
return dtos;
}
public virtual async Task<List<LocationDTO>> GetListByEnablePickAsync(bool enablePick)
{
return await _appService.GetListByEnablePickAsync(enablePick).ConfigureAwait(false);
}
public virtual async Task<List<LocationDTO>> GetListByTypesAsync(List<EnumLocationType> types)
{
return await _appService.GetListByTypesAsync(types).ConfigureAwait(false);
}
public virtual async Task<LocationDTO> GetFirstByTypeAsync(EnumLocationType locationType)
{
return await _appService.GetFirstByTypeAsync(locationType).ConfigureAwait(false);
}
public virtual async Task<List<LocationDTO>> GetListByTypesAndErpCodeAsync(List<EnumLocationType> enumLocationTypes, string erpCode)
{
return await _appService.GetListByTypesAndErpCodeAsync(enumLocationTypes, erpCode).ConfigureAwait(false);
}
public virtual async Task<List<LocationDTO>> GetListByAreasAsync(List<string> locationAreaCodes)
{
return await _appService.GetListByAreasAsync(locationAreaCodes).ConfigureAwait(false);
}
public virtual async Task<List<LocationDTO>> GetListByGroupsAsync(List<string> locationGroupCodes)
{
return await _appService.GetListByGroupsAsync(locationGroupCodes).ConfigureAwait(false);
}
}
}