导入导出

This commit is contained in:
2026-01-08 11:45:06 +08:00
parent 289ef83937
commit 912ddae8c5
5 changed files with 85 additions and 14 deletions

View File

@@ -147,14 +147,7 @@ namespace DOAN.Service.BZFM
{
// TODO 1.构建空的待导入数据集合MmMaterialExcelDto多余部分删除
int result = 0;
List<ProWorkorder> materialList = new();
DateTime dateValue = DateTime.MinValue;
// 获取 产品代号
List<MmMaterialExcelDto> ProductCodeList = Context
.Queryable<MmMaterialExcelDto>()
.Where(it => it.Type == "type")
.ToList();
List<MmMaterialExcelDto> materialList = new();
// TODO 2.使用NPOI读取Excel内容填充到MmMaterialExcelDto集合中注意列的对应关系id不要忘且跳过标题行目前需要从第2行开始读取注意修改row
using (var stream = formFile.OpenReadStream())
{
@@ -167,8 +160,6 @@ namespace DOAN.Service.BZFM
IRow secondRow = sheet.GetRow(1);
NPOI.SS.UserModel.ICell cell = secondRow.GetCell(0);
// 将单元格的数字值转换为DateTime
dateValue = cell.DateCellValue.Value;
#region excel
// 遍历每一行
@@ -179,6 +170,10 @@ namespace DOAN.Service.BZFM
{
MmMaterial material = new MmMaterial();
//00 ID
NPOI.SS.UserModel.ICell currentCell_00 = currentRow.GetCell(0);
material.Id = (int)currentCell_00?.NumericCellValue;
//01 物料标号
NPOI.SS.UserModel.ICell currentCell_01 = currentRow.GetCell(1);
material.Type = currentCell_01?.ToString();
@@ -295,7 +290,7 @@ namespace DOAN.Service.BZFM
}
catch (Exception ex)
{
//return -1;
return -1;
}
@@ -303,7 +298,7 @@ namespace DOAN.Service.BZFM
// TODO 3.调用SplitInsert方法实现导入操作,注意主键列的配置(建议优化为ID相同则修改不同则新增)
var x = Context
.Storageable(material)
.Storageable(materialList)
.SplitInsert(it => !it.Any())
.WhereColumns(it => new { it.Id, it.MaterialCode }) //如果不是主键可以这样实现多字段it=>new{it.x1,it.x2}
.ToStorage();