|
|
@ -6,7 +6,6 @@ using System.Linq; |
|
|
|
using System.Linq.Dynamic.Core; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Reflection; |
|
|
|
using System.Security.Principal; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
@ -513,12 +512,13 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq |
|
|
|
[UnitOfWork] |
|
|
|
protected virtual async Task<SfsImportResult> ImportInternalAsync(SfsImportRequestInput requestInput, byte[] inputFileBytes) |
|
|
|
{ |
|
|
|
IList<TImportInput> modelList = null; |
|
|
|
var modelDict = new Dictionary<TImportInput, List<ValidationResult>>(); |
|
|
|
var entityDict = new Dictionary<TEntity, EntityState>(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var hasDetails = typeof(TEntity).GetInterfaces().Any(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IMasterEntity<>)); |
|
|
|
var modelList = ExportImportService.Import<TImportInput>(inputFileBytes); |
|
|
|
var modelDict = new Dictionary<TImportInput, List<ValidationResult>>(); |
|
|
|
var entityDict = new Dictionary<TEntity, EntityState>(); |
|
|
|
modelList = ExportImportService.Import<TImportInput>(inputFileBytes); |
|
|
|
|
|
|
|
foreach (var model in modelList) |
|
|
|
{ |
|
|
@ -555,7 +555,7 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq |
|
|
|
// 批量更新
|
|
|
|
if (entityDict.Any()) |
|
|
|
{ |
|
|
|
entityDict=await ImportProcessingEntityAsync(entityDict).ConfigureAwait(false); |
|
|
|
entityDict=await ImportProcessingEntityAsync(entityDict); |
|
|
|
|
|
|
|
// 调用批量验证
|
|
|
|
var entityListStatus = await ValidateImportEntities(entityDict).ConfigureAwait(false); |
|
|
@ -581,7 +581,44 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Logger.LogException(ex); |
|
|
|
return new SfsImportResult() { ExceptionMessage = ex.Message }; |
|
|
|
if (modelList != null) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
foreach (var item in modelDict) |
|
|
|
{ |
|
|
|
var model = item.Key; |
|
|
|
var validationRresults = item.Value; |
|
|
|
validationRresults.Add(new ValidationResult($"无法添加,{ex.Message}", new string[] { "异常" })); |
|
|
|
} |
|
|
|
|
|
|
|
// 创建导入报告
|
|
|
|
var reportFile = ExportImportService.GetImportReport(inputFileBytes, modelDict); |
|
|
|
return new SfsImportResult |
|
|
|
{ |
|
|
|
TotalNum = modelList.Count, |
|
|
|
ErrorNum = modelDict.Count(o => o.Value.Any()), |
|
|
|
FileName = reportFile.FileDownloadName, |
|
|
|
FileContents = reportFile.FileContents |
|
|
|
}; |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
return new SfsImportResult() |
|
|
|
{ |
|
|
|
ExceptionMessage = ex.Message, |
|
|
|
FileContents = Encoding.Default.GetBytes(ex.Message) |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return new SfsImportResult() |
|
|
|
{ |
|
|
|
ExceptionMessage = ex.Message, |
|
|
|
FileContents = Encoding.Default.GetBytes(ex.Message) |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|