diff --git a/IRaCIS.Core.Application/Helper/ExcelExportHelper.cs b/IRaCIS.Core.Application/Helper/ExcelExportHelper.cs index 84a8f7dc8..8493931f8 100644 --- a/IRaCIS.Core.Application/Helper/ExcelExportHelper.cs +++ b/IRaCIS.Core.Application/Helper/ExcelExportHelper.cs @@ -1,7 +1,11 @@ using DocumentFormat.OpenXml.Drawing.Diagrams; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; +using IRaCIS.Application.Contracts; using IRaCIS.Application.Interfaces; using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Domain.Share; +using Magicodes.ExporterAndImporter.Excel; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; @@ -9,17 +13,22 @@ using MiniExcelLibs.OpenXml; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NPOI.HSSF.UserModel; +using NPOI.XSSF.UserModel; +using SkiaSharp; +using System.IO; namespace IRaCIS.Core.Application.Service; public static class ExcelExportHelper { //MiniExcel_Export - public static async Task DataExportAsync(string code, object data, string exportFileNamePrefix, IRepository _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null) + public static async Task DataExportAsync(string code, ExcelExportInfo data, string exportFileNamePrefix, IRepository _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null) { //判断是否有字典翻译 + object translateData = data; + if (_dictionaryService != null && translateType != null) { @@ -32,7 +41,7 @@ public static class ExcelExportHelper var needTranslatePropertyList = translateType.GetProperties().Where(t => t.IsDefined(typeof(DictionaryTranslateAttribute), true)) .SelectMany(c => c.GetCustomAttributes(typeof(DictionaryTranslateAttribute), false).Select(f => (DictionaryTranslateAttribute?)f).Where(t => t?.CriterionType == criterionType || t?.CriterionType == null) - .Select(k => new { c.Name, k.DicParentCode ,k.IsTranslateDenpendOtherProperty, k.DependPropertyName,k.DependPropertyValueStr}) + .Select(k => new { c.Name, k.DicParentCode, k.IsTranslateDenpendOtherProperty, k.DependPropertyName, k.DependPropertyValueStr }) ).ToList(); @@ -61,7 +70,7 @@ public static class ExcelExportHelper foreach (var needTranslateProperty in needTranslatePropertyList) { //翻译的属性依赖其他属性 - if(needTranslateProperty.IsTranslateDenpendOtherProperty) + if (needTranslateProperty.IsTranslateDenpendOtherProperty) { if (item[needTranslateProperty.DependPropertyName]?.ToString().ToLower() == needTranslateProperty.DependPropertyValueStr.ToLower()) { @@ -78,7 +87,7 @@ public static class ExcelExportHelper itemDic[needTranslateProperty.Name] = translateDataList[needTranslateProperty.DicParentCode].Where(t => t.Code.ToLower() == beforeValue?.ToLower()).FirstOrDefault()?.ValueCN ?? String.Empty; } - + } @@ -89,14 +98,15 @@ public static class ExcelExportHelper newObjList.Add(itemDic); } - dic[key] = newObjList ; + dic[key] = newObjList; } } - data = dic; + //data = dic; + translateData = dic; } @@ -110,6 +120,43 @@ public static class ExcelExportHelper //模板路径 var tplPath = physicalPath; + #region 根据中英文 删除模板sheet + + // 打开模板文件 + var templateFile = new FileStream(tplPath, FileMode.Open, FileAccess.Read); + + // 获取文件流 + var templateStream = new MemoryStream(); + templateFile.CopyTo(templateStream); + templateStream.Seek(0, SeekOrigin.Begin); + + var workbook = new XSSFWorkbook(templateStream); + + int sheetCount = workbook.NumberOfSheets; + + if (sheetCount == 2) + { + if (data.IsEn_US) + { + workbook.RemoveSheetAt(1); + } + else + { + workbook.RemoveSheetAt(0); + } + + var memoryStream2 = new MemoryStream(); + workbook.Write(memoryStream2); + + memoryStream2.Seek(0, SeekOrigin.Begin); + + templateStream = memoryStream2; + } + + #endregion + + + #region MiniExcel var memoryStream = new MemoryStream(); @@ -119,10 +166,39 @@ public static class ExcelExportHelper IgnoreTemplateParameterMissing = true, }; - await MiniExcel.SaveAsByTemplateAsync(memoryStream, tplPath, data, config); + await MiniExcel.SaveAsByTemplateAsync(memoryStream, templateStream.ToArray(), translateData, config); memoryStream.Seek(0, SeekOrigin.Begin); + #region 根据中英文 删除sheet + //var workbook = new XSSFWorkbook(memoryStream); + + //int sheetCount = workbook.NumberOfSheets; + + //if (sheetCount == 2) + //{ + + // if (data.IsEn_US) + // { + // workbook.RemoveSheetAt(0); + // } + // else + // { + // workbook.RemoveSheetAt(1); + // } + + // var memoryStream2 = new MemoryStream(); + // workbook.Write(memoryStream2); + + // memoryStream2.Seek(0, SeekOrigin.Begin); + + // memoryStream = memoryStream2; + //} + + + + #endregion + return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"{exportFileNamePrefix}_{fileNmae.Substring(0, fileNmae.LastIndexOf('.'))}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx" @@ -146,7 +222,7 @@ public static class ExcelExportHelper - public static async Task<(MemoryStream,string)> DataExport_NpoiTestAsync(string code, object data, IRepository _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null) + public static async Task<(MemoryStream, string)> DataExport_NpoiTestAsync(string code, object data, IRepository _commonDocumentRepository, IWebHostEnvironment _hostEnvironment, IDictionaryService? _dictionaryService = null, Type? translateType = null, CriterionType? criterionType = null) { //判断是否有字典翻译 @@ -231,7 +307,7 @@ public static class ExcelExportHelper var (physicalPath, fileName) = await FileStoreHelper.GetCommonDocPhysicalFilePathAsync(_hostEnvironment, _commonDocumentRepository, code); - + //模板路径 var tplPath = physicalPath; diff --git a/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs b/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs index 24dd1e858..b3d9c88fd 100644 --- a/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs +++ b/IRaCIS.Core.Application/Service/Common/ExcelExportService.cs @@ -73,7 +73,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == visitSearchDTO.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; - + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialCRCUploadImageList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(CRCVisitExportDTO)); @@ -123,6 +123,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == challengeQuery.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialQCImageChanllengeList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(QCChanllengeExportDto)); } @@ -159,6 +160,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == param.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialSubjectList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(SubjectExportDTO)); @@ -266,6 +268,7 @@ namespace IRaCIS.Core.Application.Service.Common exportInfo.CriterionName = await _repository.Where(u => u.TrialId == dto.TrialId && u.IsConfirm && u.Id == dto.TrialReadingCriterionId).Select(t => t.CriterionName).FirstOrDefaultAsync(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; var (memoryStream, fileName) = await ExcelExportHelper.DataExport_NpoiTestAsync(StaticData.Export.TrialSubjectProgressList_Export, exportInfo, /*"", */_commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(SubjectProgressDto)); @@ -405,6 +408,8 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == studyQuery.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; + return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialStudyUploadMonitor_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(UnionStudyMonitorExportDto)); @@ -439,6 +444,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == param.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialSubjectReadingPeriodList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(ReadPeriodExportDto)); @@ -527,6 +533,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == studyQuery.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialStudyList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(UnionStudyExportDTO)); } @@ -565,6 +572,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == checkQuery.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialSubjectVisitCheckList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(PMKCheckEXportDTO)); } @@ -615,6 +623,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == queryVisitTask.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialReadingTaskList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(ReadingTaskExportDto)); } @@ -665,6 +674,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == queryVisitTask.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialReReadingTaskList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(ReReadingTaskExportDto)); } @@ -706,6 +716,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == inQuery.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialMedicalReviewList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(TaskMedicalReviewExportDto)); } @@ -789,6 +800,7 @@ namespace IRaCIS.Core.Application.Service.Common exportInfo.CriterionName = await _repository.Where(u => u.TrialId == queryVisitTask.TrialId && u.IsConfirm && u.Id == queryVisitTask.TrialReadingCriterionId).Select(t => t.CriterionName).FirstOrDefaultAsync(); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialSelfAnalysisList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}_{exportInfo.CriterionName}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(SelftAnalysisExport)); } @@ -892,6 +904,7 @@ namespace IRaCIS.Core.Application.Service.Common var exportInfo = (await _trialRepository.Where(t => t.Id == queryVisitTask.TrialId).IgnoreQueryFilters().ProjectTo(_mapper.ConfigurationProvider).FirstOrDefaultAsync()).IfNullThrowException(); exportInfo.CriterionName = await _repository.Where(u => u.TrialId == queryVisitTask.TrialId && u.IsConfirm && u.Id == queryVisitTask.TrialReadingCriterionId).Select(t => t.CriterionName).FirstOrDefaultAsync(); exportInfo.List = newList; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialGroupAnalysisList_Export, exportInfo, $"{exportInfo.ResearchProgramNo}_{exportInfo.CriterionName}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(GroupAnalysisExport)); } @@ -1044,6 +1057,7 @@ namespace IRaCIS.Core.Application.Service.Common list = DealJudgeMark(criterion.ArbitrationRule, list); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.OverallTumorEvaluation_Export, exportInfo, $"{exportInfo.ResearchProgramNo}_{exportInfo.CriterionName}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(OverallTumorEvaluationExport), criterion.CriterionType); @@ -1102,6 +1116,7 @@ namespace IRaCIS.Core.Application.Service.Common list = DealJudgeMark(criterion.ArbitrationRule, list); exportInfo.List = list; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.RECIST1Point1EvaluationOfTumorEfficacy_Export, exportInfo, $"{exportInfo.ResearchProgramNo}_{exportInfo.CriterionName}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(RECIST1Point1EvaluationOfTumorEfficacyExport), criterion.CriterionType); @@ -1192,6 +1207,7 @@ namespace IRaCIS.Core.Application.Service.Common //处理裁判标记 list = DealJudgeMark(criterion.ArbitrationRule, list); exportInfo.List = exportList; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.RECIST1Point1DetailedOfEvaluatedLesion_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(RECIST1Point1DetailedOfEvaluatedLesionExport), criterion.CriterionType); @@ -1224,6 +1240,7 @@ namespace IRaCIS.Core.Application.Service.Common //处理裁判标记 list = DealJudgeMark(criterion.ArbitrationRule, list); exportInfo.List = exportList; + exportInfo.IsEn_US = _userInfo.IsEn_Us; return await ExcelExportHelper.DataExportAsync(StaticData.Export.PCWG3Point1DetailedOfEvaluatedLesion_Export, exportInfo, $"{exportInfo.ResearchProgramNo}", _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(PCWG3DetailedOfEvaluatedLesionExport), criterion.CriterionType); diff --git a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs index e3bd78cbe..4350eaa76 100644 --- a/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs +++ b/IRaCIS.Core.Application/Service/TrialSiteUser/DTO/UserTrialViewModel.cs @@ -115,6 +115,7 @@ namespace IRaCIS.Application.Contracts { public DateTime CurrentTime { get; set; } = DateTime.Now; + public bool IsEn_US { get; set; } public object List { get; set; } diff --git a/IRaCIS.Core.Domain/SQLFile/4.21号发布后维护.sql b/IRaCIS.Core.Domain/SQLFile/4.21号发布后维护.sql index 77b3e0341..372622e10 100644 --- a/IRaCIS.Core.Domain/SQLFile/4.21号发布后维护.sql +++ b/IRaCIS.Core.Domain/SQLFile/4.21号发布后维护.sql @@ -121,6 +121,10 @@ UPDATE Trial SET IndicationEnum = CASE select DISTINCT IndicationEnum ,Indication from Trial +-- 附加评估发布设置之前的默认值 +Update ReadingQuestionCriterionTrial set IsAdditionalAssessment=0,IsAutoCreate=1 + +