diff --git a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml
index 8fb7014f5..fcddf3798 100644
--- a/IRaCIS.Core.Application/IRaCIS.Core.Application.xml
+++ b/IRaCIS.Core.Application/IRaCIS.Core.Application.xml
@@ -1124,7 +1124,7 @@
-
+
读取excel 恢复oss 数据,读取dicom 恢复序列和Instance
diff --git a/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs b/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs
index a1c09a56c..443d521f3 100644
--- a/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs
+++ b/IRaCIS.Core.Application/Service/Common/TrialImageDownloadService.cs
@@ -1528,15 +1528,22 @@ namespace IRaCIS.Core.Application.Service
///
///
///
- public async Task ReadExcelReStorreOSSDeleteDataAndDBData([FromServices] IOSSService _oSSService, [FromServices] IWebHostEnvironment _hostEnvironment)
+ [AllowAnonymous]
+ public async Task ReadExcelReStorreOSSDeleteDataAndDBData([FromServices] IOSSService _oSSService, [FromServices] IWebHostEnvironment _hostEnvironment, string subjectCode)
{
var folder = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
var trialId = Guid.Parse("01000000-ac13-0242-6397-08dcd2d2a091");
- var rows = await MiniExcel.QueryAsync(@"C:\Users\hang\Desktop\删除恢复.xlsx");
+ var rows = await MiniExcel.QueryAsync(Path.Combine(folder, "删除恢复.xlsx"));
- rows = rows.Where(t => !string.IsNullOrEmpty(t.FileName.ToString())).ToList();
+ var restoreRows = await MiniExcel.QueryAsync(Path.Combine(folder, "删除需要恢复的数据.xlsx"));
+
+ rows = rows.Where(t => t.Key.IsNotNullOrEmpty()).WhereIf(subjectCode.IsNotNullOrEmpty(), t => t.SubjectCode == subjectCode.TrimStart('0')).ToList();
+
+ restoreRows = restoreRows.Where(t => t.SOPInstanceUID.IsNotNullOrEmpty()).WhereIf(subjectCode.IsNotNullOrEmpty(), t => t.SubjectCode == subjectCode).ToList();
+
+ Console.WriteLine($"恢复数量: {restoreRows.Count()}");
int total = rows.Count();
int processed = 0;
@@ -1554,39 +1561,21 @@ namespace IRaCIS.Core.Application.Service
tempToken.AliyunOSS.SecurityToken);
+ var restoreCount = 0;
foreach (var item in rows)
{
- #region 防止阿里云过期
- if (tempToken.AliyunOSS.Expiration.AddSeconds(10) <= DateTime.Now)
+ //不包含该subject的忽略
+ if (!restoreRows.Any(t => t.SubjectCode.TrimStart('0') == item.SubjectCode))
{
- tempToken = _oSSService.GetObjectStoreTempToken();
-
- _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint,
- tempToken.AliyunOSS.AccessKeyId,
- tempToken.AliyunOSS.AccessKeySecret,
- tempToken.AliyunOSS.SecurityToken);
+ continue;
}
- #endregion
-
-
- // 创建 CopyObject 请求
- // 先用构造函数指定源和目标
- var copyReq = new CopyObjectRequest(
- sourceBucketName: tempToken.AliyunOSS.BucketName,
- sourceKey: item.Key,
- destinationBucketName: tempToken.AliyunOSS.BucketName,
- destinationKey: item.Key // 覆盖到同名 Key,达到“恢复”的效果
- );
-
- // 再设置版本号
- copyReq.SourceVersionId = item.VersionId;
-
-
-
try
{
- var copyResult = _ossClient.CopyObject(copyReq);
+
+ //根据本地文件匹配studyInstanceUid 不匹配忽略
+
+ var localPath = Path.Combine(folder, item.RelativePath);
#region 读取本地dicom ,判断数据库是否存在该序列
@@ -1596,11 +1585,51 @@ namespace IRaCIS.Core.Application.Service
var dicomFile = await DicomFile.OpenAsync(dicomFilePath);
+ string sopInstanceUid = dicomFile.Dataset.GetSingleValueOrDefault(DicomTag.SOPInstanceUID, string.Empty);
+
+
+ if (!restoreRows.Any(t => t.SOPInstanceUID == sopInstanceUid))
+ {
+ continue;
+ }
+
+ restoreCount++;
+
+ Console.WriteLine($"恢复SOPInstanceUID{sopInstanceUid},当前数量{restoreCount}");
+
await ArchiveDicomFileAsync(dicomFile.Dataset, trialId, item.SubjectId, item.SubjectVisitId);
#endregion
+ #region 防止阿里云过期
+ if (tempToken.AliyunOSS.Expiration.AddSeconds(10) <= DateTime.Now)
+ {
+ tempToken = _oSSService.GetObjectStoreTempToken();
+
+ _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint,
+ tempToken.AliyunOSS.AccessKeyId,
+ tempToken.AliyunOSS.AccessKeySecret,
+ tempToken.AliyunOSS.SecurityToken);
+ }
+
+ #endregion
+
+
+ // 创建 CopyObject 请求
+ // 先用构造函数指定源和目标
+ var copyReq = new CopyObjectRequest(
+ sourceBucketName: tempToken.AliyunOSS.BucketName,
+ sourceKey: item.Key,
+ destinationBucketName: tempToken.AliyunOSS.BucketName,
+ destinationKey: item.Key // 覆盖到同名 Key,达到“恢复”的效果
+ );
+
+ // 再设置版本号
+ copyReq.SourceVersionId = item.VersionId;
+
+ var copyResult = _ossClient.CopyObject(copyReq);
+
}
catch (Exception ex)
@@ -1643,12 +1672,21 @@ namespace IRaCIS.Core.Application.Service
public string RelativePath { get; set; }
-
+ public string SubjectCode { get; set; }
public string FileName { get; set; }
#endregion
}
+ public class RestoreInstanceInfo
+ {
+ public string SubjectCode { get; set; }
+
+ public string VisitName { get; set; }
+
+ public string SOPInstanceUID { get; set; }
+ }
+
///
/// 单个文件接收 归档
///