From 3e375ea6d1b401756efe4261be03d3857a54654e Mon Sep 17 00:00:00 2001 From: he <109787524@qq.com> Date: Fri, 27 Sep 2024 15:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reading/Dto/ReadingCalculateViewModel.cs | 8 +++++- .../General/GeneralCalculateService.cs | 13 +++++----- .../ReadingCalculate/IVUSCalculateService.cs | 13 ++++++++-- .../Interface/IGeneralCalculateService.cs | 2 +- .../ReadingCalculate/OCTCalculateService.cs | 25 ++++++++++++++++--- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs index 2d2cc2469..00e20b823 100644 --- a/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs +++ b/IRaCIS.Core.Application/Service/Reading/Dto/ReadingCalculateViewModel.cs @@ -4,6 +4,7 @@ // 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。 //-------------------------------------------------------------------- using IRaCIS.Core.Domain.Share; +using System.Data; namespace IRaCIS.Core.Application.Service.Reading.Dto { @@ -283,7 +284,12 @@ namespace IRaCIS.Core.Application.Service.Reading.Dto public decimal Data { get; set; } } - + public class FileToDataTableDto + { + public DataTable DataTable { get; set; } + + public List SheetNames { get; set; } + } /// /// 阅片计算Dto diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs index 32d63d863..d39b56af1 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/General/GeneralCalculateService.cs @@ -35,12 +35,12 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate /// 从上传文件中获取Datatable /// /// - public async Task GetDataTableFromUpload(IFormFile file,string pathCode,Guid trialId) + public async Task GetDataTableFromUpload(IFormFile file,string pathCode,Guid trialId) { - + FileToDataTableDto result=new FileToDataTableDto (); - DataTable result = new DataTable(); + result.DataTable = new DataTable(); var fileFolder = "Upload\\"; if (!Directory.Exists(fileFolder)) { @@ -59,8 +59,9 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate file.CopyTo(stream); await stream.CopyToAsync(fileStream); + result.SheetNames= stream.GetSheetNames(); stream.Position = 0; - result = stream.QueryAsDataTable(useHeaderRow: false); + result.DataTable = stream.QueryAsDataTable(useHeaderRow: false); } } catch (Exception) @@ -89,7 +90,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate var rowsToRemove = new System.Collections.Generic.List(); // 遍历DataTable的每一行 - foreach (DataRow row in result.Rows) + foreach (DataRow row in result.DataTable.Rows) { bool allEmpty = true; @@ -113,7 +114,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate // 移除标记为待删除的行 foreach (var row in rowsToRemove) { - result.Rows.Remove(row); + result.DataTable.Rows.Remove(row); } return result; } diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs index b91574def..a170258ae 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/IVUSCalculateService.cs @@ -604,9 +604,18 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate var file = request.Form.Files[0]; Guid visitTaskId = Guid.Parse(request.Form["VisitTaskId"]); var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.Subject).Include(x => x.TrialReadingCriterion).FirstNotNullAsync(); - var dataTable =await _generalCalculateService.GetDataTableFromUpload(file, "IVUSTemplate", taskinfo.TrialId); + var uploadInfo =await _generalCalculateService.GetDataTableFromUpload(file, "IVUSTemplate", taskinfo.TrialId); - + List sheetNames = new List() + { + "各匹配片段测量值","MeasuredValue" + }; + + if (sheetNames.Intersect(uploadInfo.SheetNames).Count() == 0) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UplpadDataError"]); + } + var dataTable = uploadInfo.DataTable; var values = new TemplateData() { diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/Interface/IGeneralCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/Interface/IGeneralCalculateService.cs index 4444c111a..9eaefec17 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/Interface/IGeneralCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/Interface/IGeneralCalculateService.cs @@ -44,6 +44,6 @@ namespace IRaCIS.Core.Application.Service /// /// /// - Task GetDataTableFromUpload(IFormFile file, string pathCode, Guid trialId); + Task GetDataTableFromUpload(IFormFile file, string pathCode, Guid trialId); } } diff --git a/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs b/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs index bda78b098..d778140f8 100644 --- a/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs +++ b/IRaCIS.Core.Application/Service/ReadingCalculate/OCTCalculateService.cs @@ -471,9 +471,18 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate var file = request.Form.Files[0]; Guid visitTaskId = Guid.Parse(request.Form["VisitTaskId"]); var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.Subject).Include(x => x.TrialReadingCriterion).FirstNotNullAsync(); - var dataTable = await _generalCalculateService.GetDataTableFromUpload(file, "OCTFCT", taskinfo.TrialId); + var uploadInfo = await _generalCalculateService.GetDataTableFromUpload(file, "OCTFCT", taskinfo.TrialId); - + List sheetNames = new List() + { + "FCT导入","FCT" + }; + + if (sheetNames.Intersect(uploadInfo.SheetNames).Count() == 0) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UplpadDataError"]); + } + var dataTable = uploadInfo.DataTable; var values = new TemplateData() { @@ -648,9 +657,17 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate var file = request.Form.Files[0]; Guid visitTaskId = Guid.Parse(request.Form["VisitTaskId"]); var taskinfo = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.Subject).Include(x => x.TrialReadingCriterion).FirstNotNullAsync(); - var dataTable = await _generalCalculateService.GetDataTableFromUpload(file, "OCTLipidAngle", taskinfo.TrialId); + var uploadInfo = await _generalCalculateService.GetDataTableFromUpload(file, "OCTLipidAngle", taskinfo.TrialId); + List sheetNames = new List() + { + "脂质角度","LipidAngle" + }; - + if (sheetNames.Intersect(uploadInfo.SheetNames).Count() == 0) + { + throw new BusinessValidationFailedException(_localizer["IVUS_UplpadDataError"]); + } + var dataTable = uploadInfo.DataTable; var values = new TemplateData() {