45 lines
1.4 KiB
C#
Raw Permalink Normal View History

2025-03-16 03:17:36 +08:00
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;
2025-03-19 20:29:11 +08:00
private readonly IRepository<AgvBinEntity> _repository;
2025-03-16 03:17:36 +08:00
public AgvBinService(IServiceProvider provider)
{
2025-03-19 20:29:11 +08:00
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
_cache = _repository.GetList();
2025-03-16 03:17:36 +08:00
}
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;
2025-03-19 20:29:11 +08:00
return _repository.UpdateAsync(entity);
2025-03-16 03:17:36 +08:00
}
}