导入导出
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user