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-21 10:19:10 +08:00
|
|
|
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
|
|
|
|
//_repository = provider.GetService<IRepository<AgvBinEntity>>();
|
|
|
|
_cache = _repository.GetList();
|
2025-03-16 03:17:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public async Task<AgvBinEntity> GetAvailableBin(int height)
|
|
|
|
{
|
2025-03-23 13:09:36 +08:00
|
|
|
var bin = await _repository.CopyNew().AsQueryable()
|
2025-03-20 19:32:49 +08:00
|
|
|
.Where(x => x.IsFree && !x.IsDeleted).OrderBy(x => x.Sort).FirstAsync();
|
|
|
|
if (bin.BinCode == "B10")
|
2025-03-16 03:17:36 +08:00
|
|
|
{
|
2025-03-23 13:09:36 +08:00
|
|
|
await _repository.CopyNew().AsUpdateable()
|
2025-03-20 19:32:49 +08:00
|
|
|
.Where(x => x.RackType == 2 && !x.IsDeleted)
|
|
|
|
.SetColumns(x => x.IsFree, true)
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
else if (bin.BinCode == "B33")
|
|
|
|
{
|
2025-03-23 13:09:36 +08:00
|
|
|
await _repository.CopyNew().AsUpdateable()
|
2025-03-20 19:32:49 +08:00
|
|
|
.Where(x => x.RackType == 1 && !x.IsDeleted)
|
|
|
|
.SetColumns(x => x.IsFree, true)
|
|
|
|
.ExecuteCommandAsync();
|
2025-03-16 03:17:36 +08:00
|
|
|
}
|
|
|
|
|
2025-03-20 19:32:49 +08:00
|
|
|
return bin;
|
2025-03-16 03:17:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Task BindAsync(AgvBinEntity entity)
|
|
|
|
{
|
|
|
|
entity.IsFree = false;
|
|
|
|
_cache.First(e => e.Id == entity.Id).IsFree = false;
|
2025-03-23 13:09:36 +08:00
|
|
|
return _repository.CopyNew().UpdateAsync(entity);
|
2025-03-16 03:17:36 +08:00
|
|
|
}
|
|
|
|
}
|