4 changed files with 258 additions and 0 deletions
@ -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<SUPPLIER_EMPLOYEE> |
|||
{ |
|||
public SupplierEmployeeDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<SUPPLIER_EMPLOYEE> repository) : base(context, builder, configuration, repository) |
|||
{ |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Route("import")] |
|||
public async Task<IActionResult> Import(IFormFile file) |
|||
{ |
|||
if (file == null || file.Length == 0) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
MemoryStream memStream = new MemoryStream(); |
|||
await file.CopyToAsync(memStream); |
|||
|
|||
var importer = new ExcelImporter(); |
|||
ImportResult<SUPPLIER_EMPLOYEE> impResult = await importer.Import<SUPPLIER_EMPLOYEE>(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); |
|||
} |
|||
} |
|||
|
|||
} |
@ -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<SUPPLIER_INFO> |
|||
{ |
|||
public SupplierInfoDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<SUPPLIER_INFO> repository) : base(context, builder, configuration, repository) |
|||
{ |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Route("import")] |
|||
public async Task<IActionResult> Import(IFormFile file) |
|||
{ |
|||
if (file == null || file.Length == 0) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
MemoryStream memStream = new MemoryStream(); |
|||
await file.CopyToAsync(memStream); |
|||
|
|||
var importer = new ExcelImporter(); |
|||
ImportResult<SUPPLIER_INFO> impResult = await importer.Import<SUPPLIER_INFO>(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); |
|||
} |
|||
} |
|||
|
|||
} |
@ -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<SUPPLIER_PRO_ATTACHMENT_DATA> |
|||
{ |
|||
public SupplierProAttachmentDataDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<SUPPLIER_PRO_ATTACHMENT_DATA> repository) : base(context, builder, configuration, repository) |
|||
{ |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Route("import")] |
|||
public async Task<IActionResult> Import(IFormFile file) |
|||
{ |
|||
if (file == null || file.Length == 0) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
MemoryStream memStream = new MemoryStream(); |
|||
await file.CopyToAsync(memStream); |
|||
|
|||
var importer = new ExcelImporter(); |
|||
ImportResult<SUPPLIER_PRO_ATTACHMENT_DATA> impResult = await importer.Import<SUPPLIER_PRO_ATTACHMENT_DATA>(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); |
|||
} |
|||
} |
|||
|
|||
} |
@ -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<SUPPLIER_PRO_PROCESS_EQUIPMENT> |
|||
{ |
|||
public SupplierProProcessEquipmentDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT> repository) : base(context, builder, configuration, repository) |
|||
{ |
|||
} |
|||
|
|||
[HttpPost] |
|||
[Route("import")] |
|||
public async Task<IActionResult> Import(IFormFile file) |
|||
{ |
|||
if (file == null || file.Length == 0) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
MemoryStream memStream = new MemoryStream(); |
|||
await file.CopyToAsync(memStream); |
|||
|
|||
var importer = new ExcelImporter(); |
|||
ImportResult<SUPPLIER_PRO_PROCESS_EQUIPMENT> impResult = await importer.Import<SUPPLIER_PRO_PROCESS_EQUIPMENT>(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); |
|||
} |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue