diff --git a/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs b/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs index 5e3f601..13ed92a 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs @@ -385,23 +385,30 @@ namespace DOAN.Admin.WebApi.Controllers } //TODO 打印机打印工单 + + [HttpPost("print")] [AllowAnonymous] - [HttpGet("print")] - public async Task ExportWorkorderPDF(string[] workorderArray,string? path) + public async Task ExportWorkorderPDF([FromBody] ProWorkorderExportDto param) { - if(workorderArray==null||workorderArray.Length<1) + try { - throw new CustomException("workorderArray"); - } - if (path==null) - { - path ="./Resources/gxassembly_production_label.btw"; - } - //Task<(string, Stream)> conntext = _ProWorkorderService.ExportPDFByQuestPDFDemo(workorderArray); - var exception = await _ProWorkorderService.PrintTicketsByTemplate(workorderArray,path); + if (param.WorkorderArray == null || param.WorkorderArray.Length < 1) + { + return ToResponse(500, "工单列表为空"); + } + param.Path = "D:/mes/Label/Trace.btw"; + //Task<(string, Stream)> conntext = _ProWorkorderService.ExportPDFByQuestPDFDemo(workorderArray); + var exception = await _ProWorkorderService.PrintTicketsByTemplate(param); + + return (IActionResult)exception; + //return File(conntext.Result.Item2, "application/pdf", HttpUtility.UrlEncode(conntext.Result.Item1)); + } + catch (Exception ex) + { + return ToResponse(500, ex.Message); + } + - return (IActionResult)exception; - //return File(conntext.Result.Item2, "application/pdf", HttpUtility.UrlEncode(conntext.Result.Item1)); } diff --git a/DOAN.Admin.WebApi/appsettings.Development.json b/DOAN.Admin.WebApi/appsettings.Development.json index ab79f5a..c14f0d2 100644 --- a/DOAN.Admin.WebApi/appsettings.Development.json +++ b/DOAN.Admin.WebApi/appsettings.Development.json @@ -14,7 +14,7 @@ //代码生成数据库配置 "CodeGenDbConfig": { //代码生成连接字符串,注意{dbName}为固定格式,不要填写数据库名 - "Conn": "Data Source=127.0.0.1;User ID=root;Password=123456;Initial Catalog={dbName};Port=3306", + "Conn": "Data Source=139.224.232.211;User ID=root;Password=doantech123;Initial Catalog={dbName};Port=3308", "DbType": 0, "IsAutoCloseConnection": true, "DbName": "bzfm_mes" //代码生成默认连接数据库,Oracle库是实例的名称 diff --git a/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs b/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs index cdd69b2..97e1b79 100644 --- a/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs +++ b/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs @@ -26,7 +26,11 @@ namespace DOAN.Model.MES.product.Dto public DateTime WorkorderDate { get; set; } } - + public class ProWorkorderExportDto + { + public string [] WorkorderArray { get; set; } + public string Path { get; set; } + } /// diff --git a/DOAN.Service/MES/Product/IService/IProWorkorderService.cs b/DOAN.Service/MES/Product/IService/IProWorkorderService.cs index c4065b7..986d672 100644 --- a/DOAN.Service/MES/Product/IService/IProWorkorderService.cs +++ b/DOAN.Service/MES/Product/IService/IProWorkorderService.cs @@ -65,6 +65,6 @@ namespace DOAN.Service.MES.product.IService int WorkOrderLog(string workorder, string log, string Operator); Task<(string, Stream)> ExportPDFByQuestPDFDemo(string[] workorderArray); - Task PrintTicketsByTemplate(string[] workorderArray,string path); + Task PrintTicketsByTemplate(ProWorkorderExportDto param); } } diff --git a/DOAN.Service/MES/Product/ProWorkorderService.cs b/DOAN.Service/MES/Product/ProWorkorderService.cs index 1ad530b..383950d 100644 --- a/DOAN.Service/MES/Product/ProWorkorderService.cs +++ b/DOAN.Service/MES/Product/ProWorkorderService.cs @@ -1,41 +1,36 @@ using System; -using SqlSugar; -using Infrastructure.Attribute; +using System.Data.Common; +using System.Globalization; +using System.Linq; +using BarTender; +using DOAN.Infrastructure.Helper; using DOAN.Model; - +using DOAN.Model.MES.base_; +using DOAN.Model.MES.base_.Dto; using DOAN.Model.MES.product; using DOAN.Model.MES.product.Dto; - +using DOAN.Model.System; using DOAN.Repository; using DOAN.Service.MES.product.IService; - -using System.Linq; -using SqlSugar.Extensions; -using MimeKit.Tnef; -using DOAN.Model.MES.base_; +using Infrastructure; +using Infrastructure.Attribute; +using Infrastructure.Converter; +using MathNet.Numerics.RootFinding; +using Microsoft.AspNetCore.Components.Forms; using Microsoft.AspNetCore.Http; -using DOAN.Model.System; +using MimeKit.Tnef; using MiniExcelLibs; +using NPOI.HSSF.UserModel; using NPOI.SS.Formula.Functions; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; -using System.Data.Common; using NPOI.XWPF.UserModel; -using NPOI.HSSF.UserModel; -using Microsoft.AspNetCore.Components.Forms; -using System.Globalization; -using DOAN.Infrastructure.Helper; -using DOAN.Model.MES.base_.Dto; - -using Infrastructure.Converter; using QuestPDF; using QuestPDF.Fluent; using QuestPDF.Helpers; using QuestPDF.Infrastructure; -using BarTender; -using MathNet.Numerics.RootFinding; -using Infrastructure; - +using SqlSugar; +using SqlSugar.Extensions; namespace DOAN.Service.MES.product { @@ -56,39 +51,53 @@ namespace DOAN.Service.MES.product { parm.WorkorderDate[0] = parm.WorkorderDate[0].Date; parm.WorkorderDate[1] = parm.WorkorderDate[1].Date; - } - var predicate = Expressionable.Create() - .AndIF(!string.IsNullOrEmpty(parm.productionName), - it => it.productionName.Contains(parm.productionName)) - .AndIF(!string.IsNullOrEmpty(parm.productionCode), - it => it.productionCode.Contains(parm.productionCode)) - .AndIF(!string.IsNullOrEmpty(parm.RouteCode), it => it.RouteCode == parm.RouteCode) - .AndIF(!string.IsNullOrEmpty(parm.GroupCode), it => it.GroupCode == parm.GroupCode) - .AndIF(parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, - it => it.WorkorderDate >= parm.WorkorderDate[0]) - .AndIF(parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, - it => it.WorkorderDate <= parm.WorkorderDate[1]) - ; - var query = Queryable() - .Where(predicate.ToExpression()); - var finalQuery = Context.Queryable(query) + var predicate = Expressionable + .Create() + .AndIF( + !string.IsNullOrEmpty(parm.productionName), + it => it.productionName.Contains(parm.productionName) + ) + .AndIF( + !string.IsNullOrEmpty(parm.productionCode), + it => it.productionCode.Contains(parm.productionCode) + ) + .AndIF(!string.IsNullOrEmpty(parm.RouteCode), it => it.RouteCode == parm.RouteCode) + .AndIF(!string.IsNullOrEmpty(parm.GroupCode), it => it.GroupCode == parm.GroupCode) + .AndIF( + parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, + it => it.WorkorderDate >= parm.WorkorderDate[0] + ) + .AndIF( + parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, + it => it.WorkorderDate <= parm.WorkorderDate[1] + ); + var query = Queryable().Where(predicate.ToExpression()); + var finalQuery = Context + .Queryable(query) .LeftJoin((q, m) => q.productionCode == m.Code) .LeftJoin((q, m, m2) => q.productionName == m2.Name) .LeftJoin((q, m, m2, r) => q.RouteCode == r.Code) .LeftJoin((q, m, m2, r, g) => q.GroupCode == g.GroupCode) .LeftJoin((q, m, m2, r, g, u) => q.Unit == u.UnitCode) - .Select((q, m, m2, r, g, u) => new ProWorkorderDto3() - { - IsMatch_material_code = m.Code, - IsMatch_material_name = m2.Name, - IsMatch_line = r.Code, - IsMatch_group = g.GroupCode, - IsMatch_Unit = u.UnitCode, - }, true); + .Select( + (q, m, m2, r, g, u) => + new ProWorkorderDto3() + { + IsMatch_material_code = m.Code, + IsMatch_material_name = m2.Name, + IsMatch_line = r.Code, + IsMatch_group = g.GroupCode, + IsMatch_Unit = u.UnitCode, + }, + true + ); - var response = finalQuery.MergeTable().Distinct().OrderBy(it => it.WorkorderDate) + var response = finalQuery + .MergeTable() + .Distinct() + .OrderBy(it => it.WorkorderDate) .ToPage(parm); //var query = Queryable() @@ -132,7 +141,6 @@ namespace DOAN.Service.MES.product return response; } - /// /// 获取工单无校验 /// @@ -140,29 +148,38 @@ namespace DOAN.Service.MES.product /// public PagedInfo GetList_NOCheck(ProWorkorderQueryDto parm) { - var predicate = Expressionable.Create() - .AndIF(!string.IsNullOrEmpty(parm.productionName), - it => it.productionName.Contains(parm.productionName)) - .AndIF(!string.IsNullOrEmpty(parm.Workorder), it => it.Workorder.Contains(parm.Workorder)) - - .AndIF(!string.IsNullOrEmpty(parm.productionCode), - it => it.productionCode.Contains(parm.productionCode)) - .AndIF(!string.IsNullOrEmpty(parm.RouteCode), it => it.RouteCode == parm.RouteCode) - .AndIF(!string.IsNullOrEmpty(parm.GroupCode), it => it.GroupCode == parm.GroupCode) - .AndIF(parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, - it => it.WorkorderDate >= parm.WorkorderDate[0]) - .AndIF(parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, - it => it.WorkorderDate <= parm.WorkorderDate[1]) - - ; + var predicate = Expressionable + .Create() + .AndIF( + !string.IsNullOrEmpty(parm.productionName), + it => it.productionName.Contains(parm.productionName) + ) + .AndIF( + !string.IsNullOrEmpty(parm.Workorder), + it => it.Workorder.Contains(parm.Workorder) + ) + .AndIF( + !string.IsNullOrEmpty(parm.productionCode), + it => it.productionCode.Contains(parm.productionCode) + ) + .AndIF(!string.IsNullOrEmpty(parm.RouteCode), it => it.RouteCode == parm.RouteCode) + .AndIF(!string.IsNullOrEmpty(parm.GroupCode), it => it.GroupCode == parm.GroupCode) + .AndIF( + parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, + it => it.WorkorderDate >= parm.WorkorderDate[0] + ) + .AndIF( + parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, + it => it.WorkorderDate <= parm.WorkorderDate[1] + ); var query = Queryable() - .Where(predicate.ToExpression()).ToPage(parm); + .Where(predicate.ToExpression()) + .ToPage(parm); return query; } - /// /// 获取详情 /// @@ -170,9 +187,7 @@ namespace DOAN.Service.MES.product /// public ProWorkorder GetInfo(string Id) { - var response = Queryable() - .Where(x => x.Id == Id) - .First(); + var response = Queryable().Where(x => x.Id == Id).First(); return response; } @@ -207,10 +222,8 @@ namespace DOAN.Service.MES.product var response = Update(model, true); return response; - } - /// /// 生成工单号 /// @@ -220,23 +233,25 @@ namespace DOAN.Service.MES.product { DateTime update_time = parm.WorkorderDate.ToLocalTime().Date; - List proWorkorderList = Context.Queryable() + List proWorkorderList = Context + .Queryable() .Where(it => it.WorkorderDate == update_time) .Where(it => it.Status == 1) - .OrderBy(it => it.Sort).ToList(); - string maxs = Context.Queryable().Where(it => it.WorkorderDate == update_time) - .Where(it => it.Status == 3).Max(it => it.Workorder); - + .OrderBy(it => it.Sort) + .ToList(); + string maxs = Context + .Queryable() + .Where(it => it.WorkorderDate == update_time) + .Where(it => it.Status == 3) + .Max(it => it.Workorder); if (proWorkorderList != null && proWorkorderList.Count() > 0) { - string baseSort = update_time.ToString("yyyyMMdd"); int index = 1; if (!string.IsNullOrEmpty(maxs)) { index = Convert.ToInt32(maxs.Substring(maxs.Length - 3)) + 1; - } foreach (ProWorkorder item in proWorkorderList) @@ -250,23 +265,25 @@ namespace DOAN.Service.MES.product return Context.Updateable(proWorkorderList).ExecuteCommand(); } - /// /// 插入工单、新增工单 /// /// /// /// - /// + /// public int Insert_workOrder(ProWorkorder proWorkorder, string next_id) { int result = 0; proWorkorder.Id = XueHua; - proWorkorder.WorkorderDate = - DOANConvertDate.ConvertLocalDate(proWorkorder.WorkorderDate ?? DateTime.MinValue); + proWorkorder.WorkorderDate = DOANConvertDate.ConvertLocalDate( + proWorkorder.WorkorderDate ?? DateTime.MinValue + ); // 获取 产品代号 - List ProductCodeList = - Context.Queryable().Where(it => it.DictType == "product_code").ToList(); + List ProductCodeList = Context + .Queryable() + .Where(it => it.DictType == "product_code") + .ToList(); DateTime handleDate = proWorkorder.WorkorderDate.Value; //插入工单 if (!string.IsNullOrEmpty(next_id) && next_id != "-1") @@ -274,26 +291,43 @@ namespace DOAN.Service.MES.product // 向前插工单 UseTran2(() => { - ProWorkorder maxs = Context.Queryable().Where(it => it.WorkorderDate == handleDate) - .OrderByDescending(it => SqlFunc.Right(it.Workorder, 3)).First(); + ProWorkorder maxs = Context + .Queryable() + .Where(it => it.WorkorderDate == handleDate) + .OrderByDescending(it => SqlFunc.Right(it.Workorder, 3)) + .First(); int index = 1; if (!string.IsNullOrEmpty(maxs.Workorder)) { - index = Convert.ToInt32(maxs.Workorder.Substring(maxs.Workorder.Length - 3)) + 1; - + index = + Convert.ToInt32(maxs.Workorder.Substring(maxs.Workorder.Length - 3)) + + 1; } // proWorkorder.Workorder = "K" + handleDate.ToString("yyyyMMdd") + "_" + proWorkorder.GroupCode + "_" + proWorkorder.RouteCode + "_" + index.ToString("000"); - string nickCode = ProductCodeList.Where(it => it.DictLabel == proWorkorder.productionCode) - .Select(it => it.DictValue).FirstOrDefault(); - proWorkorder.Workorder = "K" + handleDate.ToString("yyyyMMdd") + "_" + proWorkorder.RouteCode + - proWorkorder.GroupCode + "_" + nickCode + "_" + index.ToString("000"); + string nickCode = ProductCodeList + .Where(it => it.DictLabel == proWorkorder.productionCode) + .Select(it => it.DictValue) + .FirstOrDefault(); + proWorkorder.Workorder = + "K" + + handleDate.ToString("yyyyMMdd") + + "_" + + proWorkorder.RouteCode + + proWorkorder.GroupCode + + "_" + + nickCode + + "_" + + index.ToString("000"); - - int sortNum = Context.Queryable().Where(it => it.Id == next_id) - .Select(it => it.Sort.Value).First(); + int sortNum = Context + .Queryable() + .Where(it => it.Id == next_id) + .Select(it => it.Sort.Value) + .First(); // 调整序号 - Context.Updateable() + Context + .Updateable() .Where(it => it.WorkorderDate == handleDate) .Where(it => it.Sort >= sortNum) .SetColumns(it => new ProWorkorder() { Sort = it.Sort + 10 }) @@ -301,8 +335,6 @@ namespace DOAN.Service.MES.product proWorkorder.Sort = sortNum; proWorkorder.Status = 1; - - //增加日志 ProWorkorderUpdateLog logObj = new ProWorkorderUpdateLog(); logObj.Id = XueHua; @@ -317,18 +349,21 @@ namespace DOAN.Service.MES.product result = Context.Insertable(proWorkorder).ExecuteCommand(); Context.Insertable(logObj).ExecuteCommand(); }); - }); } else { // 新增工单 - int sortNum = Context.Queryable().Where(it => it.WorkorderDate == handleDate) + int sortNum = Context + .Queryable() + .Where(it => it.WorkorderDate == handleDate) .Max(it => it.Sort.Value); - ProWorkorder maxWorkorder = Context.Queryable() + ProWorkorder maxWorkorder = Context + .Queryable() .Where(it => it.WorkorderDate == handleDate) - .OrderByDescending(it => SqlFunc.Right(it.Workorder, 3)).First(); + .OrderByDescending(it => SqlFunc.Right(it.Workorder, 3)) + .First(); int index = 0; if (maxWorkorder == null) @@ -344,15 +379,23 @@ namespace DOAN.Service.MES.product } //proWorkorder.Workorder = "H" + handleDate.ToString("yyyyMMdd") + "_" + proWorkorder.GroupCode + "_" + proWorkorder.RouteCode + "_" + index.ToString("000"); - string nickCode = ProductCodeList.Where(it => it.DictLabel == proWorkorder.productionCode) - .Select(it => it.DictValue).FirstOrDefault(); - proWorkorder.Workorder = "H" + handleDate.ToString("yyyyMMdd") + "_" + proWorkorder.RouteCode + - proWorkorder.GroupCode + "_" + nickCode + "_" + index.ToString("000"); - + string nickCode = ProductCodeList + .Where(it => it.DictLabel == proWorkorder.productionCode) + .Select(it => it.DictValue) + .FirstOrDefault(); + proWorkorder.Workorder = + "H" + + handleDate.ToString("yyyyMMdd") + + "_" + + proWorkorder.RouteCode + + proWorkorder.GroupCode + + "_" + + nickCode + + "_" + + index.ToString("000"); proWorkorder.Status = 1; - //增加日志 ProWorkorderUpdateLog logObj = new ProWorkorderUpdateLog(); logObj.Id = XueHua; @@ -367,16 +410,11 @@ namespace DOAN.Service.MES.product result = Context.Insertable(proWorkorder).ExecuteCommand(); Context.Insertable(logObj).ExecuteCommand(); }); - - - } return result; - } - /// /// 移动工单移动工单 /// @@ -386,25 +424,24 @@ namespace DOAN.Service.MES.product public int MoveWorkorder(string id, int type) { int result = 0; - ProWorkorder toMove = Context.Queryable().Where(it => it.Id == id).First(); - var pervious = Context.Queryable() + ProWorkorder toMove = Context + .Queryable() + .Where(it => it.Id == id) + .First(); + var pervious = Context + .Queryable() .Where(it => it.WorkorderDate == toMove.WorkorderDate); - //上移动 if (type == 1) { - - - pervious = pervious.Where(it => it.Sort <= toMove.Sort).OrderByDescending(it => it.Sort); - - + pervious = pervious + .Where(it => it.Sort <= toMove.Sort) + .OrderByDescending(it => it.Sort); } //下移 else if (type == 2) { - - pervious = pervious.Where(it => it.Sort >= toMove.Sort).OrderBy(it => it.Sort); } @@ -416,16 +453,11 @@ namespace DOAN.Service.MES.product exchange.Sort = temp; result += Context.Updateable(toMove).ExecuteCommand(); result += Context.Updateable(exchange).ExecuteCommand(); - } - - return result; - } - /// /// 导入工单 必须整删除 整改 /// @@ -437,8 +469,10 @@ namespace DOAN.Service.MES.product List workorderList = new(); DateTime dateValue = DateTime.MinValue; // 获取 产品代号 - List ProductCodeList = - Context.Queryable().Where(it => it.DictType == "product_code").ToList(); + List ProductCodeList = Context + .Queryable() + .Where(it => it.DictType == "product_code") + .ToList(); using (var stream = formFile.OpenReadStream()) { try @@ -450,7 +484,6 @@ namespace DOAN.Service.MES.product IRow secondRow = sheet.GetRow(1); NPOI.SS.UserModel.ICell cell = secondRow.GetCell(0); - // 将单元格的数字值转换为DateTime dateValue = cell.DateCellValue.Value; @@ -468,7 +501,10 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(0); workorder.productionName = currentCell_01?.ToString(); - if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName)) + if ( + currentCell_01 == null + || string.IsNullOrEmpty(workorder.productionName) + ) { continue; } @@ -477,7 +513,10 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_02 = currentRow.GetCell(1); workorder.productionCode = currentCell_02?.ToString(); - if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode)) + if ( + currentCell_02 == null + || string.IsNullOrEmpty(workorder.productionCode) + ) { continue; } @@ -491,9 +530,6 @@ namespace DOAN.Service.MES.product continue; } - - - //3 plan_num NPOI.SS.UserModel.ICell currentCell_07 = currentRow.GetCell(3); workorder.PlanNum = (int)currentCell_07?.NumericCellValue; @@ -502,27 +538,34 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_11 = currentRow.GetCell(4); workorder.MaterialName = currentCell_11?.ToString(); - if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName)) + if ( + currentCell_11 == null + || string.IsNullOrEmpty(workorder.MaterialName) + ) { continue; } - //5 材料编号 NPOI.SS.UserModel.ICell currentCell_12 = currentRow.GetCell(5); workorder.MaterialCode = currentCell_12?.ToString(); - if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode)) + if ( + currentCell_12 == null + || string.IsNullOrEmpty(workorder.MaterialCode) + ) { continue; } - //6 材质 NPOI.SS.UserModel.ICell currentCell_13 = currentRow.GetCell(6); workorder.MaterialtextureCode = currentCell_13?.ToString(); - if (currentCell_13 == null || string.IsNullOrEmpty(workorder.MaterialtextureCode)) + if ( + currentCell_13 == null + || string.IsNullOrEmpty(workorder.MaterialtextureCode) + ) { continue; } @@ -536,12 +579,14 @@ namespace DOAN.Service.MES.product continue; } - //8 图号 NPOI.SS.UserModel.ICell currentCell_15 = currentRow.GetCell(8); workorder.DrawingCode = currentCell_15?.ToString(); - if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode)) + if ( + currentCell_15 == null + || string.IsNullOrEmpty(workorder.DrawingCode) + ) { continue; } @@ -561,11 +606,9 @@ namespace DOAN.Service.MES.product //10指示日期 NPOI.SS.UserModel.ICell cell17 = currentRow.GetCell(10); - // 将单元格的数字值转换为DateTime workorder.InstructionDate = cell17.DateCellValue.Value; - //装箱容积 /*NPOI.SS.UserModel.ICell currentCell_0811 = currentRow.GetCell(6); workorder.PackageCapacity = (int)currentCell_0811?.NumericCellValue;*/ @@ -582,17 +625,15 @@ namespace DOAN.Service.MES.product { if (currentCell_18.CellType == CellType.Numeric) { - workorder.WorkshopCode = currentCell_18.NumericCellValue.ToString(); - + workorder.WorkshopCode = + currentCell_18.NumericCellValue.ToString(); } else { workorder.WorkshopCode = currentCell_18.StringCellValue; } - } - //12 组别code NPOI.SS.UserModel.ICell currentCell_19 = currentRow.GetCell(12); if (currentCell_19 == null) @@ -603,14 +644,13 @@ namespace DOAN.Service.MES.product { if (currentCell_19.CellType == CellType.Numeric) { - workorder.GroupCode = currentCell_19.NumericCellValue.ToString(); - + workorder.GroupCode = + currentCell_19.NumericCellValue.ToString(); } else { workorder.GroupCode = currentCell_19.StringCellValue; } - } //13 线别code @@ -624,8 +664,8 @@ namespace DOAN.Service.MES.product { if (currentCell_20.CellType == CellType.Numeric) { - workorder.RouteCode = currentCell_20.NumericCellValue.ToString(); - + workorder.RouteCode = + currentCell_20.NumericCellValue.ToString(); } else { @@ -633,27 +673,24 @@ namespace DOAN.Service.MES.product } } - - //14 优先级 NPOI.SS.UserModel.ICell currentCell_21 = currentRow.GetCell(14); if (currentCell_21.StringCellValue == "紧急") { workorder.Priority = 3; - } else { if (currentCell_21.StringCellValue == "插单") { workorder.Priority = 2; - } - else if (currentCell_21.StringCellValue == "正常" || - string.IsNullOrEmpty(currentCell_11.StringCellValue)) + else if ( + currentCell_21.StringCellValue == "正常" + || string.IsNullOrEmpty(currentCell_11.StringCellValue) + ) { workorder.Priority = 1; - } } @@ -669,7 +706,6 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_011 = currentRow.GetCell(17); workorder.CustomerOrder = currentCell_011?.StringCellValue; - //18备注 NPOI.SS.UserModel.ICell currentCell_012 = currentRow.GetCell(18); workorder.Remark01 = currentCell_012?.StringCellValue; @@ -681,41 +717,41 @@ namespace DOAN.Service.MES.product workorder.Status = 1; //工单 2024-9-13-组-线-序号 int index = (row - 3); - string nickCode = ProductCodeList.Where(it => it.DictLabel == workorder.productionCode) - .Select(it => it.DictValue).FirstOrDefault(); - workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" +workorder.GroupCode+ workorder.RouteCode + - "_" + nickCode + "_" + index.ToString("000"); + string nickCode = ProductCodeList + .Where(it => it.DictLabel == workorder.productionCode) + .Select(it => it.DictValue) + .FirstOrDefault(); + workorder.Workorder = + dateValue.ToString("yyyyMMdd") + + "_" + + workorder.GroupCode + + workorder.RouteCode + + "_" + + nickCode + + "_" + + index.ToString("000"); workorder.Sort = index * 10; - - CultureInfo culture = CultureInfo.CurrentCulture; workorderList.Add(workorder); - } } #endregion - - - } catch (Exception ex) { return -1; - - } - - - } UseTran2(() => { - - Context.Deleteable().Where(it => it.WorkorderDate == dateValue).ExecuteCommand(); + Context + .Deleteable() + .Where(it => it.WorkorderDate == dateValue) + .ExecuteCommand(); result = Context.Insertable(workorderList).ExecuteCommand(); }); return result; @@ -734,8 +770,10 @@ namespace DOAN.Service.MES.product DateTime dateValue = DateTime.MinValue; // 获取 产品代号 - List ProductCodeList = - Context.Queryable().Where(it => it.DictType == "product_code").ToList(); + List ProductCodeList = Context + .Queryable() + .Where(it => it.DictType == "product_code") + .ToList(); using (var stream = formFile.OpenReadStream()) { try @@ -747,11 +785,9 @@ namespace DOAN.Service.MES.product IRow secondRow = sheet.GetRow(1); NPOI.SS.UserModel.ICell cell = secondRow.GetCell(0); - // 将单元格的数字值转换为DateTime dateValue = cell.DateCellValue.Value; - // 遍历每一行 for (int row = 4; row <= sheet.LastRowNum; row++) { @@ -766,7 +802,10 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(0); workorder.productionName = currentCell_01?.ToString(); - if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName)) + if ( + currentCell_01 == null + || string.IsNullOrEmpty(workorder.productionName) + ) { continue; } @@ -775,13 +814,14 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_02 = currentRow.GetCell(1); workorder.productionCode = currentCell_02?.ToString(); - if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode)) + if ( + currentCell_02 == null + || string.IsNullOrEmpty(workorder.productionCode) + ) { continue; } - - //02单位 NPOI.SS.UserModel.ICell currentCell_04 = currentRow.GetCell(2); @@ -791,9 +831,6 @@ namespace DOAN.Service.MES.product continue; } - - - //3 plan_num NPOI.SS.UserModel.ICell currentCell_07 = currentRow.GetCell(3); workorder.PlanNum = (int)currentCell_07?.NumericCellValue; @@ -802,27 +839,34 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_11 = currentRow.GetCell(4); workorder.MaterialName = currentCell_11?.ToString(); - if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName)) + if ( + currentCell_11 == null + || string.IsNullOrEmpty(workorder.MaterialName) + ) { continue; } - //5 材料编号 NPOI.SS.UserModel.ICell currentCell_12 = currentRow.GetCell(5); workorder.MaterialCode = currentCell_12?.ToString(); - if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode)) + if ( + currentCell_12 == null + || string.IsNullOrEmpty(workorder.MaterialCode) + ) { continue; } - //6 材质 NPOI.SS.UserModel.ICell currentCell_13 = currentRow.GetCell(6); workorder.MaterialtextureCode = currentCell_13?.ToString(); - if (currentCell_13 == null || string.IsNullOrEmpty(workorder.MaterialtextureCode)) + if ( + currentCell_13 == null + || string.IsNullOrEmpty(workorder.MaterialtextureCode) + ) { continue; } @@ -836,12 +880,14 @@ namespace DOAN.Service.MES.product continue; } - //8 图号 NPOI.SS.UserModel.ICell currentCell_15 = currentRow.GetCell(8); workorder.DrawingCode = currentCell_15?.ToString(); - if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode)) + if ( + currentCell_15 == null + || string.IsNullOrEmpty(workorder.DrawingCode) + ) { continue; } @@ -861,11 +907,9 @@ namespace DOAN.Service.MES.product //10指示日期 NPOI.SS.UserModel.ICell cell17 = currentRow.GetCell(10); - // 将单元格的数字值转换为DateTime workorder.InstructionDate = cell17.DateCellValue.Value; - //装箱容积 /*NPOI.SS.UserModel.ICell currentCell_0811 = currentRow.GetCell(6); workorder.PackageCapacity = (int)currentCell_0811?.NumericCellValue;*/ @@ -882,17 +926,15 @@ namespace DOAN.Service.MES.product { if (currentCell_18.CellType == CellType.Numeric) { - workorder.WorkshopCode = currentCell_18.NumericCellValue.ToString(); - + workorder.WorkshopCode = + currentCell_18.NumericCellValue.ToString(); } else { workorder.WorkshopCode = currentCell_18.StringCellValue; } - } - //12 组别code NPOI.SS.UserModel.ICell currentCell_19 = currentRow.GetCell(12); if (currentCell_19 == null) @@ -903,14 +945,13 @@ namespace DOAN.Service.MES.product { if (currentCell_19.CellType == CellType.Numeric) { - workorder.GroupCode = currentCell_19.NumericCellValue.ToString(); - + workorder.GroupCode = + currentCell_19.NumericCellValue.ToString(); } else { workorder.GroupCode = currentCell_19.StringCellValue; } - } //13 线别code @@ -924,8 +965,8 @@ namespace DOAN.Service.MES.product { if (currentCell_20.CellType == CellType.Numeric) { - workorder.RouteCode = currentCell_20.NumericCellValue.ToString(); - + workorder.RouteCode = + currentCell_20.NumericCellValue.ToString(); } else { @@ -933,27 +974,24 @@ namespace DOAN.Service.MES.product } } - - //14 优先级 NPOI.SS.UserModel.ICell currentCell_21 = currentRow.GetCell(14); if (currentCell_21.StringCellValue == "紧急") { workorder.Priority = 3; - } else { if (currentCell_21.StringCellValue == "插单") { workorder.Priority = 2; - } - else if (currentCell_21.StringCellValue == "正常" || - string.IsNullOrEmpty(currentCell_11.StringCellValue)) + else if ( + currentCell_21.StringCellValue == "正常" + || string.IsNullOrEmpty(currentCell_11.StringCellValue) + ) { workorder.Priority = 1; - } } @@ -961,7 +999,6 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_22 = currentRow.GetCell(15); workorder.Beat = (int)currentCell_22?.NumericCellValue; - //16进料单号(领料) NPOI.SS.UserModel.ICell currentCell_010 = currentRow.GetCell(16); workorder.FeedOrder = currentCell_010?.StringCellValue; @@ -970,7 +1007,6 @@ namespace DOAN.Service.MES.product NPOI.SS.UserModel.ICell currentCell_011 = currentRow.GetCell(17); workorder.CustomerOrder = currentCell_011?.StringCellValue; - //18备注 NPOI.SS.UserModel.ICell currentCell_012 = currentRow.GetCell(18); workorder.Remark01 = currentCell_012?.StringCellValue; @@ -985,7 +1021,8 @@ namespace DOAN.Service.MES.product workorder.Status = 1; //获取当前日期工单序列号 和序号 DateTime currentDate = dateValue.Date; - var MaxWorkorder = Context.Queryable() + var MaxWorkorder = Context + .Queryable() .Where(it => it.WorkorderDate == currentDate) .OrderByDescending(it => it.Sort) .Select(it => new { it.Workorder, it.Sort }) @@ -993,49 +1030,53 @@ namespace DOAN.Service.MES.product //工单 2024-9-13-组-线-序号 int index = (row - 3); - int flowNum = index + - Convert.ToInt16( - MaxWorkorder.Workorder.Substring(MaxWorkorder.Workorder.Length - 3, 3)); + int flowNum = + index + + Convert.ToInt16( + MaxWorkorder.Workorder.Substring( + MaxWorkorder.Workorder.Length - 3, + 3 + ) + ); //workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.GroupCode + "_" + workorder.RouteCode + "_" + flowNum.ToString("000"); - string nickCode = ProductCodeList.Where(it => it.DictLabel == workorder.productionCode) - .Select(it => it.DictValue).FirstOrDefault(); - workorder.Workorder = dateValue.ToString("yyyyMMdd") + "_" + workorder.GroupCode+ workorder.RouteCode + - "_" + nickCode + "_" + index.ToString("000"); + string nickCode = ProductCodeList + .Where(it => it.DictLabel == workorder.productionCode) + .Select(it => it.DictValue) + .FirstOrDefault(); + workorder.Workorder = + dateValue.ToString("yyyyMMdd") + + "_" + + workorder.GroupCode + + workorder.RouteCode + + "_" + + nickCode + + "_" + + index.ToString("000"); workorder.Sort = index * 10 + Convert.ToInt16(MaxWorkorder.Sort); - CultureInfo culture = CultureInfo.CurrentCulture; workorderList.Add(workorder); - } } - } catch (Exception ex) { return -1; - - } - - - } UseTran2(() => { - // Context.Deleteable().Where(it => it.WorkorderDate == dateValue).ExecuteCommand(); result = Context.Insertable(workorderList).ExecuteCommand(); }); return result; } - /// /// 工单导出 /// @@ -1045,7 +1086,10 @@ namespace DOAN.Service.MES.product public PagedInfo WorkOrderExport(DateTime exportTime, PagerInfo pager) { exportTime = exportTime.Date; - return Context.Queryable().Where(it => it.WorkorderDate == exportTime).ToPage(pager); + return Context + .Queryable() + .Where(it => it.WorkorderDate == exportTime) + .ToPage(pager); } /// @@ -1055,14 +1099,22 @@ namespace DOAN.Service.MES.product /// public List GetMaterialInfo(BaseMaterialListQueryDto5 parm) { - var predicate = Expressionable.Create() - .OrIF(!string.IsNullOrEmpty(parm.Name_or_Code), it => it.Name.Contains(parm.Name_or_Code)) - .OrIF(!string.IsNullOrEmpty(parm.Name_or_Code), it => it.Code.Contains(parm.Name_or_Code)) - ; - - return Context.Queryable() - .Where(predicate.ToExpression()).Take(20).ToList(); + var predicate = Expressionable + .Create() + .OrIF( + !string.IsNullOrEmpty(parm.Name_or_Code), + it => it.Name.Contains(parm.Name_or_Code) + ) + .OrIF( + !string.IsNullOrEmpty(parm.Name_or_Code), + it => it.Code.Contains(parm.Name_or_Code) + ); + return Context + .Queryable() + .Where(predicate.ToExpression()) + .Take(20) + .ToList(); } /// @@ -1084,14 +1136,13 @@ namespace DOAN.Service.MES.product //) .And(it => it.Status == 1); - var response = Context.Queryable() + var response = Context + .Queryable() .Where(predicate.ToExpression()) .OrderBy(it => it.CustomNo) .Take(20) .ToList(); return response; - - } public List GetProcessRoute(DateTime dateTime) @@ -1099,7 +1150,6 @@ namespace DOAN.Service.MES.product throw new NotImplementedException(); } - /*/// /// 获取工艺路线 /// @@ -1124,7 +1174,6 @@ namespace DOAN.Service.MES.product return Context.Queryable().ToList(); } - /// /// 获取班组 /// @@ -1148,7 +1197,6 @@ namespace DOAN.Service.MES.product return Context.Queryable().Where(it => it.Status == 1).ToList(); } - /// /// 查询BOM 及其所需数量 /// @@ -1158,15 +1206,18 @@ namespace DOAN.Service.MES.product { List workOrderBoms = new List(); List baseMaterialBoms = null; - ProWorkorder proworkorder = - Context.Queryable().Where(it => it.Workorder == workorder_num).First(); + ProWorkorder proworkorder = Context + .Queryable() + .Where(it => it.Workorder == workorder_num) + .First(); if (proworkorder != null) { - baseMaterialBoms = Context.Queryable() - .Where(it => it.InvCode == proworkorder.productionCode).ToList(); + baseMaterialBoms = Context + .Queryable() + .Where(it => it.InvCode == proworkorder.productionCode) + .ToList(); - if (baseMaterialBoms != null && baseMaterialBoms - .Count() > 0) + if (baseMaterialBoms != null && baseMaterialBoms.Count() > 0) { foreach (var item in baseMaterialBoms) { @@ -1179,22 +1230,13 @@ namespace DOAN.Service.MES.product objectMaterial.Iusequantity_All = num.ToString(); objectMaterial.BOMVersion = item.BOMVersion; workOrderBoms.Add(objectMaterial); - } - } - - } - - return workOrderBoms; - - } - /// /// 工单日志 /// @@ -1212,9 +1254,7 @@ namespace DOAN.Service.MES.product logObj.ChangeTime = DateTime.Now; logObj.CreatedBy = Operator; - return Context.Insertable(logObj).ExecuteCommand(); - } /// @@ -1222,34 +1262,52 @@ namespace DOAN.Service.MES.product /// /// /// - public PagedInfo GetWorkorderTraceProgressList(ProWorkorderQueryDto query) + public PagedInfo GetWorkorderTraceProgressList( + ProWorkorderQueryDto query + ) { + var predicate = Expressionable + .Create() + .AndIF( + !string.IsNullOrEmpty(query.productionName), + it => it.productionName.Contains(query.productionName) + ) + .AndIF( + !string.IsNullOrEmpty(query.productionCode), + it => it.productionCode.Contains(query.productionCode) + ) + .AndIF( + !string.IsNullOrEmpty(query.RouteCode), + it => it.RouteCode == query.RouteCode + ) + .AndIF( + !string.IsNullOrEmpty(query.GroupCode), + it => it.GroupCode == query.GroupCode + ) + .AndIF( + query.WorkorderDate != null && query.WorkorderDate[0] > DateTime.MinValue, + it => it.WorkorderDate >= query.WorkorderDate[0] + ) + .AndIF( + query.WorkorderDate != null && query.WorkorderDate[1] > DateTime.MinValue, + it => it.WorkorderDate <= query.WorkorderDate[1] + ) + .AndIF(query.Status > -1, it => it.Status == query.Status); + var query2 = Queryable().Where(predicate.ToExpression()); - var predicate = Expressionable.Create() - .AndIF(!string.IsNullOrEmpty(query.productionName), - it => it.productionName.Contains(query.productionName)) - .AndIF(!string.IsNullOrEmpty(query.productionCode), - it => it.productionCode.Contains(query.productionCode)) - .AndIF(!string.IsNullOrEmpty(query.RouteCode), it => it.RouteCode == query.RouteCode) - .AndIF(!string.IsNullOrEmpty(query.GroupCode), it => it.GroupCode == query.GroupCode) - .AndIF(query.WorkorderDate != null && query.WorkorderDate[0] > DateTime.MinValue, - it => it.WorkorderDate >= query.WorkorderDate[0]) - .AndIF(query.WorkorderDate != null && query.WorkorderDate[1] > DateTime.MinValue, - it => it.WorkorderDate <= query.WorkorderDate[1]) - .AndIF(query.Status > -1, it => it.Status == query.Status) - - ; - var query2 = Queryable() - .Where(predicate.ToExpression()); - - return Context.Queryable(query2).LeftJoin((q, r) => q.Workorder == r.FkWorkorder) - .Select((q, r) => new ProWorkorderTranceProgressDto() - { - PlanNum = q.PlanNum, - ActualNum = r.FinishedNum, - }, true).ToPage_NO_Convert(query); - - + return Context + .Queryable(query2) + .LeftJoin((q, r) => q.Workorder == r.FkWorkorder) + .Select( + (q, r) => + new ProWorkorderTranceProgressDto() + { + PlanNum = q.PlanNum, + ActualNum = r.FinishedNum, + }, + true + ) + .ToPage_NO_Convert(query); } public int Insert_workOrder2(ProWorkorder proWorkorder, string next_id) @@ -1261,28 +1319,31 @@ namespace DOAN.Service.MES.product { UseTran2(() => { - - int sortNum = Context.Queryable().Where(it => it.Id == next_id) - .Select(it => it.Sort.Value).First(); - Context.Updateable() + int sortNum = Context + .Queryable() + .Where(it => it.Id == next_id) + .Select(it => it.Sort.Value) + .First(); + Context + .Updateable() .Where(it => it.WorkorderDate == proWorkorder.WorkorderDate) .Where(it => it.Sort >= sortNum) .SetColumns(it => new ProWorkorder() { Sort = it.Sort + 10 }) .ExecuteCommand(); - proWorkorder.Sort = sortNum; proWorkorder.Status = 1; Context.Insertable(proWorkorder).ExecuteCommand(); - }); } else { DateTime dateOnly = proWorkorder.WorkorderDate.Value.Date; - int sortNum = Context.Queryable().Where(it => it.WorkorderDate == dateOnly) + int sortNum = Context + .Queryable() + .Where(it => it.WorkorderDate == dateOnly) .Max(it => it.Sort.Value); proWorkorder.Sort = sortNum + 10; @@ -1292,18 +1353,13 @@ namespace DOAN.Service.MES.product Context.Insertable(proWorkorder).ExecuteCommand(); } - - - Generate_workorder(new ProWorkorderQueryDto2() - { - WorkorderDate = proWorkorder.WorkorderDate.Value - }); + Generate_workorder( + new ProWorkorderQueryDto2() { WorkorderDate = proWorkorder.WorkorderDate.Value } + ); return result; - } - /// /// https://www.questpdf.com/ /// 要打印的工单号 @@ -1311,14 +1367,15 @@ namespace DOAN.Service.MES.product /// public async Task<(string, Stream)> ExportPDFByQuestPDFDemo(string[] workorderArray) { - - var dataList = Context.Queryable().Where(it => workorderArray.Contains(it.Workorder)) + var dataList = Context + .Queryable() + .Where(it => workorderArray.Contains(it.Workorder)) .ToList(); if (dataList.Count() == 0) { return (null, null); } - + var ms = new MemoryStream(); Settings.License = LicenseType.Community; Settings.CheckIfAllTextGlyphsAreAvailable = false; @@ -1330,7 +1387,11 @@ namespace DOAN.Service.MES.product int PageHeight = 30 * 10; for (int i = 0; i < dataList.Count(); i++) { - byte[] imageBytes = PrintHelper.CreateQcCode(dataList[i].Workorder, PageHeight * 40 + 100, PageHeight * 20); + byte[] imageBytes = PrintHelper.CreateQcCode( + dataList[i].Workorder, + PageHeight * 40 + 100, + PageHeight * 20 + ); container.Page(page => { // 设置页面大小为A4,默认有页边距 @@ -1339,77 +1400,131 @@ namespace DOAN.Service.MES.product page.Size(PageWidth, PageHeight); page.DefaultTextStyle(TextStyle.Default.FontSize(10 * 2 + 2)); //page.DefaultTextStyle(TextStyle.Default.FontSize(1)); - page.Content().Column(column => - { - column.Item().Table(table => + page.Content() + .Column(column => { - // 动态计算列宽,减去必要的边距 - float columnWidth = (PageWidth) / 8; + column + .Item() + .Table(table => + { + // 动态计算列宽,减去必要的边距 + float columnWidth = (PageWidth) / 8; - table.ColumnsDefinition(columns => - { - for (int j = 0; j < 8; j++) - columns.ConstantColumn(columnWidth); - }); + table.ColumnsDefinition(columns => + { + for (int j = 0; j < 8; j++) + columns.ConstantColumn(columnWidth); + }); - // 创建一个单元格跨越所有列,用于放置图片 - table.Cell().ColumnSpan(8).Height(PageHeight / 14 * 8).Image(imageBytes); + // 创建一个单元格跨越所有列,用于放置图片 + table + .Cell() + .ColumnSpan(8) + .Height(PageHeight / 14 * 8) + .Image(imageBytes); + // 剩余内容... + // 注意:确保剩余内容的高度不超过剩余的页面空间 + // 这里只是一个简单的例子,实际应用中你可能需要更复杂的逻辑来计算剩余可用空间 - // 剩余内容... - // 注意:确保剩余内容的高度不超过剩余的页面空间 - // 这里只是一个简单的例子,实际应用中你可能需要更复杂的逻辑来计算剩余可用空间 - - table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight / 7).AlignLeft().Padding(1).Text("编号"); - table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text(dataList[i].Workorder); - table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text("炉号"); - table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text(dataList[i].StoveCode); - table.Cell().ColumnSpan(2).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text("数量"); - table.Cell().ColumnSpan(6).Border(1).MinHeight(PageHeight / 14).AlignLeft().Padding(1).Text(dataList[i].PlanNum); - for (int j = 0; j < 8; j++) - { - table.Cell().Border(1).MinHeight(PageHeight / 14).AlignCenter().Text($"[{j + 1}]"); - } - + table + .Cell() + .ColumnSpan(2) + .Border(1) + .MinHeight(PageHeight / 7) + .AlignLeft() + .Padding(1) + .Text("编号"); + table + .Cell() + .ColumnSpan(6) + .Border(1) + .MinHeight(PageHeight / 14) + .AlignLeft() + .Padding(1) + .Text(dataList[i].Workorder); + table + .Cell() + .ColumnSpan(2) + .Border(1) + .MinHeight(PageHeight / 14) + .AlignLeft() + .Padding(1) + .Text("炉号"); + table + .Cell() + .ColumnSpan(6) + .Border(1) + .MinHeight(PageHeight / 14) + .AlignLeft() + .Padding(1) + .Text(dataList[i].StoveCode); + table + .Cell() + .ColumnSpan(2) + .Border(1) + .MinHeight(PageHeight / 14) + .AlignLeft() + .Padding(1) + .Text("数量"); + table + .Cell() + .ColumnSpan(6) + .Border(1) + .MinHeight(PageHeight / 14) + .AlignLeft() + .Padding(1) + .Text(dataList[i].PlanNum); + for (int j = 0; j < 8; j++) + { + table + .Cell() + .Border(1) + .MinHeight(PageHeight / 14) + .AlignCenter() + .Text($"[{j + 1}]"); + } + }); }); - }); }); } }); document.GeneratePdf(ms); ms.Seek(0, SeekOrigin.Begin); - }); var fileName = $"工单({DateTime.Now.ToString("yyyyMMdd")}).pdf"; return new(fileName, ms); } - + /// /// 根据模板打印工单信息 /// - /// - /// 模板路径 + /// 工单号列表与打印路径 /// - public async Task PrintTicketsByTemplate(string[] workorderArray,string path) + public async Task PrintTicketsByTemplate( + ProWorkorderExportDto param + ) { - var dataList = await Context.Queryable().Where(p => workorderArray.Contains(p.Workorder)).ToListAsync(); - if (!dataList.Any()) + var dataList = await Context + .Queryable() + .Where(p => param.WorkorderArray.Contains(p.Workorder)) + .ToListAsync(); + if (dataList.Count == 0) { - return new CustomException(204, "未找到匹配的工单数据"); - + return new CustomException(500, "未找到匹配的工单数据"); } Application bartenderApp = null; Format bartenderFormat = null; try { bartenderApp = new Application { Visible = false }; - bartenderFormat = bartenderApp.Formats.Open(path); + bartenderFormat = bartenderApp.Formats.Open(param.Path); // 4. 遍历数据并打印 foreach (var data in dataList) { - bartenderFormat.SetNamedSubStringValue("Workorder", data.Workorder); - bartenderFormat.SetNamedSubStringValue("StoveCode", data.StoveCode); - bartenderFormat.SetNamedSubStringValue("PlanNum", data.PlanNum.ToString()); + bartenderFormat.SetNamedSubStringValue("workorder", data.Workorder); + bartenderFormat.SetNamedSubStringValue("stoveCode", data.StoveCode); + bartenderFormat.SetNamedSubStringValue("qty", data.PlanNum.ToString()); await Task.Delay(500); bartenderFormat.PrintOut(false, false); // 静默打印 } @@ -1420,7 +1535,7 @@ namespace DOAN.Service.MES.product { // 5. 错误处理(记录日志) Console.WriteLine($"打印标签时出错: {ex.Message}"); - return new CustomException(200, $"打印标签失败: {ex.Message}"); + return new CustomException(500, $"打印标签失败: {ex.Message}"); } finally { @@ -1436,4 +1551,4 @@ namespace DOAN.Service.MES.product } } } -} \ No newline at end of file +}