导入导出

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

35
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,35 @@
{
"version": "0.2.0",
"configurations": [
{
// 使用 IntelliSense 找出 C# 调试存在哪些属性
// 将悬停用于现有属性的说明
// 有关详细信息,请访问 https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md。
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// 如果已更改目标框架,请确保更新程序路径。
"program": "${workspaceFolder}/DOAN.Admin.WebApi/bin/Debug/net8.0/DOAN.Admin.WebApi.dll",
"args": [],
"cwd": "${workspaceFolder}/DOAN.Admin.WebApi",
"stopAtEntry": false,
// 启用在启动 ASP.NET Core 时启动 Web 浏览器。有关详细信息: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

41
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/DOAN.Admin.WebApi/DOAN.Admin.WebApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/DOAN.Admin.WebApi/DOAN.Admin.WebApi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/DOAN.Admin.WebApi/DOAN.Admin.WebApi.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@@ -138,7 +138,7 @@ namespace DOAN.Admin.WebApi.Controllers.BZFM
{ {
return SUCCESS(null); return SUCCESS(null);
} }
int response = _MmMaterialService.Importmaterial(formFile, HttpContext.GetName()); ImportResultDto response = _MmMaterialService.Importmaterial(formFile, HttpContext.GetName());
return SUCCESS(response); return SUCCESS(response);
} }

View File

@@ -28,7 +28,7 @@ namespace DOAN.Service.BZFM.IBZFMService
/// </summary> /// </summary>
/// <param name="material"></param> /// <param name="material"></param>
/// <returns></returns> /// <returns></returns>
int Importmaterial(IFormFile formFile, string username); ImportResultDto Importmaterial(IFormFile formFile, string username);
public PagedInfo<MmMaterialExcelDto> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager); public PagedInfo<MmMaterialExcelDto> SelectMaterialList(MmMaterialQueryDto material, PagerInfo pager);

View File

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