Merge branch 'Test_IRC_Net8' of https://gitea.frp.extimaging.com/XCKJ/irc-netcore-api into Test_IRC_Net8
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
commit
b048437b37
|
|
@ -0,0 +1,135 @@
|
|||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.Service;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.SCP.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.SCP;
|
||||
|
||||
|
||||
public class SyncFileRecoveryService(IServiceScopeFactory _scopeFactory, FileSyncQueue _fileSyncQueue) : BackgroundService
|
||||
{
|
||||
|
||||
private readonly int _pageSize = 500;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var fileUploadRecordRepository = scope.ServiceProvider.GetRequiredService<IRepository<FileUploadRecord>>();
|
||||
|
||||
// 延迟启动,保证主机快速启动
|
||||
await Task.Delay(5000, stoppingToken);
|
||||
|
||||
int page = 0;
|
||||
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
// 分页获取未入队任务
|
||||
var pending = await fileUploadRecordRepository
|
||||
.Where(x => x.IsNeedSync == true && (x.IsSync == false || x.IsSync == null))
|
||||
.OrderByDescending(x => x.Priority)
|
||||
.Select(t => new { t.Id, t.Priority })
|
||||
.Skip(page * _pageSize)
|
||||
.Take(_pageSize)
|
||||
.ToListAsync(stoppingToken);
|
||||
|
||||
if (!pending.Any())
|
||||
break; // 扫描完毕,退出循环
|
||||
|
||||
foreach (var file in pending)
|
||||
{
|
||||
//file.IsQueued = true; // 避免重复入队
|
||||
_fileSyncQueue.Enqueue(file.Id, file.Priority ?? 0); // 放入队列
|
||||
}
|
||||
|
||||
page++; // 下一页
|
||||
await Task.Delay(200, stoppingToken); // 缓解数据库压力
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSyncWorker(IServiceScopeFactory _scopeFactory, ILogger<FileSyncWorker> _logger, FileSyncQueue _fileSyncQueue) : BackgroundService
|
||||
{
|
||||
|
||||
// ⭐ 自动根据服务器CPU
|
||||
private readonly int _workerCount = Math.Max(1, Environment.ProcessorCount - 1);
|
||||
|
||||
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
for (int i = 0; i < _workerCount; i++)
|
||||
Task.Run(() => WorkerLoop(stoppingToken));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
private async Task WorkerLoop(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var id = await _fileSyncQueue.DequeueAsync(stoppingToken);
|
||||
|
||||
try
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var _fileUploadRecordRepository = scope.ServiceProvider.GetRequiredService<IRepository<FileUploadRecord>>();
|
||||
var _uploadFileSyncRecordRepository = scope.ServiceProvider.GetRequiredService<IRepository<UploadFileSyncRecord>>();
|
||||
var oss = scope.ServiceProvider.GetRequiredService<IOSSService>();
|
||||
|
||||
var file = await _fileUploadRecordRepository.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (file == null || file.IsNeedSync != true)
|
||||
return;
|
||||
|
||||
var log = new UploadFileSyncRecord
|
||||
{
|
||||
FileUploadRecordId = id,
|
||||
StartTime = DateTime.Now,
|
||||
JobState = jobState.RUNNING
|
||||
};
|
||||
|
||||
await _uploadFileSyncRecordRepository.AddAsync(log);
|
||||
await _uploadFileSyncRecordRepository.SaveChangesAsync(stoppingToken);
|
||||
|
||||
try
|
||||
{
|
||||
await oss.SyncFileAsync(file.Path.TrimStart('/'), file.UploadRegion == "CN" ? ObjectStoreUse.AliyunOSS : ObjectStoreUse.AWS, file.UploadRegion == "CN" ? ObjectStoreUse.AWS : ObjectStoreUse.AliyunOSS);
|
||||
|
||||
file.IsSync = true;
|
||||
file.SyncFinishedTime = DateTime.UtcNow;
|
||||
|
||||
log.JobState = jobState.SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.JobState = jobState.FAILED;
|
||||
|
||||
log.Msg = ex.Message[..300];
|
||||
}
|
||||
|
||||
log.EndTime = DateTime.UtcNow;
|
||||
|
||||
await _uploadFileSyncRecordRepository.SaveChangesAsync(stoppingToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Sync failed {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -63,6 +63,10 @@ builder.Host
|
|||
#region 配置服务
|
||||
var _configuration = builder.Configuration;
|
||||
|
||||
builder.Services.AddSingleton<FileSyncQueue>();
|
||||
builder.Services.AddHostedService<SyncFileRecoveryService>();
|
||||
builder.Services.AddHostedService<FileSyncWorker>();
|
||||
|
||||
//健康检查
|
||||
builder.Services.AddHealthChecks();
|
||||
|
||||
|
|
|
|||
|
|
@ -644,7 +644,7 @@ namespace IRaCIS.Core.SCP.Service
|
|||
ms.Position = 0;
|
||||
|
||||
//irc 从路径最后一截取Guid
|
||||
storeRelativePath = await ossService.UploadToOSSAsync(ms, ossFolderPath, instanceId.ToString(), false);
|
||||
storeRelativePath = await ossService.UploadToOSSAsync(ms, ossFolderPath, instanceId.ToString(), false, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = _trialId, BatchDataType = BatchDataType.PACSReceive });
|
||||
|
||||
fileSize = ms.Length;
|
||||
|
||||
|
|
@ -674,7 +674,7 @@ namespace IRaCIS.Core.SCP.Service
|
|||
|
||||
// 上传缩略图到 OSS
|
||||
|
||||
var seriesPath = await ossService.UploadToOSSAsync(memoryStream, ossFolderPath, $"{seriesId.ToString()}_{instanceId.ToString()}.preview.jpg", false);
|
||||
var seriesPath = await ossService.UploadToOSSAsync(memoryStream, ossFolderPath, $"{seriesId.ToString()}_{instanceId.ToString()}.preview.jpg", false,uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = _trialId, BatchDataType = BatchDataType.PACSReceive });
|
||||
|
||||
|
||||
series.ImageResizePath = seriesPath;
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ public static class CacheKeys
|
|||
public static string UserMFAVerifyPass(Guid userId, string browserFingerprint) => $"UserMFAVerifyPass:{userId}:{browserFingerprint}";
|
||||
|
||||
public static string TrialSiteInfo(Guid trialSiteId) => $"{trialSiteId}TrialSiteInfo";
|
||||
|
||||
public static string TrialDataStoreType(Guid trialId) => $"TrialDataStoreType:{trialId}";
|
||||
}
|
||||
|
||||
public static class CacheHelper
|
||||
|
|
|
|||
|
|
@ -0,0 +1,193 @@
|
|||
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由liquid模板自动生成 byzhouhang 20240909
|
||||
// 生成时间 2026-03-10 06:15:17Z
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using AutoMapper;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Infra.EFCore.Common;
|
||||
using IRaCIS.Core.Infrastructure.Extention;
|
||||
using IRaCIS.Core.SCP;
|
||||
using IRaCIS.Core.SCP.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Drawing;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace IRaCIS.Core.SCP.Service;
|
||||
|
||||
public class FileUploadRecordAddOrEdit
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
public long FileSize { get; set; }
|
||||
|
||||
public string FileType { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
|
||||
public string UploadBatchId { get; set; }
|
||||
public BatchDataType BatchDataType { get; set; }
|
||||
|
||||
|
||||
public Guid? TrialId { get; set; }
|
||||
|
||||
public Guid? SubjectId { get; set; }
|
||||
|
||||
public Guid? SubjectVisitId { get; set; }
|
||||
|
||||
public Guid? DicomStudyId { get; set; }
|
||||
|
||||
public Guid? NoneDicomStudyId { get; set; }
|
||||
|
||||
|
||||
|
||||
public string FileMarkId { get; set; }
|
||||
|
||||
public int? Priority { get; set; }
|
||||
public string IP { get; set; }
|
||||
public bool? IsNeedSync { get; set; }
|
||||
public string UploadRegion { get; set; }
|
||||
public string TargetRegion { get; set; }
|
||||
}
|
||||
public interface IFileUploadRecordService
|
||||
{
|
||||
|
||||
|
||||
Task<IResponseOutput> AddOrUpdateFileUploadRecord(FileUploadRecordAddOrEdit addOrEditFileUploadRecord);
|
||||
|
||||
}
|
||||
|
||||
[ApiExplorerSettings(GroupName = "Common")]
|
||||
public class FileUploadRecordService(IRepository<FileUploadRecord> _fileUploadRecordRepository,
|
||||
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IOptionsMonitor<ObjectStoreServiceOptions> options,
|
||||
IFusionCache _fusionCache, IRepository<Trial> _trialRepository, FileSyncQueue _fileSyncQueue) : BaseService, IFileUploadRecordService
|
||||
{
|
||||
|
||||
ObjectStoreServiceOptions ObjectStoreServiceConfig = options.CurrentValue;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<IResponseOutput> AddOrUpdateFileUploadRecord(FileUploadRecordAddOrEdit addOrEditFileUploadRecord)
|
||||
{
|
||||
|
||||
addOrEditFileUploadRecord.IP = _userInfo.IP;
|
||||
|
||||
if (ObjectStoreServiceConfig.IsOpenStoreSync && _userInfo.Domain.IsNotNullOrEmpty())
|
||||
{
|
||||
var find = ObjectStoreServiceConfig.SyncConfigList.FirstOrDefault(t => t.Domain == _userInfo.Domain);
|
||||
if (find != null)
|
||||
{
|
||||
addOrEditFileUploadRecord.UploadRegion = find.UploadRegion;
|
||||
addOrEditFileUploadRecord.TargetRegion = find.TargetRegion;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (addOrEditFileUploadRecord.TrialId != null)
|
||||
{
|
||||
|
||||
var trialDataStore = await _fusionCache.GetOrSetAsync(CacheKeys.TrialDataStoreType(addOrEditFileUploadRecord.TrialId.Value), async _ =>
|
||||
{
|
||||
return await _trialRepository.Where(t => t.Id == addOrEditFileUploadRecord.TrialId).Select(t => t.TrialDataStoreType)
|
||||
.FirstOrDefaultAsync();
|
||||
},
|
||||
TimeSpan.FromDays(7)
|
||||
);
|
||||
|
||||
//项目配置了,那么就设置需要同步
|
||||
if (trialDataStore == TrialDataStore.MUtiCenter)
|
||||
{
|
||||
addOrEditFileUploadRecord.IsNeedSync = true;
|
||||
|
||||
addOrEditFileUploadRecord.Priority = 0;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
addOrEditFileUploadRecord.TargetRegion = "";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//系统文件,默认同步
|
||||
addOrEditFileUploadRecord.IsNeedSync = true;
|
||||
|
||||
addOrEditFileUploadRecord.Priority = 0;
|
||||
}
|
||||
|
||||
var entity = await _fileUploadRecordRepository.InsertOrUpdateAsync(addOrEditFileUploadRecord, true);
|
||||
|
||||
if (addOrEditFileUploadRecord.IsNeedSync == true)
|
||||
{
|
||||
_fileSyncQueue.Enqueue(entity.Id, addOrEditFileUploadRecord.Priority ?? 0);
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 同步队列 信号量
|
||||
/// </summary>
|
||||
public class FileSyncQueue
|
||||
{
|
||||
private readonly PriorityQueue<Guid, int> _queue = new();
|
||||
private readonly SemaphoreSlim _signal = new(0);
|
||||
private readonly object _lock = new();
|
||||
|
||||
public void Enqueue(Guid id, int priority)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
// priority 越大越优先
|
||||
_queue.Enqueue(id, -priority);
|
||||
}
|
||||
|
||||
//类似于计数器,不会产生通知风暴,可消费资源 +1
|
||||
//if (有等待线程) 唤醒一个 else 仅增加计数
|
||||
_signal.Release(); // 唤醒一个 worker
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果没有任务 → 挂起等待 有任务 → 被唤醒并返回
|
||||
/// </summary>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Guid> DequeueAsync(CancellationToken ct)
|
||||
{
|
||||
await _signal.WaitAsync(ct);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
return _queue.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -143,7 +143,7 @@ namespace IRaCIS.Api.Controllers
|
|||
|
||||
var result = _oSSService.GetObjectStoreTempToken(domain);
|
||||
|
||||
//result.AWS = await GetAWSTemToken(options.CurrentValue);
|
||||
|
||||
|
||||
Log.Logger.Information($"使用域名:{domain}请求token.返回{result.ToJsonStr()}");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using IRaCIS.Core.Application.Filter;
|
|||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.MassTransit.Command;
|
||||
using IRaCIS.Core.Application.Service;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
|
|
@ -598,7 +599,7 @@ namespace IRaCIS.Core.API.Controllers
|
|||
templateFileStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, $"{trialId.ToString()}/InspectionUpload/DataReconciliation", realFileName);
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, $"{trialId.ToString()}/InspectionUpload/DataReconciliation", realFileName, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialId, BatchDataType = BatchDataType.DataReconciliation });
|
||||
|
||||
var addEntity = await _inspectionFileRepository.AddAsync(new InspectionFile() { FileName = realFileName, RelativePath = ossRelativePath, TrialId = trialId }, true);
|
||||
|
||||
|
|
@ -856,7 +857,7 @@ namespace IRaCIS.Core.API.Controllers
|
|||
throw new BusinessValidationFailedException(_localizer["UploadDownLoad_TemplateUploadData"]);
|
||||
}
|
||||
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, $"{trialId.ToString()}/InspectionUpload/SiteSurvey", realFileName);
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, $"{trialId.ToString()}/InspectionUpload/SiteSurvey", realFileName, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialId ,BatchDataType=BatchDataType.SiteUserSurvey});
|
||||
|
||||
await _inspectionFileRepository.AddAsync(new InspectionFile() { FileName = realFileName, RelativePath = ossRelativePath, TrialId = trialId }, true);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,134 @@
|
|||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.Service;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.API.HostService;
|
||||
|
||||
|
||||
public class SyncFileRecoveryService(IServiceScopeFactory _scopeFactory, FileSyncQueue _fileSyncQueue) : BackgroundService
|
||||
{
|
||||
|
||||
private readonly int _pageSize = 500;
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var fileUploadRecordRepository = scope.ServiceProvider.GetRequiredService<IRepository<FileUploadRecord>>();
|
||||
|
||||
// 延迟启动,保证主机快速启动
|
||||
await Task.Delay(5000, stoppingToken);
|
||||
|
||||
int page = 0;
|
||||
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
// 分页获取未入队任务
|
||||
var pending = await fileUploadRecordRepository
|
||||
.Where(x => x.IsNeedSync == true && (x.IsSync == false || x.IsSync == null))
|
||||
.OrderByDescending(x => x.Priority)
|
||||
.Select(t => new { t.Id, t.Priority })
|
||||
.Skip(page * _pageSize)
|
||||
.Take(_pageSize)
|
||||
.ToListAsync(stoppingToken);
|
||||
|
||||
if (!pending.Any())
|
||||
break; // 扫描完毕,退出循环
|
||||
|
||||
foreach (var file in pending)
|
||||
{
|
||||
//file.IsQueued = true; // 避免重复入队
|
||||
_fileSyncQueue.Enqueue(file.Id, file.Priority ?? 0); // 放入队列
|
||||
}
|
||||
|
||||
page++; // 下一页
|
||||
await Task.Delay(200, stoppingToken); // 缓解数据库压力
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSyncWorker(IServiceScopeFactory _scopeFactory, ILogger<FileSyncWorker> _logger, FileSyncQueue _fileSyncQueue) : BackgroundService
|
||||
{
|
||||
|
||||
// ⭐ 自动根据服务器CPU
|
||||
private readonly int _workerCount = Math.Max(1, Environment.ProcessorCount - 1);
|
||||
|
||||
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
for (int i = 0; i < _workerCount; i++)
|
||||
Task.Run(() => WorkerLoop(stoppingToken));
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
private async Task WorkerLoop(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
var id = await _fileSyncQueue.DequeueAsync(stoppingToken);
|
||||
|
||||
try
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var _fileUploadRecordRepository = scope.ServiceProvider.GetRequiredService<IRepository<FileUploadRecord>>();
|
||||
var _uploadFileSyncRecordRepository = scope.ServiceProvider.GetRequiredService<IRepository<UploadFileSyncRecord>>();
|
||||
var oss = scope.ServiceProvider.GetRequiredService<IOSSService>();
|
||||
|
||||
var file = await _fileUploadRecordRepository.FirstOrDefaultAsync(t => t.Id == id);
|
||||
|
||||
if (file == null || file.IsNeedSync != true)
|
||||
return;
|
||||
|
||||
var log = new UploadFileSyncRecord
|
||||
{
|
||||
FileUploadRecordId = id,
|
||||
StartTime = DateTime.Now,
|
||||
JobState = jobState.RUNNING
|
||||
};
|
||||
|
||||
await _uploadFileSyncRecordRepository.AddAsync(log);
|
||||
await _uploadFileSyncRecordRepository.SaveChangesAsync(stoppingToken);
|
||||
|
||||
try
|
||||
{
|
||||
await oss.SyncFileAsync(file.Path.TrimStart('/'), file.UploadRegion == "CN" ? ObjectStoreUse.AliyunOSS : ObjectStoreUse.AWS, file.UploadRegion == "CN" ? ObjectStoreUse.AWS : ObjectStoreUse.AliyunOSS);
|
||||
|
||||
file.IsSync = true;
|
||||
file.SyncFinishedTime = DateTime.UtcNow;
|
||||
|
||||
log.JobState = jobState.SUCCESS;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log.JobState = jobState.FAILED;
|
||||
|
||||
log.Msg = ex.Message[..300];
|
||||
}
|
||||
|
||||
log.EndTime = DateTime.UtcNow;
|
||||
|
||||
await _uploadFileSyncRecordRepository.SaveChangesAsync(stoppingToken);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Sync failed {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Builder;
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
|
@ -88,6 +89,10 @@ builder.Services.ConfigureServices(_configuration);
|
|||
|
||||
builder.Services.AddHostedService<HangfireHostService>();
|
||||
|
||||
builder.Services.AddSingleton<FileSyncQueue>();
|
||||
builder.Services.AddHostedService<SyncFileRecoveryService>();
|
||||
builder.Services.AddHostedService<FileSyncWorker>();
|
||||
|
||||
//minimal api 异常处理
|
||||
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
|
||||
//builder.Services.AddProblemDetails();
|
||||
|
|
|
|||
|
|
@ -29,16 +29,23 @@
|
|||
// 使用的对象存储服务类型
|
||||
"ObjectStoreUse": "AliyunOSS",
|
||||
"IsOpenStoreSync": false,
|
||||
"ApiDeployRegion": "CN",
|
||||
"SyncConfigList": [
|
||||
{
|
||||
"Domain": "ir.test.extimaging.com",
|
||||
"Primary": "AliyunOSS",
|
||||
"Target": "AWS"
|
||||
"Target": "AWS",
|
||||
"UploadRegion": "CN",
|
||||
"TargetRegion": "US",
|
||||
"IsOpenSync": true
|
||||
},
|
||||
{
|
||||
"Domain": "lili.test.extimaging.com",
|
||||
"Primary": "AWS",
|
||||
"Target": "AliyunOSS"
|
||||
"Target": "AliyunOSS",
|
||||
"UploadRegion": "US",
|
||||
"TargetRegion": "CN",
|
||||
"IsOpenSync": true
|
||||
}
|
||||
],
|
||||
// 阿里云对象存储服务的配置
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace IRaCIS.Core.Application.Helper;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
|
||||
namespace IRaCIS.Core.Application.Helper;
|
||||
|
||||
|
||||
public static class CacheKeys
|
||||
|
|
@ -66,6 +68,9 @@ public static class CacheKeys
|
|||
|
||||
public static string UserMFATag(Guid userId) => $"UserMFAVerifyPass:{userId}";
|
||||
|
||||
public static string TrialDataStoreType(Guid trialId) => $"TrialDataStoreType:{trialId}";
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static class CacheHelper
|
||||
|
|
@ -77,6 +82,9 @@ public static class CacheHelper
|
|||
return statusStr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static async Task<List<SystemAnonymization>> GetSystemAnonymizationListAsync(IRepository<SystemAnonymization> _systemAnonymizationRepository)
|
||||
{
|
||||
var list = await _systemAnonymizationRepository.Where(t => t.IsEnable).ToListAsync();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using DocumentFormat.OpenXml.Office.CustomUI;
|
||||
using FellowOakDicom;
|
||||
using FellowOakDicom.Media;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
|
@ -58,6 +60,10 @@ namespace IRaCIS.Core.Application.Helper
|
|||
var mappings = new List<string>();
|
||||
int index = 1;
|
||||
|
||||
var trialId = Guid.Empty;
|
||||
|
||||
Guid.TryParse(ossFolder.Split('/', StringSplitOptions.RemoveEmptyEntries)[0], out trialId);
|
||||
|
||||
var studyUid = list.FirstOrDefault()?.StudyInstanceUid;
|
||||
|
||||
var dicomDir = new DicomDirectory();
|
||||
|
|
@ -130,7 +136,7 @@ namespace IRaCIS.Core.Application.Helper
|
|||
// 重置流位置
|
||||
memoryStream.Position = 0;
|
||||
|
||||
var relativePath= await _oSSService.UploadToOSSAsync(memoryStream, ossFolder, "DICOMDIR", true);
|
||||
var relativePath = await _oSSService.UploadToOSSAsync(memoryStream, ossFolder, "DICOMDIR", true, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialId, BatchDataType = BatchDataType.DICOMDIR });
|
||||
|
||||
dic.Add($"{studyUid}_DICOMDIR", relativePath.Split('/').Last());
|
||||
}
|
||||
|
|
@ -146,7 +152,7 @@ namespace IRaCIS.Core.Application.Helper
|
|||
var mappingText = string.Join(Environment.NewLine, mappings);
|
||||
await using var mappingStream = new MemoryStream(Encoding.UTF8.GetBytes(mappingText));
|
||||
|
||||
await _oSSService.UploadToOSSAsync(mappingStream, ossFolder, $"Download_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}", false);
|
||||
await _oSSService.UploadToOSSAsync(mappingStream, ossFolder, $"Download_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}", false, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialId, BatchDataType = BatchDataType.DICOMDIR });
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ using Amazon.S3;
|
|||
using Amazon.S3.Model;
|
||||
using Amazon.SecurityToken;
|
||||
using Amazon.SecurityToken.Model;
|
||||
using IRaCIS.Core.Application.Interfaces;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Infrastructure;
|
||||
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
||||
using MassTransit;
|
||||
|
|
@ -16,7 +18,9 @@ using Minio;
|
|||
using Minio.DataModel;
|
||||
using Minio.DataModel.Args;
|
||||
using Minio.Exceptions;
|
||||
using Org.BouncyCastle.Tls;
|
||||
using Serilog.Parsing;
|
||||
using SkiaSharp;
|
||||
using System.IO;
|
||||
using System.Reactive.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
@ -83,6 +87,8 @@ public class ObjectStoreServiceOptions
|
|||
|
||||
public bool IsOpenStoreSync { get; set; }
|
||||
|
||||
public string ApiDeployRegion { get; set; }
|
||||
|
||||
public List<SyncStoreConfig> SyncConfigList { get; set; } = new List<SyncStoreConfig>();
|
||||
|
||||
}
|
||||
|
|
@ -91,10 +97,16 @@ public class SyncStoreConfig
|
|||
{
|
||||
public string Domain { get; set; }
|
||||
|
||||
public string UploadRegion { get; set; }
|
||||
|
||||
public string TargetRegion { get; set; }
|
||||
|
||||
public string Primary { get; set; }
|
||||
|
||||
public string Target { get; set; }
|
||||
|
||||
public bool IsOpenSync { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class ObjectStoreDTO
|
||||
|
|
@ -156,6 +168,7 @@ public enum ObjectStoreUse
|
|||
AWS = 2,
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
// aws 参考链接 https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/S3/S3_Basics
|
||||
|
|
@ -166,8 +179,8 @@ public interface IOSSService
|
|||
public Task RestoreFilesByPrefixAsync(string prefix, int restoreDays = 3, int batchSize = 100);
|
||||
|
||||
|
||||
public Task<string> UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName, bool isFileNameAddGuid = true);
|
||||
public Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true, bool randomFileName = false);
|
||||
public Task<string> UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName, bool isFileNameAddGuid = true, FileUploadRecordAddOrEdit? uploadInfo = null);
|
||||
public Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true, bool randomFileName = false, FileUploadRecordAddOrEdit? uploadInfo = null);
|
||||
|
||||
public Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath);
|
||||
|
||||
|
|
@ -183,28 +196,27 @@ public interface IOSSService
|
|||
|
||||
List<string> GetRootFolderNames();
|
||||
|
||||
public ObjectStoreDTO GetObjectStoreTempToken(string? domain = null);
|
||||
public ObjectStoreDTO GetObjectStoreTempToken(string? domain = null, bool? isGetAllTempToken = null);
|
||||
|
||||
public Task MoveObject(string sourcePath, string destPath, bool overwrite = true);
|
||||
|
||||
public Task<long> GetObjectSizeAsync(string sourcePath);
|
||||
|
||||
public Task SyncFileAsync(string objectKey, ObjectStoreUse source, ObjectStoreUse destination, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
|
||||
public class OSSService : IOSSService
|
||||
public class OSSService(IOptionsMonitor<ObjectStoreServiceOptions> options,
|
||||
IFileUploadRecordService _fileUploadRecordService) : IOSSService
|
||||
{
|
||||
public ObjectStoreServiceOptions ObjectStoreServiceOptions { get; set; }
|
||||
public ObjectStoreServiceOptions ObjectStoreServiceOptions { get; set; } = options.CurrentValue;
|
||||
|
||||
private AliyunOSSTempToken AliyunOSSTempToken { get; set; }
|
||||
|
||||
private AWSTempToken AWSTempToken { get; set; }
|
||||
|
||||
|
||||
public OSSService(IOptionsMonitor<ObjectStoreServiceOptions> options)
|
||||
{
|
||||
ObjectStoreServiceOptions = options.CurrentValue;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将指定前缀下的所有现有文件立即转为目标存储类型
|
||||
|
|
@ -719,6 +731,9 @@ public class OSSService : IOSSService
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||
/// </summary>
|
||||
|
|
@ -726,8 +741,9 @@ public class OSSService : IOSSService
|
|||
/// <param name="oosFolderPath"></param>
|
||||
/// <param name="fileRealName"></param>
|
||||
/// <param name="isFileNameAddGuid"></param>
|
||||
/// <param name="uploadInfo"> 只用赋值业务参数Id 和批次信息即可,其他信息不用传递</param>
|
||||
/// <returns></returns>
|
||||
public async Task<string> UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName, bool isFileNameAddGuid = true)
|
||||
public async Task<string> UploadToOSSAsync(Stream fileStream, string oosFolderPath, string fileRealName, bool isFileNameAddGuid = true, FileUploadRecordAddOrEdit? uploadInfo = null)
|
||||
{
|
||||
BackBatchGetToken();
|
||||
|
||||
|
|
@ -735,14 +751,9 @@ public class OSSService : IOSSService
|
|||
|
||||
try
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
if (fileStream.CanSeek)
|
||||
fileStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
fileStream.CopyTo(memoryStream);
|
||||
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
|
||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||
{
|
||||
|
|
@ -753,7 +764,7 @@ public class OSSService : IOSSService
|
|||
|
||||
|
||||
// 上传文件
|
||||
var result = _ossClient.PutObject(aliConfig.BucketName, ossRelativePath, memoryStream);
|
||||
var result = _ossClient.PutObject(aliConfig.BucketName, ossRelativePath, fileStream);
|
||||
|
||||
}
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
||||
|
|
@ -768,8 +779,8 @@ public class OSSService : IOSSService
|
|||
var putObjectArgs = new PutObjectArgs()
|
||||
.WithBucket(minIOConfig.BucketName)
|
||||
.WithObject(ossRelativePath)
|
||||
.WithStreamData(memoryStream)
|
||||
.WithObjectSize(memoryStream.Length);
|
||||
.WithStreamData(fileStream)
|
||||
.WithObjectSize(fileStream.Length);
|
||||
|
||||
await minioClient.PutObjectAsync(putObjectArgs);
|
||||
}
|
||||
|
|
@ -793,7 +804,7 @@ public class OSSService : IOSSService
|
|||
var putObjectRequest = new Amazon.S3.Model.PutObjectRequest()
|
||||
{
|
||||
BucketName = awsConfig.BucketName,
|
||||
InputStream = memoryStream,
|
||||
InputStream = fileStream,
|
||||
Key = ossRelativePath,
|
||||
};
|
||||
|
||||
|
|
@ -804,7 +815,6 @@ public class OSSService : IOSSService
|
|||
throw new BusinessValidationFailedException("未定义的存储介质类型");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
|
|
@ -812,13 +822,27 @@ public class OSSService : IOSSService
|
|||
}
|
||||
|
||||
|
||||
var returnPath = "/" + ossRelativePath;
|
||||
|
||||
|
||||
return "/" + ossRelativePath;
|
||||
if (ObjectStoreServiceOptions.IsOpenStoreSync && uploadInfo != null)
|
||||
{
|
||||
uploadInfo.FileSize = fileStream.CanSeek ? fileStream.Length : 0;
|
||||
uploadInfo.Path = returnPath;
|
||||
uploadInfo.FileName = fileRealName;
|
||||
uploadInfo.FileType = Path.GetExtension(returnPath);
|
||||
|
||||
|
||||
await _fileUploadRecordService.AddOrUpdateFileUploadRecord(uploadInfo);
|
||||
}
|
||||
|
||||
|
||||
return returnPath;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//后端批量上传 或者下载,不每个文件获取临时token
|
||||
private void BackBatchGetToken()
|
||||
{
|
||||
|
|
@ -860,10 +884,12 @@ public class OSSService : IOSSService
|
|||
/// <param name="randomFileName">随机文件名</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
||||
public async Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true, bool randomFileName = false)
|
||||
public async Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true, bool randomFileName = false, FileUploadRecordAddOrEdit? uploadInfo = null)
|
||||
{
|
||||
BackBatchGetToken();
|
||||
|
||||
long fileSize = 0;
|
||||
|
||||
var localFileName = Path.GetFileName(localFilePath);
|
||||
|
||||
var ossRelativePath = isFileNameAddGuid ? $"{oosFolderPath}/{Guid.NewGuid()}_{localFileName}" : $"{oosFolderPath}/{localFileName}";
|
||||
|
|
@ -883,6 +909,8 @@ public class OSSService : IOSSService
|
|||
// 上传文件
|
||||
var result = _ossClient.PutObject(aliConfig.BucketName, ossRelativePath, localFilePath);
|
||||
|
||||
fileSize = result.ContentLength;
|
||||
|
||||
}
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
||||
{
|
||||
|
|
@ -898,7 +926,9 @@ public class OSSService : IOSSService
|
|||
.WithObject(ossRelativePath)
|
||||
.WithFileName(localFilePath);
|
||||
|
||||
await minioClient.PutObjectAsync(putObjectArgs);
|
||||
var result = await minioClient.PutObjectAsync(putObjectArgs);
|
||||
|
||||
fileSize = result.Size;
|
||||
}
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS")
|
||||
{
|
||||
|
|
@ -923,14 +953,30 @@ public class OSSService : IOSSService
|
|||
Key = ossRelativePath,
|
||||
};
|
||||
|
||||
await amazonS3Client.PutObjectAsync(putObjectRequest);
|
||||
|
||||
var result = await amazonS3Client.PutObjectAsync(putObjectRequest);
|
||||
fileSize = result.ContentLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BusinessValidationFailedException("未定义的存储介质类型");
|
||||
}
|
||||
return "/" + ossRelativePath;
|
||||
|
||||
var returnPath = "/" + ossRelativePath;
|
||||
|
||||
|
||||
if (ObjectStoreServiceOptions.IsOpenStoreSync && uploadInfo != null)
|
||||
{
|
||||
uploadInfo.FileSize = fileSize;
|
||||
uploadInfo.Path = returnPath;
|
||||
uploadInfo.FileName = Path.GetFileName(localFilePath);
|
||||
uploadInfo.FileType = Path.GetExtension(returnPath);
|
||||
|
||||
|
||||
await _fileUploadRecordService.AddOrUpdateFileUploadRecord(uploadInfo);
|
||||
}
|
||||
|
||||
|
||||
return returnPath;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1042,11 +1088,6 @@ public class OSSService : IOSSService
|
|||
// 直接返回流
|
||||
return result.Content;
|
||||
|
||||
//// 将OSS返回的流复制到内存流中并返回
|
||||
//var memoryStream = new MemoryStream();
|
||||
//await result.Content.CopyToAsync(memoryStream);
|
||||
//memoryStream.Position = 0; // 重置位置以便读取
|
||||
//return memoryStream;
|
||||
}
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
||||
{
|
||||
|
|
@ -1112,10 +1153,6 @@ public class OSSService : IOSSService
|
|||
// ⭐ 直接返回流
|
||||
return response.ResponseStream;
|
||||
|
||||
//var memoryStream = new MemoryStream();
|
||||
//await response.ResponseStream.CopyToAsync(memoryStream);
|
||||
//memoryStream.Position = 0;
|
||||
//return memoryStream;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1459,8 +1496,31 @@ public class OSSService : IOSSService
|
|||
/// <returns></returns>
|
||||
public async Task DeleteFromPrefix(string prefix, bool isCache = false)
|
||||
{
|
||||
|
||||
//打开了同步的,删除的时候,一起删除
|
||||
if (ObjectStoreServiceOptions.IsOpenStoreSync && ObjectStoreServiceOptions.SyncConfigList.Any(t => t.IsOpenSync))
|
||||
{
|
||||
foreach (var config in ObjectStoreServiceOptions.SyncConfigList.Where(t => t.IsOpenSync))
|
||||
{
|
||||
ObjectStoreServiceOptions.ObjectStoreUse = config.Primary;
|
||||
|
||||
GetObjectStoreTempToken();
|
||||
|
||||
await DeleteFromPrefixInternal(prefix, isCache);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetObjectStoreTempToken();
|
||||
|
||||
await DeleteFromPrefixInternal(prefix, isCache);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private async Task DeleteFromPrefixInternal(string prefix, bool isCache = false)
|
||||
{
|
||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||
{
|
||||
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
||||
|
|
@ -1610,8 +1670,32 @@ public class OSSService : IOSSService
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task DeleteObjects(List<string> objectKeys, bool isCache = false)
|
||||
{
|
||||
//打开了同步的,删除的时候,一起删除
|
||||
if (ObjectStoreServiceOptions.IsOpenStoreSync && ObjectStoreServiceOptions.SyncConfigList.Any(t => t.IsOpenSync))
|
||||
{
|
||||
foreach (var config in ObjectStoreServiceOptions.SyncConfigList.Where(t => t.IsOpenSync))
|
||||
{
|
||||
ObjectStoreServiceOptions.ObjectStoreUse = config.Primary;
|
||||
|
||||
GetObjectStoreTempToken();
|
||||
|
||||
await DeleteObjectsInternal(objectKeys, isCache);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GetObjectStoreTempToken();
|
||||
|
||||
await DeleteObjectsInternal(objectKeys, isCache);
|
||||
}
|
||||
}
|
||||
public async Task DeleteObjectsInternal(List<string> objectKeys, bool isCache = false)
|
||||
{
|
||||
|
||||
|
||||
GetObjectStoreTempToken();
|
||||
|
||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||
|
|
@ -1774,7 +1858,7 @@ public class OSSService : IOSSService
|
|||
|
||||
|
||||
|
||||
public ObjectStoreDTO GetObjectStoreTempToken(string? domain = null)
|
||||
public ObjectStoreDTO GetObjectStoreTempToken(string? domain = null, bool? isGetAllTempToken = null)
|
||||
{
|
||||
//如果传递了域名,并且打开了存储同步,根据域名使用的具体存储覆盖之前的配置,否则就用固定的配置
|
||||
if (ObjectStoreServiceOptions.IsOpenStoreSync && domain.IsNotNullOrEmpty())
|
||||
|
|
@ -1790,7 +1874,7 @@ public class OSSService : IOSSService
|
|||
|
||||
var objectStoreDTO = new ObjectStoreDTO() { ObjectStoreUse = ObjectStoreServiceOptions.ObjectStoreUse, IsOpenStoreSync = ObjectStoreServiceOptions.IsOpenStoreSync, SyncConfigList = ObjectStoreServiceOptions.SyncConfigList };
|
||||
|
||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS" || isGetAllTempToken == true)
|
||||
{
|
||||
var ossOptions = ObjectStoreServiceOptions.AliyunOSS;
|
||||
|
||||
|
|
@ -1842,7 +1926,7 @@ public class OSSService : IOSSService
|
|||
{
|
||||
objectStoreDTO.MinIO = ObjectStoreServiceOptions.MinIO;
|
||||
}
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS")
|
||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS" || isGetAllTempToken == true)
|
||||
{
|
||||
var awsOptions = ObjectStoreServiceOptions.AWS;
|
||||
|
||||
|
|
@ -1895,4 +1979,58 @@ public class OSSService : IOSSService
|
|||
return objectStoreDTO;
|
||||
}
|
||||
|
||||
|
||||
public async Task SyncFileAsync(string objectKey, ObjectStoreUse source, ObjectStoreUse destination, CancellationToken ct = default)
|
||||
{
|
||||
GetObjectStoreTempToken(isGetAllTempToken: true);
|
||||
|
||||
|
||||
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
||||
|
||||
var _ossClient = new OssClient(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? aliConfig.EndPoint : aliConfig.InternalEndpoint, AliyunOSSTempToken.AccessKeyId, AliyunOSSTempToken.AccessKeySecret, AliyunOSSTempToken.SecurityToken);
|
||||
|
||||
var awsConfig = ObjectStoreServiceOptions.AWS;
|
||||
|
||||
var credentials = new SessionAWSCredentials(AWSTempToken.AccessKeyId, AWSTempToken.SecretAccessKey, AWSTempToken.SessionToken);
|
||||
|
||||
//提供awsEndPoint(域名)进行访问配置
|
||||
var clientConfig = new AmazonS3Config
|
||||
{
|
||||
RegionEndpoint = RegionEndpoint.GetBySystemName(awsConfig.Region)
|
||||
};
|
||||
|
||||
var amazonS3Client = new AmazonS3Client(credentials, clientConfig);
|
||||
|
||||
|
||||
// 根据源选择流式下载
|
||||
Stream sourceStream = source switch
|
||||
{
|
||||
ObjectStoreUse.AliyunOSS => _ossClient.GetObject(aliConfig.BucketName, objectKey).Content,
|
||||
ObjectStoreUse.AWS => (await amazonS3Client.GetObjectAsync(awsConfig.BucketName, objectKey, ct)).ResponseStream,
|
||||
_ => throw new BusinessValidationFailedException("未定义的同步类型")
|
||||
};
|
||||
|
||||
if (source == ObjectStoreUse.AliyunOSS)
|
||||
{
|
||||
var putRequest = new Amazon.S3.Model.PutObjectRequest
|
||||
{
|
||||
BucketName = awsConfig.BucketName,
|
||||
Key = objectKey,
|
||||
InputStream = sourceStream
|
||||
};
|
||||
|
||||
await amazonS3Client.PutObjectAsync(putRequest, ct);
|
||||
}
|
||||
else if (source == ObjectStoreUse.AWS)
|
||||
{
|
||||
_ossClient.PutObject(aliConfig.BucketName, objectKey, sourceStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new BusinessValidationFailedException("未定义的同步类型");
|
||||
}
|
||||
|
||||
await sourceStream.DisposeAsync(); // 释放流
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1556,6 +1556,45 @@
|
|||
<param name="_attachmentrepository"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.Application.Service.FileSyncQueue">
|
||||
<summary>
|
||||
同步队列 信号量
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileSyncQueue.DequeueAsync(System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
如果没有任务 → 挂起等待 有任务 → 被唤醒并返回
|
||||
</summary>
|
||||
<param name="ct"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.SyncQueueUseChannel.Enqueue(System.Guid,System.Int32)">
|
||||
<summary>
|
||||
入队任务
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.SyncQueueUseChannel.DequeueAsync(System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
Worker 等待并获取任务
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:IRaCIS.Core.Application.Service.SyncQueueUseChannel.Count">
|
||||
<summary>
|
||||
当前排队数量(调试用)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.Application.Service.FileSyncScheduler">
|
||||
<summary>
|
||||
同步调度器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Service.FileSyncScheduler.WaitAsync(System.Threading.CancellationToken)">
|
||||
<summary>
|
||||
如果没有任务 → 挂起等待 有任务 → 被唤醒并返回
|
||||
</summary>
|
||||
<param name="ct"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:IRaCIS.Core.Application.Service.InternationalizationService">
|
||||
<summary>
|
||||
InternationalizationService
|
||||
|
|
@ -15895,7 +15934,7 @@
|
|||
<returns></returns>
|
||||
<exception cref="T:IRaCIS.Core.Infrastructure.BusinessValidationFailedException"></exception>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Helper.OSSService.UploadToOSSAsync(System.IO.Stream,System.String,System.String,System.Boolean)">
|
||||
<member name="M:IRaCIS.Core.Application.Helper.OSSService.UploadToOSSAsync(System.IO.Stream,System.String,System.String,System.Boolean,IRaCIS.Core.Application.ViewModel.FileUploadRecordAddOrEdit)">
|
||||
<summary>
|
||||
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||
</summary>
|
||||
|
|
@ -15903,9 +15942,10 @@
|
|||
<param name="oosFolderPath"></param>
|
||||
<param name="fileRealName"></param>
|
||||
<param name="isFileNameAddGuid"></param>
|
||||
<param name="uploadInfo"> 只用赋值业务参数Id 和批次信息即可,其他信息不用传递</param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:IRaCIS.Core.Application.Helper.OSSService.UploadToOSSAsync(System.String,System.String,System.Boolean,System.Boolean)">
|
||||
<member name="M:IRaCIS.Core.Application.Helper.OSSService.UploadToOSSAsync(System.String,System.String,System.Boolean,System.Boolean,IRaCIS.Core.Application.ViewModel.FileUploadRecordAddOrEdit)">
|
||||
<summary>
|
||||
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||
</summary>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ using IRaCIS.Core.Application.Contracts;
|
|||
using IRaCIS.Core.Application.Contracts.DTO;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.MassTransit.Command;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using MassTransit;
|
||||
|
|
@ -448,7 +449,7 @@ namespace IRaCIS.Core.Application.MassTransit.Consumer
|
|||
|
||||
var fileStreamResult = (FileStreamResult)await ExcelExportHelper.DataExportAsync(StaticData.Export.TrialConsistentFUllCheckList_Export, exportInfo, exportInfo.TrialCode, _commonDocumentRepository, _hostEnvironment, _dictionaryService, typeof(FullCheckResult));
|
||||
|
||||
var ossRelativePath = await _oSSService.UploadToOSSAsync(fileStreamResult.FileStream, $"{trialId.ToString()}/InspectionUpload/DataReconciliation", "DataReconciliation");
|
||||
var ossRelativePath = await _oSSService.UploadToOSSAsync(fileStreamResult.FileStream, $"{trialId.ToString()}/InspectionUpload/DataReconciliation", "DataReconciliation", uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialId, BatchDataType = BatchDataType.DataReconciliation });
|
||||
|
||||
|
||||
//var add = await _inspectionFileRepository.FindAsync(inspectionFileId);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,107 @@
|
|||
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由liquid模板自动生成 byzhouhang 20240909
|
||||
// 生成时间 2026-03-10 06:15:31Z
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using System;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using System.Collections.Generic;
|
||||
namespace IRaCIS.Core.Application.ViewModel;
|
||||
|
||||
public class FileUploadRecordView : FileUploadRecordAddOrEdit
|
||||
{
|
||||
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
public DateTime UpdateTime { get; set; }
|
||||
|
||||
public bool? IsSync { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class FileUploadRecordAddOrEdit
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
|
||||
public string FileName { get; set; }
|
||||
|
||||
public long FileSize { get; set; }
|
||||
|
||||
public string FileType { get; set; }
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
|
||||
public string UploadBatchId { get; set; }
|
||||
public BatchDataType BatchDataType { get; set; }
|
||||
|
||||
|
||||
public Guid? TrialId { get; set; }
|
||||
|
||||
public Guid? SubjectId { get; set; }
|
||||
|
||||
public Guid? SubjectVisitId { get; set; }
|
||||
|
||||
public Guid? DicomStudyId { get; set; }
|
||||
|
||||
public Guid? NoneDicomStudyId { get; set; }
|
||||
|
||||
|
||||
|
||||
public string FileMarkId { get; set; }
|
||||
|
||||
public int? Priority { get; set; }
|
||||
public string IP { get; set; }
|
||||
public bool? IsNeedSync { get; set; }
|
||||
public string UploadRegion { get; set; }
|
||||
public string TargetRegion { get; set; }
|
||||
}
|
||||
|
||||
public class FileUploadRecordQuery : PageInput
|
||||
{
|
||||
public BatchDataType? BatchDataType { get; set; }
|
||||
|
||||
|
||||
public string? FileMarkId { get; set; }
|
||||
|
||||
public string? FileName { get; set; }
|
||||
|
||||
|
||||
public string? FileType { get; set; }
|
||||
|
||||
public string? IP { get; set; }
|
||||
|
||||
public bool? IsNeedSync { get; set; }
|
||||
|
||||
public bool? IsSync { get; set; }
|
||||
|
||||
|
||||
public string? Path { get; set; }
|
||||
|
||||
public int? Priority { get; set; }
|
||||
|
||||
public string? TargetRegion { get; set; }
|
||||
|
||||
|
||||
public string? UploadBatchId { get; set; }
|
||||
|
||||
public string? UploadRegion { get; set; }
|
||||
|
||||
|
||||
public DateTime? SyncFinishedStartTime { get; set; }
|
||||
|
||||
public DateTime? SyncFinishedEndTime { get; set; }
|
||||
|
||||
public DateTime? UploadStartTime { get; set; }
|
||||
|
||||
public DateTime? UploadEndTime { get; set; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -155,7 +155,8 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
|||
fileStream: decodeStream,
|
||||
oosFolderPath: $"EmailAttachment/{emailInfo.Id}", // OSS 虚拟目录
|
||||
fileRealName: emaliAttachmentInfo.AttachmentName,
|
||||
isFileNameAddGuid: true); // 让方法自己在文件名前加 Guid
|
||||
isFileNameAddGuid: true,
|
||||
uploadInfo: new FileUploadRecordAddOrEdit() {TrialId= inDto.TrialId, BatchDataType = BatchDataType.EmailAttach }); // 让方法自己在文件名前加 Guid
|
||||
|
||||
attachmentInfos.Add(emaliAttachmentInfo);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,292 @@
|
|||
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由liquid模板自动生成 byzhouhang 20240909
|
||||
// 生成时间 2026-03-10 06:15:17Z
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.Interfaces;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Infra.EFCore;
|
||||
using IRaCIS.Core.Infra.EFCore.Common;
|
||||
using IRaCIS.Core.Infrastructure.Extention;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Spire.Doc.Interface;
|
||||
using System.Drawing;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IRaCIS.Core.Application.Service;
|
||||
|
||||
[ApiExplorerSettings(GroupName = "Common")]
|
||||
public class FileUploadRecordService(IRepository<FileUploadRecord> _fileUploadRecordRepository,
|
||||
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer, IOptionsMonitor<ObjectStoreServiceOptions> options,
|
||||
IFusionCache _fusionCache, IRepository<Trial> _trialRepository, FileSyncQueue _fileSyncQueue) : BaseService, IFileUploadRecordService
|
||||
{
|
||||
|
||||
ObjectStoreServiceOptions ObjectStoreServiceConfig = options.CurrentValue;
|
||||
|
||||
[HttpPost]
|
||||
public async Task<PageOutput<FileUploadRecordView>> GetFileUploadRecordList(FileUploadRecordQuery inQuery)
|
||||
{
|
||||
|
||||
var fileUploadRecordQueryable = _fileUploadRecordRepository
|
||||
.WhereIf(inQuery.BatchDataType != null, t => t.BatchDataType == inQuery.BatchDataType)
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.FileName), t => t.FileName.Contains(inQuery.FileName))
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.FileType), t => t.FileType.Contains(inQuery.FileType))
|
||||
.WhereIf(inQuery.IsSync != null, t => t.IsSync == inQuery.IsSync)
|
||||
.WhereIf(inQuery.Priority != null, t => t.Priority == inQuery.Priority)
|
||||
.WhereIf(inQuery.BatchDataType != null, t => t.BatchDataType == inQuery.BatchDataType)
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.UploadRegion), t => t.UploadRegion.Contains(inQuery.UploadRegion))
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.TargetRegion), t => t.TargetRegion.Contains(inQuery.TargetRegion))
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.UploadBatchId), t => t.UploadBatchId.Contains(inQuery.UploadBatchId))
|
||||
.WhereIf(!string.IsNullOrEmpty(inQuery.Path), t => t.Path.Contains(inQuery.Path))
|
||||
.WhereIf(inQuery.UploadStartTime != null, t => t.CreateTime >= inQuery.UploadStartTime)
|
||||
.WhereIf(inQuery.UploadEndTime != null, t => t.CreateTime <= inQuery.UploadEndTime)
|
||||
.WhereIf(inQuery.SyncFinishedStartTime != null, t => t.SyncFinishedTime >= inQuery.SyncFinishedStartTime)
|
||||
.WhereIf(inQuery.SyncFinishedEndTime != null, t => t.SyncFinishedTime <= inQuery.SyncFinishedEndTime)
|
||||
|
||||
.ProjectTo<FileUploadRecordView>(_mapper.ConfigurationProvider);
|
||||
|
||||
var pageList = await fileUploadRecordQueryable.ToPagedListAsync(inQuery);
|
||||
|
||||
return pageList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public async Task<IResponseOutput> AddOrUpdateFileUploadRecord(FileUploadRecordAddOrEdit addOrEditFileUploadRecord)
|
||||
{
|
||||
|
||||
addOrEditFileUploadRecord.IP = _userInfo.IP;
|
||||
|
||||
if (ObjectStoreServiceConfig.IsOpenStoreSync && _userInfo.Domain.IsNotNullOrEmpty())
|
||||
{
|
||||
var find = ObjectStoreServiceConfig.SyncConfigList.FirstOrDefault(t => t.Domain == _userInfo.Domain);
|
||||
if (find != null)
|
||||
{
|
||||
addOrEditFileUploadRecord.UploadRegion = find.UploadRegion;
|
||||
addOrEditFileUploadRecord.TargetRegion = find.TargetRegion;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (addOrEditFileUploadRecord.TrialId != null)
|
||||
{
|
||||
|
||||
var trialDataStore = await _fusionCache.GetOrSetAsync(CacheKeys.TrialDataStoreType(addOrEditFileUploadRecord.TrialId.Value), async _ =>
|
||||
{
|
||||
return await _trialRepository.Where(t => t.Id == addOrEditFileUploadRecord.TrialId).Select(t => t.TrialDataStoreType)
|
||||
.FirstOrDefaultAsync();
|
||||
},
|
||||
TimeSpan.FromDays(7)
|
||||
);
|
||||
|
||||
//项目配置了,那么就设置需要同步
|
||||
if (trialDataStore == TrialDataStore.MUtiCenter)
|
||||
{
|
||||
addOrEditFileUploadRecord.IsNeedSync = true;
|
||||
|
||||
addOrEditFileUploadRecord.Priority = 0;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
addOrEditFileUploadRecord.TargetRegion = "";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//系统文件,默认同步
|
||||
addOrEditFileUploadRecord.IsNeedSync = true;
|
||||
|
||||
addOrEditFileUploadRecord.Priority = 0;
|
||||
}
|
||||
|
||||
var entity = await _fileUploadRecordRepository.InsertOrUpdateAsync(addOrEditFileUploadRecord, true);
|
||||
|
||||
if (addOrEditFileUploadRecord.IsNeedSync == true)
|
||||
{
|
||||
_fileSyncQueue.Enqueue(entity.Id, addOrEditFileUploadRecord.Priority ?? 0);
|
||||
}
|
||||
|
||||
return ResponseOutput.Ok(entity.Id.ToString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("{fileUploadRecordId:guid}")]
|
||||
public async Task<IResponseOutput> DeleteFileUploadRecord(Guid fileUploadRecordId)
|
||||
{
|
||||
var success = await _fileUploadRecordRepository.BatchDeleteNoTrackingAsync(t => t.Id == fileUploadRecordId);
|
||||
return ResponseOutput.Ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 同步队列
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 同步队列 信号量
|
||||
/// </summary>
|
||||
public class FileSyncQueue
|
||||
{
|
||||
private readonly PriorityQueue<Guid, int> _queue = new();
|
||||
private readonly SemaphoreSlim _signal = new(0);
|
||||
private readonly object _lock = new();
|
||||
|
||||
public void Enqueue(Guid id, int priority)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
// priority 越大越优先
|
||||
_queue.Enqueue(id, -priority);
|
||||
}
|
||||
|
||||
//类似于计数器,不会产生通知风暴,可消费资源 +1
|
||||
//if (有等待线程) 唤醒一个 else 仅增加计数
|
||||
_signal.Release(); // 唤醒一个 worker
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果没有任务 → 挂起等待 有任务 → 被唤醒并返回
|
||||
/// </summary>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Guid> DequeueAsync(CancellationToken ct)
|
||||
{
|
||||
await _signal.WaitAsync(ct);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
return _queue.Dequeue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region 这里不用 SyncQueueUseChannel 和调度器 SyncScheduler
|
||||
public class SyncQueueUseChannel
|
||||
{
|
||||
// 优先级队列(priority 越大越先执行)
|
||||
private readonly PriorityQueue<Guid, int> _queue = new();
|
||||
|
||||
// Worker 唤醒信号
|
||||
private readonly Channel<bool> _signal =
|
||||
Channel.CreateUnbounded<bool>(new UnboundedChannelOptions
|
||||
{
|
||||
SingleReader = false,
|
||||
SingleWriter = false
|
||||
});
|
||||
|
||||
// 队列任务数量(不是CPU数量!)
|
||||
private int _count = 0;
|
||||
|
||||
|
||||
private readonly object _lock = new();
|
||||
|
||||
/// <summary>
|
||||
/// 入队任务
|
||||
/// </summary>
|
||||
public void Enqueue(Guid id, int priority)
|
||||
{
|
||||
bool needSignal = false;
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
// priority 越大越优先 → 转负数
|
||||
_queue.Enqueue(id, -priority);
|
||||
|
||||
// 只有从 0 → 1 才需要唤醒 worker
|
||||
if (_count == 0)
|
||||
needSignal = true;
|
||||
|
||||
_count++;
|
||||
}
|
||||
|
||||
// 避免 signal 风暴
|
||||
if (needSignal)
|
||||
_signal.Writer.TryWrite(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Worker 等待并获取任务
|
||||
/// </summary>
|
||||
public async Task<Guid> DequeueAsync(CancellationToken ct)
|
||||
{
|
||||
|
||||
// 没任务时挂起(不会占CPU)
|
||||
await _signal.Reader.ReadAsync(ct);
|
||||
|
||||
lock (_lock)
|
||||
{
|
||||
var id = _queue.Dequeue();
|
||||
|
||||
_count--;
|
||||
|
||||
// 如果还有任务,继续唤醒下一个 worker
|
||||
if (_count > 0)
|
||||
_signal.Writer.TryWrite(true);
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前排队数量(调试用)
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_lock)
|
||||
return _count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步调度器
|
||||
/// </summary>
|
||||
public class FileSyncScheduler
|
||||
{
|
||||
private readonly FileSyncQueue _queue;
|
||||
|
||||
public FileSyncScheduler(FileSyncQueue queue)
|
||||
{
|
||||
_queue = queue;
|
||||
}
|
||||
|
||||
public void Enqueue(FileUploadRecord file)
|
||||
{
|
||||
if (file.IsNeedSync != true)
|
||||
return;
|
||||
|
||||
_queue.Enqueue(file.Id, file.Priority ?? 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果没有任务 → 挂起等待 有任务 → 被唤醒并返回
|
||||
/// </summary>
|
||||
/// <param name="ct"></param>
|
||||
/// <returns></returns>
|
||||
public Task<Guid> WaitAsync(CancellationToken ct)
|
||||
=> _queue.DequeueAsync(ct);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
//--------------------------------------------------------------------
|
||||
// 此代码由liquid模板自动生成 byzhouhang 20240909
|
||||
// 生成时间 2026-03-10 06:15:31Z
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
|
||||
//--------------------------------------------------------------------
|
||||
using System;
|
||||
using IRaCIS.Core.Infrastructure.Extention;
|
||||
using System.Threading.Tasks;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
namespace IRaCIS.Core.Application.Interfaces;
|
||||
|
||||
public interface IFileUploadRecordService
|
||||
{
|
||||
|
||||
Task<PageOutput<FileUploadRecordView>> GetFileUploadRecordList(FileUploadRecordQuery inQuery);
|
||||
|
||||
Task<IResponseOutput> AddOrUpdateFileUploadRecord(FileUploadRecordAddOrEdit addOrEditFileUploadRecord);
|
||||
|
||||
Task<IResponseOutput> DeleteFileUploadRecord(Guid fileUploadRecordId);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -124,6 +124,9 @@ namespace IRaCIS.Core.Application.Service
|
|||
CreateMap<IVUS_OCTBaseDto, IvusExportDto>();
|
||||
CreateMap<IVUS_OCTBaseDto, OctExportDto>();
|
||||
|
||||
|
||||
CreateMap<FileUploadRecord, FileUploadRecordView>();
|
||||
CreateMap<FileUploadRecord, FileUploadRecordAddOrEdit>().ReverseMap();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
||||
using IRaCIS.Core.Application.Helper;
|
||||
using IRaCIS.Core.Application.Service.Reading.Dto;
|
||||
using IRaCIS.Core.Application.ViewModel;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using IRaCIS.Core.Domain.Share;
|
||||
using IRaCIS.Core.Infra.EFCore.Common;
|
||||
|
|
@ -432,7 +433,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
|||
|
||||
try
|
||||
{
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, "InspectionUpload/"+ pathCode, file.FileName);
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, $"{trialId}/InspectionUpload/" + pathCode, file.FileName, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialId, BatchDataType = BatchDataType.ReadingImportTemplete });
|
||||
await _inspectionFileRepository.AddAsync(new InspectionFile() { FileName = file.FileName, RelativePath = ossRelativePath, TrialId = trialId });
|
||||
}
|
||||
catch (Exception)
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
|||
await file.CopyToAsync(streamCopy);
|
||||
// 重置流的位置,以便后续读取
|
||||
streamCopy.Position = 0;
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(streamCopy, $"{visitTaskInfo.TrialId.ToString()}/InspectionUpload/ReadingImport", file.FileName);
|
||||
var ossRelativePath = await oSSService.UploadToOSSAsync(streamCopy, $"{visitTaskInfo.TrialId.ToString()}/InspectionUpload/ReadingImport", file.FileName, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = visitTaskInfo.TrialId, BatchDataType = BatchDataType.ReadingImportTemplete });
|
||||
|
||||
|
||||
await _readingImportFileRepository.AddAsync(new ReadingImportFile()
|
||||
|
|
@ -351,7 +351,8 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
|||
private async Task<GetReportsChartDataOutDto> GetReportsChartTypeData(GetReportsChartTypeDataInDto inDto)
|
||||
{
|
||||
var visitTaskNameList = inDto.Data.VisitTaskList.Select(x => x.BlindName).ToList();
|
||||
GetReportsChartDataOutDto result = new GetReportsChartDataOutDto() {
|
||||
GetReportsChartDataOutDto result = new GetReportsChartDataOutDto()
|
||||
{
|
||||
|
||||
ChartDataList = new List<ReportChartData>() { },
|
||||
VisitTaskNameList = visitTaskNameList,
|
||||
|
|
@ -518,7 +519,8 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
|||
|
||||
|
||||
|
||||
result.Evaluation.Add(visitTaskName.Select(x=> new EvaluationValue() {
|
||||
result.Evaluation.Add(visitTaskName.Select(x => new EvaluationValue()
|
||||
{
|
||||
Value = x
|
||||
}).ToList());
|
||||
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ namespace IRaCIS.Core.Application
|
|||
foreach (var item in systemCriterionKeyFile)
|
||||
{
|
||||
|
||||
var path = await _oSSService.UploadToOSSAsync(item.FilePath, $"{trialCriterion.TrialId}/ReadingModule/{trialCriterion.CriterionName}", true, true);
|
||||
var path = await _oSSService.UploadToOSSAsync(item.FilePath, $"{trialCriterion.TrialId}/ReadingModule/{trialCriterion.CriterionName}", true, true, uploadInfo: new FileUploadRecordAddOrEdit() { TrialId = trialCriterion.TrialId ,BatchDataType=BatchDataType.ReadingKeyFile });
|
||||
|
||||
trialCriterionKeyFiles.Add(new TrialCriterionKeyFile
|
||||
{
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ public class FileUploadRecord : BaseFullAuditEntity
|
|||
public string UploadBatchId { get; set; }
|
||||
|
||||
[Comment("该批次数据类型")]
|
||||
public int BatchDataType { get; set; }
|
||||
public BatchDataType BatchDataType { get; set; }
|
||||
|
||||
[Comment("上传区域")]
|
||||
public string UploadRegion { get; set; }
|
||||
|
|
@ -109,3 +109,25 @@ public enum jobState
|
|||
CANCELLED = 4
|
||||
|
||||
}
|
||||
|
||||
public enum BatchDataType
|
||||
{
|
||||
//前端自定义 1-99
|
||||
//后端自定义100开始
|
||||
|
||||
|
||||
DataReconciliation=100,
|
||||
|
||||
SiteUserSurvey=101,
|
||||
|
||||
DICOMDIR = 102,
|
||||
|
||||
EmailAttach=103,
|
||||
|
||||
ReadingImportTemplete=105,
|
||||
|
||||
ReadingKeyFile=106,
|
||||
|
||||
PACSReceive = 107
|
||||
|
||||
}
|
||||
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
string IP { get; }
|
||||
|
||||
string Domain { get; }
|
||||
|
||||
string LocalIp { get; }
|
||||
|
||||
bool IsEn_Us { get; }
|
||||
|
|
|
|||
|
|
@ -227,7 +227,17 @@ namespace IRaCIS.Core.Domain.Share
|
|||
get
|
||||
{
|
||||
|
||||
return _accessor?.HttpContext.GetClientIP();
|
||||
return _accessor?.HttpContext?.GetClientIP() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string Domain
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
return _accessor?.HttpContext?.Request.Host.Host ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -237,7 +247,7 @@ namespace IRaCIS.Core.Domain.Share
|
|||
get
|
||||
{
|
||||
|
||||
return _accessor?.HttpContext?.Connection.LocalIpAddress.MapToIPv4().ToString();
|
||||
return _accessor?.HttpContext?.Connection?.LocalIpAddress?.MapToIPv4().ToString() ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue