diff --git a/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs b/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs index d5baad4..a947d04 100644 --- a/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs +++ b/DOAN.Admin.WebApi/Controllers/MES/Product/ProWorkorderController.cs @@ -217,13 +217,21 @@ namespace DOAN.Admin.WebApi.Controllers [AllowAnonymous] public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile) { - if (formFile == null) + try { - return SUCCESS(null); - } - int response = _ProWorkorderService.ImportData(formFile, HttpContext.GetName()); + if (formFile == null) + { + return SUCCESS(null); + } + int response = _ProWorkorderService.ImportData(formFile, HttpContext.GetName()); + + return SUCCESS(response); + } + catch (Exception ex) + { + return ToResponse(new ApiResult(500, ex.Message)); + } - return SUCCESS(response); } //TODO 分批导入工单,追加工单 @@ -237,13 +245,21 @@ namespace DOAN.Admin.WebApi.Controllers [AllowAnonymous] public IActionResult ImportDataAppend([FromForm(Name = "file")] IFormFile formFile) { - if (formFile == null) + try { - return SUCCESS(null); - } - int response = _ProWorkorderService.ImportDataAppend(formFile, HttpContext.GetName()); + if (formFile == null) + { + return SUCCESS(null); + } + int response = _ProWorkorderService.ImportDataAppend(formFile, HttpContext.GetName()); + + return SUCCESS(response); + } + catch (Exception ex) + { + return ToResponse(new ApiResult(500, ex.Message)); + } - return SUCCESS(response); } /// diff --git a/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx b/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx index be2589c..09bc5d1 100644 Binary files a/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx and b/DOAN.Admin.WebApi/wwwroot/ImportTemplate/workorder.xlsx differ diff --git a/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs b/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs index a59283b..c68cab3 100644 --- a/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs +++ b/DOAN.Model/MES/Product/Dto/ProWorkorderDto.cs @@ -58,8 +58,9 @@ namespace DOAN.Model.MES.product.Dto public string Unit { get; set; } - public int? PlanNum { get; set; } - public int? ShipmentNum { get; set; } + public int? PlanNum { get; set; } = 0; + public int? ShipmentNum { get; set; } = 0; + public int? DefectNum { get; set; } = 0; public int? Sort { get; set; } public DateTime? WorkorderDate { get; set; } diff --git a/DOAN.Model/MES/Product/ProWorkorder.cs b/DOAN.Model/MES/Product/ProWorkorder.cs index 7d46a6e..4ae36e5 100644 --- a/DOAN.Model/MES/Product/ProWorkorder.cs +++ b/DOAN.Model/MES/Product/ProWorkorder.cs @@ -48,6 +48,12 @@ namespace DOAN.Model.MES.product [SugarColumn(ColumnName = "shipment_num")] public int? ShipmentNum { get; set; } + /// + /// 缺陷数量 + /// + [SugarColumn(ColumnName = "defect_num")] + public int? DefectNum { get; set; } + /// /// 序号 /// diff --git a/DOAN.Service/MES/Product/ProWorkorderImportService.cs b/DOAN.Service/MES/Product/ProWorkorderImportService.cs index 0820365..d35afcf 100644 --- a/DOAN.Service/MES/Product/ProWorkorderImportService.cs +++ b/DOAN.Service/MES/Product/ProWorkorderImportService.cs @@ -62,12 +62,12 @@ namespace DOAN.Service.MES.product { ProWorkorder workorder = new ProWorkorder(); - //00 成品名称 + //00 主体品名 ICell currentCell_01 = currentRow.GetCell(0); workorder.productionName = currentCell_01?.ToString(); if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName)) { - continue; + throw new Exception($"{row + 1}行【主体品名】不可为空"); } //01 成品型号 @@ -75,7 +75,7 @@ namespace DOAN.Service.MES.product workorder.productionCode = currentCell_02?.ToString(); if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode)) { - continue; + throw new Exception($"{row + 1}行【主体型号】不可为空"); } //02 单位 @@ -85,13 +85,17 @@ namespace DOAN.Service.MES.product //3 计划数量 ICell currentCell_07 = currentRow.GetCell(3); workorder.PlanNum = (int)currentCell_07?.NumericCellValue; + if (currentCell_07 == null || workorder.PlanNum < 0) + { + workorder.PlanNum = 0; + } //4 原材料名称 ICell currentCell_11 = currentRow.GetCell(4); workorder.MaterialName = currentCell_11?.ToString(); if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName)) { - continue; + throw new Exception($"{row + 1}行【材料型号】不可为空"); } //5 原材料编号 @@ -99,7 +103,7 @@ namespace DOAN.Service.MES.product workorder.MaterialCode = currentCell_12?.ToString(); if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode)) { - continue; + throw new Exception($"{row + 1}行【材料编码】不可为空"); } //6 原材料材质 @@ -109,18 +113,10 @@ namespace DOAN.Service.MES.product //7 炉号 ICell currentCell_14 = currentRow.GetCell(7); workorder.StoveCode = currentCell_14?.ToString(); - if (currentCell_14 == null || string.IsNullOrEmpty(workorder.StoveCode)) - { - continue; - } //8 图号 ICell currentCell_15 = currentRow.GetCell(8); workorder.DrawingCode = currentCell_15?.ToString(); - if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode)) - { - continue; - } //9 版本 ICell currentCell_16 = currentRow.GetCell(9); @@ -301,7 +297,7 @@ namespace DOAN.Service.MES.product workorder.productionName = currentCell_01?.ToString(); if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName)) { - continue; + throw new Exception($"{row + 1}行【主体品名】不可为空"); } //01 成品型号 @@ -309,7 +305,7 @@ namespace DOAN.Service.MES.product workorder.productionCode = currentCell_02?.ToString(); if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode)) { - continue; + throw new Exception($"{row + 1}行【主体型号】不可为空"); } //02 单位 @@ -319,13 +315,17 @@ namespace DOAN.Service.MES.product //3 计划数量 ICell currentCell_07 = currentRow.GetCell(3); workorder.PlanNum = (int)currentCell_07?.NumericCellValue; + if (currentCell_07 == null || workorder.PlanNum < 0) + { + workorder.PlanNum = 0; + } //4 原材料名称 ICell currentCell_11 = currentRow.GetCell(4); workorder.MaterialName = currentCell_11?.ToString(); if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName)) { - continue; + throw new Exception($"{row + 1}行【材料型号】不可为空"); } //5 原材料编号 @@ -333,32 +333,20 @@ namespace DOAN.Service.MES.product workorder.MaterialCode = currentCell_12?.ToString(); if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode)) { - continue; + throw new Exception($"{row + 1}行【材料编码】不可为空"); } //6 材质 ICell currentCell_13 = currentRow.GetCell(6); workorder.MaterialtextureCode = currentCell_13?.ToString(); - if (currentCell_13 == null || string.IsNullOrEmpty(workorder.MaterialtextureCode)) - { - continue; - } //7 炉号 ICell currentCell_14 = currentRow.GetCell(7); workorder.StoveCode = currentCell_14?.ToString(); - if (currentCell_14 == null || string.IsNullOrEmpty(workorder.StoveCode)) - { - continue; - } //8 图号 ICell currentCell_15 = currentRow.GetCell(8); workorder.DrawingCode = currentCell_15?.ToString(); - if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode)) - { - continue; - } //9 版本 ICell currentCell_16 = currentRow.GetCell(9); @@ -368,6 +356,10 @@ namespace DOAN.Service.MES.product ICell cell17 = currentRow.GetCell(10); // 将单元格的数字值转换为DateTime workorder.InstructionDate = cell17.DateCellValue.Value; + if(cell17 == null) + { + workorder.InstructionDate = dateValue; + } // 11 车间code ICell currentCell_18 = currentRow.GetCell(11); @@ -491,7 +483,7 @@ namespace DOAN.Service.MES.product } catch (Exception ex) { - return -1; + throw new Exception(ex.Message); } } @@ -501,6 +493,7 @@ namespace DOAN.Service.MES.product result = Context.Insertable(workorderList).ExecuteCommand(); }); + return result; } }