Browse Source

解决冲突

集成Redis
郑勃旭 2 years ago
parent
commit
a4c81707b9
  1. 6
      be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs
  2. 49
      be/Modules/Shared/src/Win_in.Sfs.Shared.Application/SfsCrudWithDetailsAppServiceBase.cs

6
be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs

@ -26,7 +26,7 @@ public class ClosedXmlExportImportService : IExportImportService
public FileContentResult Export<TModel>(List<TModel> list, bool includeAuditedProperties = false, string detailsProptyName = null)
{
using (var fallbackFontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name +".Resources.calibril.ttf"))
using (var fallbackFontStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + ".Resources.calibril.ttf"))
{
LoadOptions.DefaultGraphicEngine = DefaultGraphicEngine.CreateWithFontsAndSystemFonts(fallbackFontStream);
}
@ -104,7 +104,7 @@ public class ClosedXmlExportImportService : IExportImportService
if (propertyType.Name == typeof(bool).Name)
{
var cdv = ws.Column(i + 1).CreateDataValidation();
var options = new List<string> { "是","否"};
var options = new List<string> { "是", "否" };
var validOptions = $"\"{string.Join(",", options)}\"";
cdv.List(validOptions, true);
}
@ -162,7 +162,7 @@ public class ClosedXmlExportImportService : IExportImportService
.FirstOrDefault();
property.SetValue(model, enumValue);
}
else if(propertyType.Name== nameof(Boolean))
else if (propertyType.Name == nameof(Boolean))
{
if (value.GetText() == "是")
{

49
be/Modules/Shared/src/Win_in.Sfs.Shared.Application/SfsCrudWithDetailsAppServiceBase.cs

@ -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)
};
}
}
}

Loading…
Cancel
Save