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,
IAgvBinService agvBinService,
ITrayService trayService,
IVarietyService varietyService,
IDictService dictService) : IHyosungAgvService
{
private readonly HikAgv _agv = new(loggerFactory.CreateLogger<HikAgv>());
@ -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)

View File

@ -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; }
/// <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; }
}

View File

@ -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; }
}

View File

@ -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<PalletEntity> 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;
}

View File

@ -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<IRepository<AgvBinEntity>>();
_repository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<AgvBinEntity>>();
//_repository = provider.GetService<IRepository<AgvBinEntity>>();
_cache = _repository.GetList();
_cache = _repository.GetList();
}
public async Task<AgvBinEntity> GetAvailableBin(int height)
public async Task<AgvBinEntity> 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);
}
}

View File

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