From 2c3f35c26b93e11027aef8a2ca01afe05b168882 Mon Sep 17 00:00:00 2001 From: hang <872297557@qq.com> Date: Thu, 7 Aug 2025 15:37:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=B1=E5=83=8F=E6=B1=87=E6=80=BB=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRaCIS.Core.Application/Helper/OSSService.cs | 4 +- .../Common/TrialImageDownloadService.cs | 43 ++++++++++++++++--- .../ImageAndDoc/DTO/UnionStudyViewDodel.cs | 25 +++++++++++ .../ImageAndDoc/DownloadAndUploadService.cs | 19 +++++--- 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/IRaCIS.Core.Application/Helper/OSSService.cs b/IRaCIS.Core.Application/Helper/OSSService.cs index 9199c19c6..6138d2cfc 100644 --- a/IRaCIS.Core.Application/Helper/OSSService.cs +++ b/IRaCIS.Core.Application/Helper/OSSService.cs @@ -389,14 +389,12 @@ public class OSSService : IOSSService var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, AliyunOSSTempToken.AccessKeyId, AliyunOSSTempToken.AccessKeySecret, AliyunOSSTempToken.SecurityToken); - // 上传文件 var result = _ossClient.GetObject(aliConfig.BucketName, ossRelativePath); // 将下载的文件流保存到本地文件 using (var fs = File.OpenWrite(localFilePath)) { - result.Content.CopyTo(fs); - fs.Close(); + await result.Content.CopyToAsync(fs); } } diff --git a/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs b/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs index 87a6bac1f..0de78c012 100644 --- a/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs +++ b/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs @@ -180,21 +180,50 @@ namespace IRaCIS.Core.Application.Service } + #region 异步方式处理 - const int batchSize = 15; int totalCount = downloadJobs.Count; int downloadedCount = 0; - for (int i = 0; i < downloadJobs.Count; i += batchSize) + foreach (var job in downloadJobs) { - var batch = downloadJobs.Skip(i).Take(batchSize).Select(job => job()); + try + { + await job(); + } + catch (Exception ex) + { + Console.WriteLine($"下载失败: {ex.Message}"); + } - await Task.WhenAll(batch); + downloadedCount++; - downloadedCount += batch.Count(); - - Console.WriteLine($"已下载 {downloadedCount} / {totalCount} 个文件,完成 {(downloadedCount * 100.0 / totalCount):F2}%"); + // 每处理50个,输出一次进度(或最后一个时也输出) + if (downloadedCount % 50 == 0 || downloadedCount == totalCount) + { + Console.WriteLine($"已下载 {downloadedCount} / {totalCount} 个文件,完成 {(downloadedCount * 100.0 / totalCount):F2}%"); + } } + #endregion + + #region 多线程测试 + + //const int batchSize = 15; + //int totalCount = downloadJobs.Count; + //int downloadedCount = 0; + + //for (int i = 0; i < downloadJobs.Count; i += batchSize) + //{ + // var batch = downloadJobs.Skip(i).Take(batchSize).Select(job => job()); + + // await Task.WhenAll(batch); + + // downloadedCount += batch.Count(); + + // Console.WriteLine($"已下载 {downloadedCount} / {totalCount} 个文件,完成 {(downloadedCount * 100.0 / totalCount):F2}%"); + //} + #endregion + } return ResponseOutput.Ok(); diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs index c188dbd04..6422b2645 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DTO/UnionStudyViewDodel.cs @@ -612,6 +612,9 @@ namespace IRaCIS.Core.Application.Contracts public bool IsKeyImage { get; set; } + + // true 导出阅片,null 就是所有影像 + public bool? IsExportReading { get; set; } } @@ -655,10 +658,16 @@ namespace IRaCIS.Core.Application.Contracts public long? TotalImageSize { get; set; } + public long? TotalReadingImageSize { get; set; } + public string TotalImageSizeStr => TotalImageSize.HasValue ? $"{TotalImageSize.Value / 1024d / 1024d:F3} MB" : "0.000 MB"; + public string TotalReadingImageSizeStr => TotalReadingImageSize.HasValue + ? $"{TotalReadingImageSize.Value / 1024d / 1024d:F3} MB" + : "0.000 MB"; + public string ImageTypeStr => $"{(IsHaveDicom ? "DICOM" : "")}{(IsHaveNoneDicom&&IsHaveDicom?" , ":"")}{(IsHaveNoneDicom ? "Non-DICOM" : "")}"; public bool IsHaveDicom { get; set; } @@ -710,6 +719,22 @@ namespace IRaCIS.Core.Application.Contracts ? $"{TotalImageSize.Value / SubjectVisitCount / 1024d / 1024d:F3} MB" : "0.000 MB"; + public long? TotalReadingImageSize { get; set; } + + + public string TotalReadingImageSizeStr => TotalReadingImageSize.HasValue + ? $"{TotalReadingImageSize.Value / 1024d / 1024d:F3} MB" + : "0.000 MB"; + + + public string SubjectReadingImageAVGSizeStr => TotalReadingImageSize.HasValue + ? $"{TotalReadingImageSize.Value / SubjectCount / 1024d / 1024d:F3} MB" + : "0.000 MB"; + + + public string SubjectVisitReadingImageAVGSizeStr => TotalReadingImageSize.HasValue + ? $"{TotalReadingImageSize.Value / SubjectVisitCount / 1024d / 1024d:F3} MB" + : "0.000 MB"; } public class TrialImageDownloadView diff --git a/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs b/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs index c468fb52f..186e25183 100644 --- a/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs +++ b/IRaCIS.Core.Application/Service/ImageAndDoc/DownloadAndUploadService.cs @@ -1218,6 +1218,9 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc TotalImageSize = t.StudyList.SelectMany(t => t.InstanceList).Sum(t => t.FileSize) + t.NoneDicomStudyList.SelectMany(t => t.NoneDicomFileList).Sum(t => t.FileSize), + TotalReadingImageSize = t.StudyList.SelectMany(t => t.InstanceList.Where(t => t.IsReading && t.DicomSerie.IsReading)).Sum(t => t.FileSize) + + t.NoneDicomStudyList.Where(t => t.IsReading).SelectMany(t => t.NoneDicomFileList.Where(t => t.IsReading)).Sum(t => t.FileSize), + //DicomStudyCount = t.StudyList.Count(), //NoneDicomStudyCount = t.NoneDicomStudyList.Count(), @@ -1249,6 +1252,10 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc { SubjectId = g.Key, VisitCount = g.Count(), + ReadingImageSize = g.SelectMany(t => t.NoneDicomStudyList.Where(t => t.IsReading)).SelectMany(t => t.NoneDicomFileList.Where(t => t.IsReading)).Sum(t => t.FileSize) + + + g.SelectMany(t => t.StudyList).SelectMany(t => t.InstanceList.Where(t => t.IsReading && t.DicomSerie.IsReading)).Sum(t => t.FileSize), + ImageSize = g.SelectMany(t => t.NoneDicomStudyList).SelectMany(t => t.NoneDicomFileList).Sum(t => t.FileSize) + g.SelectMany(t => t.StudyList).SelectMany(t => t.InstanceList).Sum(t => t.FileSize) @@ -1261,7 +1268,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc var totalImageSize = subjectImageList.Sum(t => t.ImageSize); - return ResponseOutput.Ok(new TrialImageStatInfo { SubjectCount = subjectCount, SubjectVisitCount = subjectVisitCount, TotalImageSize = totalImageSize }); + return ResponseOutput.Ok(new TrialImageStatInfo { SubjectCount = subjectCount, SubjectVisitCount = subjectVisitCount, TotalImageSize = totalImageSize,Tot }); } @@ -1275,6 +1282,8 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc public async Task GetExportSubjectVisitImageList(TrialExportImageCommand inCommand) { + var isExportReading = inCommand.IsExportReading == true; + if (inCommand.IsKeyImage) { var downloadInfoList = _visitTaskRepository.Where(t => t.TrialId == inCommand.TrialId && (t.ReadingCategory == ReadingCategory.Visit || t.ReadingCategory == ReadingCategory.Global) @@ -1538,11 +1547,11 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc u.StudyTime, u.StudyCode, - SeriesList = u.SeriesList.Select(z => new + SeriesList = u.SeriesList.Where(t => isExportReading ? t.IsReading : true).Select(z => new { z.Modality, - InstancePathList = z.DicomInstanceList.Select(k => new + InstancePathList = z.DicomInstanceList.Where(t => isExportReading ? t.IsReading : true).Select(k => new { k.Path }) @@ -1550,13 +1559,13 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc }), - NoneDicomStudyList = sv.NoneDicomStudyList.Select(nd => new + NoneDicomStudyList = sv.NoneDicomStudyList.Where(t => isExportReading ? t.IsReading : true).Select(nd => new { nd.Modality, nd.StudyCode, nd.ImageDate, - FileList = nd.NoneDicomFileList.Select(file => new + FileList = nd.NoneDicomFileList.Where(t => isExportReading ? t.IsReading : true).Select(file => new { file.FileName, file.Path,