Browse Source

解决冲突

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

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

@ -23,10 +23,10 @@ namespace Win_in.Sfs.Shared.Application;
public class ClosedXmlExportImportService : IExportImportService public class ClosedXmlExportImportService : IExportImportService
{ {
public string ContentType => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; public string ContentType => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
public FileContentResult Export<TModel>(List<TModel> list, bool includeAuditedProperties = false, string detailsProptyName = null) 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); LoadOptions.DefaultGraphicEngine = DefaultGraphicEngine.CreateWithFontsAndSystemFonts(fallbackFontStream);
} }
@ -104,7 +104,7 @@ public class ClosedXmlExportImportService : IExportImportService
if (propertyType.Name == typeof(bool).Name) if (propertyType.Name == typeof(bool).Name)
{ {
var cdv = ws.Column(i + 1).CreateDataValidation(); var cdv = ws.Column(i + 1).CreateDataValidation();
var options = new List<string> { "是","否"}; var options = new List<string> { "是", "否" };
var validOptions = $"\"{string.Join(",", options)}\""; var validOptions = $"\"{string.Join(",", options)}\"";
cdv.List(validOptions, true); cdv.List(validOptions, true);
} }
@ -162,7 +162,7 @@ public class ClosedXmlExportImportService : IExportImportService
.FirstOrDefault(); .FirstOrDefault();
property.SetValue(model, enumValue); property.SetValue(model, enumValue);
} }
else if(propertyType.Name== nameof(Boolean)) else if (propertyType.Name == nameof(Boolean))
{ {
if (value.GetText() == "是") if (value.GetText() == "是")
{ {

51
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.Dynamic.Core;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Security.Principal;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -513,13 +512,14 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq
[UnitOfWork] [UnitOfWork]
protected virtual async Task<SfsImportResult> ImportInternalAsync(SfsImportRequestInput requestInput, byte[] inputFileBytes) 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 try
{ {
var hasDetails = typeof(TEntity).GetInterfaces().Any(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IMasterEntity<>)); var hasDetails = typeof(TEntity).GetInterfaces().Any(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IMasterEntity<>));
var modelList = ExportImportService.Import<TImportInput>(inputFileBytes); modelList = ExportImportService.Import<TImportInput>(inputFileBytes);
var modelDict = new Dictionary<TImportInput, List<ValidationResult>>();
var entityDict = new Dictionary<TEntity, EntityState>();
foreach (var model in modelList) foreach (var model in modelList)
{ {
// DataAnnotations 静态验证 // DataAnnotations 静态验证
@ -555,7 +555,7 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq
// 批量更新 // 批量更新
if (entityDict.Any()) if (entityDict.Any())
{ {
entityDict=await ImportProcessingEntityAsync(entityDict).ConfigureAwait(false); entityDict=await ImportProcessingEntityAsync(entityDict);
// 调用批量验证 // 调用批量验证
var entityListStatus = await ValidateImportEntities(entityDict).ConfigureAwait(false); var entityListStatus = await ValidateImportEntities(entityDict).ConfigureAwait(false);
@ -581,7 +581,44 @@ public abstract class SfsCrudWithDetailsAppServiceBase<TEntity, TEntityDto, TReq
catch (Exception ex) catch (Exception ex)
{ {
Logger.LogException(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