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 配置服务
|
#region 配置服务
|
||||||
var _configuration = builder.Configuration;
|
var _configuration = builder.Configuration;
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<FileSyncQueue>();
|
||||||
|
builder.Services.AddHostedService<SyncFileRecoveryService>();
|
||||||
|
builder.Services.AddHostedService<FileSyncWorker>();
|
||||||
|
|
||||||
//健康检查
|
//健康检查
|
||||||
builder.Services.AddHealthChecks();
|
builder.Services.AddHealthChecks();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -644,7 +644,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
|
|
||||||
//irc 从路径最后一截取Guid
|
//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;
|
fileSize = ms.Length;
|
||||||
|
|
||||||
|
|
@ -674,7 +674,7 @@ namespace IRaCIS.Core.SCP.Service
|
||||||
|
|
||||||
// 上传缩略图到 OSS
|
// 上传缩略图到 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;
|
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 UserMFAVerifyPass(Guid userId, string browserFingerprint) => $"UserMFAVerifyPass:{userId}:{browserFingerprint}";
|
||||||
|
|
||||||
public static string TrialSiteInfo(Guid trialSiteId) => $"{trialSiteId}TrialSiteInfo";
|
public static string TrialSiteInfo(Guid trialSiteId) => $"{trialSiteId}TrialSiteInfo";
|
||||||
|
|
||||||
|
public static string TrialDataStoreType(Guid trialId) => $"TrialDataStoreType:{trialId}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CacheHelper
|
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);
|
var result = _oSSService.GetObjectStoreTempToken(domain);
|
||||||
|
|
||||||
//result.AWS = await GetAWSTemToken(options.CurrentValue);
|
|
||||||
|
|
||||||
Log.Logger.Information($"使用域名:{domain}请求token.返回{result.ToJsonStr()}");
|
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.Helper;
|
||||||
using IRaCIS.Core.Application.MassTransit.Command;
|
using IRaCIS.Core.Application.MassTransit.Command;
|
||||||
using IRaCIS.Core.Application.Service;
|
using IRaCIS.Core.Application.Service;
|
||||||
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Domain.Models;
|
using IRaCIS.Core.Domain.Models;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infra.EFCore;
|
using IRaCIS.Core.Infra.EFCore;
|
||||||
|
|
@ -598,7 +599,7 @@ namespace IRaCIS.Core.API.Controllers
|
||||||
templateFileStream.Seek(0, SeekOrigin.Begin);
|
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);
|
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"]);
|
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);
|
await _inspectionFileRepository.AddAsync(new InspectionFile() { FileName = realFileName, RelativePath = ossRelativePath, TrialId = trialId }, true);
|
||||||
|
|
||||||
|
|
@ -1008,7 +1009,7 @@ namespace IRaCIS.Core.API.Controllers
|
||||||
|
|
||||||
Other = 6,
|
Other = 6,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -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.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
@ -88,6 +89,10 @@ builder.Services.ConfigureServices(_configuration);
|
||||||
|
|
||||||
builder.Services.AddHostedService<HangfireHostService>();
|
builder.Services.AddHostedService<HangfireHostService>();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<FileSyncQueue>();
|
||||||
|
builder.Services.AddHostedService<SyncFileRecoveryService>();
|
||||||
|
builder.Services.AddHostedService<FileSyncWorker>();
|
||||||
|
|
||||||
//minimal api 异常处理
|
//minimal api 异常处理
|
||||||
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
|
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
|
||||||
//builder.Services.AddProblemDetails();
|
//builder.Services.AddProblemDetails();
|
||||||
|
|
|
||||||
|
|
@ -29,16 +29,23 @@
|
||||||
// 使用的对象存储服务类型
|
// 使用的对象存储服务类型
|
||||||
"ObjectStoreUse": "AliyunOSS",
|
"ObjectStoreUse": "AliyunOSS",
|
||||||
"IsOpenStoreSync": false,
|
"IsOpenStoreSync": false,
|
||||||
|
"ApiDeployRegion": "CN",
|
||||||
"SyncConfigList": [
|
"SyncConfigList": [
|
||||||
{
|
{
|
||||||
"Domain": "ir.test.extimaging.com",
|
"Domain": "ir.test.extimaging.com",
|
||||||
"Primary": "AliyunOSS",
|
"Primary": "AliyunOSS",
|
||||||
"Target": "AWS"
|
"Target": "AWS",
|
||||||
|
"UploadRegion": "CN",
|
||||||
|
"TargetRegion": "US",
|
||||||
|
"IsOpenSync": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Domain": "lili.test.extimaging.com",
|
"Domain": "lili.test.extimaging.com",
|
||||||
"Primary": "AWS",
|
"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
|
public static class CacheKeys
|
||||||
|
|
@ -66,6 +68,9 @@ public static class CacheKeys
|
||||||
|
|
||||||
public static string UserMFATag(Guid userId) => $"UserMFAVerifyPass:{userId}";
|
public static string UserMFATag(Guid userId) => $"UserMFAVerifyPass:{userId}";
|
||||||
|
|
||||||
|
public static string TrialDataStoreType(Guid trialId) => $"TrialDataStoreType:{trialId}";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CacheHelper
|
public static class CacheHelper
|
||||||
|
|
@ -77,6 +82,9 @@ public static class CacheHelper
|
||||||
return statusStr;
|
return statusStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static async Task<List<SystemAnonymization>> GetSystemAnonymizationListAsync(IRepository<SystemAnonymization> _systemAnonymizationRepository)
|
public static async Task<List<SystemAnonymization>> GetSystemAnonymizationListAsync(IRepository<SystemAnonymization> _systemAnonymizationRepository)
|
||||||
{
|
{
|
||||||
var list = await _systemAnonymizationRepository.Where(t => t.IsEnable).ToListAsync();
|
var list = await _systemAnonymizationRepository.Where(t => t.IsEnable).ToListAsync();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using DocumentFormat.OpenXml.Office.CustomUI;
|
using DocumentFormat.OpenXml.Office.CustomUI;
|
||||||
using FellowOakDicom;
|
using FellowOakDicom;
|
||||||
using FellowOakDicom.Media;
|
using FellowOakDicom.Media;
|
||||||
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
|
using IRaCIS.Core.Domain.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
|
@ -58,7 +60,11 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
var mappings = new List<string>();
|
var mappings = new List<string>();
|
||||||
int index = 1;
|
int index = 1;
|
||||||
|
|
||||||
var studyUid=list.FirstOrDefault()?.StudyInstanceUid;
|
var trialId = Guid.Empty;
|
||||||
|
|
||||||
|
Guid.TryParse(ossFolder.Split('/', StringSplitOptions.RemoveEmptyEntries)[0], out trialId);
|
||||||
|
|
||||||
|
var studyUid = list.FirstOrDefault()?.StudyInstanceUid;
|
||||||
|
|
||||||
var dicomDir = new DicomDirectory();
|
var dicomDir = new DicomDirectory();
|
||||||
|
|
||||||
|
|
@ -130,9 +136,9 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
// 重置流位置
|
// 重置流位置
|
||||||
memoryStream.Position = 0;
|
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());
|
dic.Add($"{studyUid}_DICOMDIR", relativePath.Split('/').Last());
|
||||||
}
|
}
|
||||||
|
|
||||||
//清理临时文件
|
//清理临时文件
|
||||||
|
|
@ -146,7 +152,7 @@ namespace IRaCIS.Core.Application.Helper
|
||||||
var mappingText = string.Join(Environment.NewLine, mappings);
|
var mappingText = string.Join(Environment.NewLine, mappings);
|
||||||
await using var mappingStream = new MemoryStream(Encoding.UTF8.GetBytes(mappingText));
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ using Amazon.S3;
|
||||||
using Amazon.S3.Model;
|
using Amazon.S3.Model;
|
||||||
using Amazon.SecurityToken;
|
using Amazon.SecurityToken;
|
||||||
using Amazon.SecurityToken.Model;
|
using Amazon.SecurityToken.Model;
|
||||||
|
using IRaCIS.Core.Application.Interfaces;
|
||||||
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Infrastructure;
|
using IRaCIS.Core.Infrastructure;
|
||||||
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
using IRaCIS.Core.Infrastructure.NewtonsoftJson;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
|
|
@ -16,7 +18,9 @@ using Minio;
|
||||||
using Minio.DataModel;
|
using Minio.DataModel;
|
||||||
using Minio.DataModel.Args;
|
using Minio.DataModel.Args;
|
||||||
using Minio.Exceptions;
|
using Minio.Exceptions;
|
||||||
|
using Org.BouncyCastle.Tls;
|
||||||
using Serilog.Parsing;
|
using Serilog.Parsing;
|
||||||
|
using SkiaSharp;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
@ -83,6 +87,8 @@ public class ObjectStoreServiceOptions
|
||||||
|
|
||||||
public bool IsOpenStoreSync { get; set; }
|
public bool IsOpenStoreSync { get; set; }
|
||||||
|
|
||||||
|
public string ApiDeployRegion { get; set; }
|
||||||
|
|
||||||
public List<SyncStoreConfig> SyncConfigList { get; set; } = new List<SyncStoreConfig>();
|
public List<SyncStoreConfig> SyncConfigList { get; set; } = new List<SyncStoreConfig>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -91,10 +97,16 @@ public class SyncStoreConfig
|
||||||
{
|
{
|
||||||
public string Domain { get; set; }
|
public string Domain { get; set; }
|
||||||
|
|
||||||
|
public string UploadRegion { get; set; }
|
||||||
|
|
||||||
|
public string TargetRegion { get; set; }
|
||||||
|
|
||||||
public string Primary { get; set; }
|
public string Primary { get; set; }
|
||||||
|
|
||||||
public string Target { get; set; }
|
public string Target { get; set; }
|
||||||
|
|
||||||
|
public bool IsOpenSync { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ObjectStoreDTO
|
public class ObjectStoreDTO
|
||||||
|
|
@ -156,6 +168,7 @@ public enum ObjectStoreUse
|
||||||
AWS = 2,
|
AWS = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// aws 参考链接 https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/S3/S3_Basics
|
// 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 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(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);
|
public Task<string> UploadToOSSAsync(string localFilePath, string oosFolderPath, bool isFileNameAddGuid = true, bool randomFileName = false, FileUploadRecordAddOrEdit? uploadInfo = null);
|
||||||
|
|
||||||
public Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath);
|
public Task DownLoadFromOSSAsync(string ossRelativePath, string localFilePath);
|
||||||
|
|
||||||
|
|
@ -183,28 +196,27 @@ public interface IOSSService
|
||||||
|
|
||||||
List<string> GetRootFolderNames();
|
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 MoveObject(string sourcePath, string destPath, bool overwrite = true);
|
||||||
|
|
||||||
public Task<long> GetObjectSizeAsync(string sourcePath);
|
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 AliyunOSSTempToken AliyunOSSTempToken { get; set; }
|
||||||
|
|
||||||
private AWSTempToken AWSTempToken { get; set; }
|
private AWSTempToken AWSTempToken { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public OSSService(IOptionsMonitor<ObjectStoreServiceOptions> options)
|
|
||||||
{
|
|
||||||
ObjectStoreServiceOptions = options.CurrentValue;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 将指定前缀下的所有现有文件立即转为目标存储类型
|
/// 将指定前缀下的所有现有文件立即转为目标存储类型
|
||||||
|
|
@ -719,6 +731,9 @@ public class OSSService : IOSSService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
/// oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -726,8 +741,9 @@ public class OSSService : IOSSService
|
||||||
/// <param name="oosFolderPath"></param>
|
/// <param name="oosFolderPath"></param>
|
||||||
/// <param name="fileRealName"></param>
|
/// <param name="fileRealName"></param>
|
||||||
/// <param name="isFileNameAddGuid"></param>
|
/// <param name="isFileNameAddGuid"></param>
|
||||||
|
/// <param name="uploadInfo"> 只用赋值业务参数Id 和批次信息即可,其他信息不用传递</param>
|
||||||
/// <returns></returns>
|
/// <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();
|
BackBatchGetToken();
|
||||||
|
|
||||||
|
|
@ -735,13 +751,8 @@ public class OSSService : IOSSService
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var memoryStream = new MemoryStream())
|
if (fileStream.CanSeek)
|
||||||
{
|
fileStream.Seek(0, SeekOrigin.Begin);
|
||||||
fileStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
fileStream.CopyTo(memoryStream);
|
|
||||||
|
|
||||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
|
|
||||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
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")
|
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
||||||
|
|
@ -768,8 +779,8 @@ public class OSSService : IOSSService
|
||||||
var putObjectArgs = new PutObjectArgs()
|
var putObjectArgs = new PutObjectArgs()
|
||||||
.WithBucket(minIOConfig.BucketName)
|
.WithBucket(minIOConfig.BucketName)
|
||||||
.WithObject(ossRelativePath)
|
.WithObject(ossRelativePath)
|
||||||
.WithStreamData(memoryStream)
|
.WithStreamData(fileStream)
|
||||||
.WithObjectSize(memoryStream.Length);
|
.WithObjectSize(fileStream.Length);
|
||||||
|
|
||||||
await minioClient.PutObjectAsync(putObjectArgs);
|
await minioClient.PutObjectAsync(putObjectArgs);
|
||||||
}
|
}
|
||||||
|
|
@ -793,7 +804,7 @@ public class OSSService : IOSSService
|
||||||
var putObjectRequest = new Amazon.S3.Model.PutObjectRequest()
|
var putObjectRequest = new Amazon.S3.Model.PutObjectRequest()
|
||||||
{
|
{
|
||||||
BucketName = awsConfig.BucketName,
|
BucketName = awsConfig.BucketName,
|
||||||
InputStream = memoryStream,
|
InputStream = fileStream,
|
||||||
Key = ossRelativePath,
|
Key = ossRelativePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -803,7 +814,6 @@ public class OSSService : IOSSService
|
||||||
{
|
{
|
||||||
throw new BusinessValidationFailedException("未定义的存储介质类型");
|
throw new BusinessValidationFailedException("未定义的存储介质类型");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
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
|
//后端批量上传 或者下载,不每个文件获取临时token
|
||||||
private void BackBatchGetToken()
|
private void BackBatchGetToken()
|
||||||
{
|
{
|
||||||
|
|
@ -860,10 +884,12 @@ public class OSSService : IOSSService
|
||||||
/// <param name="randomFileName">随机文件名</param>
|
/// <param name="randomFileName">随机文件名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="BusinessValidationFailedException"></exception>
|
/// <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();
|
BackBatchGetToken();
|
||||||
|
|
||||||
|
long fileSize = 0;
|
||||||
|
|
||||||
var localFileName = Path.GetFileName(localFilePath);
|
var localFileName = Path.GetFileName(localFilePath);
|
||||||
|
|
||||||
var ossRelativePath = isFileNameAddGuid ? $"{oosFolderPath}/{Guid.NewGuid()}_{localFileName}" : $"{oosFolderPath}/{localFileName}";
|
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);
|
var result = _ossClient.PutObject(aliConfig.BucketName, ossRelativePath, localFilePath);
|
||||||
|
|
||||||
|
fileSize = result.ContentLength;
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
||||||
{
|
{
|
||||||
|
|
@ -898,7 +926,9 @@ public class OSSService : IOSSService
|
||||||
.WithObject(ossRelativePath)
|
.WithObject(ossRelativePath)
|
||||||
.WithFileName(localFilePath);
|
.WithFileName(localFilePath);
|
||||||
|
|
||||||
await minioClient.PutObjectAsync(putObjectArgs);
|
var result = await minioClient.PutObjectAsync(putObjectArgs);
|
||||||
|
|
||||||
|
fileSize = result.Size;
|
||||||
}
|
}
|
||||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS")
|
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS")
|
||||||
{
|
{
|
||||||
|
|
@ -923,14 +953,30 @@ public class OSSService : IOSSService
|
||||||
Key = ossRelativePath,
|
Key = ossRelativePath,
|
||||||
};
|
};
|
||||||
|
|
||||||
await amazonS3Client.PutObjectAsync(putObjectRequest);
|
var result = await amazonS3Client.PutObjectAsync(putObjectRequest);
|
||||||
|
fileSize = result.ContentLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new BusinessValidationFailedException("未定义的存储介质类型");
|
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;
|
return result.Content;
|
||||||
|
|
||||||
//// 将OSS返回的流复制到内存流中并返回
|
|
||||||
//var memoryStream = new MemoryStream();
|
|
||||||
//await result.Content.CopyToAsync(memoryStream);
|
|
||||||
//memoryStream.Position = 0; // 重置位置以便读取
|
|
||||||
//return memoryStream;
|
|
||||||
}
|
}
|
||||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
else if (ObjectStoreServiceOptions.ObjectStoreUse == "MinIO")
|
||||||
{
|
{
|
||||||
|
|
@ -1112,10 +1153,6 @@ public class OSSService : IOSSService
|
||||||
// ⭐ 直接返回流
|
// ⭐ 直接返回流
|
||||||
return response.ResponseStream;
|
return response.ResponseStream;
|
||||||
|
|
||||||
//var memoryStream = new MemoryStream();
|
|
||||||
//await response.ResponseStream.CopyToAsync(memoryStream);
|
|
||||||
//memoryStream.Position = 0;
|
|
||||||
//return memoryStream;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -1459,8 +1496,31 @@ public class OSSService : IOSSService
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task DeleteFromPrefix(string prefix, bool isCache = false)
|
public async Task DeleteFromPrefix(string prefix, bool isCache = false)
|
||||||
{
|
{
|
||||||
GetObjectStoreTempToken();
|
|
||||||
|
|
||||||
|
//打开了同步的,删除的时候,一起删除
|
||||||
|
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")
|
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
||||||
{
|
{
|
||||||
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
var aliConfig = ObjectStoreServiceOptions.AliyunOSS;
|
||||||
|
|
@ -1610,8 +1670,32 @@ public class OSSService : IOSSService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task DeleteObjects(List<string> objectKeys, bool isCache = false)
|
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();
|
GetObjectStoreTempToken();
|
||||||
|
|
||||||
if (ObjectStoreServiceOptions.ObjectStoreUse == "AliyunOSS")
|
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())
|
if (ObjectStoreServiceOptions.IsOpenStoreSync && domain.IsNotNullOrEmpty())
|
||||||
|
|
@ -1788,9 +1872,9 @@ public class OSSService : IOSSService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var objectStoreDTO = new ObjectStoreDTO() { ObjectStoreUse= ObjectStoreServiceOptions.ObjectStoreUse, IsOpenStoreSync = ObjectStoreServiceOptions.IsOpenStoreSync ,SyncConfigList= ObjectStoreServiceOptions .SyncConfigList};
|
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;
|
var ossOptions = ObjectStoreServiceOptions.AliyunOSS;
|
||||||
|
|
||||||
|
|
@ -1842,7 +1926,7 @@ public class OSSService : IOSSService
|
||||||
{
|
{
|
||||||
objectStoreDTO.MinIO = ObjectStoreServiceOptions.MinIO;
|
objectStoreDTO.MinIO = ObjectStoreServiceOptions.MinIO;
|
||||||
}
|
}
|
||||||
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS")
|
else if (ObjectStoreServiceOptions.ObjectStoreUse == "AWS" || isGetAllTempToken == true)
|
||||||
{
|
{
|
||||||
var awsOptions = ObjectStoreServiceOptions.AWS;
|
var awsOptions = ObjectStoreServiceOptions.AWS;
|
||||||
|
|
||||||
|
|
@ -1895,4 +1979,58 @@ public class OSSService : IOSSService
|
||||||
return objectStoreDTO;
|
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>
|
<param name="_attachmentrepository"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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">
|
<member name="T:IRaCIS.Core.Application.Service.InternationalizationService">
|
||||||
<summary>
|
<summary>
|
||||||
InternationalizationService
|
InternationalizationService
|
||||||
|
|
@ -15895,7 +15934,7 @@
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
<exception cref="T:IRaCIS.Core.Infrastructure.BusinessValidationFailedException"></exception>
|
<exception cref="T:IRaCIS.Core.Infrastructure.BusinessValidationFailedException"></exception>
|
||||||
</member>
|
</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>
|
<summary>
|
||||||
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||||
</summary>
|
</summary>
|
||||||
|
|
@ -15903,9 +15942,10 @@
|
||||||
<param name="oosFolderPath"></param>
|
<param name="oosFolderPath"></param>
|
||||||
<param name="fileRealName"></param>
|
<param name="fileRealName"></param>
|
||||||
<param name="isFileNameAddGuid"></param>
|
<param name="isFileNameAddGuid"></param>
|
||||||
|
<param name="uploadInfo"> 只用赋值业务参数Id 和批次信息即可,其他信息不用传递</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</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>
|
<summary>
|
||||||
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
oosFolderPath 不要 "/ "开头 应该: TempFolder/ChildFolder
|
||||||
</summary>
|
</summary>
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ using IRaCIS.Core.Application.Contracts;
|
||||||
using IRaCIS.Core.Application.Contracts.DTO;
|
using IRaCIS.Core.Application.Contracts.DTO;
|
||||||
using IRaCIS.Core.Application.Helper;
|
using IRaCIS.Core.Application.Helper;
|
||||||
using IRaCIS.Core.Application.MassTransit.Command;
|
using IRaCIS.Core.Application.MassTransit.Command;
|
||||||
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Domain.Models;
|
using IRaCIS.Core.Domain.Models;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using MassTransit;
|
using MassTransit;
|
||||||
|
|
@ -320,7 +321,7 @@ namespace IRaCIS.Core.Application.MassTransit.Consumer
|
||||||
join study in _studyRepository.AsQueryable() on sv.Id equals study.SubjectVisitId
|
join study in _studyRepository.AsQueryable() on sv.Id equals study.SubjectVisitId
|
||||||
select new CheckDBModel()
|
select new CheckDBModel()
|
||||||
{
|
{
|
||||||
SubjectStatus = sv.Subject.Status,
|
SubjectStatus = sv.Subject.Status,
|
||||||
SubjectVisitId = sv.Id,
|
SubjectVisitId = sv.Id,
|
||||||
SiteCode = sv.TrialSite.TrialSiteCode,
|
SiteCode = sv.TrialSite.TrialSiteCode,
|
||||||
StudyDate = study.StudyTime == null ? string.Empty : ((DateTime)study.StudyTime).ToString("yyyy-MM-dd"),
|
StudyDate = study.StudyTime == null ? string.Empty : ((DateTime)study.StudyTime).ToString("yyyy-MM-dd"),
|
||||||
|
|
@ -403,7 +404,7 @@ namespace IRaCIS.Core.Application.MassTransit.Consumer
|
||||||
{
|
{
|
||||||
SubjectStatus = dbCurrentVisitFirst.SubjectStatus,
|
SubjectStatus = dbCurrentVisitFirst.SubjectStatus,
|
||||||
CheckTime = DateTime.Now,
|
CheckTime = DateTime.Now,
|
||||||
CheckState=CheckStateEnum.CVPassed,
|
CheckState = CheckStateEnum.CVPassed,
|
||||||
SiteCode = dbCurrentVisitFirst.SiteCode,
|
SiteCode = dbCurrentVisitFirst.SiteCode,
|
||||||
SubjectCode = dbCurrentVisitFirst.SubjectCode,
|
SubjectCode = dbCurrentVisitFirst.SubjectCode,
|
||||||
VisitName = dbCurrentVisitFirst.VisitName,
|
VisitName = dbCurrentVisitFirst.VisitName,
|
||||||
|
|
@ -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 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);
|
//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,
|
fileStream: decodeStream,
|
||||||
oosFolderPath: $"EmailAttachment/{emailInfo.Id}", // OSS 虚拟目录
|
oosFolderPath: $"EmailAttachment/{emailInfo.Id}", // OSS 虚拟目录
|
||||||
fileRealName: emaliAttachmentInfo.AttachmentName,
|
fileRealName: emaliAttachmentInfo.AttachmentName,
|
||||||
isFileNameAddGuid: true); // 让方法自己在文件名前加 Guid
|
isFileNameAddGuid: true,
|
||||||
|
uploadInfo: new FileUploadRecordAddOrEdit() {TrialId= inDto.TrialId, BatchDataType = BatchDataType.EmailAttach }); // 让方法自己在文件名前加 Guid
|
||||||
|
|
||||||
attachmentInfos.Add(emaliAttachmentInfo);
|
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, IvusExportDto>();
|
||||||
CreateMap<IVUS_OCTBaseDto, OctExportDto>();
|
CreateMap<IVUS_OCTBaseDto, OctExportDto>();
|
||||||
|
|
||||||
|
|
||||||
|
CreateMap<FileUploadRecord, FileUploadRecordView>();
|
||||||
|
CreateMap<FileUploadRecord, FileUploadRecordAddOrEdit>().ReverseMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2582,7 +2582,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 后台任务调用,前端忽略该接口
|
/// 后台任务调用,前端忽略该接口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
using DocumentFormat.OpenXml.Drawing.Spreadsheet;
|
||||||
using IRaCIS.Core.Application.Helper;
|
using IRaCIS.Core.Application.Helper;
|
||||||
using IRaCIS.Core.Application.Service.Reading.Dto;
|
using IRaCIS.Core.Application.Service.Reading.Dto;
|
||||||
|
using IRaCIS.Core.Application.ViewModel;
|
||||||
using IRaCIS.Core.Domain.Models;
|
using IRaCIS.Core.Domain.Models;
|
||||||
using IRaCIS.Core.Domain.Share;
|
using IRaCIS.Core.Domain.Share;
|
||||||
using IRaCIS.Core.Infra.EFCore.Common;
|
using IRaCIS.Core.Infra.EFCore.Common;
|
||||||
|
|
@ -47,7 +48,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
/// <param name="needChangeType"></param>
|
/// <param name="needChangeType"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<ReadingReportDto>> GetReadingReportQuestion(
|
public async Task<List<ReadingReportDto>> GetReadingReportQuestion(
|
||||||
List<ReadingQuestionTrial>? questionList,
|
List<ReadingQuestionTrial>? questionList,
|
||||||
List<VisitTaskInfo> taskInfoList,
|
List<VisitTaskInfo> taskInfoList,
|
||||||
List<Globalanswer>? globalanswerList,
|
List<Globalanswer>? globalanswerList,
|
||||||
List<ReadingTaskQuestionAnswer>? answers,
|
List<ReadingTaskQuestionAnswer>? answers,
|
||||||
|
|
@ -217,7 +218,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
/// 复制既往新病灶答案
|
/// 复制既往新病灶答案
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task CopyHistoryAnswer(VisitTask taskinfo, List<ReadingTableAnswerRowInfo> tableRowList,List<ReadingTableQuestionAnswer> tableAnswerList)
|
public async Task CopyHistoryAnswer(VisitTask taskinfo, List<ReadingTableAnswerRowInfo> tableRowList, List<ReadingTableQuestionAnswer> tableAnswerList)
|
||||||
{
|
{
|
||||||
if (_userInfo.RequestUrl == "ReadingImageTask/resetReadingTask")
|
if (_userInfo.RequestUrl == "ReadingImageTask/resetReadingTask")
|
||||||
{
|
{
|
||||||
|
|
@ -226,16 +227,16 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
|
|
||||||
if (taskinfo.IsCopyLesionAnswer)
|
if (taskinfo.IsCopyLesionAnswer)
|
||||||
{
|
{
|
||||||
var historyTaskId = await _visitTaskRepository.Where(x =>
|
var historyTaskId = await _visitTaskRepository.Where(x =>
|
||||||
x.ReadingCategory == ReadingCategory.Visit &&
|
x.ReadingCategory == ReadingCategory.Visit &&
|
||||||
x.TrialReadingCriterionId == taskinfo.TrialReadingCriterionId &&
|
x.TrialReadingCriterionId == taskinfo.TrialReadingCriterionId &&
|
||||||
x.IsAnalysisCreate == taskinfo.IsAnalysisCreate &&
|
x.IsAnalysisCreate == taskinfo.IsAnalysisCreate &&
|
||||||
x.DoctorUserId == taskinfo.DoctorUserId &&
|
x.DoctorUserId == taskinfo.DoctorUserId &&
|
||||||
x.IsSelfAnalysis == taskinfo.IsSelfAnalysis &&
|
x.IsSelfAnalysis == taskinfo.IsSelfAnalysis &&
|
||||||
x.SubjectId == taskinfo.SubjectId &&
|
x.SubjectId == taskinfo.SubjectId &&
|
||||||
x.ReadingTaskState == ReadingTaskState.HaveSigned &&
|
x.ReadingTaskState == ReadingTaskState.HaveSigned &&
|
||||||
x.VisitTaskNum == taskinfo.VisitTaskNum &&
|
x.VisitTaskNum == taskinfo.VisitTaskNum &&
|
||||||
x.TaskState != TaskState.Effect &&
|
x.TaskState != TaskState.Effect &&
|
||||||
x.ArmEnum == taskinfo.ArmEnum)
|
x.ArmEnum == taskinfo.ArmEnum)
|
||||||
.OrderByDescending(x => x.SignTime)
|
.OrderByDescending(x => x.SignTime)
|
||||||
.Select(x => x.Id).FirstOrDefaultAsync();
|
.Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
@ -251,9 +252,9 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
var answerList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
var answerList = await _readingTaskQuestionAnswerRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
var questionMarkList=await _readingTaskQuestionMarkRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
var questionMarkList = await _readingTaskQuestionMarkRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
||||||
var noneDicomMarkList=await _readingNoneDicomMarkRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
var noneDicomMarkList = await _readingNoneDicomMarkRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
||||||
var noneDicomMarkBindingList=await _readingNoneDicomMarkBindingRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
var noneDicomMarkBindingList = await _readingNoneDicomMarkBindingRepository.Where(x => x.VisitTaskId == historyTaskId).ToListAsync();
|
||||||
|
|
||||||
foreach (var item in tableRowList)
|
foreach (var item in tableRowList)
|
||||||
{
|
{
|
||||||
|
|
@ -261,32 +262,32 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var historyRow = historyTableRowList.Where(x =>
|
var historyRow = historyTableRowList.Where(x =>
|
||||||
x.QuestionId == item.QuestionId &&
|
x.QuestionId == item.QuestionId &&
|
||||||
x.RowIndex == item.RowIndex &&
|
x.RowIndex == item.RowIndex &&
|
||||||
x.IdentityRowId==item.IdentityRowId &&
|
x.IdentityRowId == item.IdentityRowId &&
|
||||||
x.IdentityRowId !=null &&
|
x.IdentityRowId != null &&
|
||||||
x.OrganInfoId==item.OrganInfoId
|
x.OrganInfoId == item.OrganInfoId
|
||||||
).FirstOrDefault();
|
).FirstOrDefault();
|
||||||
|
|
||||||
if (historyRow != null)
|
if (historyRow != null)
|
||||||
{
|
{
|
||||||
item.StudyId= historyRow.StudyId;
|
item.StudyId = historyRow.StudyId;
|
||||||
item.SeriesId= historyRow.SeriesId;
|
item.SeriesId = historyRow.SeriesId;
|
||||||
item.InstanceId= historyRow.InstanceId;
|
item.InstanceId = historyRow.InstanceId;
|
||||||
|
|
||||||
item.OtherStudyId = historyRow.OtherStudyId;
|
item.OtherStudyId = historyRow.OtherStudyId;
|
||||||
item.OtherSeriesId = historyRow.OtherSeriesId;
|
item.OtherSeriesId = historyRow.OtherSeriesId;
|
||||||
item.OtherInstanceId= historyRow.OtherInstanceId;
|
item.OtherInstanceId = historyRow.OtherInstanceId;
|
||||||
|
|
||||||
item.MeasureData= historyRow.MeasureData.Replace(historyTaskId.ToString(),taskinfo.Id.ToString());
|
item.MeasureData = historyRow.MeasureData.Replace(historyTaskId.ToString(), taskinfo.Id.ToString());
|
||||||
item.OtherMeasureData = historyRow.OtherMeasureData.Replace(historyTaskId.ToString(), taskinfo.Id.ToString());
|
item.OtherMeasureData = historyRow.OtherMeasureData.Replace(historyTaskId.ToString(), taskinfo.Id.ToString());
|
||||||
|
|
||||||
|
|
||||||
tableAnswerList.Where(x => x.RowId == item.Id).ForEach(x =>
|
tableAnswerList.Where(x => x.RowId == item.Id).ForEach(x =>
|
||||||
{
|
{
|
||||||
x.Answer = x.Answer.IsNullOrEmpty() ?
|
x.Answer = x.Answer.IsNullOrEmpty() ?
|
||||||
historyTableAnswerList.Where(y => y.RowId == historyRow.Id && y.TableQuestionId == x.TableQuestionId).Select(x => x.Answer).FirstOrDefault()??string.Empty :
|
historyTableAnswerList.Where(y => y.RowId == historyRow.Id && y.TableQuestionId == x.TableQuestionId).Select(x => x.Answer).FirstOrDefault() ?? string.Empty :
|
||||||
x.Answer;
|
x.Answer;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -304,7 +305,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
|
|
||||||
|
|
||||||
// 处理标记
|
// 处理标记
|
||||||
Dictionary<Guid,Guid> dicomKeys=new Dictionary<Guid, Guid> ();
|
Dictionary<Guid, Guid> dicomKeys = new Dictionary<Guid, Guid>();
|
||||||
|
|
||||||
foreach (var item in questionMarkList)
|
foreach (var item in questionMarkList)
|
||||||
{
|
{
|
||||||
|
|
@ -336,7 +337,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
Dictionary<Guid, Guid> noneKeys = new Dictionary<Guid, Guid>();
|
Dictionary<Guid, Guid> noneKeys = new Dictionary<Guid, Guid>();
|
||||||
foreach (var item in noneDicomMarkList)
|
foreach (var item in noneDicomMarkList)
|
||||||
{
|
{
|
||||||
var newid= NewId.NextGuid();
|
var newid = NewId.NextGuid();
|
||||||
|
|
||||||
item.VisitTaskId = taskinfo.Id;
|
item.VisitTaskId = taskinfo.Id;
|
||||||
if (item.MarkId != null)
|
if (item.MarkId != null)
|
||||||
|
|
@ -372,7 +373,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -388,17 +389,17 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从上传文件中获取Datatable
|
/// 从上传文件中获取Datatable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<FileToDataTableDto> GetDataTableFromUpload(IFormFile file,string pathCode,Guid trialId)
|
public async Task<FileToDataTableDto> GetDataTableFromUpload(IFormFile file, string pathCode, Guid trialId)
|
||||||
{
|
{
|
||||||
|
|
||||||
FileToDataTableDto result=new FileToDataTableDto ();
|
FileToDataTableDto result = new FileToDataTableDto();
|
||||||
|
|
||||||
result.DataTable = new DataTable();
|
result.DataTable = new DataTable();
|
||||||
var fileFolder = "Upload\\";
|
var fileFolder = "Upload\\";
|
||||||
|
|
@ -419,7 +420,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
file.CopyTo(stream);
|
file.CopyTo(stream);
|
||||||
await stream.CopyToAsync(fileStream);
|
await stream.CopyToAsync(fileStream);
|
||||||
|
|
||||||
result.SheetNames= stream.GetSheetNames();
|
result.SheetNames = stream.GetSheetNames();
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
result.DataTable = stream.QueryAsDataTable(useHeaderRow: false);
|
result.DataTable = stream.QueryAsDataTable(useHeaderRow: false);
|
||||||
}
|
}
|
||||||
|
|
@ -432,15 +433,15 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
|
|
||||||
try
|
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 });
|
await _inspectionFileRepository.AddAsync(new InspectionFile() { FileName = file.FileName, RelativePath = ossRelativePath, TrialId = trialId });
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -457,7 +458,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
// 遍历每一列,检查值
|
// 遍历每一列,检查值
|
||||||
foreach (var item in row.ItemArray)
|
foreach (var item in row.ItemArray)
|
||||||
{
|
{
|
||||||
if (item!=null&&!item.ToString().IsNullOrEmpty())
|
if (item != null && !item.ToString().IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
allEmpty = false;
|
allEmpty = false;
|
||||||
break; // 只要有一个不为空,跳出循环
|
break; // 只要有一个不为空,跳出循环
|
||||||
|
|
@ -532,7 +533,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<ReadingCalculateDto> GetReadingCalculateDto(Guid visitTaskId)
|
public async Task<ReadingCalculateDto> GetReadingCalculateDto(Guid visitTaskId)
|
||||||
{
|
{
|
||||||
var visitTask = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x=>x.SourceSubjectVisit).FirstNotNullAsync();
|
var visitTask = await _visitTaskRepository.Where(x => x.Id == visitTaskId).Include(x => x.SourceSubjectVisit).FirstNotNullAsync();
|
||||||
|
|
||||||
var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == visitTask.TrialReadingCriterionId).FirstNotNullAsync();
|
var criterionInfo = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == visitTask.TrialReadingCriterionId).FirstNotNullAsync();
|
||||||
var subjectVisit = await _subjectVisitRepository.Where(x => x.Id == (visitTask.SourceSubjectVisitId ?? default(Guid))).FirstOrDefaultAsync();
|
var subjectVisit = await _subjectVisitRepository.Where(x => x.Id == (visitTask.SourceSubjectVisitId ?? default(Guid))).FirstOrDefaultAsync();
|
||||||
|
|
@ -540,7 +541,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
var baseLineVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == visitTask.SubjectId && x.IsBaseLine).Select(x => x.Id).FirstOrDefaultAsync();
|
var baseLineVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == visitTask.SubjectId && x.IsBaseLine).Select(x => x.Id).FirstOrDefaultAsync();
|
||||||
|
|
||||||
|
|
||||||
var rowInfoList = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == visitTaskId).Include(x=>x.FristAddTask).ToListAsync();
|
var rowInfoList = await _readingTableAnswerRowInfoRepository.Where(x => x.VisitTaskId == visitTaskId).Include(x => x.FristAddTask).ToListAsync();
|
||||||
|
|
||||||
var baseLinetaskId = await _visitTaskRepository.Where(x => x.SourceSubjectVisitId == baseLineVisitId && x.TaskState == TaskState.Effect
|
var baseLinetaskId = await _visitTaskRepository.Where(x => x.SourceSubjectVisitId == baseLineVisitId && x.TaskState == TaskState.Effect
|
||||||
&& x.TrialReadingCriterionId == visitTask.TrialReadingCriterionId
|
&& x.TrialReadingCriterionId == visitTask.TrialReadingCriterionId
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
await file.CopyToAsync(streamCopy);
|
await file.CopyToAsync(streamCopy);
|
||||||
// 重置流的位置,以便后续读取
|
// 重置流的位置,以便后续读取
|
||||||
streamCopy.Position = 0;
|
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()
|
await _readingImportFileRepository.AddAsync(new ReadingImportFile()
|
||||||
|
|
@ -348,13 +348,14 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async Task<GetReportsChartDataOutDto> GetReportsChartTypeData(GetReportsChartTypeDataInDto inDto)
|
private async Task<GetReportsChartDataOutDto> GetReportsChartTypeData(GetReportsChartTypeDataInDto inDto)
|
||||||
{
|
{
|
||||||
var visitTaskNameList = inDto.Data.VisitTaskList.Select(x => x.BlindName).ToList();
|
var visitTaskNameList = inDto.Data.VisitTaskList.Select(x => x.BlindName).ToList();
|
||||||
GetReportsChartDataOutDto result = new GetReportsChartDataOutDto() {
|
GetReportsChartDataOutDto result = new GetReportsChartDataOutDto()
|
||||||
|
{
|
||||||
ChartDataList=new List<ReportChartData>() { },
|
|
||||||
VisitTaskNameList= visitTaskNameList,
|
ChartDataList = new List<ReportChartData>() { },
|
||||||
|
VisitTaskNameList = visitTaskNameList,
|
||||||
|
|
||||||
};
|
};
|
||||||
switch (inDto.ReportChartTypeEnum)
|
switch (inDto.ReportChartTypeEnum)
|
||||||
|
|
@ -455,30 +456,30 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
public async Task<GetReportsChartSummaryOutDto> GetReportsChartSummary(GetReportsChartSummaryInDto inDto)
|
public async Task<GetReportsChartSummaryOutDto> GetReportsChartSummary(GetReportsChartSummaryInDto inDto)
|
||||||
{
|
{
|
||||||
var criterion = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialCriterionId).FirstNotNullAsync();
|
var criterion = await _readingQuestionCriterionTrialRepository.Where(x => x.Id == inDto.TrialCriterionId).FirstNotNullAsync();
|
||||||
var result= new GetReportsChartSummaryOutDto();
|
var result = new GetReportsChartSummaryOutDto();
|
||||||
var r1Data = await GetData(new List<Arm>() { Arm.SingleReadingArm, Arm.DoubleReadingArm1 });
|
var r1Data = await GetData(new List<Arm>() { Arm.SingleReadingArm, Arm.DoubleReadingArm1 });
|
||||||
var r2Data = await GetData(new List<Arm>() { Arm.DoubleReadingArm2 });
|
var r2Data = await GetData(new List<Arm>() { Arm.DoubleReadingArm2 });
|
||||||
|
|
||||||
var alldata = r1Data.VisitTaskList.Count() > r2Data.VisitTaskList.Count() ? r1Data : r2Data;
|
var alldata = r1Data.VisitTaskList.Count() > r2Data.VisitTaskList.Count() ? r1Data : r2Data;
|
||||||
var visitTaskName = alldata.VisitTaskList.Select(x => x.BlindName).ToList();
|
var visitTaskName = alldata.VisitTaskList.Select(x => x.BlindName).ToList();
|
||||||
var length = alldata.VisitTaskList.Count();
|
var length = alldata.VisitTaskList.Count();
|
||||||
|
|
||||||
// -1转为空
|
// -1转为空
|
||||||
List<QuestionType?> negativeToString = new List<QuestionType?>()
|
List<QuestionType?> negativeToString = new List<QuestionType?>()
|
||||||
{
|
{
|
||||||
QuestionType.DaysBetween,
|
QuestionType.DaysBetween,
|
||||||
};
|
};
|
||||||
|
|
||||||
async Task<GetReadingReportEvaluationOutDto> GetData(List<Arm> arms)
|
async Task<GetReadingReportEvaluationOutDto> GetData(List<Arm> arms)
|
||||||
{
|
{
|
||||||
var data = new GetReadingReportEvaluationOutDto() { };
|
var data = new GetReadingReportEvaluationOutDto() { };
|
||||||
var task = await _visitTaskRepository.Where(x =>
|
var task = await _visitTaskRepository.Where(x =>
|
||||||
x.SubjectId == inDto.SubjectId
|
x.SubjectId == inDto.SubjectId
|
||||||
&& arms.Contains(x.ArmEnum)
|
&& arms.Contains(x.ArmEnum)
|
||||||
&& x.ReadingCategory== ReadingCategory.Visit
|
&& x.ReadingCategory == ReadingCategory.Visit
|
||||||
&& x.ReadingTaskState == ReadingTaskState.HaveSigned
|
&& x.ReadingTaskState == ReadingTaskState.HaveSigned
|
||||||
&& x.TaskState == TaskState.Effect
|
&& x.TaskState == TaskState.Effect
|
||||||
&& x.TrialReadingCriterionId==inDto.TrialCriterionId
|
&& x.TrialReadingCriterionId == inDto.TrialCriterionId
|
||||||
).OrderByDescending(x => x.VisitTaskNum).FirstOrDefaultAsync();
|
).OrderByDescending(x => x.VisitTaskNum).FirstOrDefaultAsync();
|
||||||
if (task != null)
|
if (task != null)
|
||||||
{
|
{
|
||||||
|
|
@ -499,13 +500,13 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
Evaluation = new List<List<EvaluationValue>>() { }
|
Evaluation = new List<List<EvaluationValue>>() { }
|
||||||
};
|
};
|
||||||
|
|
||||||
var baseLineAnswerType= QuestionType.ExistDisease;
|
var baseLineAnswerType = QuestionType.ExistDisease;
|
||||||
|
|
||||||
var visitAnswerType = QuestionType.Tumor;
|
var visitAnswerType = QuestionType.Tumor;
|
||||||
switch (criterion.CriterionType)
|
switch (criterion.CriterionType)
|
||||||
{
|
{
|
||||||
case CriterionType.PCWG3:
|
case CriterionType.PCWG3:
|
||||||
baseLineAnswerType= QuestionType.SiteVisitForTumorEvaluation;
|
baseLineAnswerType = QuestionType.SiteVisitForTumorEvaluation;
|
||||||
visitAnswerType = QuestionType.SiteVisitForTumorEvaluation;
|
visitAnswerType = QuestionType.SiteVisitForTumorEvaluation;
|
||||||
break;
|
break;
|
||||||
case CriterionType.Lugano2014WithoutPET:
|
case CriterionType.Lugano2014WithoutPET:
|
||||||
|
|
@ -515,14 +516,15 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
visitAnswerType = QuestionType.ImgOncology;
|
visitAnswerType = QuestionType.ImgOncology;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
result.Evaluation.Add(visitTaskName.Select(x=> new EvaluationValue() {
|
|
||||||
Value=x
|
result.Evaluation.Add(visitTaskName.Select(x => new EvaluationValue()
|
||||||
|
{
|
||||||
|
Value = x
|
||||||
}).ToList());
|
}).ToList());
|
||||||
|
|
||||||
var r1baseLine= r1.TaskQuestions
|
var r1baseLine = r1.TaskQuestions
|
||||||
.SelectMany(x => x.Childrens)
|
.SelectMany(x => x.Childrens)
|
||||||
.Where(x => x.QuestionType == baseLineAnswerType)
|
.Where(x => x.QuestionType == baseLineAnswerType)
|
||||||
.SelectMany(x => x.Answer.Select(a => new EvaluationValue
|
.SelectMany(x => x.Answer.Select(a => new EvaluationValue
|
||||||
|
|
@ -545,7 +547,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
|
|
||||||
r1data = r1baseLine.Take(1).Concat(r1data.Skip(1)).ToList();
|
r1data = r1baseLine.Take(1).Concat(r1data.Skip(1)).ToList();
|
||||||
|
|
||||||
r1data= r1data.Concat(Enumerable.Repeat(new EvaluationValue() { Value = "" }, length))
|
r1data = r1data.Concat(Enumerable.Repeat(new EvaluationValue() { Value = "" }, length))
|
||||||
.Take(length)
|
.Take(length)
|
||||||
.ToList();
|
.ToList();
|
||||||
result.Evaluation.Add(r1data);
|
result.Evaluation.Add(r1data);
|
||||||
|
|
@ -581,7 +583,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
.ToList();
|
.ToList();
|
||||||
result.Evaluation.Add(r2data);
|
result.Evaluation.Add(r2data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -597,17 +599,17 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
|
||||||
var chartList = new List<ReportChartData>();
|
var chartList = new List<ReportChartData>();
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
var itemdata= data.TaskQuestions.SelectMany(x => x.Childrens)
|
var itemdata = data.TaskQuestions.SelectMany(x => x.Childrens)
|
||||||
.Where(x => x.QuestionId == item.QuestionId)
|
.Where(x => x.QuestionId == item.QuestionId)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
var cd = new ReportChartData
|
var cd = new ReportChartData
|
||||||
{
|
{
|
||||||
Name = item?.QuestionName??string.Empty,
|
Name = item?.QuestionName ?? string.Empty,
|
||||||
Value = itemdata?.Answer?.Select(a => a.Answer).ToList() ?? new List<string>()
|
Value = itemdata?.Answer?.Select(a => a.Answer).ToList() ?? new List<string>()
|
||||||
};
|
};
|
||||||
if (negativeToString.Contains(item.QuestionType))
|
if (negativeToString.Contains(item.QuestionType))
|
||||||
{
|
{
|
||||||
cd.Value = cd.Value.Select(item => item == "-1"|| item == "-2" ? string.Empty : item).ToList();
|
cd.Value = cd.Value.Select(item => item == "-1" || item == "-2" ? string.Empty : item).ToList();
|
||||||
}
|
}
|
||||||
chartList.Add(cd);
|
chartList.Add(cd);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -341,7 +341,7 @@ namespace IRaCIS.Core.Application
|
||||||
foreach (var item in systemCriterionKeyFile)
|
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
|
trialCriterionKeyFiles.Add(new TrialCriterionKeyFile
|
||||||
{
|
{
|
||||||
|
|
@ -1559,13 +1559,13 @@ namespace IRaCIS.Core.Application
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<TrialConfigInfo> GetTrialExtralConfig(Guid trialId)
|
public async Task<TrialConfigInfo> GetTrialExtralConfig(Guid trialId)
|
||||||
{
|
{
|
||||||
var extralObj = _trialRepository.Where(t => t.Id == trialId).Select(t => new { t.TrialExtraConfigJsonStr, t.IsExternalViewTrialChart, t.TrialObjectNameList, t.CollectImagesEnum, t.IsIQCAutoNextTask,t.IsImageQualityControl }).FirstOrDefault();
|
var extralObj = _trialRepository.Where(t => t.Id == trialId).Select(t => new { t.TrialExtraConfigJsonStr, t.IsExternalViewTrialChart, t.TrialObjectNameList, t.CollectImagesEnum, t.IsIQCAutoNextTask, t.IsImageQualityControl }).FirstOrDefault();
|
||||||
|
|
||||||
var extralConfig = JsonConvert.DeserializeObject<TrialExtraConfig>(extralObj?.TrialExtraConfigJsonStr) ?? new TrialExtraConfig();
|
var extralConfig = JsonConvert.DeserializeObject<TrialExtraConfig>(extralObj?.TrialExtraConfigJsonStr) ?? new TrialExtraConfig();
|
||||||
|
|
||||||
var trialConfig = _mapper.Map<TrialConfigInfo>(extralConfig);
|
var trialConfig = _mapper.Map<TrialConfigInfo>(extralConfig);
|
||||||
|
|
||||||
trialConfig.IsImageQualityControl= extralObj.IsImageQualityControl;
|
trialConfig.IsImageQualityControl = extralObj.IsImageQualityControl;
|
||||||
trialConfig.TrialObjectNameList = extralObj.TrialObjectNameList;
|
trialConfig.TrialObjectNameList = extralObj.TrialObjectNameList;
|
||||||
trialConfig.IsExternalViewTrialChart = extralObj.IsExternalViewTrialChart;
|
trialConfig.IsExternalViewTrialChart = extralObj.IsExternalViewTrialChart;
|
||||||
trialConfig.CollectImagesEnum = extralObj.CollectImagesEnum;
|
trialConfig.CollectImagesEnum = extralObj.CollectImagesEnum;
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ public class FileUploadRecord : BaseFullAuditEntity
|
||||||
public string UploadBatchId { get; set; }
|
public string UploadBatchId { get; set; }
|
||||||
|
|
||||||
[Comment("该批次数据类型")]
|
[Comment("该批次数据类型")]
|
||||||
public int BatchDataType { get; set; }
|
public BatchDataType BatchDataType { get; set; }
|
||||||
|
|
||||||
[Comment("上传区域")]
|
[Comment("上传区域")]
|
||||||
public string UploadRegion { get; set; }
|
public string UploadRegion { get; set; }
|
||||||
|
|
@ -108,4 +108,26 @@ public enum jobState
|
||||||
|
|
||||||
CANCELLED = 4
|
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 IP { get; }
|
||||||
|
|
||||||
|
string Domain { get; }
|
||||||
|
|
||||||
string LocalIp { get; }
|
string LocalIp { get; }
|
||||||
|
|
||||||
bool IsEn_Us { get; }
|
bool IsEn_Us { get; }
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTestUser
|
public bool IsTestUser
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -227,7 +227,17 @@ namespace IRaCIS.Core.Domain.Share
|
||||||
get
|
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
|
get
|
||||||
{
|
{
|
||||||
|
|
||||||
return _accessor?.HttpContext?.Connection.LocalIpAddress.MapToIPv4().ToString();
|
return _accessor?.HttpContext?.Connection?.LocalIpAddress?.MapToIPv4().ToString() ?? string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue