From 8dedacf1cdbf7795dfcbce48460ab4fde3c4da71 Mon Sep 17 00:00:00 2001 From: mahao Date: Mon, 3 Apr 2023 16:48:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=BC=82=E5=B8=B8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=BC=82=E5=B8=B8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClosedXmlExportImportService.cs | 8 +-- .../SfsCrudWithDetailsAppServiceBase.cs | 51 ++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-) 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 dfdd4e0dc..cec935fa0 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,6 +6,7 @@ using System.Linq; using System.Linq.Dynamic.Core; using System.Linq.Expressions; using System.Reflection; +using System.Text; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -508,13 +509,14 @@ public abstract class SfsCrudWithDetailsAppServiceBase protected virtual async Task 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 静态验证 @@ -550,7 +552,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) + }; + } } }