feat(工单): 添加工单缺陷数量字段并优化导入逻辑

为工单模型添加缺陷数量字段,优化Excel导入逻辑
增加必填字段校验和异常处理,完善默认值设置
This commit is contained in:
2026-02-09 16:23:13 +08:00
parent bfc0f27b18
commit 898ee3de2a
5 changed files with 58 additions and 42 deletions

View File

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