66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using Seyounth.Hyosung.Data.Entities;
|
|
using Seyounth.Hyosung.Data.Models;
|
|
using Seyounth.Hyosung.Data.Repositories;
|
|
|
|
namespace Seyounth.Hyosung.Data.Services;
|
|
|
|
public class StorageBinService(IRepository<StorageBinEntity> repository)
|
|
:IStorageBinService
|
|
{
|
|
public async Task<StorageBinEntity> GetAvailableBin(Tray tray, Variety variety)
|
|
{
|
|
StorageBinEntity bin;
|
|
var db = repository.CopyNew();
|
|
if (tray.StackHeight >= 180)
|
|
{
|
|
bin = await db.AsQueryable()
|
|
.Where(x => !x.IsDouble && x.BinStatus == 0)
|
|
.OrderBy(x => x.Sort).FirstAsync() ?? await db.AsQueryable()
|
|
.Where(x => x.BinStatus == 0)
|
|
.OrderBy(x => x.Sort).FirstAsync();
|
|
}
|
|
else if (variety.NeedSameStack)
|
|
{
|
|
bin = await db.AsQueryable()
|
|
.Where(x => x.BinStatus == 1 && x.IsDouble && x.BindLot == variety.Lot)
|
|
.OrderBy(x => x.Sort).FirstAsync() ?? await db.AsQueryable()
|
|
.Where(x => x.BinStatus == 0)
|
|
.OrderBy(x => x.Sort).FirstAsync();
|
|
}
|
|
else
|
|
{
|
|
bin = await db.AsQueryable()
|
|
.Where(x => x.BinStatus == 1 && !x.NeedSameLot)
|
|
.OrderBy(x => x.Sort).FirstAsync() ?? await db.AsQueryable()
|
|
.Where(x => x.BinStatus == 0)
|
|
.OrderBy(x => x.Sort).FirstAsync();
|
|
}
|
|
|
|
if (bin.BinName == "B10")
|
|
{
|
|
await db.AsUpdateable()
|
|
.Where(x => x.BinPosition == 2)
|
|
.SetColumns(x => x.BinStatus, 0)
|
|
.SetColumns(x => x.BindLot, 0)
|
|
.SetColumns(x => x.NeedSameLot, false)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
else if (bin.BinName == "B32")
|
|
{
|
|
await db.AsUpdateable()
|
|
.Where(x => x.BinPosition == 1)
|
|
.SetColumns(x => x.BinStatus, 0)
|
|
.SetColumns(x => x.BindLot, 0)
|
|
.SetColumns(x => x.NeedSameLot, false)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
return bin;
|
|
}
|
|
|
|
|
|
public async Task BindAsync(StorageBinEntity entity)
|
|
{
|
|
await repository.AsUpdateable(entity).ExecuteCommandAsync();
|
|
}
|
|
} |