diff --git a/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs b/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs index 1ec3295..1925faa 100644 --- a/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs +++ b/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs @@ -9,6 +9,7 @@ public class HyosungAgvService( ILoggerFactory loggerFactory, IAgvBinService agvBinService, ITrayService trayService, + IVarietyService varietyService, IDictService dictService) : IHyosungAgvService { private readonly HikAgv _agv = new(loggerFactory.CreateLogger()); @@ -24,8 +25,9 @@ public class HyosungAgvService( } while (status is null); var tray = await trayService.GetByCode(trayCode); - var height = (int)Math.Ceiling((double)((tray.StackHeight ?? 0) / 10.0)!); - var bin = await agvBinService.GetAvailableBin(height); + var variety = await varietyService.GetById(tray.VarietyId); + var height = (int)Math.Ceiling(((tray.StackHeight ?? 0) / 10.0)!); + var bin = await agvBinService.GetAvailableBin(variety); AgvPosition start = new AgvPosition() { PositionCode = "A1", @@ -38,14 +40,15 @@ public class HyosungAgvService( }; if (!string.IsNullOrEmpty(bin.HeightCode)) await UnBin(bin); - var ctnrType = await dictService.GetKeyAsync("AgvRackType", bin.Height.ToString()); + // var ctnrType = await dictService.GetKeyAsync("AgvRackType", bin.Height.ToString()); + var ctnrType = variety.CtnrType; if (string.IsNullOrEmpty(ctnrType)) ctnrType = "14"; bin.HeightCode = ctnrType; var taskCode = await _agv.CarryToAsync(start, stop, ctnrType, 120, "1"); await _agv.WaitingForTaskCompletedAsync(taskCode); - await agvBinService.BindAsync(bin); + await agvBinService.BindAsync(bin, variety.Lot); } public async Task UnBin(AgvBinEntity bin) diff --git a/Seyounth.Hyosung.Data/Entities/AgvBinEntity.cs b/Seyounth.Hyosung.Data/Entities/AgvBinEntity.cs index 4f129a4..c14a30b 100644 --- a/Seyounth.Hyosung.Data/Entities/AgvBinEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/AgvBinEntity.cs @@ -32,8 +32,14 @@ public class AgvBinEntity [SugarColumn(ColumnDescription = "排序")] public int Sort { get; set; } - [SugarColumn(IsNullable =true)] - public string HeightCode { get; set; } + [SugarColumn(IsNullable = true)] public string HeightCode { get; set; } + /// + /// 是否是第二层 + /// + [SugarColumn(IsNullable = true)] + public bool IsSecondLayer { get; set; } = false; + + [SugarColumn(IsNullable = true)] public int BindLot { get; set; } = 0; public bool IsDeleted { get; set; } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs index eb09ce4..79152db 100644 --- a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs @@ -57,7 +57,7 @@ public class VarietyEntity [SugarColumn(ColumnDescription = "垛头数量")] public int? StackHeadCount { get; set; } - [SugarColumn(ColumnDescription = "纸托Id",IsNullable =true)] + [SugarColumn(ColumnDescription = "纸托Id", IsNullable = true)] public int? PaperTrayId { get; set; } [SugarColumn(ColumnDescription = "是否需要纸箱")] @@ -84,13 +84,13 @@ public class VarietyEntity [SugarColumn(ColumnDescription = "副标签数量")] public int SubLabelCount { get; set; } - [SugarColumn(IsNullable =true)] - public int? LastNo { get; set; } - - [SugarColumn(IsNullable =true)] - public double? NetWeight { get; set; } - - [SugarColumn(IsNullable =true)] - public double? GrossWeight { get; set; } + [SugarColumn(IsNullable = true)] public int? LastNo { get; set; } + + [SugarColumn(IsNullable = true)] public double? NetWeight { get; set; } + + [SugarColumn(IsNullable = true)] public double? GrossWeight { get; set; } + + [SugarColumn(IsNullable = true)] public bool? IsDoubleStack { get; set; } + [SugarColumn(IsNullable = true)] public string? CtnrType { get; set; } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Models/Variety.cs b/Seyounth.Hyosung.Data/Models/Variety.cs index b4fd677..9bebe15 100644 --- a/Seyounth.Hyosung.Data/Models/Variety.cs +++ b/Seyounth.Hyosung.Data/Models/Variety.cs @@ -70,6 +70,10 @@ public class Variety public double? GrossWeight { get; set; } + public bool? IsDoubleStack { get; set; } + + public string? CtnrType { get; set; } + public static Variety Create(VarietyEntity entity, List pallets) { var variety = new Variety() @@ -101,7 +105,9 @@ public class Variety HasBox = entity.HasBox, LastNo = entity.LastNo, NetWeight = entity.NetWeight, - GrossWeight = entity.GrossWeight + GrossWeight = entity.GrossWeight, + IsDoubleStack = entity.IsDoubleStack, + CtnrType = entity.CtnrType }; if (entity.PaperTrayId != null && entity.PaperTrayId != 0) variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId)); @@ -141,7 +147,9 @@ public class Variety HasBox = HasBox, LastNo = LastNo, NetWeight = NetWeight, - GrossWeight = GrossWeight + GrossWeight = GrossWeight, + IsDoubleStack = IsDoubleStack, + CtnrType = CtnrType }; return entity; } diff --git a/Seyounth.Hyosung.Data/Services/AgvBinService.cs b/Seyounth.Hyosung.Data/Services/AgvBinService.cs index d14fa6c..831590f 100644 --- a/Seyounth.Hyosung.Data/Services/AgvBinService.cs +++ b/Seyounth.Hyosung.Data/Services/AgvBinService.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Seyounth.Hyosung.Data.Entities; +using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Repositories; namespace Seyounth.Hyosung.Data.Services; @@ -12,37 +13,69 @@ public class AgvBinService : IAgvBinService public AgvBinService(IServiceProvider provider) { - _repository = provider.CreateScope().ServiceProvider.GetRequiredService>(); + _repository = provider.CreateScope().ServiceProvider.GetRequiredService>(); //_repository = provider.GetService>(); - _cache = _repository.GetList(); + _cache = _repository.GetList(); } - public async Task GetAvailableBin(int height) + public async Task GetAvailableBin(Variety variety) { - var bin = await _repository.CopyNew().AsQueryable() - .Where(x => x.IsFree && !x.IsDeleted).OrderBy(x => x.Sort).FirstAsync(); - if (bin.BinCode == "B10") + var repo = _repository.CopyNew(); + AgvBinEntity? bin = null; + + if (variety.IsDoubleStack ?? false) { - await _repository.CopyNew().AsUpdateable() - .Where(x => x.RackType == 2 && !x.IsDeleted) - .SetColumns(x => x.IsFree, true) - .ExecuteCommandAsync(); + 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 if (bin.BinCode == "B33") + else { - await _repository.CopyNew().AsUpdateable() - .Where(x => x.RackType == 1 && !x.IsDeleted) - .SetColumns(x => x.IsFree, true) - .ExecuteCommandAsync(); + bin = await repo.AsQueryable() + .Where(x => x.IsFree && !x.IsDeleted) + .OrderBy(x => x.Sort) + .FirstAsync(); + } + + if (bin != null) + { + 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(); + } } return bin; } - public Task BindAsync(AgvBinEntity entity) + public Task BindAsync(AgvBinEntity entity, int lot) { entity.IsFree = false; _cache.First(e => e.Id == entity.Id).IsFree = false; + entity.BindLot = lot; return _repository.CopyNew().UpdateAsync(entity); } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/IAgvBinService.cs b/Seyounth.Hyosung.Data/Services/IAgvBinService.cs index b9e8021..e2a37e4 100644 --- a/Seyounth.Hyosung.Data/Services/IAgvBinService.cs +++ b/Seyounth.Hyosung.Data/Services/IAgvBinService.cs @@ -8,14 +8,14 @@ public interface IAgvBinService /// /// 获取可用的库位信息 /// - /// + /// /// - Task GetAvailableBin(int height); + Task GetAvailableBin(Variety variety); /// /// 绑定相应的库 /// /// /// - Task BindAsync(AgvBinEntity entity); + Task BindAsync(AgvBinEntity entity,int lot); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/TrayService.cs b/Seyounth.Hyosung.Data/Services/TrayService.cs index fab7e0e..f3f3e65 100644 --- a/Seyounth.Hyosung.Data/Services/TrayService.cs +++ b/Seyounth.Hyosung.Data/Services/TrayService.cs @@ -89,8 +89,8 @@ public class TrayService : ITrayService tray.NetWeight = variety.NetWeight ?? itemInfo.NET_WEIGHT; tray.GrossWeight = variety.GrossWeight ?? itemInfo.GROSS_WEIGHT; tray.Barcode = - $"{itemInfo.ITEM_CODE} {DateTime.Now:yyMMdd}00{itemInfo.LOTNO.PadLeft(4, '0')}{tray.ControlNo?.ToString().PadLeft(4, '0')}0"; - await _db.Updateable(tray.ToEntity()).ExecuteCommandAsync(); + $"{itemInfo.ITEM_CODE} {DateTime.Now:yyMMdd}{tray.NetWeight.ToString("0.0").PadLeft(6,'0')}{itemInfo.LOTNO.PadLeft(4, '0')}{tray.ControlNo?.ToString().PadLeft(4, '0')}0"; + await _db.Updateable(tray.ToEntity()).ExecuteCommandAsync(); // _cache.Remove(tray.TrayCode, out _); return tray; }