Compare commits
No commits in common. "84349c19e7851dce4b1e6d51f57b26b78b0bcfca" and "197aa9bf0afd009030ef4babeef5372b9eca42f3" have entirely different histories.
84349c19e7
...
197aa9bf0a
|
|
@ -1,6 +1,5 @@
|
||||||
using Aliyun.OSS;
|
using Aliyun.OSS;
|
||||||
using DocumentFormat.OpenXml.Spreadsheet;
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
using FellowOakDicom;
|
|
||||||
using FellowOakDicom.Imaging;
|
using FellowOakDicom.Imaging;
|
||||||
using IRaCIS.Application.Contracts;
|
using IRaCIS.Application.Contracts;
|
||||||
using IRaCIS.Core.Application.BusinessFilter;
|
using IRaCIS.Core.Application.BusinessFilter;
|
||||||
|
|
@ -16,9 +15,7 @@ using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.Encryption;
|
using IRaCIS.Core.Infrastructure.Encryption;
|
||||||
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
using MassTransit.Caching.Internals;
|
|
||||||
using MassTransit.Mediator;
|
using MassTransit.Mediator;
|
||||||
using MathNet.Numerics;
|
|
||||||
using MaxMind.GeoIP2;
|
using MaxMind.GeoIP2;
|
||||||
using Medallion.Threading;
|
using Medallion.Threading;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
@ -30,22 +27,18 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using MiniExcelLibs;
|
using MiniExcelLibs;
|
||||||
using Minio.DataModel;
|
|
||||||
using NPOI.SS.Formula.Functions;
|
using NPOI.SS.Formula.Functions;
|
||||||
using NPOI.XWPF.UserModel;
|
using NPOI.XWPF.UserModel;
|
||||||
using SharpCompress.Common;
|
using SharpCompress.Common;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Formats.Jpeg;
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
||||||
using SixLabors.ImageSharp.Processing;
|
using SixLabors.ImageSharp.Processing;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq.Dynamic.Core;
|
using System.Linq.Dynamic.Core;
|
||||||
using System.Reactive.Subjects;
|
using System.Reactive.Subjects;
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using static IRaCIS.Core.Domain.Share.StaticData;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -143,7 +136,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
if (!_readingMedicineSystemQuestion.Any(t => t.CriterionTypeEnum == CriterionType.mRECISTHCC))
|
if (!_readingMedicineSystemQuestion.Any(t => t.CriterionTypeEnum == CriterionType.mRECISTHCC))
|
||||||
{
|
{
|
||||||
var list = _readingMedicineSystemQuestion.Where(t => t.CriterionTypeEnum == CriterionType.RECIST1Point1).OrderBy(t => t.ShowOrder).ToList();
|
var list = _readingMedicineSystemQuestion.Where(t => t.CriterionTypeEnum == CriterionType.RECIST1Point1).OrderBy(t=>t.ShowOrder).ToList();
|
||||||
|
|
||||||
var initOrder = 500;
|
var initOrder = 500;
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
|
|
@ -158,7 +151,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
initOrder = initOrder + 1;
|
initOrder = initOrder + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _readingMedicineSystemQuestion.AddRangeAsync(list, true);
|
await _readingMedicineSystemQuestion.AddRangeAsync(list,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -372,308 +365,6 @@ namespace IRaCIS.Core.Application.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[AllowAnonymous]
|
|
||||||
public async Task<IResponseOutput> RestoreDBOSSDate(
|
|
||||||
[FromServices] IOSSService _oSSService, [FromServices] IWebHostEnvironment _hostEnvironment, [FromServices] IRepository<DicomStudy> _studyRepository)
|
|
||||||
{
|
|
||||||
var folder = FileStoreHelper.GetIRaCISRootDataFolder(_hostEnvironment);
|
|
||||||
|
|
||||||
var outputFile = Path.Combine(folder, $"{Guid.NewGuid()}_deleteKey_info.txt");
|
|
||||||
var outputFile2 = Path.Combine(folder, $"{Guid.NewGuid()}_deleteKeyExport_info.txt");
|
|
||||||
|
|
||||||
var outputErrorFile = Path.Combine(folder, $"{Guid.NewGuid()}_deleteKeyerror.txt");
|
|
||||||
var outputErrorFile2 = Path.Combine(folder, $"{Guid.NewGuid()}_deleteKeyerrorStudy.txt");
|
|
||||||
|
|
||||||
|
|
||||||
var aliConfig = _oSSService.ObjectStoreServiceOptions.AliyunOSS;
|
|
||||||
|
|
||||||
var tempToken = _oSSService.GetObjectStoreTempToken();
|
|
||||||
|
|
||||||
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint,
|
|
||||||
tempToken.AliyunOSS.AccessKeyId,
|
|
||||||
tempToken.AliyunOSS.AccessKeySecret,
|
|
||||||
tempToken.AliyunOSS.SecurityToken);
|
|
||||||
|
|
||||||
|
|
||||||
var allVersions = new List<ObjectVersionSummary>();
|
|
||||||
var allDeleteMarkers = new List<DeleteMarkerSummary>();
|
|
||||||
|
|
||||||
var request = new ListObjectVersionsRequest(tempToken.AliyunOSS.BucketName)
|
|
||||||
{
|
|
||||||
Prefix = "01000000-ac13-0242-6397-08dcd2d2a091/Image",
|
|
||||||
//Prefix = "01000000-ac13-0242-6397-08dcd2d2a091/Image/08dd9c04-c1b2-c2da-0242-ac1301000000/01000000-ac13-0242-235b-08dd9c04c1b3",
|
|
||||||
MaxKeys = 1000,
|
|
||||||
};
|
|
||||||
|
|
||||||
ObjectVersionList result;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
result = _ossClient.ListObjectVersions(request);
|
|
||||||
|
|
||||||
if (result.ObjectVersionSummaries != null)
|
|
||||||
allVersions.AddRange(result.ObjectVersionSummaries);
|
|
||||||
|
|
||||||
if (result.DeleteMarkerSummaries != null)
|
|
||||||
allDeleteMarkers.AddRange(result.DeleteMarkerSummaries);
|
|
||||||
|
|
||||||
request.KeyMarker = result.NextKeyMarker;
|
|
||||||
request.VersionIdMarker = result.NextVersionIdMarker;
|
|
||||||
|
|
||||||
} while (result.IsTruncated);
|
|
||||||
|
|
||||||
Console.WriteLine($"共找到 {allDeleteMarkers.Count} 个删除标记");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int total = allDeleteMarkers.Count;
|
|
||||||
|
|
||||||
int processed = 0;
|
|
||||||
double lastPercent = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// 按 Key 分组,找每个删除标记前的最近版本
|
|
||||||
var versionsByKey = allVersions
|
|
||||||
.GroupBy(v => v.Key)
|
|
||||||
.ToDictionary(g => g.Key, g => g.OrderByDescending(x => x.LastModified).ToList());
|
|
||||||
|
|
||||||
foreach (var del in allDeleteMarkers)
|
|
||||||
{
|
|
||||||
#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
|
|
||||||
|
|
||||||
if (!versionsByKey.TryGetValue(del.Key, out var versions))
|
|
||||||
continue; // 没有历史版本无法恢复
|
|
||||||
|
|
||||||
var prevVersion = versions.FirstOrDefault(v => v.LastModified < del.LastModified);
|
|
||||||
if (prevVersion == null)
|
|
||||||
continue; // 没找到可恢复版本
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await File.AppendAllTextAsync(outputFile, $"{prevVersion.Key},{prevVersion.VersionId}" + Environment.NewLine);
|
|
||||||
|
|
||||||
var getReq = new GetObjectRequest(tempToken.AliyunOSS.BucketName, prevVersion.Key)
|
|
||||||
{
|
|
||||||
VersionId = prevVersion.VersionId
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var getResult = _ossClient.GetObject(getReq))
|
|
||||||
using (var memStream = new MemoryStream())
|
|
||||||
{
|
|
||||||
// 先把 OSS 流复制到内存流
|
|
||||||
getResult.Content.CopyTo(memStream);
|
|
||||||
memStream.Position = 0;
|
|
||||||
|
|
||||||
// 读取 DICOM 信息
|
|
||||||
var dicomFile = DicomFile.Open(memStream);
|
|
||||||
var studyInstanceUID = dicomFile.Dataset.GetString(DicomTag.StudyInstanceUID);
|
|
||||||
|
|
||||||
var findInfo = await _studyRepository.Where(t => t.StudyInstanceUid == studyInstanceUID && t.TrialId == Guid.Parse("01000000-ac13-0242-6397-08dcd2d2a091"))
|
|
||||||
.Select(t => new { t.StudyInstanceUid, t.Subject.Code, t.SubjectVisit.VisitName, t.SubjectId, t.SubjectVisitId }).FirstOrDefaultAsync();
|
|
||||||
|
|
||||||
if (findInfo != null)
|
|
||||||
{
|
|
||||||
|
|
||||||
// 再保存到另一个路径(可以使用 fo-dicom 保存)
|
|
||||||
|
|
||||||
var fileName = Path.GetFileNameWithoutExtension(prevVersion.Key);
|
|
||||||
var anotherPath = Path.Combine(folder, findInfo.Code, findInfo.VisitName, studyInstanceUID, fileName);
|
|
||||||
// 去掉 folder 部分,得到相对路径
|
|
||||||
var relativePath = Path.GetRelativePath(folder, anotherPath);
|
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(anotherPath));
|
|
||||||
dicomFile.Save(anotherPath);
|
|
||||||
|
|
||||||
await File.AppendAllTextAsync(outputFile2, $"{findInfo.SubjectId},{findInfo.SubjectVisitId},{prevVersion.Key},{prevVersion.VersionId},{relativePath},{findInfo.Code},{findInfo.VisitName},{findInfo.StudyInstanceUid},{fileName}" + Environment.NewLine);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await File.AppendAllTextAsync(outputErrorFile2, $"{studyInstanceUID},{prevVersion.Key},{prevVersion.VersionId}" + Environment.NewLine);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Console.WriteLine($"读取到 studyInstanceUID: {studyInstanceUID}");
|
|
||||||
|
|
||||||
//var localPath = Path.Combine(folder, prevVersion.Key.Trim('/').Replace('/', Path.DirectorySeparatorChar));
|
|
||||||
//Directory.CreateDirectory(Path.GetDirectoryName(localPath));
|
|
||||||
//// 保存到原本路径
|
|
||||||
//memStream.Position = 0;
|
|
||||||
//using (var fs = File.Create(localPath))
|
|
||||||
//{
|
|
||||||
// memStream.CopyTo(fs);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Console.WriteLine($"✅ 下载成功: {prevVersion.Key} (version={prevVersion.VersionId})");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"❌ 下载失败: {prevVersion.Key}, 错误: {ex.Message}");
|
|
||||||
|
|
||||||
await File.AppendAllTextAsync(outputErrorFile, $"{prevVersion.Key},{prevVersion.VersionId}" + Environment.NewLine);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
processed++;
|
|
||||||
double percent = processed * 100.0 / total;
|
|
||||||
|
|
||||||
// 每提升 5% 或完成时输出
|
|
||||||
if (percent - lastPercent >= 2.0 || processed == total)
|
|
||||||
{
|
|
||||||
lastPercent = percent;
|
|
||||||
Console.WriteLine($"{DateTime.Now} 进度: {processed}/{total} ({percent:F2}%)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 使用 CopyObject 把历史版本拷贝为最新版本(恢复)
|
|
||||||
//var copyReq = new CopyObjectRequest
|
|
||||||
//{
|
|
||||||
// Bucket = bucketName,
|
|
||||||
// Key = prevVersion.Key,
|
|
||||||
// SourceBucket = bucketName,
|
|
||||||
// SourceKey = prevVersion.Key,
|
|
||||||
// SourceVersionId = prevVersion.VersionId
|
|
||||||
//};
|
|
||||||
|
|
||||||
//try
|
|
||||||
//{
|
|
||||||
// var copyResult = client.CopyObject(copyReq);
|
|
||||||
// Console.WriteLine($"✅ 恢复成功: {prevVersion.Key} -> newVersionId={copyResult.VersionId}");
|
|
||||||
//}
|
|
||||||
//catch (Exception ex)
|
|
||||||
//{
|
|
||||||
// Console.WriteLine($"❌ 恢复失败: {prevVersion.Key}, 错误: {ex.Message}");
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public async Task<IResponseOutput> OSSDeleteReStorre([FromServices] IOSSService _oSSService, [FromServices] IWebHostEnvironment _hostEnvironment)
|
|
||||||
{
|
|
||||||
var aliConfig = _oSSService.ObjectStoreServiceOptions.AliyunOSS;
|
|
||||||
|
|
||||||
var tempToken = _oSSService.GetObjectStoreTempToken();
|
|
||||||
|
|
||||||
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint,
|
|
||||||
tempToken.AliyunOSS.AccessKeyId,
|
|
||||||
tempToken.AliyunOSS.AccessKeySecret,
|
|
||||||
tempToken.AliyunOSS.SecurityToken);
|
|
||||||
|
|
||||||
|
|
||||||
var allVersions = new List<ObjectVersionSummary>();
|
|
||||||
var allDeleteMarkers = new List<DeleteMarkerSummary>();
|
|
||||||
|
|
||||||
var request = new ListObjectVersionsRequest(tempToken.AliyunOSS.BucketName)
|
|
||||||
{
|
|
||||||
Prefix = "test-delete-restore",
|
|
||||||
//Prefix = "01000000-ac13-0242-6397-08dcd2d2a091/Image/08dd9c04-c1b2-c2da-0242-ac1301000000/01000000-ac13-0242-235b-08dd9c04c1b3",
|
|
||||||
MaxKeys = 1000,
|
|
||||||
};
|
|
||||||
|
|
||||||
ObjectVersionList result;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
result = _ossClient.ListObjectVersions(request);
|
|
||||||
|
|
||||||
if (result.ObjectVersionSummaries != null)
|
|
||||||
allVersions.AddRange(result.ObjectVersionSummaries);
|
|
||||||
|
|
||||||
if (result.DeleteMarkerSummaries != null)
|
|
||||||
allDeleteMarkers.AddRange(result.DeleteMarkerSummaries);
|
|
||||||
|
|
||||||
request.KeyMarker = result.NextKeyMarker;
|
|
||||||
request.VersionIdMarker = result.NextVersionIdMarker;
|
|
||||||
|
|
||||||
} while (result.IsTruncated);
|
|
||||||
|
|
||||||
Console.WriteLine($"共找到 {allDeleteMarkers.Count} 个删除标记");
|
|
||||||
|
|
||||||
var versionsByKey = allVersions
|
|
||||||
.GroupBy(v => v.Key)
|
|
||||||
.ToDictionary(g => g.Key, g => g.OrderByDescending(x => x.LastModified).ToList());
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var del in allDeleteMarkers)
|
|
||||||
{
|
|
||||||
#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
|
|
||||||
|
|
||||||
if (!versionsByKey.TryGetValue(del.Key, out var versions))
|
|
||||||
continue; // 没有历史版本无法恢复
|
|
||||||
|
|
||||||
var prevVersion = versions.FirstOrDefault(v => v.LastModified < del.LastModified);
|
|
||||||
if (prevVersion == null)
|
|
||||||
continue; // 没找到可恢复版本
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 创建 CopyObject 请求
|
|
||||||
// 先用构造函数指定源和目标
|
|
||||||
var copyReq = new CopyObjectRequest(
|
|
||||||
sourceBucketName: tempToken.AliyunOSS.BucketName,
|
|
||||||
sourceKey: prevVersion.Key,
|
|
||||||
destinationBucketName: tempToken.AliyunOSS.BucketName,
|
|
||||||
destinationKey: prevVersion.Key // 覆盖到同名 Key,达到“恢复”的效果
|
|
||||||
);
|
|
||||||
|
|
||||||
// 再设置版本号
|
|
||||||
copyReq.SourceVersionId = prevVersion.VersionId;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var copyResult = _ossClient.CopyObject(copyReq);
|
|
||||||
Console.WriteLine($"✅ 恢复成功: {prevVersion.Key}, 新版本ID={copyResult.VersionId}");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"❌ 恢复失败: {prevVersion.Key}, 错误: {ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseOutput.Ok();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<IResponseOutput> UserCreateSourceDeal([FromServices] IRepository<IdentityUser> _identityUserRepository,
|
public async Task<IResponseOutput> UserCreateSourceDeal([FromServices] IRepository<IdentityUser> _identityUserRepository,
|
||||||
[FromServices] IRepository<TrialUserRole> _trialUserRoleRepository)
|
[FromServices] IRepository<TrialUserRole> _trialUserRoleRepository)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue