81 lines
2.7 KiB
C#
Raw Permalink Normal View History

2025-03-16 03:17:36 +08:00
using Microsoft.Extensions.DependencyInjection;
using Seyounth.Hyosung.Data.Entities;
2025-03-26 17:53:13 +08:00
using Seyounth.Hyosung.Data.Models;
2025-03-16 03:17:36 +08:00
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-26 17:53:13 +08:00
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
2025-03-21 10:19:10 +08:00
//_repository = provider.GetService<IRepository<AgvBinEntity>>();
2025-03-26 17:53:13 +08:00
_cache = _repository.GetList();
2025-03-16 03:17:36 +08:00
}
2025-03-26 17:53:13 +08:00
public async Task<AgvBinEntity> GetAvailableBin(Variety variety)
2025-03-16 03:17:36 +08:00
{
2025-03-26 17:53:13 +08:00
var repo = _repository.CopyNew();
AgvBinEntity? bin = null;
if (variety.IsDoubleStack ?? false)
{
bin = await repo.AsQueryable()
.Where(x =>
x.IsFree && // 二层是空的
!x.IsDeleted &&
x.IsSecondLayer &&
// 查找底层放了相同产品且底层不是 Free 的情况
repo.AsQueryable()
.Any(y =>
y.BinCode == x.BinCode && // 底层和二层库位码相同
!y.IsSecondLayer && // 是底层
!y.IsFree && // 底层不是 Free
y.BindLot == variety.Lot // 底层和二层绑定的 Lot 相同
)
)
.OrderBy(x => x.Sort)
.FirstAsync();
}
else
2025-03-16 03:17:36 +08:00
{
2025-03-26 17:53:13 +08:00
bin = await repo.AsQueryable()
.Where(x => x.IsFree && !x.IsDeleted)
.OrderBy(x => x.Sort)
.FirstAsync();
2025-03-20 19:32:49 +08:00
}
2025-03-26 17:53:13 +08:00
if (bin != null)
2025-03-20 19:32:49 +08:00
{
2025-03-26 17:53:13 +08:00
if (bin.BinCode == "B10")
{
await repo.AsUpdateable()
.Where(x => x.RackType == 2 && !x.IsDeleted)
.SetColumns(x => x.IsFree, true)
.ExecuteCommandAsync();
}
else if (bin.BinCode == "B33")
{
await repo.AsUpdateable()
.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
}
2025-03-26 17:53:13 +08:00
public Task BindAsync(AgvBinEntity entity, int lot)
2025-03-16 03:17:36 +08:00
{
entity.IsFree = false;
_cache.First(e => e.Id == entity.Id).IsFree = false;
2025-03-26 17:53:13 +08:00
entity.BindLot = lot;
2025-03-23 13:09:36 +08:00
return _repository.CopyNew().UpdateAsync(entity);
2025-03-16 03:17:36 +08:00
}
}