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

@@ -217,13 +217,21 @@ namespace DOAN.Admin.WebApi.Controllers
[AllowAnonymous] [AllowAnonymous]
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile) public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
{ {
if (formFile == null) try
{ {
return SUCCESS(null); if (formFile == null)
} {
int response = _ProWorkorderService.ImportData(formFile, HttpContext.GetName()); 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 分批导入工单,追加工单 //TODO 分批导入工单,追加工单
@@ -237,13 +245,21 @@ namespace DOAN.Admin.WebApi.Controllers
[AllowAnonymous] [AllowAnonymous]
public IActionResult ImportDataAppend([FromForm(Name = "file")] IFormFile formFile) public IActionResult ImportDataAppend([FromForm(Name = "file")] IFormFile formFile)
{ {
if (formFile == null) try
{ {
return SUCCESS(null); if (formFile == null)
} {
int response = _ProWorkorderService.ImportDataAppend(formFile, HttpContext.GetName()); 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);
} }
/// <summary> /// <summary>

View File

@@ -58,8 +58,9 @@ namespace DOAN.Model.MES.product.Dto
public string Unit { get; set; } public string Unit { get; set; }
public int? PlanNum { get; set; } public int? PlanNum { get; set; } = 0;
public int? ShipmentNum { get; set; } public int? ShipmentNum { get; set; } = 0;
public int? DefectNum { get; set; } = 0;
public int? Sort { get; set; } public int? Sort { get; set; }
public DateTime? WorkorderDate { get; set; } public DateTime? WorkorderDate { get; set; }

View File

@@ -48,6 +48,12 @@ namespace DOAN.Model.MES.product
[SugarColumn(ColumnName = "shipment_num")] [SugarColumn(ColumnName = "shipment_num")]
public int? ShipmentNum { get; set; } public int? ShipmentNum { get; set; }
/// <summary>
/// 缺陷数量
/// </summary>
[SugarColumn(ColumnName = "defect_num")]
public int? DefectNum { get; set; }
/// <summary> /// <summary>
/// 序号 /// 序号
/// </summary> /// </summary>

View File

@@ -62,12 +62,12 @@ namespace DOAN.Service.MES.product
{ {
ProWorkorder workorder = new ProWorkorder(); ProWorkorder workorder = new ProWorkorder();
//00 品名 //00 主体品名
ICell currentCell_01 = currentRow.GetCell(0); ICell currentCell_01 = currentRow.GetCell(0);
workorder.productionName = currentCell_01?.ToString(); workorder.productionName = currentCell_01?.ToString();
if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName)) if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName))
{ {
continue; throw new Exception($"{row + 1}行【主体品名】不可为空");
} }
//01 成品型号 //01 成品型号
@@ -75,7 +75,7 @@ namespace DOAN.Service.MES.product
workorder.productionCode = currentCell_02?.ToString(); workorder.productionCode = currentCell_02?.ToString();
if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode)) if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode))
{ {
continue; throw new Exception($"{row + 1}行【主体型号】不可为空");
} }
//02 单位 //02 单位
@@ -85,13 +85,17 @@ namespace DOAN.Service.MES.product
//3 计划数量 //3 计划数量
ICell currentCell_07 = currentRow.GetCell(3); ICell currentCell_07 = currentRow.GetCell(3);
workorder.PlanNum = (int)currentCell_07?.NumericCellValue; workorder.PlanNum = (int)currentCell_07?.NumericCellValue;
if (currentCell_07 == null || workorder.PlanNum < 0)
{
workorder.PlanNum = 0;
}
//4 原材料名称 //4 原材料名称
ICell currentCell_11 = currentRow.GetCell(4); ICell currentCell_11 = currentRow.GetCell(4);
workorder.MaterialName = currentCell_11?.ToString(); workorder.MaterialName = currentCell_11?.ToString();
if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName)) if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName))
{ {
continue; throw new Exception($"{row + 1}行【材料型号】不可为空");
} }
//5 原材料编号 //5 原材料编号
@@ -99,7 +103,7 @@ namespace DOAN.Service.MES.product
workorder.MaterialCode = currentCell_12?.ToString(); workorder.MaterialCode = currentCell_12?.ToString();
if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode)) if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode))
{ {
continue; throw new Exception($"{row + 1}行【材料编码】不可为空");
} }
//6 原材料材质 //6 原材料材质
@@ -109,18 +113,10 @@ namespace DOAN.Service.MES.product
//7 炉号 //7 炉号
ICell currentCell_14 = currentRow.GetCell(7); ICell currentCell_14 = currentRow.GetCell(7);
workorder.StoveCode = currentCell_14?.ToString(); workorder.StoveCode = currentCell_14?.ToString();
if (currentCell_14 == null || string.IsNullOrEmpty(workorder.StoveCode))
{
continue;
}
//8 图号 //8 图号
ICell currentCell_15 = currentRow.GetCell(8); ICell currentCell_15 = currentRow.GetCell(8);
workorder.DrawingCode = currentCell_15?.ToString(); workorder.DrawingCode = currentCell_15?.ToString();
if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode))
{
continue;
}
//9 版本 //9 版本
ICell currentCell_16 = currentRow.GetCell(9); ICell currentCell_16 = currentRow.GetCell(9);
@@ -301,7 +297,7 @@ namespace DOAN.Service.MES.product
workorder.productionName = currentCell_01?.ToString(); workorder.productionName = currentCell_01?.ToString();
if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName)) if (currentCell_01 == null || string.IsNullOrEmpty(workorder.productionName))
{ {
continue; throw new Exception($"{row + 1}行【主体品名】不可为空");
} }
//01 成品型号 //01 成品型号
@@ -309,7 +305,7 @@ namespace DOAN.Service.MES.product
workorder.productionCode = currentCell_02?.ToString(); workorder.productionCode = currentCell_02?.ToString();
if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode)) if (currentCell_02 == null || string.IsNullOrEmpty(workorder.productionCode))
{ {
continue; throw new Exception($"{row + 1}行【主体型号】不可为空");
} }
//02 单位 //02 单位
@@ -319,13 +315,17 @@ namespace DOAN.Service.MES.product
//3 计划数量 //3 计划数量
ICell currentCell_07 = currentRow.GetCell(3); ICell currentCell_07 = currentRow.GetCell(3);
workorder.PlanNum = (int)currentCell_07?.NumericCellValue; workorder.PlanNum = (int)currentCell_07?.NumericCellValue;
if (currentCell_07 == null || workorder.PlanNum < 0)
{
workorder.PlanNum = 0;
}
//4 原材料名称 //4 原材料名称
ICell currentCell_11 = currentRow.GetCell(4); ICell currentCell_11 = currentRow.GetCell(4);
workorder.MaterialName = currentCell_11?.ToString(); workorder.MaterialName = currentCell_11?.ToString();
if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName)) if (currentCell_11 == null || string.IsNullOrEmpty(workorder.MaterialName))
{ {
continue; throw new Exception($"{row + 1}行【材料型号】不可为空");
} }
//5 原材料编号 //5 原材料编号
@@ -333,32 +333,20 @@ namespace DOAN.Service.MES.product
workorder.MaterialCode = currentCell_12?.ToString(); workorder.MaterialCode = currentCell_12?.ToString();
if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode)) if (currentCell_12 == null || string.IsNullOrEmpty(workorder.MaterialCode))
{ {
continue; throw new Exception($"{row + 1}行【材料编码】不可为空");
} }
//6 材质 //6 材质
ICell currentCell_13 = currentRow.GetCell(6); ICell currentCell_13 = currentRow.GetCell(6);
workorder.MaterialtextureCode = currentCell_13?.ToString(); workorder.MaterialtextureCode = currentCell_13?.ToString();
if (currentCell_13 == null || string.IsNullOrEmpty(workorder.MaterialtextureCode))
{
continue;
}
//7 炉号 //7 炉号
ICell currentCell_14 = currentRow.GetCell(7); ICell currentCell_14 = currentRow.GetCell(7);
workorder.StoveCode = currentCell_14?.ToString(); workorder.StoveCode = currentCell_14?.ToString();
if (currentCell_14 == null || string.IsNullOrEmpty(workorder.StoveCode))
{
continue;
}
//8 图号 //8 图号
ICell currentCell_15 = currentRow.GetCell(8); ICell currentCell_15 = currentRow.GetCell(8);
workorder.DrawingCode = currentCell_15?.ToString(); workorder.DrawingCode = currentCell_15?.ToString();
if (currentCell_15 == null || string.IsNullOrEmpty(workorder.DrawingCode))
{
continue;
}
//9 版本 //9 版本
ICell currentCell_16 = currentRow.GetCell(9); ICell currentCell_16 = currentRow.GetCell(9);
@@ -368,6 +356,10 @@ namespace DOAN.Service.MES.product
ICell cell17 = currentRow.GetCell(10); ICell cell17 = currentRow.GetCell(10);
// 将单元格的数字值转换为DateTime // 将单元格的数字值转换为DateTime
workorder.InstructionDate = cell17.DateCellValue.Value; workorder.InstructionDate = cell17.DateCellValue.Value;
if(cell17 == null)
{
workorder.InstructionDate = dateValue;
}
// 11 车间code // 11 车间code
ICell currentCell_18 = currentRow.GetCell(11); ICell currentCell_18 = currentRow.GetCell(11);
@@ -491,7 +483,7 @@ namespace DOAN.Service.MES.product
} }
catch (Exception ex) catch (Exception ex)
{ {
return -1; throw new Exception(ex.Message);
} }
} }
@@ -501,6 +493,7 @@ namespace DOAN.Service.MES.product
result = Context.Insertable(workorderList).ExecuteCommand(); result = Context.Insertable(workorderList).ExecuteCommand();
}); });
return result; return result;
} }
} }