|
|
@ -92,7 +92,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
// Content = memoryStream.ToArray()
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
await fc.SaveAsync(FileOriginName, memoryStream.ToArray(),true).ConfigureAwait(false); |
|
|
|
await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false); |
|
|
|
} |
|
|
|
////读取文件保存的根目录
|
|
|
|
//string fileSaveRootDir = ConfigDirHelper.GetAppSetting("App", "FileRootPath");
|
|
|
@ -164,6 +164,8 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
public virtual async Task<List<T>> UploadExcelImportByHeadDesc<T>([FromForm] IFormFileCollection files, IExcelImportAppService _excelImportService) |
|
|
|
where T : class, new() |
|
|
|
{ |
|
|
|
using var fs = ServiceProvider.CreateScope(); |
|
|
|
var fc = fs.ServiceProvider.GetRequiredService<IBlobContainer<MyFileContainer>>(); |
|
|
|
Type type = typeof(T); |
|
|
|
var ImportList = new List<T>(); |
|
|
|
ExcelImportResult returnResult = new ExcelImportResult(); |
|
|
@ -182,54 +184,52 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
{ |
|
|
|
//保存成物理文件
|
|
|
|
await file.CopyToAsync(memoryStream); |
|
|
|
await _excelImportService.SaveBlobAsync( |
|
|
|
new SaveExcelImportInputDto |
|
|
|
{ |
|
|
|
Name = Path.GetFileName(FileOriginName), |
|
|
|
Content = memoryStream.ToArray() |
|
|
|
} |
|
|
|
); |
|
|
|
//await _excelImportService.SaveBlobAsync(
|
|
|
|
// new SaveExcelImportInputDto
|
|
|
|
// {
|
|
|
|
// Name = Path.GetFileName(FileOriginName),
|
|
|
|
// Content = memoryStream.ToArray()
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
await fc.SaveAsync(FileOriginName, memoryStream.ToArray(), true).ConfigureAwait(false); |
|
|
|
} |
|
|
|
//读取文件保存的根目录
|
|
|
|
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
|
|
|
|
////读取文件保存的根目录
|
|
|
|
//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)) |
|
|
|
using (var stream = new MemoryStream()) |
|
|
|
{ |
|
|
|
import = await importer.Import(null); |
|
|
|
|
|
|
|
Stream Stream = new FileStream(filePath, FileMode.Open); |
|
|
|
using (Stream) |
|
|
|
await file.CopyToAsync(stream).ConfigureAwait(false); |
|
|
|
stream.Position = 0; |
|
|
|
IWorkbook wk = new XSSFWorkbook(stream); |
|
|
|
//读取当前表数据
|
|
|
|
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) |
|
|
|
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null); |
|
|
|
foreach (var item in excelImporterHeadDescAttributeProperties) |
|
|
|
{ |
|
|
|
IWorkbook wk = new XSSFWorkbook(Stream); |
|
|
|
//读取当前表数据
|
|
|
|
ISheet sheet = wk.GetSheetAt(0); |
|
|
|
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(); |
|
|
|
|
|
|
|
var excelImporterHeadDescAttributeProperties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty) |
|
|
|
.Where(o => o.GetCustomAttribute<ExcelImporterHeadDescAttribute>(true) != null); |
|
|
|
foreach (var item in excelImporterHeadDescAttributeProperties) |
|
|
|
if (import.Data != null) |
|
|
|
{ |
|
|
|
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) |
|
|
|
{ |
|
|
|
foreach (var item2 in import.Data) |
|
|
|
{ |
|
|
|
item2.GetType().GetProperty(propertyName).SetValue(item2, value); |
|
|
|
} |
|
|
|
item2.GetType().GetProperty(propertyName).SetValue(item2, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -291,6 +291,7 @@ namespace Win.Sfs.SettleAccount.ExcelImporter |
|
|
|
} |
|
|
|
if (_errorList.Count > 0) |
|
|
|
{ |
|
|
|
throw new UserFriendlyException(string.Join("\r\n", _errorList), "400"); |
|
|
|
throw new BusinessException("8989", string.Join("\r\n", _errorList)); |
|
|
|
} |
|
|
|
return ImportList;//返回客户端
|
|
|
|