|
|
@ -332,13 +332,13 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq |
|
|
|
/// </summary>
|
|
|
|
[HttpPost("import")] |
|
|
|
[Consumes("multipart/form-data")] |
|
|
|
[UnitOfWork] |
|
|
|
//[UnitOfWork]
|
|
|
|
public virtual async Task<IActionResult> ImportAsync([FromForm] SfsImportRequestInput requestInput, [Required] IFormFile file) |
|
|
|
{ |
|
|
|
using var ms = new MemoryStream(); |
|
|
|
await file.OpenReadStream().CopyToAsync(ms).ConfigureAwait(false); |
|
|
|
var inputFileBytes = ms.GetAllBytes(); |
|
|
|
var result = await ImportInternalAsync(requestInput, inputFileBytes); |
|
|
|
var result = await ImportInternalAsync(requestInput, inputFileBytes).ConfigureAwait(false); |
|
|
|
var bytes = result.FileContents; |
|
|
|
result.FileContents = null; |
|
|
|
|
|
|
@ -511,7 +511,7 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq |
|
|
|
/// <summary>
|
|
|
|
/// 导入数据具体实现,可重写
|
|
|
|
/// </summary>
|
|
|
|
[UnitOfWork] |
|
|
|
//[UnitOfWork]
|
|
|
|
protected virtual async Task<SfsImportResult> ImportInternalAsync(SfsImportRequestInput requestInput, byte[] inputFileBytes) |
|
|
|
{ |
|
|
|
IList<TImportInput> modelList = null; |
|
|
@ -684,12 +684,23 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq |
|
|
|
}; |
|
|
|
|
|
|
|
var addList = dict.Where(p => p.Value == EntityState.Added).Select(p => p.Key).ToList(); |
|
|
|
try |
|
|
|
{ |
|
|
|
await context.BulkInsertOrUpdateAsync(addList, bulkConfig).ConfigureAwait(false); |
|
|
|
await context.BulkInsertAsync(list).ConfigureAwait(false); |
|
|
|
|
|
|
|
//await _repository.InsertManyAsync(addList).ConfigureAwait(true);
|
|
|
|
//await _repository.UpdateManyAsync(dict.Where(p => p.Value == EntityState.Modified).Select(p => p.Key)).ConfigureAwait(false);
|
|
|
|
await PublishCreatedAsync(addList).ConfigureAwait(false); |
|
|
|
await LocalEventBus.PublishAsync(new SfsCreatedEntityEventData<List<TEntity>>(addList), false).ConfigureAwait(false); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
await context.Database.RollbackTransactionAsync().ConfigureAwait(false); |
|
|
|
Logger.LogDebug($"{typeof(TEntity).Name} Created Event:{ex.Message}", null); |
|
|
|
Console.WriteLine(ex.Source); |
|
|
|
throw; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|