45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Seyounth.Hyosung.Data.Entities;
|
|
using Seyounth.Hyosung.Data.Repositories;
|
|
|
|
namespace Seyounth.Hyosung.Data.Services;
|
|
|
|
public class AgvBinService : IAgvBinService
|
|
{
|
|
private readonly List<AgvBinEntity> _cache;
|
|
|
|
private readonly IRepository<AgvBinEntity> repository;
|
|
|
|
public AgvBinService(IServiceProvider provider)
|
|
{
|
|
repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
|
|
_cache = repository.GetList();
|
|
}
|
|
|
|
public async Task<AgvBinEntity> GetAvailableBin(int height)
|
|
{
|
|
if (height < 180)
|
|
{
|
|
return _cache
|
|
.Where(x =>
|
|
x is { CtnrType: 1, IsFree: true } ||
|
|
x is { CtnrType: 2, IsFree: true } &&
|
|
_cache.Any(y =>
|
|
y is { CtnrType: 1, IsFree: false } && y.BinCode == x.BinCode &&
|
|
y is { Height: < 180 })
|
|
)
|
|
.OrderByDescending(x => x.CtnrType)
|
|
.ThenBy(x => x.Sort)
|
|
.First();
|
|
}
|
|
|
|
return _cache.Where(a => a is { IsFree: true }).OrderBy(a => a.CtnrType).First();
|
|
}
|
|
|
|
public Task BindAsync(AgvBinEntity entity)
|
|
{
|
|
entity.IsFree = false;
|
|
_cache.First(e => e.Id == entity.Id).IsFree = false;
|
|
return repository.UpdateAsync(entity);
|
|
}
|
|
} |