From 22576d17cc318270b65796f74baa02b2ee4218e1 Mon Sep 17 00:00:00 2001 From: anerx <512464164@qq.com> Date: Mon, 24 Mar 2025 16:57:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=87=8D=E9=87=8F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/VarietyEntity.cs | 6 ++ Seyounth.Hyosung.Data/Models/Variety.cs | 18 +++-- .../Services/IReportExportService.cs | 2 + .../Services/ITrayService.cs | 4 +- .../Services/ReportExportService.cs | 74 ++++++++++++++++++- Seyounth.Hyosung.Data/Services/TrayService.cs | 14 +++- Seyounth.Hyosung.Runtime/HyosungRuntime.cs | 13 +++- Seyounth.Hyosung.Runtime/IHyosungRuntime.cs | 6 ++ 8 files changed, 125 insertions(+), 12 deletions(-) diff --git a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs index 4befcaa..eb09ce4 100644 --- a/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs +++ b/Seyounth.Hyosung.Data/Entities/VarietyEntity.cs @@ -87,4 +87,10 @@ public class VarietyEntity [SugarColumn(IsNullable =true)] public int? LastNo { get; set; } + [SugarColumn(IsNullable =true)] + public double? NetWeight { get; set; } + + [SugarColumn(IsNullable =true)] + public double? GrossWeight { 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 13fd136..b4fd677 100644 --- a/Seyounth.Hyosung.Data/Models/Variety.cs +++ b/Seyounth.Hyosung.Data/Models/Variety.cs @@ -66,6 +66,10 @@ public class Variety public int? LastNo { get; set; } + public double? NetWeight { get; set; } + + public double? GrossWeight { get; set; } + public static Variety Create(VarietyEntity entity, List pallets) { var variety = new Variety() @@ -95,7 +99,9 @@ public class Variety TopAndBottomPallet = Pallet.FromEntity(pallets.First(x => x.Id == entity.TopAndBottomPalletId)), Tray = Pallet.FromEntity(pallets.First(x => x.Id == entity.TrayId)), HasBox = entity.HasBox, - LastNo = entity.LastNo + LastNo = entity.LastNo, + NetWeight = entity.NetWeight, + GrossWeight = entity.GrossWeight }; if (entity.PaperTrayId != null && entity.PaperTrayId != 0) variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId)); @@ -133,7 +139,9 @@ public class Variety TopAndBottomPalletId = TopAndBottomPallet.Id, TrayId = Tray.Id, HasBox = HasBox, - LastNo=LastNo + LastNo = LastNo, + NetWeight = NetWeight, + GrossWeight = GrossWeight }; return entity; } @@ -168,13 +176,13 @@ public class Variety ls.Add((short)PaperTray.Height); } - ls.Add((short)(TopAndBottomPallet.HoleCount is null?0: TopAndBottomPallet.HoleCount)); - ls.Add((short)(TopAndBottomPallet.IsBigHole is null?2:(TopAndBottomPallet.IsBigHole.Value?1:2))); + ls.Add((short)(TopAndBottomPallet.HoleCount is null ? 0 : TopAndBottomPallet.HoleCount)); + ls.Add((short)(TopAndBottomPallet.IsBigHole is null ? 2 : (TopAndBottomPallet.IsBigHole.Value ? 1 : 2))); ls.Add((short)TopAndBottomPallet.Length); ls.Add((short)TopAndBottomPallet.Width); ls.Add((short)TopAndBottomPallet.Height); ls.Add((short)(MiddlePallet.HoleCount is null ? 0 : MiddlePallet.HoleCount)); - ls.Add((short)(MiddlePallet.IsBigHole is null ? 2 : (MiddlePallet.IsBigHole.Value ?1 : 2))); + ls.Add((short)(MiddlePallet.IsBigHole is null ? 2 : (MiddlePallet.IsBigHole.Value ? 1 : 2))); ls.Add((short)MiddlePallet.Length); ls.Add((short)MiddlePallet.Width); ls.Add((short)MiddlePallet.Height); diff --git a/Seyounth.Hyosung.Data/Services/IReportExportService.cs b/Seyounth.Hyosung.Data/Services/IReportExportService.cs index 73dc58f..7f62c64 100644 --- a/Seyounth.Hyosung.Data/Services/IReportExportService.cs +++ b/Seyounth.Hyosung.Data/Services/IReportExportService.cs @@ -6,4 +6,6 @@ public interface IReportExportService Task ExportNoExportAsync(); + + Task ExportTodayTotalReportAsync(); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/ITrayService.cs b/Seyounth.Hyosung.Data/Services/ITrayService.cs index 4175b37..078cb98 100644 --- a/Seyounth.Hyosung.Data/Services/ITrayService.cs +++ b/Seyounth.Hyosung.Data/Services/ITrayService.cs @@ -44,7 +44,7 @@ public interface ITrayService /// /// /// - Task PrintTrayAsync(string trayCode, MST_ITEM_2240_V itemInfo); + Task PrintTrayAsync(string trayCode, MST_ITEM_2240_V itemInfo,Variety variety); Task UpdateHeightAsync(string trayCode, int height); @@ -54,4 +54,6 @@ public interface ITrayService Task> GetNoExportCodesAsync(); Task SetControlNoAsync(string trayCode, int controlNo); + + Task> GetTodayTrayAsync(); } \ No newline at end of file diff --git a/Seyounth.Hyosung.Data/Services/ReportExportService.cs b/Seyounth.Hyosung.Data/Services/ReportExportService.cs index eee4571..079be16 100644 --- a/Seyounth.Hyosung.Data/Services/ReportExportService.cs +++ b/Seyounth.Hyosung.Data/Services/ReportExportService.cs @@ -62,10 +62,15 @@ public class ReportExportService( row++; } + for (int i = 8; i < row; i++) + { + worksheet.Row(i).Height = 31.5; + } + // 自动调整列宽 // worksheet.Columns().AdjustToContents(); // 获取数据区域 - var dataRange = worksheet.Range(8, 2, row, 18); + var dataRange = worksheet.Range(8, 2, row - 1, 18); // 设置外边框样式 dataRange.Style.Border.OutsideBorder = XLBorderStyleValues.Thick; dataRange.Style.Border.InsideBorder = XLBorderStyleValues.Medium; @@ -94,6 +99,73 @@ public class ReportExportService( }); } + public async Task ExportTodayTotalReportAsync() + { + try + { + DataTable dt = new DataTable(); + dt.Columns.Add("序号"); + dt.Columns.Add("LOT"); + dt.Columns.Add("品类"); + dt.Columns.Add("条码"); + dt.Columns.Add("数量"); + dt.Columns.Add("毛重"); + dt.Columns.Add("净重"); + dt.Columns.Add("控制号"); + dt.Columns.Add("完成时间"); + var trays = await trayService.GetTodayTrayAsync(); + for (int i = 0; i < trays.Count; i++) + { + var variety = await varietyService.GetById(trays[i].VarietyId); + var yarns = await yarnService.GetYarnsByTrayIdAsync(trays[i].Id); + dt.Rows.Add(i + 1, variety.Lot, variety.Code, trays[i].Barcode, yarns.Count, + trays[i].GrossWeight, trays[i].NetWeight, trays[i].ControlNo, + trays[i].FinishTime?.ToString("yyyy-MM-dd HH:mm:ss")); + } + + var path = await GetTotalDirectoryAsync(); + var fileName = $"每日报表-{DateTime.Now:yyyyMMdd}.xlsx"; + var filePath = Path.Combine(path, fileName); + using var workbook = new XLWorkbook(); + var worksheet = workbook.Worksheets.Add(dt); + var headerRow = worksheet.FirstRowUsed(); + headerRow.Style.Font.FontSize = 16; + + // 设置数据行字体大小 + var dataRows = worksheet.RowsUsed().Skip(1); + 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 GetTotalDirectoryAsync(DateTime? date = null) + { + var root = "D:\\每日报表"; + if (date is null) + date = DateTime.Now; + // 构建文件夹路径,格式为 年/月/日 + string directoryPath = Path.Combine(root, date.Value.Year.ToString(), date.Value.Month.ToString()); + + // 检查文件夹是否存在 + if (!Directory.Exists(directoryPath)) + { + // 如果不存在,则创建文件夹 + await Task.Run(() => Directory.CreateDirectory(directoryPath)); + } + + return directoryPath; + } + public async Task GetDirectoryAsync(DateTime? date = null) { var root = "D:\\码垛信息"; diff --git a/Seyounth.Hyosung.Data/Services/TrayService.cs b/Seyounth.Hyosung.Data/Services/TrayService.cs index a86e9a5..fab7e0e 100644 --- a/Seyounth.Hyosung.Data/Services/TrayService.cs +++ b/Seyounth.Hyosung.Data/Services/TrayService.cs @@ -69,7 +69,7 @@ public class TrayService : ITrayService throw new NotImplementedException(); } - public async Task PrintTrayAsync(string trayCode, MST_ITEM_2240_V itemInfo) + public async Task PrintTrayAsync(string trayCode, MST_ITEM_2240_V itemInfo, Variety variety) { Tray tray; //try @@ -86,8 +86,8 @@ public class TrayService : ITrayService tray.DenFila = itemInfo.DEN_FILA; tray.DtexFila = itemInfo.DTEX_FILA; tray.Unit = itemInfo.UNIT; - tray.NetWeight = itemInfo.NET_WEIGHT; - tray.GrossWeight = itemInfo.GROSS_WEIGHT; + 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(); @@ -137,6 +137,14 @@ public class TrayService : ITrayService .ExecuteCommandAsync(); } + public Task> GetTodayTrayAsync() + { + return _db.CopyNew() + .Queryable() + .Where(x => x.FinishTime >= DateTime.Today && x.FinishTime < DateTime.Today.AddDays(1)) + .ToListAsync(x => Tray.FromEntity(x)); + } + public async Task GetIsPacking() { var tray = await _db.CopyNew().Queryable().Where(x => x.IsPacking != null && x.IsPacking.Value) diff --git a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs index 20d31d8..7978416 100644 --- a/Seyounth.Hyosung.Runtime/HyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/HyosungRuntime.cs @@ -116,6 +116,15 @@ public class HyosungRuntime( logger.LogInformation($"send variety to plc success: {variety.Id}"); } + public async Task GenerateReportAsync() + { + var trays = await trayService.GetTodayTrayAsync(); + foreach (var tray in trays) + { + + } + } + /// /// 处理PLC请求扫描治具事件 /// @@ -194,7 +203,7 @@ public class HyosungRuntime( try { await trayService.StorageAsync(info.TrayCode); - + await hyosungAgvService.StorageAsync(info.TrayCode); //标志下线已完成 await hyosungPlcService.LeaveCompletedAsync(); @@ -372,7 +381,7 @@ public class HyosungRuntime( // controlNo += 1; // // } - tray = await trayService.PrintTrayAsync(arg, mod); + tray = await trayService.PrintTrayAsync(arg, mod,variety); await dictService.SetValue("System", "CurrentPackingTrayCode", arg); await hyosungPlcService.WritePrintLableOptionsAsync(variety.MasterLabelCount); } diff --git a/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs b/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs index d5a8143..88bea7d 100644 --- a/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs +++ b/Seyounth.Hyosung.Runtime/IHyosungRuntime.cs @@ -32,4 +32,10 @@ public interface IHyosungRuntime /// /// Task SendVarietyToPlcAsync(Variety variety); + + /// + /// 生成当日报表 + /// + /// + Task GenerateReportAsync(); } \ No newline at end of file