diff --git a/ZR.Admin.WebApi/Controllers/mes/wms/WmMaterialController.cs b/ZR.Admin.WebApi/Controllers/mes/wms/WmMaterialController.cs index 6cab4e03..c38deeed 100644 --- a/ZR.Admin.WebApi/Controllers/mes/wms/WmMaterialController.cs +++ b/ZR.Admin.WebApi/Controllers/mes/wms/WmMaterialController.cs @@ -1,4 +1,8 @@ +using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; +using Microsoft.IdentityModel.Tokens; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; using System.Collections.Generic; using ZR.Admin.WebApi.Extensions; using ZR.Admin.WebApi.Filters; @@ -127,7 +131,7 @@ namespace ZR.Admin.WebApi.Controllers } - [HttpGet("importData")] + [HttpPost("importData")] [Log(Title = "物料清单批量导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = true)] [AllowAnonymous] //不需要授权 就可以访问 public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile, bool updateSupport) @@ -145,7 +149,7 @@ namespace ZR.Admin.WebApi.Controllers } //2.0 解析 excel - + List materials = new List(); using (var stream = formFile.OpenReadStream()) { FileStream targetFileStream = new FileStream(target, FileMode.Create, FileAccess.Write); @@ -157,27 +161,49 @@ namespace ZR.Admin.WebApi.Controllers targetFileStream.Write(buffer, 0, bytesRead); } + stream.Position = 0; //这一句不加就会上面的异常错误 + IWorkbook workbook = new XSSFWorkbook(stream); + ISheet sheet = workbook.GetSheetAt(0); // 读取第一个工作表 - //IWorkbook workbook = new XSSFWorkbook(stream); - //ISheet sheet = workbook.GetSheetAt(0); // 读取第一个工作表 - //for (int i = 0; i <= sheet.LastRowNum; i++) - //{ - // IRow row = sheet.GetRow(i); - // if (row != null) - // { - // for (int j = 0; j < row.LastCellNum; j++) - // { - // Console.Write(row.GetCell(j) + "\t"); - // } - // Console.WriteLine(); - // } - //} + + + for (int i = 2; i <= sheet.LastRowNum; i++) + { + IRow row = sheet.GetRow(i); + if (row != null) + { + if(row.GetCell(0)!=null &&row.GetCell(0).ToString()!="") + { + WmMaterial material = new WmMaterial(); + + material.Partnumber = row.GetCell(0)?.ToString(); + material.U8InventoryCode = row.GetCell(1)?.ToString(); + material.BlankNum = row.GetCell(2)?.ToString(); + material.Unit = row.GetCell(3)?.ToString(); + material.ProductName = row.GetCell(4)?.ToString(); + material.Color = row.GetCell(5)?.ToString(); + material.Specification = row.GetCell(6)?.ToString(); + material.Description = row.GetCell(7)?.ToString(); + material.Version = row.GetCell(8)?.ToString(); + material.Remarks = row.GetCell(9)?.ToString(); + material.Search1 = row.GetCell(10)?.ToString(); + material.Search2 = row.GetCell(11)?.ToString(); + material.Status = 1; + material.Sort = i; + material.ToCreate(HttpContext); + materials.Add(material); + + } + + } + } } + (int,int) result= _WmMaterialService.ExcelADD(materials); - return null; + return SUCCESS(result); } diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514150089e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514150089e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514150089e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514195289e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514195289e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514195289e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514211889e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514211889e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514211889e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514262889e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514262889e699b8e595a8e788.xlsx new file mode 100644 index 00000000..a5e75782 Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514262889e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514281889e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514281889e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514281889e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514301289e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514301289e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041514301289e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041518234389e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041518234389e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041518234389e699b8e595a8e788.xlsx differ diff --git a/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041518243289e699b8e595a8e788.xlsx b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041518243289e699b8e595a8e788.xlsx new file mode 100644 index 00000000..7f55f9bc Binary files /dev/null and b/ZR.Admin.WebApi/wwwroot/wmmaterial/2024041518243289e699b8e595a8e788.xlsx differ diff --git a/ZR.Service/mes/wms/IService/IWmMaterialService.cs b/ZR.Service/mes/wms/IService/IWmMaterialService.cs index 7d981b76..0426d4c1 100644 --- a/ZR.Service/mes/wms/IService/IWmMaterialService.cs +++ b/ZR.Service/mes/wms/IService/IWmMaterialService.cs @@ -22,5 +22,8 @@ namespace ZR.Service.mes.wms.IService WmGoodsNowProduction GetInfoByPatchCode(string patchCode); + + (int,int) ExcelADD(List materials); + } } diff --git a/ZR.Service/mes/wms/WmMaterialService.cs b/ZR.Service/mes/wms/WmMaterialService.cs index 0ccc5caf..e99afe65 100644 --- a/ZR.Service/mes/wms/WmMaterialService.cs +++ b/ZR.Service/mes/wms/WmMaterialService.cs @@ -116,5 +116,24 @@ namespace ZR.Service.mes.wms .Where(it => it.PackageCodeClient == patchCode).First(); } + /// + /// excel 插入或者更新 + /// + /// + /// + public (int, int) ExcelADD(List materials) + { + if(materials == null || materials.Count == 0) + { + return (-1,-1); + } + var x=Context.Storageable(materials) + .WhereColumns(it => it.BlankNum).ToStorage(); + + int insert= x.AsInsertable.ExecuteCommand(); //执行插入 + int update= x.AsUpdateable.ExecuteCommand(); //执行更新  + return (insert, update); + + } } } \ No newline at end of file