diff --git a/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs b/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs index e7b98c9..0c572d9 100644 --- a/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs +++ b/Seyounth.Hyosung.Core/Printer/HyosungPrinter.cs @@ -21,8 +21,8 @@ public class HyosungPrinter( public async Task StartAsync(CancellationToken token) { List ls = new List(); - ls.Add(_masterPrinter.ConnectAsync(token)) ; - ls.Add(_slavePrinter.ConnectAsync(token)) ; + ls.Add(_masterPrinter.ConnectAsync(token)); + ls.Add(_slavePrinter.ConnectAsync(token)); await Task.WhenAll(ls); logger.LogInformation("printer connected"); } @@ -103,23 +103,23 @@ public class HyosungPrinter( private async Task GetPrint2Content(Tray tray) { var variety = await varietyService.GetById(tray.VarietyId); - var labelResult = - await hyosungWmsService.GetLabelResult(variety.Code, variety.Lot.ToString(), tray.ControlNo!.Value); + + var dic = new Dictionary { { "$1153", $"\"{variety.Lot}\"" }, { "1670dtex -144F", $"\"{tray.DtexFila}\"" }, { "1500D - 144F", $"\"{tray.DenFila}\"" }, { "$SA", $"\"{tray.Grade}\"" }, - { "$900", $"\"{labelResult.NET_WEIGHT.ToString("0.0")}\"" }, + { "$900", $"\"{tray.NetWeight:0.0}\"" }, { "25-01-01", $"\"{DateTime.Now:yy-MM-dd}\"" }, { "$90", $"\"{variety.TotalCount}\"" }, - { "$965", $"\"{labelResult.GROSS_WEIGHT}\"" }, + { "$965", $"\"{tray.GrossWeight}\"" }, { "250101J068", $"\"{DateTime.Now.ToString("yyMMdd" + "J") + tray.ControlNo.ToString()?.PadLeft(3, '0')}\"" }, - { "DTYY-JPA11530SFG250101000900115305480", $"\"{labelResult.BAR_CODE}\"" } + { "DTYY-JPA11530SFG250101000900115305480", $"\"{tray.Barcode}\"" } }; string content = options.Value.DefaultTemp; foreach (var (key, value) in dic) diff --git a/Seyounth.Hyosung.Data/Entities/TrayEntity.cs b/Seyounth.Hyosung.Data/Entities/TrayEntity.cs index 5f69179..3e4c1d3 100644 --- a/Seyounth.Hyosung.Data/Entities/TrayEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/TrayEntity.cs @@ -40,4 +40,6 @@ public class TrayEntity [SugarColumn(IsNullable = true)] public double GrossWeight { get; set; } [SugarColumn(IsNullable = true)] public int? AgvBinId { get; set; } + + [SugarColumn(IsNullable = true)] public string? Barcode { get; set; } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Models/Tray.cs b/Seyounth.Hyosung.Data/Models/Tray.cs index dbb07df..523c9c9 100644 --- a/Seyounth.Hyosung.Data/Models/Tray.cs +++ b/Seyounth.Hyosung.Data/Models/Tray.cs @@ -36,6 +36,8 @@ public class Tray public int? AgvBinId { get; set; } + public string? Barcode { get; set; } + public TrayEntity ToEntity() { return new TrayEntity() @@ -55,7 +57,8 @@ public class Tray Grade = Grade, Type = Type, Unit = Unit, - AgvBinId = AgvBinId + AgvBinId = AgvBinId, + Barcode = Barcode }; } @@ -78,7 +81,8 @@ public class Tray Grade = entity.Grade, Type = entity.Type, Unit = entity.Unit, - AgvBinId = entity.AgvBinId + AgvBinId = entity.AgvBinId, + Barcode = entity.Barcode }; } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/Hyosung/Entities/LabelResult.cs b/Seyounth.Hyosung.Data/Services/Hyosung/Entities/LabelResult.cs index 0cbe46a..88a88dd 100644 --- a/Seyounth.Hyosung.Data/Services/Hyosung/Entities/LabelResult.cs +++ b/Seyounth.Hyosung.Data/Services/Hyosung/Entities/LabelResult.cs @@ -1,3 +1,4 @@ +using Seyounth.Hyosung.Data.Models; using SqlSugar; namespace Seyounth.Hyosung.Data.Services.Hyosung.Entities; @@ -5,34 +6,54 @@ namespace Seyounth.Hyosung.Data.Services.Hyosung.Entities; [SugarTable("LABEL_RESULT")] public class LabelResult { - public string BE_ID { get; set; } - public string BAR_CODE { get; set; } - public string ITEM_CODE { get; set; } - public string LABEL_ID { get; set; } - public string WMS_UOM { get; set; } - public string ERP_UOM { get; set; } - public string MFG_DATE { get; set; } - public decimal NET_WEIGHT { get; set; } - public double GROSS_WEIGHT { get; set; } - public string MFG_LINE { get; set; } - public string GRADE { get; set; } - public string LOT { get; set; } - public string BOX_NO { get; set; } - public string DENIER { get; set; } - public string FILA { get; set; } - public string CUSTOMER_NAME { get; set; } - public string REMARKS { get; set; } - public string TRI_INTERFACE_YN { get; set; } - public string TRI_TYPE { get; set; } - public string COMMON_S1 { get; set; } - public string COMMON_S2 { get; set; } - public string COMMON_S3 { get; set; } - public string COMMON_S4 { get; set; } - public string COMMON_S5 { get; set; } - public string COMMON_N1 { get; set; } - public string TRI_YN { get; set; } - public string CREATED_BY { get; set; } - public string CREATED_ON { get; set; } - public string MODIFIED_BY { get; set; } - public string MODIFIED_ON { get; set; } + public string BE_ID { get; set; } = "2240"; + public string BAR_CODE { get; set; } = ""; + public string ITEM_CODE { get; set; } = ""; + public string LABEL_ID { get; set; } = ""; + public string WMS_UOM { get; set; } = ""; + public string ERP_UOM { get; set; } = ""; + public string MFG_DATE { get; set; } = ""; + public decimal NET_WEIGHT { get; set; } = 0; + public double GROSS_WEIGHT { get; set; } = 0; + public string MFG_LINE { get; set; } = ""; + public string GRADE { get; set; } = ""; + public string LOT { get; set; } = ""; + public string BOX_NO { get; set; } = ""; + public string DENIER { get; set; } = ""; + public string FILA { get; set; } = ""; + public string CUSTOMER_NAME { get; set; } = ""; + public string REMARKS { get; set; } = ""; + public string TRI_INTERFACE_YN { get; set; } = ""; + public string TRI_TYPE { get; set; } = "zp10"; + public string COMMON_S1 { get; set; } = ""; + public string COMMON_S2 { get; set; } = ""; + public string COMMON_S3 { get; set; } = ""; + public string COMMON_S4 { get; set; } = ""; + public string COMMON_S5 { get; set; } = ""; + public string COMMON_N1 { get; set; } = ""; + public string TRI_YN { get; set; } = ""; + public string CREATED_BY { get; set; } = "seyounth"; + public string CREATED_ON { get; set; } = DateTime.Now.ToString("yyyy-MM-dd"); + public string MODIFIED_BY { get; set; } = "seyounth"; + public string MODIFIED_ON { get; set; } = DateTime.Now.ToString("yyyy-MM-dd"); + + public LabelResult(Tray tray, Variety variety) + { + LABEL_ID = tray.TrayCode; + BE_ID = "2240"; + BAR_CODE = tray.Barcode ?? ""; + ITEM_CODE = variety.Code; + MFG_DATE = DateTime.Now.ToString("yyyy-MM-dd"); + NET_WEIGHT = (decimal)tray.NetWeight; + GROSS_WEIGHT = tray.GrossWeight; + GRADE = tray.Grade ?? ""; + LOT = variety.Lot.ToString(); + BOX_NO = tray.ControlNo?.ToString() ?? ""; + CREATED_BY = "seyounth"; + CREATED_ON = DateTime.Now.ToString("yyyy-MM-dd"); + } + + public LabelResult() + { + } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/Hyosung/Entities/MST_ITEM.cs b/Seyounth.Hyosung.Data/Services/Hyosung/Entities/MST_ITEM.cs new file mode 100644 index 0000000..71d03e0 --- /dev/null +++ b/Seyounth.Hyosung.Data/Services/Hyosung/Entities/MST_ITEM.cs @@ -0,0 +1,26 @@ +namespace Seyounth.Hyosung.Data.Services.Hyosung.Entities; + +public class MST_ITEM +{ + public string BE_ID { get; set; } = "2240"; + + public string ITEM_CODE { get; set; } + + public string ITEM_CODE_TYPE { get; set; } = "FERT"; + + public string COMMON_S1 { get; set; } + + public string COMMON_S2 { get; set; } + + public string COMMON_S3 { get; set; } + + public string COMMON_S4 { get; set; } + + public string COMMON_S5 { get; set; } + + public string ERP_UOM_ID { get; set; } + + public string WMS_UOM_ID { get; set; } + + +} \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/Hyosung/Entities/MST_ITEM_VERSION.cs b/Seyounth.Hyosung.Data/Services/Hyosung/Entities/MST_ITEM_VERSION.cs new file mode 100644 index 0000000..aaa6a19 --- /dev/null +++ b/Seyounth.Hyosung.Data/Services/Hyosung/Entities/MST_ITEM_VERSION.cs @@ -0,0 +1,9 @@ +namespace Seyounth.Hyosung.Data.Services.Hyosung.Entities; + +public class MST_ITEM_VERSION +{ + public string ITEM_CODE { get; set; } + + public string WORK_CENTER { get; set; } + +} \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/Hyosung/HyosungWmsService.cs b/Seyounth.Hyosung.Data/Services/Hyosung/HyosungWmsService.cs index 7cb6c21..91a2d7e 100644 --- a/Seyounth.Hyosung.Data/Services/Hyosung/HyosungWmsService.cs +++ b/Seyounth.Hyosung.Data/Services/Hyosung/HyosungWmsService.cs @@ -53,12 +53,12 @@ public class HyosungWmsService : IHyosungWmsService else { await _db.Updateable() - .SetColumns(i => new MST_BOXNO_SEQ_NON_DATE - { - LastNo = controlNo, - ModifiedTime = DateTime.Now, - ModifiedBy = "seyounth" - }) + .SetColumns(i => new MST_BOXNO_SEQ_NON_DATE + { + LastNo = controlNo, + ModifiedTime = DateTime.Now, + ModifiedBy = "seyounth" + }) .Where(i => i.BeId == "2240" && i.ItemCode == variety.Code && i.CheckCode == checkCode).ExecuteCommandAsync(); @@ -70,7 +70,7 @@ public class HyosungWmsService : IHyosungWmsService try { string code = $"{itemCode.Trim()} {DateTime.Now.AddDays(0):yyMMdd}"; - string code2 = $"{lot.Trim()}{(controlNo-1).ToString().PadLeft(4, '0')}0"; + string code2 = $"{lot.Trim()}{(controlNo - 1).ToString().PadLeft(4, '0')}0"; // 使用 SqlSugar 进行查询 return await _db.Queryable() @@ -80,10 +80,26 @@ public class HyosungWmsService : IHyosungWmsService x.BE_ID == "2240" ) .FirstAsync(); - } catch (Exception e) + } + catch (Exception e) { throw e; } - + } + + public async Task AddLabelResult(LabelResult result) + { + var mst_item = await _db.Queryable() + .FirstAsync(t => t.BE_ID == "2240" + && t.ITEM_CODE == result.ITEM_CODE + && t.ITEM_CODE_TYPE == "FERT"); + result.COMMON_S1 = mst_item.COMMON_S1; + result.COMMON_S3 = mst_item.COMMON_S3; + result.COMMON_S5 = mst_item.COMMON_S5; + result.WMS_UOM = mst_item.WMS_UOM_ID; + result.ERP_UOM = mst_item.ERP_UOM_ID; + var workCenter = await _db.Queryable() + .FirstAsync(v => v.ITEM_CODE == result.ITEM_CODE); + await _db.Insertable(result).ExecuteCommandAsync(); } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/Hyosung/IHyosungWmsService.cs b/Seyounth.Hyosung.Data/Services/Hyosung/IHyosungWmsService.cs index ca619b5..9aa1172 100644 --- a/Seyounth.Hyosung.Data/Services/Hyosung/IHyosungWmsService.cs +++ b/Seyounth.Hyosung.Data/Services/Hyosung/IHyosungWmsService.cs @@ -10,6 +10,8 @@ public interface IHyosungWmsService Task GetItemInfoByItemCode(string itemCode); Task UpdateControlNo(Variety variety, int controlNo); - - Task GetLabelResult(string itemCode,string lot,int controlNo); + + Task GetLabelResult(string itemCode, string lot, int controlNo); + + Task AddLabelResult(LabelResult result); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/ITrayService.cs b/Seyounth.Hyosung.Data/Services/ITrayService.cs index bc574f9..9db78da 100644 --- a/Seyounth.Hyosung.Data/Services/ITrayService.cs +++ b/Seyounth.Hyosung.Data/Services/ITrayService.cs @@ -41,5 +41,5 @@ public interface ITrayService /// /// /// - Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo); + Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/TrayService.cs b/Seyounth.Hyosung.Data/Services/TrayService.cs index 143d75b..2c535fb 100644 --- a/Seyounth.Hyosung.Data/Services/TrayService.cs +++ b/Seyounth.Hyosung.Data/Services/TrayService.cs @@ -30,7 +30,7 @@ public class TrayService : ITrayService { var tray = new Tray() { - TrayCode =DateTime.Now.ToTimestamp().ToString(), + TrayCode = DateTime.Now.ToTimestamp().ToString(), VarietyId = varietyId, CreateTime = DateTime.Now }; @@ -47,13 +47,11 @@ public class TrayService : ITrayService try { return _cache[code].Id; - } catch { return (await _repository.GetFirstAsync(d => d.TrayCode == code)).Id; } - } public async Task GetByCode(string code) @@ -66,7 +64,7 @@ public class TrayService : ITrayService throw new NotImplementedException(); } - public async Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo) + public async Task PrintTrayAsync(string trayCode, int stackHeight, int controlNo, MST_ITEM_2240_V itemInfo) { Tray tray; try @@ -77,7 +75,7 @@ public class TrayService : ITrayService { tray = await GetByCode(trayCode); } - + tray.ControlNo = controlNo; tray.StackHeight = stackHeight; tray.Grade = itemInfo.GRADE; @@ -87,12 +85,14 @@ public class TrayService : ITrayService tray.Unit = itemInfo.UNIT; tray.NetWeight = itemInfo.NET_WEIGHT; tray.GrossWeight = itemInfo.GROSS_WEIGHT; + tray.Barcode = + $"{itemInfo.ITEM_CODE} {DateTime.Now:yyMMdd}00{controlNo.ToString().PadLeft(4, '0')}{itemInfo.LOTNO.PadLeft(4, '0')}0"; await _repository.UpdateAsync(tray.ToEntity()); _cache.Remove(tray.TrayCode, out _); + return tray; } public async Task StorageAsync(string trayCode) { - } } \ No newline at end of file diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index 18b7d17..51bd3f7 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -10,6 +10,7 @@ using Seyounth.Hyosung.Data.Models; using Seyounth.Hyosung.Data.Models.Plc; using Seyounth.Hyosung.Data.Services; using Seyounth.Hyosung.Data.Services.Hyosung; +using Seyounth.Hyosung.Data.Services.Hyosung.Entities; using Seyounth.Hyosung.Runtime.Models; namespace Seyounth.Hyosung.Runtime; @@ -297,7 +298,7 @@ public class HyosungRuntime( var grade = "1"; if (mod.GRADE != "AA") grade = mod.GRADE; var controlNo = await hyosungWmsService.GetControlNo(variety, grade); - await trayService.PrintTrayAsync(trayCode, height, controlNo, mod); + tray = await trayService.PrintTrayAsync(trayCode, height, controlNo, mod); if (arg1 == 1) { await printer.PrintAsync(1, trayCode); @@ -311,11 +312,12 @@ public class HyosungRuntime( await hyosungWmsService.UpdateControlNo(variety, controlNo); + await hyosungWmsService.AddLabelResult(new LabelResult(tray, variety)); logger.LogInformation($"plc request print label success"); } catch (Exception e) { - await hyosungPlcService.WritePrintLabelResultAsync(arg1, 1,false); + await hyosungPlcService.WritePrintLabelResultAsync(arg1, 1, false); logger.LogError(e, "print label fail"); } }