Compare commits

..

1 Commits

Author SHA1 Message Date
anerx
d9ea5f837e asdjklas 2025-03-26 17:53:13 +08:00
15 changed files with 109 additions and 148 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

@ -148,7 +148,7 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
break; break;
} }
await _writer.WriteShortsAsync(13050, [1, 1, 1, 2]); await _writer.WriteShortsAsync(13050, [1, 1, 1, masterCount]);
} }
public async Task WritePrintLabelResultAsync(int index, bool result) public async Task WritePrintLabelResultAsync(int index, bool result)

View File

@ -49,7 +49,7 @@ public class AveryPrinter(string host, int port)
await ConnectAsync(CancellationToken.None); await ConnectAsync(CancellationToken.None);
} }
await _socket.SendAsync(Encoding.ASCII.GetBytes(context)); await _socket.SendAsync(Encoding.UTF8.GetBytes(context));
} }
private const string CleanCmd = "#!A1#!CA#!P1"; private const string CleanCmd = "#!A1#!CA#!P1";
@ -63,7 +63,7 @@ public class AveryPrinter(string host, int port)
await ConnectAsync(CancellationToken.None); await ConnectAsync(CancellationToken.None);
} }
await _socket.SendAsync(Encoding.ASCII.GetBytes(CleanCmd)); await _socket.SendAsync(Encoding.UTF8.GetBytes(CleanCmd));
} }
public async Task PrintAsync() public async Task PrintAsync()
@ -74,6 +74,6 @@ public class AveryPrinter(string host, int port)
await ConnectAsync(CancellationToken.None); await ConnectAsync(CancellationToken.None);
} }
await _socket.SendAsync(Encoding.ASCII.GetBytes(PrintCmd)); await _socket.SendAsync(Encoding.UTF8.GetBytes(PrintCmd));
} }
} }

View File

@ -121,14 +121,14 @@ public class HyosungPrinter(
"250101J068", "250101J068",
$"\"{DateTime.Now.ToString("yyMMdd" + "J") + tray.ControlNo.ToString()?.PadLeft(3, '0')}\"" $"\"{DateTime.Now.ToString("yyMMdd" + "J") + tray.ControlNo.ToString()?.PadLeft(3, '0')}\""
}, },
{ "DTYY-JPA11530SFG250101000900115305480", $"{tray.Barcode}" } { "DTYY-JPA11530SFG250101000900115305480", $"\"{tray.Barcode}\"" }
}; };
string content = options.Value.DefaultTemp; string content = options.Value.DefaultTemp;
foreach (var (key, value) in dic) foreach (var (key, value) in dic)
{ {
content = content.Replace(key, value); content = content.Replace(key, value);
} }
logger.LogInformation($"print content: {content}");
return content; return content;
} }
} }

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

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

