diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs index 61c84d4e9..959560ceb 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/ExportAndImport/ClosedXmlExportImportService.cs +++ b/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 string ContentType => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; - + public FileContentResult Export(List 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 { "是","否"}; + var options = new List { "是", "否" }; 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() == "是") { diff --git a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/SfsCrudWithDetailsAppServiceBase.cs b/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/SfsCrudWithDetailsAppServiceBase.cs index 53375f171..cf7f7c0cb 100644 --- a/be/Modules/Shared/src/Win_in.Sfs.Shared.Application/SfsCrudWithDetailsAppServiceBase.cs +++ b/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,13 +512,14 @@ public abstract class SfsCrudWithDetailsAppServiceBase ImportInternalAsync(SfsImportRequestInput requestInput, byte[] inputFileBytes) { + IList modelList = null; + var modelDict = new Dictionary>(); + var entityDict = new Dictionary(); try { var hasDetails = typeof(TEntity).GetInterfaces().Any(o => o.IsGenericType && o.GetGenericTypeDefinition() == typeof(IMasterEntity<>)); - var modelList = ExportImportService.Import(inputFileBytes); - var modelDict = new Dictionary>(); - var entityDict = new Dictionary(); - + modelList = ExportImportService.Import(inputFileBytes); + foreach (var model in modelList) { // DataAnnotations 静态验证 @@ -555,7 +555,7 @@ public abstract class SfsCrudWithDetailsAppServiceBase 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) + }; + } } }