数据库生命周期条调整
continuous-integration/drone/push Build is passing Details

Test_HIR_Net8
hang 2026-01-04 12:28:19 +08:00
parent 7fa043793e
commit b95cc97f55
2 changed files with 66 additions and 15 deletions

View File

@ -32,6 +32,7 @@ using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
@ -940,17 +941,24 @@ namespace IRaCIS.Core.API.Controllers
[HttpGet("download/GetPatientStudyBatchDownload")]
public async Task<IActionResult> GetDownloadPatientStudyBatch([FromServices] IPatientService _patientService, [FromServices] IOSSService _oSSService,
public async Task<IActionResult> GetDownloadPatientStudyBatch( [FromServices] IOSSService _oSSService,
[FromServices] IHubContext<DownloadHub, IDownloadClient> _downLoadHub,
//[FromServices] IPatientService _patientService,
[FromServices] IServiceScopeFactory _serviceScopeFactory,
[FromQuery] PatientImageDownloadCommand inCommand)
{
inCommand.SCPStudyIdList = inCommand.SCPStudyIdList.Where(t => t != Guid.Empty).ToList();
var rusult = await _patientService.GetDownloadPatientStudyInfo(inCommand);
var patientList = rusult.Data;
var downloadInfo = (SubejctVisitDownload)rusult.OtherData;
// 1. 获取患者研究数据使用独立Scope
var (patientList, downloadInfo) = await Task.Run(async () =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var patientService = scope.ServiceProvider.GetRequiredService<IPatientService>();
var result = await patientService.GetDownloadPatientStudyInfo(inCommand);
return (result.Data, (SubejctVisitDownload)result.OtherData);
}
});
long receivedSize = 0;
long receivedCount = 0;
long totalSize = downloadInfo.ImageSize;
@ -1172,7 +1180,15 @@ namespace IRaCIS.Core.API.Controllers
// 正常完成
await NotifyProgressAsync(true);
await _patientService.DownloadImageSuccess(downloadInfo.Id);
// 3. 成功后调用Service也使用独立Scope
await Task.Run(async () =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var patientService = scope.ServiceProvider.GetRequiredService<IPatientService>();
await patientService.DownloadImageSuccess(downloadInfo.Id);
}
});
}
catch (OperationCanceledException)
{
@ -1867,17 +1883,42 @@ namespace IRaCIS.Core.API.Controllers
[HttpGet("download/VisitImageDownload")]
public async Task<IActionResult> VisitImageDownload([FromServices] IPatientService _patientService, [FromServices] IOSSService _oSSService,
public async Task<IActionResult> VisitImageDownload( [FromServices] IOSSService _oSSService,
[FromServices] IHubContext<DownloadHub, IDownloadClient> _downLoadHub,
[FromServices] IRepository<Trial> _trialRepository,
//[FromServices] IRepository<Trial> _trialRepository,
//[FromServices] IPatientService _patientService,
[FromServices] IServiceScopeFactory _serviceScopeFactory, // 注入ServiceScopeFactory
[FromQuery] VisitImageDownloadCommand inCommand)
{
var rusult = await _patientService.GetDownloadSubjectVisitStudyInfo(inCommand);
var visitList = rusult.Data;
var downloadInfo = (SubejctVisitDownload)rusult.OtherData;
// 1. 使用独立Scope获取Patient数据
var (visitList, downloadInfo) = await Task.Run(async () =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var patientService = scope.ServiceProvider.GetRequiredService<IPatientService>();
var result = await patientService.GetDownloadSubjectVisitStudyInfo(inCommand);
return (result.Data, (SubejctVisitDownload)result.OtherData);
}
});
var trialInfo = _trialRepository.Where(t => t.Id == inCommand.TrialId).Select(t => new { t.TrialCode, t.ResearchProgramNo }).FirstOrDefault();
var trialInfo = await Task.Run(async () =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var trialRepository = scope.ServiceProvider.GetRequiredService<IRepository<Trial>>();
return await trialRepository.Where(t => t.Id == inCommand.TrialId)
.Select(t => new { t.TrialCode, t.ResearchProgramNo })
.FirstOrDefaultAsync();
}
});
//var rusult = await _patientService.GetDownloadSubjectVisitStudyInfo(inCommand);
//List<DownloadVisitDto> visitList = rusult.Data;
//SubejctVisitDownload downloadInfo = (SubejctVisitDownload)rusult.OtherData;
//var trialInfo = _trialRepository.Where(t => t.Id == inCommand.TrialId).Select(t => new { t.TrialCode, t.ResearchProgramNo }).FirstOrDefault();
var trialZipName = $"{trialInfo.TrialCode}_{trialInfo.ResearchProgramNo}_Image_";
@ -2083,7 +2124,16 @@ namespace IRaCIS.Core.API.Controllers
// 正常完成
await NotifyProgressAsync(true);
await _patientService.DownloadImageSuccess(downloadInfo.Id);
// 3. 成功后调用Service也使用独立Scope
await Task.Run(async () =>
{
using (var scope = _serviceScopeFactory.CreateScope())
{
var patientService = scope.ServiceProvider.GetRequiredService<IPatientService>();
await patientService.DownloadImageSuccess(downloadInfo.Id);
}
});
}
catch (OperationCanceledException)
{

View File

@ -14053,6 +14053,7 @@
<param name="outEnrollTime"></param>
<returns></returns>
</member>
<!-- Badly formed XML comment ignored for member "M:IRaCIS.Core.Application.Service.TestService.ImageAddExtralField(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.SCPInstance},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.DicomStudy},IRaCIS.Core.Application.Helper.IOSSService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.DicomSeries})" -->
<member name="M:IRaCIS.Core.Application.Service.TestService.DeleteConsistentDate(System.Guid,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.TaskConsistentRule},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingConsistentClinicalDataPDF},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.ReadingConsistentClinicalData})">
<summary>
清理一致性分析任务