@ -9,32 +9,25 @@ public class LabelResult
public string BE_ID { get; set; } = "2240"; public string BE_ID { get; set; } = "2240";
public string BAR_CODE { get; set; } = ""; public string BAR_CODE { get; set; } = "";
public string ITEM_CODE { get; set; } = ""; public string ITEM_CODE { get; set; } = "";
public string LABEL_ID { get; set; } = "TY_CN_PRODUCT"; public string LABEL_ID { get; set; } = "";
public string WMS_UOM { get; set; } = ""; public string WMS_UOM { get; set; } = "";
public string ERP_UOM { get; set; } = ""; public string ERP_UOM { get; set; } = "";
public string MFG_DATE { get; set; } = ""; public string MFG_DATE { get; set; } = "";
public decimal NET_WEIGHT { get; set; } = 0; public decimal NET_WEIGHT { get; set; } = 0;
public decimal GROSS_WEIGHT { get; set; } = 0; public decimal GROSS_WEIGHT { get; set; } = 0;
public string MFG_LINE { get; set; } = "TYJP11"; public string MFG_LINE { get; set; } = "";
public string GRADE { get; set; } = ""; public string GRADE { get; set; } = "";
public string LOT { get; set; } = ""; public string LOT { get; set; } = "";
public string BOX_NO { get; set; } = ""; public string BOX_NO { get; set; } = "";
// public string DENIER { get; set; } = ""; // public string DENIER { get; set; } = "";
// public string FILA { get; set; } = ""; // public string FILA { get; set; } = "";
public string CUSTOMER_NAME { get; set; } = ""; public string CUSTOMER_NAME { get; set; } = "";
// public string REMARKS { get; set; } = ""; // public string REMARKS { get; set; } = "";
// public string TRI_INTERFACE_YN { get; set; } = ""; // public string TRI_INTERFACE_YN { get; set; } = "";
public string TRI_TYPE { get; set; } = "ZP10"; public string TRI_TYPE { get; set; } = "zp10";
public string COMMON_S1 { get; set; } = ""; //public string COMMON_S1 { get; set; } = "";
public string COMMON_S2 { get; set; } = ""; //public string COMMON_S2 { get; set; } = "";
//public string COMMON_S3 { get; set; } = "";
public string COMMON_S3 { get; set; } = "";
public string COMMON_S4 { get; set; } = "";
public string COMMON_S5 { get; set; } = "";
//public string COMMON_S4 { get; set; } = ""; //public string COMMON_S4 { get; set; } = "";
//public string COMMON_S5 { get; set; } = ""; //public string COMMON_S5 { get; set; } = "";
//public string COMMON_N1 { get; set; } = ""; //public string COMMON_N1 { get; set; } = "";
@ -44,30 +37,20 @@ public class LabelResult
public string MODIFIED_BY { get; set; } = "seyounth"; public string MODIFIED_BY { get; set; } = "seyounth";
public string MODIFIED_ON { get; set; } = DateTime.Now.ToString("yyyy-MM-dd"); public string MODIFIED_ON { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
public double COMMON_N1 { get; set; } = 0;
public LabelResult(Tray tray, Variety variety) public LabelResult(Tray tray, Variety variety)
{ {
LABEL_ID = tray.TrayCode; LABEL_ID = tray.TrayCode;
BE_ID = "2240"; BE_ID = "2240";
BAR_CODE = tray.Barcode ?? ""; BAR_CODE = tray.Barcode ?? "";
ITEM_CODE = variety.Code; ITEM_CODE = variety.Code;
MFG_DATE = DateTime.Now.ToString("yyyyMMdd"); MFG_DATE = DateTime.Now.ToString("yyyy-MM-dd");
NET_WEIGHT = (decimal)tray.NetWeight; NET_WEIGHT = (decimal)tray.NetWeight;
GROSS_WEIGHT = (decimal)tray.GrossWeight; GROSS_WEIGHT = (decimal)tray.GrossWeight;
GRADE = tray.Grade ?? ""; GRADE = tray.Grade ?? "";
LOT = variety.Lot.ToString(); LOT = variety.Lot.ToString();
BOX_NO = $"{DateTime.Now.ToString("yyMMdd" + "J") + tray.ControlNo.ToString()?.PadLeft(3, '0')}"; BOX_NO = tray.ControlNo?.ToString() ?? "";
CREATED_BY = "seyounth"; CREATED_BY = "seyounth";
CREATED_ON = DateTime.Now.ToString("yyyy-MM-dd"); CREATED_ON = DateTime.Now.ToString("yyyy-MM-dd");
COMMON_S1 = tray.Type?? "";
COMMON_S2 = variety.TotalCount.ToString();
COMMON_S3=tray.DenFila?? "";
COMMON_S4 = tray.DtexFila?? "";
COMMON_S5 = "0";
COMMON_N1 = (double)tray.ControlNo;
MODIFIED_BY = "seyounth";
MODIFIED_ON = DateTime.Now.ToString("yyyy-MM-dd");
} }
public LabelResult() public LabelResult()

View File

@ -97,10 +97,8 @@ public class HyosungWmsService : IHyosungWmsService
&& t.ITEM_CODE_TYPE == "FERT"); && t.ITEM_CODE_TYPE == "FERT");
result.WMS_UOM = mst_item.WMS_UOM_ID; result.WMS_UOM = mst_item.WMS_UOM_ID;
result.ERP_UOM = mst_item.ERP_UOM_ID; result.ERP_UOM = mst_item.ERP_UOM_ID;
var workCenter = await _db.Queryable<MST_ITEM_VERSION>() var workCenter = await _db.Queryable<MST_ITEM_VERSION>()
.FirstAsync(v => v.ITEM_CODE == result.ITEM_CODE); .FirstAsync(v => v.ITEM_CODE == result.ITEM_CODE);
result.MFG_LINE=(workCenter?.WORK_CENTER)??"TYJP11";
await _db.Insertable(result).ExecuteCommandAsync(); await _db.Insertable(result).ExecuteCommandAsync();
}catch(Exception e) }catch(Exception e)
{ {

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

@ -4,8 +4,6 @@ public interface IReportExportService
{ {
Task ExportAsync(string trayCode); Task ExportAsync(string trayCode);
Task ExportSampleAsync(string trayCode);
Task ExportNoExportAsync(); Task ExportNoExportAsync();

View File

@ -31,70 +31,6 @@ public class ReportExportService(
} }
} }
public async Task ExportSampleAsync(string trayCode)
{
try
{
var tray = await trayService.GetByCode(trayCode);
var variety = await varietyService.GetById(tray.VarietyId);
var yarns = await yarnService.GetYarnsByTrayIdAsync(tray.Id);
await CreateSample(tray, variety, yarns);
await trayService.ExportedAsync(tray.TrayCode);
}
catch (Exception e)
{
logger.LogError(e, $"export report [{trayCode}] error");
}
}
private async Task CreateSample(Tray tray, Variety variety, List<Yarn> yarns)
{
try
{
DataTable dt = new DataTable();
dt.Columns.Add("LOT");
dt.Columns.Add("DEN");
dt.Columns.Add("总个数/垛");
dt.Columns.Add("生产时间");
dt.Columns.Add("机台");
dt.Columns.Add("班次");
dt.Columns.Add("码垛时间");
for (int i = 1; i <= yarns.Count; i++)
{
if (i == 1)
{
dt.Rows.Add(yarns[i - 1].Lot, tray.DenFila, yarns.Count, yarns[i - 1].ProduceTime,
yarns[i - 1].Machine, yarns[i - 1].WorkShift, yarns[i - 1].StackTime);
}
else
{
dt.Rows.Add(yarns[i - 1].Lot, tray.DenFila, " ", yarns[i - 1].ProduceTime,
yarns[i - 1].Machine, yarns[i - 1].WorkShift,yarns[i - 1].StackTime);
}
}
var path = await GetDirectoryAsync();
var fileName = $"{variety.Lot}_{tray.Barcode.Split(" ")[1]}_{DateTime.Now:yyyyMMdd}.xlsx";
var filePath = Path.Combine(path, fileName);
using var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add(dt,"export");
// 设置数据行字体大小
var dataRows = worksheet.RowsUsed();
foreach (var row in dataRows)
{
row.Style.Font.FontSize = 14;
}
// 自动调整列宽
worksheet.Columns().AdjustToContents();
workbook.SaveAs(filePath);
}
catch (Exception e)
{
logger.LogError(e, "export today report error");
}
}
private async Task Create(Tray tray, Variety variety, List<Yarn> yarns) private async Task Create(Tray tray, Variety variety, List<Yarn> yarns)
{ {
using var workbook = new XLWorkbook(TempPath); using var workbook = new XLWorkbook(TempPath);
@ -154,7 +90,7 @@ public class ReportExportService(
{ {
try try
{ {
await ExportSampleAsync(code); await ExportAsync(code);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -88,12 +88,9 @@ public class TrayService : ITrayService
tray.Unit = itemInfo.UNIT; tray.Unit = itemInfo.UNIT;
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;
var netWeight = tray.NetWeight.ToString("0.0");
if (netWeight.EndsWith(".0"))
netWeight = netWeight.Replace(".0", "");
tray.Barcode = tray.Barcode =
$"{itemInfo.ITEM_CODE} {DateTime.Now:yyMMdd}{netWeight.PadLeft(6,'0')}{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;
} }

View File

@ -204,10 +204,10 @@ public class HyosungRuntime(
{ {
await trayService.StorageAsync(info.TrayCode); await trayService.StorageAsync(info.TrayCode);
reportExportService.ExportSampleAsync(info.TrayCode);
await hyosungAgvService.StorageAsync(info.TrayCode); await hyosungAgvService.StorageAsync(info.TrayCode);
//标志下线已完成 //标志下线已完成
await hyosungPlcService.LeaveCompletedAsync(); await hyosungPlcService.LeaveCompletedAsync();
await reportExportService.ExportAsync(info.TrayCode);
logger.LogInformation($"plc leaving production line success"); logger.LogInformation($"plc leaving production line success");
} }
catch (Exception e) catch (Exception e)
@ -422,10 +422,9 @@ public class HyosungRuntime(
{ {
await printer.PrintAsync(2, tray.TrayCode); await printer.PrintAsync(2, tray.TrayCode);
await hyosungPlcService.WritePrintLabelResultAsync(arg1, true); await hyosungPlcService.WritePrintLabelResultAsync(arg1, true);
var version=await hyosungWmsService.GetItemInfoByItemCode(variety.Code);
// await varietyService.SetLastNo(variety.Id, tray.ControlNo.Value); // await varietyService.SetLastNo(variety.Id, tray.ControlNo.Value);
//await hyosungWmsService.UpdateControlNo(variety, tray.ControlNo.Value); //await hyosungWmsService.UpdateControlNo(variety, tray.ControlNo.Value);
// await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety)); await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety));
} }
logger.LogInformation($"plc request print label success"); logger.LogInformation($"plc request print label success");