This commit is contained in:
anerx 2025-03-26 17:53:13 +08:00
parent e3e12cb62b
commit d9ea5f837e
7 changed files with 88 additions and 38 deletions

View File

@ -9,6 +9,7 @@ public class HyosungAgvService(
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IAgvBinService agvBinService, IAgvBinService agvBinService,
ITrayService trayService, ITrayService trayService,
IVarietyService varietyService,
IDictService dictService) : IHyosungAgvService IDictService dictService) : IHyosungAgvService
{ {
private readonly HikAgv _agv = new(loggerFactory.CreateLogger<HikAgv>()); private readonly HikAgv _agv = new(loggerFactory.CreateLogger<HikAgv>());
@ -24,8 +25,9 @@ public class HyosungAgvService(
} while (status is null); } while (status is null);
var tray = await trayService.GetByCode(trayCode); var tray = await trayService.GetByCode(trayCode);
var height = (int)Math.Ceiling((double)((tray.StackHeight ?? 0) / 10.0)!); var variety = await varietyService.GetById(tray.VarietyId);
var bin = await agvBinService.GetAvailableBin(height); var height = (int)Math.Ceiling(((tray.StackHeight ?? 0) / 10.0)!);
var bin = await agvBinService.GetAvailableBin(variety);
AgvPosition start = new AgvPosition() AgvPosition start = new AgvPosition()
{ {
PositionCode = "A1", PositionCode = "A1",
@ -38,14 +40,15 @@ public class HyosungAgvService(
}; };
if (!string.IsNullOrEmpty(bin.HeightCode)) if (!string.IsNullOrEmpty(bin.HeightCode))
await UnBin(bin); 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)) if (string.IsNullOrEmpty(ctnrType))
ctnrType = "14"; ctnrType = "14";
bin.HeightCode = ctnrType; bin.HeightCode = ctnrType;
var taskCode = await _agv.CarryToAsync(start, stop, ctnrType, 120, "1"); var taskCode = await _agv.CarryToAsync(start, stop, ctnrType, 120, "1");
await _agv.WaitingForTaskCompletedAsync(taskCode); await _agv.WaitingForTaskCompletedAsync(taskCode);
await agvBinService.BindAsync(bin); await agvBinService.BindAsync(bin, variety.Lot);
} }
public async Task UnBin(AgvBinEntity bin) public async Task UnBin(AgvBinEntity bin)

View File

@ -32,8 +32,14 @@ public class AgvBinEntity
[SugarColumn(ColumnDescription = "排序")] [SugarColumn(ColumnDescription = "排序")]
public int Sort { get; set; } public int Sort { get; set; }
[SugarColumn(IsNullable =true)] [SugarColumn(IsNullable = true)] public string HeightCode { get; set; }
public string HeightCode { get; set; }
/// <summary>
/// 是否是第二层
/// </summary>
[SugarColumn(IsNullable = true)]
public bool IsSecondLayer { get; set; } = false;
[SugarColumn(IsNullable = true)] public int BindLot { get; set; } = 0;
public bool IsDeleted { get; set; } public bool IsDeleted { get; set; }
} }

View File

@ -57,7 +57,7 @@ public class VarietyEntity
[SugarColumn(ColumnDescription = "垛头数量")] [SugarColumn(ColumnDescription = "垛头数量")]
public int? StackHeadCount { get; set; } public int? StackHeadCount { get; set; }
[SugarColumn(ColumnDescription = "纸托Id",IsNullable =true)] [SugarColumn(ColumnDescription = "纸托Id", IsNullable = true)]
public int? PaperTrayId { get; set; } public int? PaperTrayId { get; set; }
[SugarColumn(ColumnDescription = "是否需要纸箱")] [SugarColumn(ColumnDescription = "是否需要纸箱")]
@ -84,13 +84,13 @@ public class VarietyEntity
[SugarColumn(ColumnDescription = "副标签数量")] [SugarColumn(ColumnDescription = "副标签数量")]
public int SubLabelCount { get; set; } public int SubLabelCount { get; set; }
[SugarColumn(IsNullable =true)] [SugarColumn(IsNullable = true)] public int? LastNo { get; set; }
public int? LastNo { get; set; }
[SugarColumn(IsNullable =true)] [SugarColumn(IsNullable = true)] public double? NetWeight { get; set; }
public double? NetWeight { get; set; }
[SugarColumn(IsNullable =true)] [SugarColumn(IsNullable = true)] public double? GrossWeight { get; set; }
public double? GrossWeight { get; set; }
[SugarColumn(IsNullable = true)] public bool? IsDoubleStack { get; set; }
[SugarColumn(IsNullable = true)] public string? CtnrType { get; set; }
} }

View File

