|
@ -164,6 +164,8 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
public virtual async Task<List<T>> UploadExcelImportByHeadDesc<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) |
|
|
public virtual async Task<List<T>> UploadExcelImportByHeadDesc<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) |
|
|
where T : class, new() |
|
|
where T : class, new() |
|
|
{ |
|
|
{ |
|
|
|
|
|
using var fs = ServiceProvider.CreateScope(); |
|
|
|
|
|
var fc = fs.ServiceProvider.GetRequiredService<IBlobContainer<MyFileContainer>>(); |
|
|
Type type = typeof(T); |
|
|
Type type = typeof(T); |
|
|
var ImportList = new List<T>(); |
|
|
var ImportList = new List<T>(); |
|
|
ExcelImportResult returnResult = new ExcelImportResult(); |
|
|
ExcelImportResult returnResult = new ExcelImportResult(); |
|
@ -182,37 +184,36 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
{ |
|
|
{ |
|
|
//保存成物理文件
|
|
|
//保存成物理文件
|
|
|
await file.CopyToAsync(memoryStream); |
|
|
await file.CopyToAsync(memoryStream); |
|
|
await _excelImportService.SaveBlobAsync( |
|
|
//await _excelImportService.SaveBlobAsync(
|
|
|
new SaveExcelImportInputDto |
|
|
// new SaveExcelImportInputDto
|
|
|
{ |
|
|
// {
|
|
|
Name = Path.GetFileName(FileOriginName), |
|
|
// Name = Path.GetFileName(FileOriginName),
|
|
|
Content = memoryStream.ToArray() |
|
|
// Content = memoryStream.ToArray()
|
|
|
} |
|
|
// }
|
|
|
); |
|
|
// );
|
|
|
|
|
|
await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
//读取文件保存的根目录
|
|
|
////读取文件保存的根目录
|
|
|
string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath"); |
|
|
//string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath");
|
|
|
//读取WMS文件保存的模块的根目录
|
|
|
////读取WMS文件保存的模块的根目录
|
|
|
string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles"); |
|
|
//string fileSaveDir = ConfigDirHelper.GetAppSetting("App", "WMSFiles");
|
|
|
//文件保存的相对文件夹(保存到wwwroot目录下)
|
|
|
////文件保存的相对文件夹(保存到wwwroot目录下)
|
|
|
string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir; |
|
|
//string absoluteFileDir = fileSaveRootDir + @"\" + fileSaveDir;
|
|
|
//文件保存的路径(应用的工作目录+文件夹相对路径);
|
|
|
////文件保存的路径(应用的工作目录+文件夹相对路径);
|
|
|
string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir; |
|
|
//string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container" + absoluteFileDir;
|
|
|
var filePath = fileSavePath + getFileName;//获取到导入的excel
|
|
|
//var filePath = fileSavePath + getFileName;//获取到导入的excel
|
|
|
//var import = await _importer.Import<T>(filePath);
|
|
|
//var import = await _importer.Import<T>(filePath);
|
|
|
|
|
|
|
|
|
var import = new ImportResult<T>(); |
|
|
var import = new ImportResult<T>(); |
|
|
|
|
|
|
|
|
using (var importer = new ImportHelper<T>(filePath, null)) |
|
|
using (var stream = new MemoryStream()) |
|
|
{ |
|
|
|
|
|
import = await importer.Import(null); |
|
|
|
|
|
|
|
|
|
|
|
Stream Stream = new FileStream(filePath, FileMode.Open); |
|
|
|
|
|
using (Stream) |
|
|
|
|
|
{ |
|
|
{ |
|
|
IWorkbook wk = new XSSFWorkbook(Stream); |
|
|
await file.CopyToAsync(stream).ConfigureAwait(false); |
|
|
|
|
|
stream.Position = 0; |
|
|
|
|
|
IWorkbook wk = new XSSFWorkbook(stream); |
|
|
//读取当前表数据
|
|
|
//读取当前表数据
|
|
|
ISheet sheet = wk.GetSheetAt(0); |
|
|
ISheet sheet = wk.GetSheetAt(0); |
|
|
|
|
|
import = await _importer.Import<T>(await fc.GetAsync(FileOriginName).ConfigureAwait(false)).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) |
|
|
var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) |
|
|
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null); |
|
|
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null); |
|
@ -233,7 +234,6 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (import.Exception != null) |
|
|
if (import.Exception != null) |
|
|
{ |
|
|
{ |
|
@ -291,6 +291,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
} |
|
|
} |
|
|
if (_errorList.Count > 0) |
|
|
if (_errorList.Count > 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException(string.Join("\r\n", _errorList), "400"); |
|
|
throw new BusinessException("8989", string.Join("\r\n", _errorList)); |
|
|
throw new BusinessException("8989", string.Join("\r\n", _errorList)); |
|
|
} |
|
|
} |
|
|
return ImportList;//返回客户端
|
|
|
return ImportList;//返回客户端
|
|
|