From d9c9d64ab6040578cedc8987c64acbe6bcfb37bb Mon Sep 17 00:00:00 2001 From: me Date: Fri, 30 May 2025 13:43:45 +0800 Subject: [PATCH] =?UTF-8?q?datas=E7=9A=844=E4=B8=AA=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Datas/SupplierEmployeeDtService.cs | 64 ++++++++++++++++++ .../Datas/SupplierInfoDtService.cs | 64 ++++++++++++++++++ .../SupplierProAttachmentDataDtService.cs | 65 +++++++++++++++++++ .../SupplierProProcessEquipmentDtService.cs | 65 +++++++++++++++++++ 4 files changed, 258 insertions(+) create mode 100644 API/Wood.Service/Datas/SupplierEmployeeDtService.cs create mode 100644 API/Wood.Service/Datas/SupplierInfoDtService.cs create mode 100644 API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs create mode 100644 API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs diff --git a/API/Wood.Service/Datas/SupplierEmployeeDtService.cs b/API/Wood.Service/Datas/SupplierEmployeeDtService.cs new file mode 100644 index 0000000..fc4414e --- /dev/null +++ b/API/Wood.Service/Datas/SupplierEmployeeDtService.cs @@ -0,0 +1,64 @@ +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using TaskManager.Entity; +using TaskManager.EntityFramework.Repository; +using TaskManager.EntityFramework; +using Wood.Service.Controllers; +using Magicodes.ExporterAndImporter.Core.Models; + +namespace Wood.Service.Datas +{ + + + public class SupplierEmployeeDtService : NormalBaseController + { + public SupplierEmployeeDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository repository) : base(context, builder, configuration, repository) + { + } + + [HttpPost] + [Route("import")] + public async Task Import(IFormFile file) + { + if (file == null || file.Length == 0) + { + return NotFound(); + } + MemoryStream memStream = new MemoryStream(); + await file.CopyToAsync(memStream); + + var importer = new ExcelImporter(); + ImportResult impResult = await importer.Import(memStream); + if (impResult.HasError) + { + StringBuilder sb = new StringBuilder(); + foreach (var rowErr in impResult.RowErrors) + { + string temp = string.Join(";", rowErr.FieldErrors.Select(itm => $"第{rowErr.RowIndex}行:{itm.Key}-{itm.Value}")); + sb.AppendLine(temp); + } + foreach (var templateErr in impResult.TemplateErrors) + { + string temp = $"列名:{templateErr.RequireColumnName},错误信息:{templateErr.Message}"; + sb.AppendLine(temp); + } + throw new Exception(sb.ToString()); + } + foreach (var item in impResult.Data) //??增加批量插入 + { + await Create(item); + } + return Ok(true); + } + } + +} diff --git a/API/Wood.Service/Datas/SupplierInfoDtService.cs b/API/Wood.Service/Datas/SupplierInfoDtService.cs new file mode 100644 index 0000000..c5a0944 --- /dev/null +++ b/API/Wood.Service/Datas/SupplierInfoDtService.cs @@ -0,0 +1,64 @@ +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using TaskManager.Entity; +using TaskManager.EntityFramework.Repository; +using TaskManager.EntityFramework; +using Wood.Service.Controllers; +using Magicodes.ExporterAndImporter.Core.Models; + +namespace Wood.Service.Datas +{ + + + public class SupplierInfoDtService : NormalBaseController + { + public SupplierInfoDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository repository) : base(context, builder, configuration, repository) + { + } + + [HttpPost] + [Route("import")] + public async Task Import(IFormFile file) + { + if (file == null || file.Length == 0) + { + return NotFound(); + } + MemoryStream memStream = new MemoryStream(); + await file.CopyToAsync(memStream); + + var importer = new ExcelImporter(); + ImportResult impResult = await importer.Import(memStream); + if (impResult.HasError) + { + StringBuilder sb = new StringBuilder(); + foreach (var rowErr in impResult.RowErrors) + { + string temp = string.Join(";", rowErr.FieldErrors.Select(itm => $"第{rowErr.RowIndex}行:{itm.Key}-{itm.Value}")); + sb.AppendLine(temp); + } + foreach (var templateErr in impResult.TemplateErrors) + { + string temp = $"列名:{templateErr.RequireColumnName},错误信息:{templateErr.Message}"; + sb.AppendLine(temp); + } + throw new Exception(sb.ToString()); + } + foreach (var item in impResult.Data) //??增加批量插入 + { + await Create(item); + } + return Ok(true); + } + } + +} diff --git a/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs b/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs new file mode 100644 index 0000000..76c8604 --- /dev/null +++ b/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs @@ -0,0 +1,65 @@ +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using TaskManager.Entity; +using TaskManager.EntityFramework.Repository; +using TaskManager.EntityFramework; +using Wood.Service.Controllers; +using Magicodes.ExporterAndImporter.Core.Models; +using TaskManager.Entity.Entitys; + +namespace Wood.Service.Datas +{ + + + public class SupplierProAttachmentDataDtService : NormalBaseController + { + public SupplierProAttachmentDataDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository repository) : base(context, builder, configuration, repository) + { + } + + [HttpPost] + [Route("import")] + public async Task Import(IFormFile file) + { + if (file == null || file.Length == 0) + { + return NotFound(); + } + MemoryStream memStream = new MemoryStream(); + await file.CopyToAsync(memStream); + + var importer = new ExcelImporter(); + ImportResult impResult = await importer.Import(memStream); + if (impResult.HasError) + { + StringBuilder sb = new StringBuilder(); + foreach (var rowErr in impResult.RowErrors) + { + string temp = string.Join(";", rowErr.FieldErrors.Select(itm => $"第{rowErr.RowIndex}行:{itm.Key}-{itm.Value}")); + sb.AppendLine(temp); + } + foreach (var templateErr in impResult.TemplateErrors) + { + string temp = $"列名:{templateErr.RequireColumnName},错误信息:{templateErr.Message}"; + sb.AppendLine(temp); + } + throw new Exception(sb.ToString()); + } + foreach (var item in impResult.Data) //??增加批量插入 + { + await Create(item); + } + return Ok(true); + } + } + +} diff --git a/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs b/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs new file mode 100644 index 0000000..0b93ffd --- /dev/null +++ b/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs @@ -0,0 +1,65 @@ +using Magicodes.ExporterAndImporter.Excel; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using TaskManager.Entity; +using TaskManager.EntityFramework.Repository; +using TaskManager.EntityFramework; +using Wood.Service.Controllers; +using Magicodes.ExporterAndImporter.Core.Models; +using TaskManager.Entity.Entitys; + +namespace Wood.Service.Datas +{ + + + public class SupplierProProcessEquipmentDtService : NormalBaseController + { + public SupplierProProcessEquipmentDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository repository) : base(context, builder, configuration, repository) + { + } + + [HttpPost] + [Route("import")] + public async Task Import(IFormFile file) + { + if (file == null || file.Length == 0) + { + return NotFound(); + } + MemoryStream memStream = new MemoryStream(); + await file.CopyToAsync(memStream); + + var importer = new ExcelImporter(); + ImportResult impResult = await importer.Import(memStream); + if (impResult.HasError) + { + StringBuilder sb = new StringBuilder(); + foreach (var rowErr in impResult.RowErrors) + { + string temp = string.Join(";", rowErr.FieldErrors.Select(itm => $"第{rowErr.RowIndex}行:{itm.Key}-{itm.Value}")); + sb.AppendLine(temp); + } + foreach (var templateErr in impResult.TemplateErrors) + { + string temp = $"列名:{templateErr.RequireColumnName},错误信息:{templateErr.Message}"; + sb.AppendLine(temp); + } + throw new Exception(sb.ToString()); + } + foreach (var item in impResult.Data) //??增加批量插入 + { + await Create(item); + } + return Ok(true); + } + } + +}