@ -70,6 +70,10 @@ public class Variety
public double? GrossWeight { get; set; } public double? GrossWeight { get; set; }
public bool? IsDoubleStack { get; set; }
public string? CtnrType { get; set; }
public static Variety Create(VarietyEntity entity, List<PalletEntity> pallets) public static Variety Create(VarietyEntity entity, List<PalletEntity> pallets)
{ {
var variety = new Variety() var variety = new Variety()
@ -101,7 +105,9 @@ public class Variety
HasBox = entity.HasBox, HasBox = entity.HasBox,
LastNo = entity.LastNo, LastNo = entity.LastNo,
NetWeight = entity.NetWeight, NetWeight = entity.NetWeight,
GrossWeight = entity.GrossWeight GrossWeight = entity.GrossWeight,
IsDoubleStack = entity.IsDoubleStack,
CtnrType = entity.CtnrType
}; };
if (entity.PaperTrayId != null && entity.PaperTrayId != 0) if (entity.PaperTrayId != null && entity.PaperTrayId != 0)
variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId)); variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId));
@ -141,7 +147,9 @@ public class Variety
HasBox = HasBox, HasBox = HasBox,
LastNo = LastNo, LastNo = LastNo,
NetWeight = NetWeight, NetWeight = NetWeight,
GrossWeight = GrossWeight GrossWeight = GrossWeight,
IsDoubleStack = IsDoubleStack,
CtnrType = CtnrType
}; };
return entity; return entity;
} }

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Seyounth.Hyosung.Data.Entities; using Seyounth.Hyosung.Data.Entities;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Repositories; using Seyounth.Hyosung.Data.Repositories;
namespace Seyounth.Hyosung.Data.Services; namespace Seyounth.Hyosung.Data.Services;
@ -17,32 +18,64 @@ public class AgvBinService : IAgvBinService
_cache = _repository.GetList(); _cache = _repository.GetList();
} }
public async Task<AgvBinEntity> GetAvailableBin(int height) public async Task<AgvBinEntity> GetAvailableBin(Variety variety)
{
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
{
bin = await repo.AsQueryable()
.Where(x => x.IsFree && !x.IsDeleted)
.OrderBy(x => x.Sort)
.FirstAsync();
}
if (bin != null)
{ {
var bin = await _repository.CopyNew().AsQueryable()
.Where(x => x.IsFree && !x.IsDeleted).OrderBy(x => x.Sort).FirstAsync();
if (bin.BinCode == "B10") if (bin.BinCode == "B10")
{ {
await _repository.CopyNew().AsUpdateable() await repo.AsUpdateable()
.Where(x => x.RackType == 2 && !x.IsDeleted) .Where(x => x.RackType == 2 && !x.IsDeleted)
.SetColumns(x => x.IsFree, true) .SetColumns(x => x.IsFree, true)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }
else if (bin.BinCode == "B33") else if (bin.BinCode == "B33")
{ {
await _repository.CopyNew().AsUpdateable() await repo.AsUpdateable()
.Where(x => x.RackType == 1 && !x.IsDeleted) .Where(x => x.RackType == 1 && !x.IsDeleted)
.SetColumns(x => x.IsFree, true) .SetColumns(x => x.IsFree, true)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
} }
}
return bin; return bin;
} }
public Task BindAsync(AgvBinEntity entity) public Task BindAsync(AgvBinEntity entity, int lot)
{ {
entity.IsFree = false; entity.IsFree = false;
_cache.First(e => e.Id == entity.Id).IsFree = false; _cache.First(e => e.Id == entity.Id).IsFree = false;
entity.BindLot = lot;
return _repository.CopyNew().UpdateAsync(entity); return _repository.CopyNew().UpdateAsync(entity);
} }
} }

View File

@ -8,14 +8,14 @@ public interface IAgvBinService
/// <summary> /// <summary>
/// 获取可用的库位信息 /// 获取可用的库位信息
/// </summary> /// </summary>
/// <param name="height"></param> /// <param name="variety"></param>
/// <returns></returns> /// <returns></returns>
Task<AgvBinEntity> GetAvailableBin(int height); Task<AgvBinEntity> GetAvailableBin(Variety variety);
/// <summary> /// <summary>
/// 绑定相应的库 /// 绑定相应的库
/// </summary> /// </summary>
/// <param name="entity"></param> /// <param name="entity"></param>
/// <returns></returns> /// <returns></returns>
Task BindAsync(AgvBinEntity entity); Task BindAsync(AgvBinEntity entity,int lot);
} }

View File

@ -89,8 +89,8 @@ public class TrayService : ITrayService
tray.NetWeight = variety.NetWeight ?? itemInfo.NET_WEIGHT; tray.NetWeight = variety.NetWeight ?? itemInfo.NET_WEIGHT;
tray.GrossWeight = variety.GrossWeight ?? itemInfo.GROSS_WEIGHT; tray.GrossWeight = variety.GrossWeight ?? itemInfo.GROSS_WEIGHT;
tray.Barcode = tray.Barcode =
$"{itemInfo.ITEM_CODE} {DateTime.Now:yyMMdd}00{itemInfo.LOTNO.PadLeft(4, '0')}{tray.ControlNo?.ToString().PadLeft(4, '0')}0"; $"{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<TrayEntity>(tray.ToEntity()).ExecuteCommandAsync(); await _db.Updateable(tray.ToEntity()).ExecuteCommandAsync();
// _cache.Remove(tray.TrayCode, out _); // _cache.Remove(tray.TrayCode, out _);
return tray; return tray;
} }