|
|
@ -30,6 +30,12 @@ using Win.Sfs.SettleAccount.Entities.Errors; |
|
|
|
|
|
|
|
using Win.Sfs.SettleAccount.Entities.TaskJobs; |
|
|
|
using Win.Sfs.SettleAccount.Entities.ImportMap; |
|
|
|
using Magicodes.ExporterAndImporter.Excel.Utility; |
|
|
|
using Magicodes.ExporterAndImporter.Core.Models; |
|
|
|
using Magicodes.ExporterAndImporter.Core.Filters; |
|
|
|
using OfficeOpenXml.Attributes; |
|
|
|
using Win.Sfs.SettleAccount.Attributes; |
|
|
|
using Magicodes.ExporterAndImporter.Core.Extension; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
{ |
|
|
@ -38,7 +44,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IExporter _csvExporter= new Magicodes.ExporterAndImporter.Csv.CsvExporter();//导出CSV
|
|
|
|
private readonly IExporter _csvExporter = new Magicodes.ExporterAndImporter.Csv.CsvExporter();//导出CSV
|
|
|
|
private readonly IExcelImporter _importer = new Magicodes.ExporterAndImporter.Excel.ExcelImporter();//导入Excel
|
|
|
|
private readonly IExporter _exporter = new ExcelExporter();//导出Excel
|
|
|
|
|
|
|
@ -50,7 +56,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
ExcelImportResult returnResult = new ExcelImportResult(); |
|
|
|
List<string> _errorList = new List<string>(); |
|
|
|
|
|
|
|
var importAttrib= type.GetCustomAttribute<ImportProjectAttribute>(); |
|
|
|
var importAttrib = type.GetCustomAttribute<ImportProjectAttribute>(); |
|
|
|
if (importAttrib != null) |
|
|
|
{ |
|
|
|
|
|
|
@ -98,18 +104,18 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
{ |
|
|
|
if (import.Exception.Message.ToString() == "导入文件不存在!") |
|
|
|
{ |
|
|
|
throw new BusinessException("8989","文件容器配置的路径错误,请检查!"); |
|
|
|
throw new BusinessException("8989", "文件容器配置的路径错误,请检查!"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new BusinessException("8989",import.Exception.Message.ToString()); |
|
|
|
throw new BusinessException("8989", import.Exception.Message.ToString()); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (import.TemplateErrors.Count > 0) |
|
|
|
{ |
|
|
|
throw new BusinessException("8989","模板错误!当前模板中字段不匹配!!请正确上传模板数据!导入不对的列名:"+import.TemplateErrors.FirstOrDefault().RequireColumnName); |
|
|
|
throw new BusinessException("8989", "模板错误!当前模板中字段不匹配!!请正确上传模板数据!导入不对的列名:" + import.TemplateErrors.FirstOrDefault().RequireColumnName); |
|
|
|
} |
|
|
|
import.ShouldNotBeNull(); |
|
|
|
if (import.Exception != null) |
|
|
@ -125,10 +131,10 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
string error = string.Empty; |
|
|
|
foreach (var dic in itm.FieldErrors) |
|
|
|
{ |
|
|
|
error += (dic.Key+ dic.Value+"|"); |
|
|
|
error += (dic.Key + dic.Value + "|"); |
|
|
|
} |
|
|
|
|
|
|
|
_errorList.Add(string.Format("第{0}行{1}", itm.RowIndex.ToString(),error)); |
|
|
|
_errorList.Add(string.Format("第{0}行{1}", itm.RowIndex.ToString(), error)); |
|
|
|
} |
|
|
|
//自动保存“{ 目标文件名称}_.xlsx”的标注文件到目标位置
|
|
|
|
//导入的数据有错误,比如重复列,必填项为空等(不包含警告),主要看DTO的设置
|
|
|
@ -150,142 +156,277 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
} |
|
|
|
if (_errorList.Count > 0) |
|
|
|
{ |
|
|
|
throw new BusinessException("8989",string.Join("\r\n", _errorList)); |
|
|
|
throw new BusinessException("8989", string.Join("\r\n", _errorList)); |
|
|
|
} |
|
|
|
return ImportList;//返回客户端
|
|
|
|
} |
|
|
|
// public virtual async Task<List<T>> UploadExcelImport<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService, ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> repository=null)
|
|
|
|
//where T : class, new()
|
|
|
|
// {
|
|
|
|
// Type type = typeof(T);
|
|
|
|
// var ImportList = new List<T>();
|
|
|
|
// ExcelImportResult returnResult = new ExcelImportResult();
|
|
|
|
// List<string> _errorList = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //if (repository != null)
|
|
|
|
// //{
|
|
|
|
// // var importAttrib = type.GetCustomAttribute<ImportProjectAttribute>();
|
|
|
|
// // if (importAttrib != null)
|
|
|
|
// // {
|
|
|
|
// // var _columnList = repository.Where(p => p.ProjectName == importAttrib.Name);
|
|
|
|
// // if (_columnList.Count() > 0)
|
|
|
|
// // {
|
|
|
|
// // foreach (var itm in type.GetProperties())
|
|
|
|
// // {
|
|
|
|
// // var attrib = itm.GetCustomAttribute<ImporterHeaderAttribute>();
|
|
|
|
// // if (attrib != null)
|
|
|
|
// // {
|
|
|
|
// // var newColumn = _columnList.FirstOrDefault(p => p.OldColumnName == attrib.Name);
|
|
|
|
// // if (newColumn != null && !string.IsNullOrEmpty(newColumn.NewColumnName))
|
|
|
|
// // {
|
|
|
|
|
|
|
|
// // attrib.Name = !string.IsNullOrEmpty(newColumn.NewColumnName)? newColumn.NewColumnName:attrib.Name;
|
|
|
|
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// //}
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var file in files)
|
|
|
|
// {
|
|
|
|
// if (file == null)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("上传附件不能为空!");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// string FileOriginName = file.FileName;
|
|
|
|
// string getFileName = Path.GetFileName(FileOriginName);//获取附件名称
|
|
|
|
// using (var memoryStream = new MemoryStream())
|
|
|
|
// {
|
|
|
|
// //保存成物理文件
|
|
|
|
// await file.CopyToAsync(memoryStream);
|
|
|
|
// await _excelImportService.SaveBlobAsync(
|
|
|
|
// new SaveExcelImportInputDto
|
|
|
|
// {
|
|
|
|
// Name = Path.GetFileName(FileOriginName),
|
|
|
|
// Content = memoryStream.ToArray()
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// //读取文件保存的根目录
|
|
|
|
// string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath");
|
|
|
|
// //读取WMS文件保存的模块的根目录
|
|
|
|
// string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles");
|
|
|
|
// //文件保存的相对文件夹(保存到wwwroot目录下)
|
|
|
|
// string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir;
|
|
|
|
// //文件保存的路径(应用的工作目录+文件夹相对路径);
|
|
|
|
// string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir;
|
|
|
|
// var filePath = fileSavePath + getFileName;//获取到导入的excel
|
|
|
|
// var import = await _importer.Import<T>(filePath);
|
|
|
|
// if (import.Exception != null)
|
|
|
|
// {
|
|
|
|
// if (import.Exception.Message.ToString() == "导入文件不存在!")
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", "文件容器配置的路径错误,请检查!");
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", import.Exception.Message.ToString());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// if (import.TemplateErrors.Count > 0)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", "模板错误!当前模板中字段不匹配!!请正确上传模板数据!");
|
|
|
|
// }
|
|
|
|
// import.ShouldNotBeNull();
|
|
|
|
// if (import.Exception != null)
|
|
|
|
// {
|
|
|
|
// //导入的数据有异常
|
|
|
|
// throw new BusinessException(import.Exception.ToString());
|
|
|
|
// }
|
|
|
|
// returnResult.totalSize = import.Data.Count;
|
|
|
|
// if (import.RowErrors.Count > 0)
|
|
|
|
// {
|
|
|
|
// foreach (var itm in import.RowErrors)
|
|
|
|
// {
|
|
|
|
// string error = string.Empty;
|
|
|
|
// foreach (var dic in itm.FieldErrors)
|
|
|
|
// {
|
|
|
|
// error += (dic.Key + dic.Value + "|");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _errorList.Add(string.Format("第{0}行{1}", itm.RowIndex.ToString(), error));
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //自动保存“{ 目标文件名称}_.xlsx”的标注文件到目标位置
|
|
|
|
// //导入的数据有错误,比如重复列,必填项为空等(不包含警告),主要看DTO的设置
|
|
|
|
// import.HasError.ShouldBeTrue();//标识导入的数据有错误
|
|
|
|
// returnResult.errSize = import.RowErrors.Count;
|
|
|
|
// returnResult.errTemplate = Path.GetFileNameWithoutExtension(FileOriginName) + "_.xlsx";//返回错误模板名称作为参数
|
|
|
|
// returnResult.errMessage = "RowErrors";
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// import.HasError.ShouldBeFalse();//标识导入的数据没有错误了
|
|
|
|
// if (import.Data.Count > 0)
|
|
|
|
// {
|
|
|
|
// ImportList.AddRange(import.Data.ToList());
|
|
|
|
// }
|
|
|
|
// returnResult.errMessage = "SccessData";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if (_errorList.Count > 0)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", string.Join("\r\n", _errorList));
|
|
|
|
// }
|
|
|
|
// return ImportList;//返回客户端
|
|
|
|
// }
|
|
|
|
|
|
|
|
public virtual async Task<List<T>> UploadExcelImportByHeadDesc<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) |
|
|
|
where T : class, new() |
|
|
|
{ |
|
|
|
Type type = typeof(T); |
|
|
|
var ImportList = new List<T>(); |
|
|
|
ExcelImportResult returnResult = new ExcelImportResult(); |
|
|
|
List<string> _errorList = new List<string>(); |
|
|
|
|
|
|
|
foreach (var file in files) |
|
|
|
{ |
|
|
|
if (file == null) |
|
|
|
{ |
|
|
|
throw new BusinessException("上传附件不能为空!"); |
|
|
|
} |
|
|
|
|
|
|
|
string FileOriginName = file.FileName; |
|
|
|
string getFileName = Path.GetFileName(FileOriginName);//获取附件名称
|
|
|
|
using (var memoryStream = new MemoryStream()) |
|
|
|
{ |
|
|
|
//保存成物理文件
|
|
|
|
await file.CopyToAsync(memoryStream); |
|
|
|
await _excelImportService.SaveBlobAsync( |
|
|
|
new SaveExcelImportInputDto |
|
|
|
{ |
|
|
|
Name = Path.GetFileName(FileOriginName), |
|
|
|
Content = memoryStream.ToArray() |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
//读取文件保存的根目录
|
|
|
|
string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); |
|
|
|
//读取WMS文件保存的模块的根目录
|
|
|
|
string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles"); |
|
|
|
//文件保存的相对文件夹(保存到wwwroot目录下)
|
|
|
|
string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir; |
|
|
|
//文件保存的路径(应用的工作目录+文件夹相对路径);
|
|
|
|
string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir; |
|
|
|
var filePath = fileSavePath + getFileName;//获取到导入的excel
|
|
|
|
//var import = await _importer.Import<T>(filePath);
|
|
|
|
|
|
|
|
var import = new ImportResult<T>(); |
|
|
|
|
|
|
|
using (var importer = new ImportHelper<T>(filePath, null)) |
|
|
|
{ |
|
|
|
import = await importer.Import(null); |
|
|
|
|
|
|
|
Stream Stream = new FileStream(filePath, FileMode.Open); |
|
|
|
using (Stream) |
|
|
|
{ |
|
|
|
IWorkbook wk = new XSSFWorkbook(Stream); |
|
|
|
//读取当前表数据
|
|
|
|
ISheet sheet = wk.GetSheetAt(0); |
|
|
|
|
|
|
|
var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) |
|
|
|
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null); |
|
|
|
foreach (var item in excelImporterHeadDescAttributeProperties) |
|
|
|
{ |
|
|
|
string propertyName = item.Name; |
|
|
|
var excelImporterHeadDesc = item.GetCustomAttribute<ExcelImporterHeadDescAttribute>(); |
|
|
|
var row = excelImporterHeadDesc.Row; |
|
|
|
var cell = excelImporterHeadDesc.Cell; |
|
|
|
var value = sheet.GetRow(row).GetCell(cell).ToString(); |
|
|
|
|
|
|
|
if (import.Data != null) |
|
|
|
{ |
|
|
|
foreach (var item2 in import.Data) |
|
|
|
{ |
|
|
|
item2.GetType().GetProperty(propertyName).SetValue(item2, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (import.Exception != null) |
|
|
|
{ |
|
|
|
if (import.Exception.Message.ToString() == "导入文件不存在!") |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", "文件容器配置的路径错误,请检查!"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", import.Exception.Message.ToString()); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (import.TemplateErrors.Count > 0) |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", "模板错误!当前模板中字段不匹配!!请正确上传模板数据!导入不对的列名:" + import.TemplateErrors.FirstOrDefault().RequireColumnName); |
|
|
|
} |
|
|
|
import.ShouldNotBeNull(); |
|
|
|
if (import.Exception != null) |
|
|
|
{ |
|
|
|
//导入的数据有异常
|
|
|
|
throw new BusinessException(import.Exception.ToString()); |
|
|
|
} |
|
|
|
returnResult.totalSize = import.Data.Count; |
|
|
|
if (import.RowErrors.Count > 0) |
|
|
|
{ |
|
|
|
foreach (var itm in import.RowErrors) |
|
|
|
{ |
|
|
|
string error = string.Empty; |
|
|
|
foreach (var dic in itm.FieldErrors) |
|
|
|
{ |
|
|
|
error += (dic.Key + dic.Value + "|"); |
|
|
|
} |
|
|
|
|
|
|
|
_errorList.Add(string.Format("第{0}行{1}", itm.RowIndex.ToString(), error)); |
|
|
|
} |
|
|
|
//自动保存“{ 目标文件名称}_.xlsx”的标注文件到目标位置
|
|
|
|
//导入的数据有错误,比如重复列,必填项为空等(不包含警告),主要看DTO的设置
|
|
|
|
import.HasError.ShouldBeTrue();//标识导入的数据有错误
|
|
|
|
returnResult.errSize = import.RowErrors.Count; |
|
|
|
returnResult.errTemplate = Path.GetFileNameWithoutExtension(FileOriginName) + "_.xlsx";//返回错误模板名称作为参数
|
|
|
|
returnResult.errMessage = "RowErrors"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
import.HasError.ShouldBeFalse();//标识导入的数据没有错误了
|
|
|
|
if (import.Data.Count > 0) |
|
|
|
{ |
|
|
|
ImportList.AddRange(import.Data.ToList()); |
|
|
|
} |
|
|
|
returnResult.errMessage = "SccessData"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (_errorList.Count > 0) |
|
|
|
{ |
|
|
|
throw new BusinessException("8989", string.Join("\r\n", _errorList)); |
|
|
|
} |
|
|
|
return ImportList;//返回客户端
|
|
|
|
} |
|
|
|
// public virtual async Task<List<T>> UploadExcelImport<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService, ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> repository=null)
|
|
|
|
//where T : class, new()
|
|
|
|
// {
|
|
|
|
// Type type = typeof(T);
|
|
|
|
// var ImportList = new List<T>();
|
|
|
|
// ExcelImportResult returnResult = new ExcelImportResult();
|
|
|
|
// List<string> _errorList = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //if (repository != null)
|
|
|
|
// //{
|
|
|
|
// // var importAttrib = type.GetCustomAttribute<ImportProjectAttribute>();
|
|
|
|
// // if (importAttrib != null)
|
|
|
|
// // {
|
|
|
|
// // var _columnList = repository.Where(p => p.ProjectName == importAttrib.Name);
|
|
|
|
// // if (_columnList.Count() > 0)
|
|
|
|
// // {
|
|
|
|
// // foreach (var itm in type.GetProperties())
|
|
|
|
// // {
|
|
|
|
// // var attrib = itm.GetCustomAttribute<ImporterHeaderAttribute>();
|
|
|
|
// // if (attrib != null)
|
|
|
|
// // {
|
|
|
|
// // var newColumn = _columnList.FirstOrDefault(p => p.OldColumnName == attrib.Name);
|
|
|
|
// // if (newColumn != null && !string.IsNullOrEmpty(newColumn.NewColumnName))
|
|
|
|
// // {
|
|
|
|
|
|
|
|
// // attrib.Name = !string.IsNullOrEmpty(newColumn.NewColumnName)? newColumn.NewColumnName:attrib.Name;
|
|
|
|
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
// //}
|
|
|
|
|
|
|
|
|
|
|
|
// foreach (var file in files)
|
|
|
|
// {
|
|
|
|
// if (file == null)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("上传附件不能为空!");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// string FileOriginName = file.FileName;
|
|
|
|
// string getFileName = Path.GetFileName(FileOriginName);//获取附件名称
|
|
|
|
// using (var memoryStream = new MemoryStream())
|
|
|
|
// {
|
|
|
|
// //保存成物理文件
|
|
|
|
// await file.CopyToAsync(memoryStream);
|
|
|
|
// await _excelImportService.SaveBlobAsync(
|
|
|
|
// new SaveExcelImportInputDto
|
|
|
|
// {
|
|
|
|
// Name = Path.GetFileName(FileOriginName),
|
|
|
|
// Content = memoryStream.ToArray()
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// //读取文件保存的根目录
|
|
|
|
// string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath");
|
|
|
|
// //读取WMS文件保存的模块的根目录
|
|
|
|
// string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles");
|
|
|
|
// //文件保存的相对文件夹(保存到wwwroot目录下)
|
|
|
|
// string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir;
|
|
|
|
// //文件保存的路径(应用的工作目录+文件夹相对路径);
|
|
|
|
// string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir;
|
|
|
|
// var filePath = fileSavePath + getFileName;//获取到导入的excel
|
|
|
|
// var import = await _importer.Import<T>(filePath);
|
|
|
|
// if (import.Exception != null)
|
|
|
|
// {
|
|
|
|
// if (import.Exception.Message.ToString() == "导入文件不存在!")
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", "文件容器配置的路径错误,请检查!");
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", import.Exception.Message.ToString());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// if (import.TemplateErrors.Count > 0)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", "模板错误!当前模板中字段不匹配!!请正确上传模板数据!");
|
|
|
|
// }
|
|
|
|
// import.ShouldNotBeNull();
|
|
|
|
// if (import.Exception != null)
|
|
|
|
// {
|
|
|
|
// //导入的数据有异常
|
|
|
|
// throw new BusinessException(import.Exception.ToString());
|
|
|
|
// }
|
|
|
|
// returnResult.totalSize = import.Data.Count;
|
|
|
|
// if (import.RowErrors.Count > 0)
|
|
|
|
// {
|
|
|
|
// foreach (var itm in import.RowErrors)
|
|
|
|
// {
|
|
|
|
// string error = string.Empty;
|
|
|
|
// foreach (var dic in itm.FieldErrors)
|
|
|
|
// {
|
|
|
|
// error += (dic.Key + dic.Value + "|");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _errorList.Add(string.Format("第{0}行{1}", itm.RowIndex.ToString(), error));
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //自动保存“{ 目标文件名称}_.xlsx”的标注文件到目标位置
|
|
|
|
// //导入的数据有错误,比如重复列,必填项为空等(不包含警告),主要看DTO的设置
|
|
|
|
// import.HasError.ShouldBeTrue();//标识导入的数据有错误
|
|
|
|
// returnResult.errSize = import.RowErrors.Count;
|
|
|
|
// returnResult.errTemplate = Path.GetFileNameWithoutExtension(FileOriginName) + "_.xlsx";//返回错误模板名称作为参数
|
|
|
|
// returnResult.errMessage = "RowErrors";
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// import.HasError.ShouldBeFalse();//标识导入的数据没有错误了
|
|
|
|
// if (import.Data.Count > 0)
|
|
|
|
// {
|
|
|
|
// ImportList.AddRange(import.Data.ToList());
|
|
|
|
// }
|
|
|
|
// returnResult.errMessage = "SccessData";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// if (_errorList.Count > 0)
|
|
|
|
// {
|
|
|
|
// throw new BusinessException("8989", string.Join("\r\n", _errorList));
|
|
|
|
// }
|
|
|
|
// return ImportList;//返回客户端
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -305,7 +446,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task<List<T>> ExtendExcelImport<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService, List<ImportColumnMap> p_list=null) |
|
|
|
public virtual async Task<List<T>> ExtendExcelImport<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService, List<ImportColumnMap> p_list = null) |
|
|
|
where T : class, new() |
|
|
|
{ |
|
|
|
|
|
|
@ -432,40 +573,40 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
/// 获取配置下面的具体属性的值
|
|
|
|
/// </summary>
|
|
|
|
public class GetSetting |
|
|
|
{ |
|
|
|
public string option1 { get; } |
|
|
|
public GetSetting(IConfiguration Configuration) |
|
|
|
{ |
|
|
|
public string option1 { get; } |
|
|
|
public GetSetting(IConfiguration Configuration) |
|
|
|
{ |
|
|
|
this.option1 = Configuration.GetSection("option1").Value; |
|
|
|
} |
|
|
|
this.option1 = Configuration.GetSection("option1").Value; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ExcelImportResult |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// 导入的数据总数
|
|
|
|
/// </summary>
|
|
|
|
public long totalSize { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 成功的个数
|
|
|
|
/// </summary>
|
|
|
|
public long succeessSize { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 错误数据个数
|
|
|
|
/// </summary>
|
|
|
|
public long errSize { get; set; } |
|
|
|
/// <summary>
|
|
|
|
/// 导入错误生成的模板名称
|
|
|
|
/// </summary>
|
|
|
|
public string errTemplate { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 返回错误信息
|
|
|
|
/// </summary>
|
|
|
|
public string errMessage { get; set; } |
|
|
|
} |
|
|
|
public class ExcelImportResult |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// 导入的数据总数
|
|
|
|
/// </summary>
|
|
|
|
public long totalSize { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 成功的个数
|
|
|
|
/// </summary>
|
|
|
|
public long succeessSize { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 错误数据个数
|
|
|
|
/// </summary>
|
|
|
|
public long errSize { get; set; } |
|
|
|
/// <summary>
|
|
|
|
/// 导入错误生成的模板名称
|
|
|
|
/// </summary>
|
|
|
|
public string errTemplate { get; set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 返回错误信息
|
|
|
|
/// </summary>
|
|
|
|
public string errMessage { get; set; } |
|
|
|
} |