diff --git a/DOAN.Service/MES/Material/MmMaterialService.cs b/DOAN.Service/MES/Material/MmMaterialService.cs
index d25f3d8..70a9954 100644
--- a/DOAN.Service/MES/Material/MmMaterialService.cs
+++ b/DOAN.Service/MES/Material/MmMaterialService.cs
@@ -145,7 +145,7 @@ namespace DOAN.Service.BZFM
///
public ImportResultDto Importmaterial(IFormFile formFile, string username)
{
-
+ string message = "导入成功";
// TODO 1.构建空的待导入数据集合MmMaterialExcelDto,多余部分删除
List materialList = new();
// TODO 2.使用NPOI读取Excel内容,填充到MmMaterialExcelDto集合中,注意列的对应关系,id不要忘,且跳过标题行,目前需要从第2行开始读取注意修改row
@@ -172,84 +172,67 @@ namespace DOAN.Service.BZFM
//01 物料标号
NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(1);
- material.Type = currentCell_01?.ToString();
- if (currentCell_01 == null || string.IsNullOrEmpty(material.Type))
- {
- continue;
- }
+ material.Type = currentCell_01?.ToString() ?? string.Empty;
//02物料编码
NPOI.SS.UserModel.ICell currentCell_02 = currentRow.GetCell(2);
-
material.MaterialCode = currentCell_02?.ToString();
if (
currentCell_02 == null
|| string.IsNullOrEmpty(material.MaterialCode)
)
{
- continue;
+ message = $"物料编码不可为空,第{row + 1}行";
+ break;
}
//03物料名称
NPOI.SS.UserModel.ICell currentCell_03 = currentRow.GetCell(3);
-
- material.MaterialName = currentCell_03?.ToString();
- if (
- currentCell_03 == null
- || string.IsNullOrEmpty(material.MaterialName)
- )
- {
- continue;
- }
+ material.MaterialName = currentCell_03?.ToString() ?? string.Empty;
//04规格
NPOI.SS.UserModel.ICell currentCell_04 = currentRow.GetCell(4);
-
- material.Specification = currentCell_04?.ToString();
+ material.Specification = currentCell_04?.ToString() ?? string.Empty;
//05 类型编码
NPOI.SS.UserModel.ICell currentCell_05 = currentRow.GetCell(5);
-
material.CategoryCode = currentCell_05?.ToString();
if (
currentCell_05 == null
|| string.IsNullOrEmpty(material.CategoryCode)
)
{
- continue;
+ message = $"类型编码不可为空,第{row + 1}行";
+ break;
}
//06 类型名称
NPOI.SS.UserModel.ICell currentCell_06 = currentRow.GetCell(6);
-
- material.CategoryName = currentCell_06?.ToString();
- if (
- currentCell_06 == null
- || string.IsNullOrEmpty(material.CategoryName)
- )
- {
- continue;
- }
-
+ material.CategoryName = currentCell_06?.ToString() ?? string.Empty;
//07 单位
NPOI.SS.UserModel.ICell currentCell_07 = currentRow.GetCell(7);
-
- material.Unit = currentCell_07?.ToString();
-
+ material.Unit = currentCell_07?.ToString() ?? string.Empty;
//08 供应商编码
NPOI.SS.UserModel.ICell currentCell_08 = currentRow.GetCell(8);
-
- material.SupplierCode = currentCell_08?.ToString();
+ material.SupplierCode = currentCell_08?.ToString() ?? string.Empty;
//09 供应商名称
NPOI.SS.UserModel.ICell currentCell_09 = currentRow.GetCell(9);
-
- material.SupplierName = currentCell_09?.ToString();
-
- //10 状态
+ material.SupplierName = currentCell_09?.ToString() ?? string.Empty;
+ //10 安全库存
NPOI.SS.UserModel.ICell currentCell_10 = currentRow.GetCell(10);
-
- material.Status = currentCell_10?.ToString();
-
+ material.SafetyStock = (int)currentCell_10?.NumericCellValue;
+ //11 状态
+ NPOI.SS.UserModel.ICell currentCell_11 = currentRow.GetCell(11);
+ material.Status = currentCell_11?.ToString() ?? "启用";
+ //12 创建时间
+ NPOI.SS.UserModel.ICell currentCell_12 = currentRow.GetCell(12);
+ material.CreatedTime = currentCell_12?.DateCellValue ?? DateTime.Now;
+ //13 更新时间
+ NPOI.SS.UserModel.ICell currentCell_13 = currentRow.GetCell(13);
+ material.UpdatedTime = currentCell_13?.DateCellValue ?? DateTime.Now;
+ //14 描述
+ NPOI.SS.UserModel.ICell currentCell_14 = currentRow.GetCell(14);
+ material.Description = currentCell_14?.ToString() ?? "Excel导入";
materialList.Add(material);
}
}
@@ -267,14 +250,15 @@ namespace DOAN.Service.BZFM
var x = Context
.Storageable(materialList)
- .SplitInsert(it => !it.Any())
- .WhereColumns(it => it.Id) //如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
+ //.SplitInsert(it => !it.Any())
+ //.WhereColumns(it => it.Id) //如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
.ToStorage();
- var result = x.AsUpdateable.ExecuteCommand(); //插入可插入部分;
+ var result = x.AsInsertable.ExecuteCommand();
+ var result2 = x.AsUpdateable.IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); //插入可插入部分;
var importResult = new ImportResultDto
{
- Message = "导入完成",
+ Message = message,
Inserted = x.InsertList.Count,
Updated = x.UpdateList.Count,
ErrorCount = x.ErrorList.Count,