diff --git a/IRaCIS.Core.Application/Helper/FileDocProcess/ExcelExportHelper.cs b/IRaCIS.Core.Application/Helper/FileDocProcess/ExcelExportHelper.cs index e4d82de07..bf0861df9 100644 --- a/IRaCIS.Core.Application/Helper/FileDocProcess/ExcelExportHelper.cs +++ b/IRaCIS.Core.Application/Helper/FileDocProcess/ExcelExportHelper.cs @@ -16,6 +16,7 @@ using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System.Collections; using System.Globalization; +using Xceed.Document.NET; namespace IRaCIS.Core.Application.Service; @@ -85,27 +86,27 @@ public static class ExcelExportHelper foreach (var needTranslateProperty in needTranslatePropertyList) { - //翻译的属性依赖其他属性 - if (needTranslateProperty.IsTranslateDenpendOtherProperty) + if (itemDic.Keys.Any(t => t == needTranslateProperty.Name)) { - if (itemDic[needTranslateProperty.DependPropertyName]?.ToString().ToLower() == needTranslateProperty.DependPropertyValueStr.ToLower()) + //翻译的属性依赖其他属性 + if (needTranslateProperty.IsTranslateDenpendOtherProperty) + { + if (itemDic[needTranslateProperty.DependPropertyName]?.ToString().ToLower() == needTranslateProperty.DependPropertyValueStr.ToLower()) + { + var beforeValue = itemDic[needTranslateProperty.Name]?.ToString(); + + itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty; + } + } + //普通翻译 或者某一标准翻译 + else { var beforeValue = itemDic[needTranslateProperty.Name]?.ToString(); + itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty; } } - //普通翻译 或者某一标准翻译 - else - { - var beforeValue = itemDic[needTranslateProperty.Name]?.ToString(); - - - itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty; - } - - - } itemDic.Add("No", no++); @@ -125,6 +126,7 @@ public static class ExcelExportHelper translateData = dic; + } @@ -162,12 +164,49 @@ public static class ExcelExportHelper workbook.RemoveSheetAt(1); } - var memoryStream2 = new MemoryStream(); - workbook.Write(memoryStream2, true); + //中文替换项目术语 + if (isEn_US == false) + { + var replaceObjectList = data.TrialObjectNameList; + + var sheet = workbook.GetSheetAt(0); + + int rowCount = sheet.PhysicalNumberOfRows; + + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) + { + var row = sheet.GetRow(rowIndex); + var colums = row.LastCellNum; + + for (int colIndex = 0; colIndex < colums; colIndex++) + { + var cell = row.GetCell(colIndex); + + // 只处理字符串类型的单元格 + if (cell != null) + { + var cellValue = cell.StringCellValue; + + var find = replaceObjectList.FirstOrDefault(t => t.Name == cellValue); + if (find != null) + { + cell.SetCellValue(find.TrialName); + } + } + } + } + } + + using (var memoryStream2 = new MemoryStream()) + { + workbook.Write(memoryStream2, true); + + memoryStream2.Seek(0, SeekOrigin.Begin); + + templateStream = memoryStream2; + } - memoryStream2.Seek(0, SeekOrigin.Begin); - templateStream = memoryStream2; } // 文件名称 从sheet里面取 @@ -300,25 +339,29 @@ public static class ExcelExportHelper foreach (var needTranslateProperty in needTranslatePropertyList) { - //翻译的属性依赖其他属性 - if (needTranslateProperty.IsTranslateDenpendOtherProperty) + if (itemDic.Keys.Any(t => t == needTranslateProperty.Name)) { - if (itemDic[needTranslateProperty.DependPropertyName]?.ToString().ToLower() == needTranslateProperty.DependPropertyValueStr.ToLower()) + //翻译的属性依赖其他属性 + if (needTranslateProperty.IsTranslateDenpendOtherProperty) + { + if (itemDic[needTranslateProperty.DependPropertyName]?.ToString().ToLower() == needTranslateProperty.DependPropertyValueStr.ToLower()) + { + var beforeValue = itemDic[needTranslateProperty.Name]?.ToString(); + + itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty; + } + } + //普通翻译 或者某一标准翻译 + else { var beforeValue = itemDic[needTranslateProperty.Name]?.ToString(); + itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty; } } - //普通翻译 或者某一标准翻译 - else - { - var beforeValue = itemDic[needTranslateProperty.Name]?.ToString(); - itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).Select(t => isEn_US ? t.Value : t.ValueCN).FirstOrDefault() ?? String.Empty; - } - } @@ -371,6 +414,38 @@ public static class ExcelExportHelper workbook.RemoveSheetAt(1); } + //中文替换项目术语 + if (isEn_US == false) + { + var replaceObjectList = data.TrialObjectNameList; + + var sheet = workbook.GetSheetAt(0); + + int rowCount = sheet.PhysicalNumberOfRows; + + for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) + { + var row = sheet.GetRow(rowIndex); + var colums = row.LastCellNum; + + for (int colIndex = 0; colIndex < colums; colIndex++) + { + var cell = row.GetCell(colIndex); + + // 只处理字符串类型的单元格 + if (cell != null) + { + var cellValue = cell.StringCellValue; + + var find = replaceObjectList.FirstOrDefault(t => t.Name == cellValue); + if (find != null) + { + cell.SetCellValue(find.TrialName); + } + } + } + } + } if (dynamicColumnConfig != null) { @@ -391,7 +466,7 @@ public static class ExcelExportHelper var originTotalEndIndex = dynamicColumnConfig.TempalteLastColumnIndex; //减去动态移除后原始结束索引 - var originRemoveEndIndex= originTotalEndIndex- dynamicRemoveColunmCount; + var originRemoveEndIndex = originTotalEndIndex - dynamicRemoveColunmCount; //最终表 动态列开始索引 var dynamicColunmStartIndex = dynamicColumnConfig.AutoColumnStartIndex - beforeDynamicRemoveCount; @@ -513,8 +588,8 @@ public static class ExcelExportHelper //var writeIndex = itemList.IndexOf(itemObj) + dynamicColumnConfig.AutoColumnStartIndex; - var writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex; - + var writeIndex = dynamicColumnConfig.ColumnNameList.IndexOf(iteObjDic[dynamicColumnConfig.DynamicItemTitleName].ToString()) + dynamicColumnConfig.AutoColumnStartIndex; + if (itemDicName.IsNotNullOrEmpty()) { diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialViewModel.cs index 70894a30d..cf76591ed 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/TrialViewModel.cs @@ -88,7 +88,7 @@ namespace IRaCIS.Application.Contracts public string CriterionName { get; set; } = string.Empty; - + public List TrialObjectNameList { get; set; } } public class TrialModalitySelectDto diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index e5c04e10f..f4f70b2fe 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -77,9 +77,8 @@ public class IRaCISDBContext : DbContext }); modelBuilder.Entity(entity => - { - - + { + //项目术语配置 entity.OwnsMany(x => x.TrialObjectNameList, ownedNavigationBuilder => { ownedNavigationBuilder.ToJson(); diff --git a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs index 3c5061e7c..a3224346c 100644 --- a/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs +++ b/IRaCIS.Core.Infra.EFCore/Interceptor/AuditEntityInterceptor.cs @@ -3,11 +3,14 @@ using IRaCIS.Core.Domain.BaseModel; using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Infra.EFCore.Common; +using IRaCIS.Core.Infrastructure.Extention; using MassTransit; using MassTransit.Mediator; using MassTransit.Transports; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic; +using System.Collections; using System.Data; @@ -75,9 +78,18 @@ public class AuditEntityInterceptor(IUserInfo _userInfo, //.Where(x => !typeof(DataInspection).IsAssignableFrom(x.Entity.GetType())) .ToList()) { + + + + //foreach (var property in entry.Navigations.Where(t => typeof(IEnumerable).IsAssignableFrom(t.Metadata.ClrType) && t.Metadata.ClrType !=typeof(string) /*&& t.CurrentValue == null*/)) + //{ + // Console.WriteLine($"属性名{property.Metadata.Name} 现在值:{property.CurrentValue.ToJsonStr()}"); + //} + // 检查属性是否为string类型,并且值为null foreach (var property in entry.Properties.Where(t => t.Metadata.ClrType == typeof(string) && t.CurrentValue == null)) { + property.CurrentValue = string.Empty; }