Merge branch 'Test.IRC' of http://192.168.3.69:2000/XCKJ/irc-netcore-api into Test.IRC

IRC_NewDev
hang 2023-10-12 10:26:43 +08:00
commit 746f2ba7e0
22 changed files with 326 additions and 353 deletions

View File

@ -70,8 +70,8 @@
<PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" /> <PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" /> <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" /> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="EasyCaching.InMemory" Version="1.7.0" /> <PackageReference Include="EasyCaching.Interceptor.Castle" Version="1.9.1" />
<PackageReference Include="EasyCaching.Interceptor.Castle" Version="1.7.0" /> <PackageReference Include="EasyCaching.Serialization.MessagePack" Version="1.9.1" />
<PackageReference Include="EntityFrameworkCore.Triggered.Extensions" Version="3.2.1" /> <PackageReference Include="EntityFrameworkCore.Triggered.Extensions" Version="3.2.1" />
<PackageReference Include="Google.Protobuf" Version="3.21.8" /> <PackageReference Include="Google.Protobuf" Version="3.21.8" />
<PackageReference Include="Grpc.Net.Client" Version="2.49.0" /> <PackageReference Include="Grpc.Net.Client" Version="2.49.0" />

View File

@ -110,7 +110,7 @@ namespace IRaCIS.Core.API
// MediatR 进程内消息 事件解耦 从程序集中 注册命令和handler对应关系 // MediatR 进程内消息 事件解耦 从程序集中 注册命令和handler对应关系
services.AddMediatR(typeof(ConsistencyVerificationHandler).Assembly); services.AddMediatR(typeof(ConsistencyVerificationHandler).Assembly);
// EasyCaching 缓存 // EasyCaching 缓存
services.AddEasyCachingSetup(); services.AddEasyCachingSetup(_configuration);
//services.AddDistributedMemoryCache(); //services.AddDistributedMemoryCache();

View File

@ -1,8 +1,12 @@
using IRaCIS.Core.Application.Triggers; using Hangfire.SqlServer;
using IRaCIS.Core.Application.Triggers;
using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Infra.EFCore;
using Medallion.Threading;
using Medallion.Threading.SqlServer;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
namespace IRaCIS.Core.API namespace IRaCIS.Core.API
{ {
@ -55,6 +59,13 @@ namespace IRaCIS.Core.API
}); });
//注意区分 easy caching 也有 IDistributedLockProvider
services.AddSingleton<IDistributedLockProvider>(sp =>
{
//var connection = ConnectionMultiplexer.Connect(configuration["Redis:Configuration"]!);
return new SqlDistributedSynchronizationProvider(configuration.GetSection("ConnectionStrings:RemoteNew").Value);
});
//services.AddAssemblyTriggers(typeof(SubjectVisitImageDateTrigger).Assembly); //services.AddAssemblyTriggers(typeof(SubjectVisitImageDateTrigger).Assembly);
} }

View File

@ -1,17 +1,26 @@
using EasyCaching.Core; using EasyCaching.Core;
using EasyCaching.Core.Configurations;
using EasyCaching.Interceptor.Castle; using EasyCaching.Interceptor.Castle;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace IRaCIS.Core.API namespace IRaCIS.Core.API
{ {
public static class EasyCachingSetup public static class EasyCachingSetup
{ {
public static void AddEasyCachingSetup(this IServiceCollection services) public static void AddEasyCachingSetup(this IServiceCollection services, IConfiguration configuration)
{ {
services.AddEasyCaching(options => services.AddEasyCaching(options =>
{ {
options.UseInMemory(); options.UseInMemory();
//options.UseRedis(configuration, EasyCachingConstValue.DefaultRedisName).WithMessagePack(EasyCachingConstValue.DefaultRedisName);
}); });
//services.ConfigureCastleInterceptor(options => options.CacheProviderName = EasyCachingConstValue.DefaultRedisName);
services.ConfigureCastleInterceptor(options => options.CacheProviderName = EasyCachingConstValue.DefaultInMemoryName); services.ConfigureCastleInterceptor(options => options.CacheProviderName = EasyCachingConstValue.DefaultInMemoryName);
} }
} }

View File

@ -18,7 +18,6 @@ namespace IRaCIS.Core.API
{ {
public static void AddSwaggerSetup(this IServiceCollection services) public static void AddSwaggerSetup(this IServiceCollection services)
{ {
services.AddSwaggerExamplesFromAssemblyOf<JsonPatchUserRequestExample>();
services.AddSwaggerGen(options => services.AddSwaggerGen(options =>
{ {

View File

@ -55,6 +55,26 @@
"EnableReadDeepClone": true, "EnableReadDeepClone": true,
"EnableWriteDeepClone": false "EnableWriteDeepClone": false
} }
},
"redis": {
"MaxRdSecond": 120,
"EnableLogging": false,
"LockMs": 5000,
"SleepMs": 300,
"dbconfig": {
"Password": "xc@123456",
"IsSsl": false,
"SslHost": null,
"ConnectionTimeout": 5000,
"AllowAdmin": true,
"Endpoints": [
{
"Host": "47.117.164.182",
"Port": 6379
}
],
"Database": 0
}
} }
}, },
"IRaCISImageStore": { "IRaCISImageStore": {

View File

@ -68,9 +68,12 @@
<PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="9.0.0" /> <PackageReference Include="AutoMapper.Collection.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="BeetleX.BNR" Version="1.0.1" /> <PackageReference Include="BeetleX.BNR" Version="1.0.1" />
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" /> <PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" />
<PackageReference Include="EasyCaching.Interceptor.AspectCore" Version="1.7.0" /> <PackageReference Include="EasyCaching.Redis" Version="1.9.1" />
<PackageReference Include="EasyCaching.InMemory" Version="1.9.1" />
<PackageReference Include="ExcelDataReader" Version="3.6.0" /> <PackageReference Include="ExcelDataReader" Version="3.6.0" />
<PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" /> <PackageReference Include="ExcelDataReader.DataSet" Version="3.6.0" />
<PackageReference Include="DistributedLock.Redis" Version="1.0.2" />
<PackageReference Include="DistributedLock.SqlServer" Version="1.0.3" />
<PackageReference Include="fo-dicom.Codecs" Version="5.1.0"> <PackageReference Include="fo-dicom.Codecs" Version="5.1.0">
<TreatAsUsed>true</TreatAsUsed> <TreatAsUsed>true</TreatAsUsed>
</PackageReference> </PackageReference>
@ -87,7 +90,6 @@
<PackageReference Include="Magicodes.IE.Excel.AspNetCore" Version="2.7.4.2" /> <PackageReference Include="Magicodes.IE.Excel.AspNetCore" Version="2.7.4.2" />
<PackageReference Include="MailKit" Version="3.4.2" /> <PackageReference Include="MailKit" Version="3.4.2" />
<PackageReference Include="MediatR" Version="11.0.0" /> <PackageReference Include="MediatR" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10"> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10">
<TreatAsUsed>true</TreatAsUsed> <TreatAsUsed>true</TreatAsUsed>
</PackageReference> </PackageReference>
@ -97,7 +99,6 @@
<PackageReference Include="My.Extensions.Localization.Json" Version="3.0.0"> <PackageReference Include="My.Extensions.Localization.Json" Version="3.0.0">
<TreatAsUsed>true</TreatAsUsed> <TreatAsUsed>true</TreatAsUsed>
</PackageReference> </PackageReference>
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="NPOI" Version="2.6.0" /> <PackageReference Include="NPOI" Version="2.6.0" />
<PackageReference Include="Panda.DynamicWebApi" Version="1.2.0" /> <PackageReference Include="Panda.DynamicWebApi" Version="1.2.0" />
<PackageReference Include="Quartz" Version="3.5.0" /> <PackageReference Include="Quartz" Version="3.5.0" />

View File

@ -1976,6 +1976,13 @@
<param name="inDto"></param> <param name="inDto"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:IRaCIS.Core.Application.Service.ReadingCalculate.LuganoCalculateService.GetExistPET(IRaCIS.Core.Application.Service.Reading.Dto.ReadingCalculateDto)">
<summary>
是否存在PET
</summary>
<param name="inDto"></param>
<returns></returns>
</member>
<member name="M:IRaCIS.Core.Application.Service.ReadingCalculate.LuganoCalculateService.GetImgOncology(IRaCIS.Core.Application.Service.Reading.Dto.ReadingCalculateDto)"> <member name="M:IRaCIS.Core.Application.Service.ReadingCalculate.LuganoCalculateService.GetImgOncology(IRaCIS.Core.Application.Service.Reading.Dto.ReadingCalculateDto)">
<summary> <summary>
影像学整体肿瘤评估 影像学整体肿瘤评估
@ -10348,11 +10355,6 @@
<member name="T:IRaCIS.Core.Application.Contracts.TrialSiteUserSurveyAddOrEdit"> <member name="T:IRaCIS.Core.Application.Contracts.TrialSiteUserSurveyAddOrEdit">
<summary> TrialSiteUserSurveyAddOrEdit 列表查询参数模型</summary> <summary> TrialSiteUserSurveyAddOrEdit 列表查询参数模型</summary>
</member> </member>
<member name="T:IRaCIS.Core.Application.Contracts.JsonPatchUserRequestExample">
<summary>
实测 标注在服务方法上 没用
</summary>
</member>
<member name="T:IRaCIS.Core.Application.Contracts.TrialSiteEquipmentSurveyService"> <member name="T:IRaCIS.Core.Application.Contracts.TrialSiteEquipmentSurveyService">
<summary> <summary>
TrialSiteEquipmentSurveyService TrialSiteEquipmentSurveyService

View File

@ -13,9 +13,9 @@ using IRaCIS.Core.Domain.Share;
using System.Linq.Expressions; using System.Linq.Expressions;
using IRaCIS.Core.Infra.EFCore.Common; using IRaCIS.Core.Infra.EFCore.Common;
using System.Linq; using System.Linq;
using Nito.AsyncEx;
using IRaCIS.Core.Application.Contracts; using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using Medallion.Threading;
namespace IRaCIS.Core.Application.Service namespace IRaCIS.Core.Application.Service
{ {
@ -31,16 +31,17 @@ namespace IRaCIS.Core.Application.Service
private readonly IRepository<SubjectUser> _subjectUserRepository; private readonly IRepository<SubjectUser> _subjectUserRepository;
private readonly IRepository<Subject> _subjectRepository; private readonly IRepository<Subject> _subjectRepository;
private readonly IRepository<Enroll> _enrollRepository; private readonly IRepository<Enroll> _enrollRepository;
private readonly IDistributedLockProvider _distributedLockProvider;
private readonly AsyncLock _mutex = new AsyncLock();
public TaskConsistentRuleService(IRepository<VisitTask> visitTaskRepository, IRepository<Enroll> enrollRepository, IRepository<TaskConsistentRule> taskConsistentRuleRepository, IRepository<SubjectUser> subjectUserRepository, IRepository<Subject> subjectRepository) public TaskConsistentRuleService(IRepository<VisitTask> visitTaskRepository, IRepository<Enroll> enrollRepository, IRepository<TaskConsistentRule> taskConsistentRuleRepository, IRepository<SubjectUser> subjectUserRepository, IRepository<Subject> subjectRepository, IDistributedLockProvider distributedLockProvider)
{ {
_taskConsistentRuleRepository = taskConsistentRuleRepository; _taskConsistentRuleRepository = taskConsistentRuleRepository;
_visitTaskRepository = visitTaskRepository; _visitTaskRepository = visitTaskRepository;
_subjectUserRepository = subjectUserRepository; _subjectUserRepository = subjectUserRepository;
_subjectRepository = subjectRepository; _subjectRepository = subjectRepository;
_enrollRepository = enrollRepository; _enrollRepository = enrollRepository;
_distributedLockProvider = distributedLockProvider;
} }
/// <summary> /// <summary>
@ -142,7 +143,9 @@ namespace IRaCIS.Core.Application.Service
//var list = query.OrderByDescending(t => t.IsHaveGeneratedTask).ToList(); //var list = query.OrderByDescending(t => t.IsHaveGeneratedTask).ToList();
using (await _mutex.LockAsync()) var @lock = _distributedLockProvider.CreateLock($"VisitTaskCode");
using (await @lock.AcquireAsync())
{ {
int maxCodeInt = 0; int maxCodeInt = 0;
@ -293,7 +296,9 @@ namespace IRaCIS.Core.Application.Service
var configDoctorUserIdList = await doctorUserIdQuery.ToListAsync(); var configDoctorUserIdList = await doctorUserIdQuery.ToListAsync();
using (await _mutex.LockAsync()) var @lock = _distributedLockProvider.CreateLock($"VisitTaskCode");
using (await @lock.AcquireAsync())
{ {
int maxCodeInt = 0; int maxCodeInt = 0;

View File

@ -6,8 +6,8 @@ using Microsoft.AspNetCore.Hosting;
using IRaCIS.Core.Application.Auth; using IRaCIS.Core.Application.Auth;
using AutoMapper; using AutoMapper;
using IRaCIS.Application.Contracts; using IRaCIS.Application.Contracts;
using Nito.AsyncEx;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Medallion.Threading;
namespace IRaCIS.Application.Services namespace IRaCIS.Application.Services
{ {
@ -54,8 +54,7 @@ namespace IRaCIS.Application.Services
private readonly IRepository<UserType> _userTypeRepository; private readonly IRepository<UserType> _userTypeRepository;
private readonly IRepository<Doctor> _doctorTypeRepository; private readonly IRepository<Doctor> _doctorTypeRepository;
private readonly IDistributedLockProvider _distributedLockProvider;
private readonly AsyncLock _mutex = new AsyncLock();
private readonly SystemEmailSendConfig _systemEmailConfig; private readonly SystemEmailSendConfig _systemEmailConfig;
@ -69,7 +68,7 @@ namespace IRaCIS.Application.Services
IRepository<Trial> trialRepository, IRepository<Trial> trialRepository,
IRepository<UserType> userTypeRepository, IRepository<UserType> userTypeRepository,
IRepository<Doctor> doctorTypeRepository, IRepository<Doctor> doctorTypeRepository,
IMapper mapper, IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig) IMapper mapper, IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig, IDistributedLockProvider distributedLockProvider)
{ {
_systemEmailConfig = systemEmailConfig.CurrentValue; _systemEmailConfig = systemEmailConfig.CurrentValue;
_verificationCodeRepository = verificationCodeRepository; _verificationCodeRepository = verificationCodeRepository;
@ -85,7 +84,7 @@ namespace IRaCIS.Application.Services
_userTypeRepository = userTypeRepository; _userTypeRepository = userTypeRepository;
_doctorTypeRepository = doctorTypeRepository; _doctorTypeRepository = doctorTypeRepository;
_distributedLockProvider = distributedLockProvider;
} }
//重置邮箱 //重置邮箱
@ -606,7 +605,9 @@ namespace IRaCIS.Application.Services
var userType = await _userTypeRepository.FirstAsync(t => t.UserTypeEnum == UserTypeEnum.IndependentReviewer); var userType = await _userTypeRepository.FirstAsync(t => t.UserTypeEnum == UserTypeEnum.IndependentReviewer);
using (await _mutex.LockAsync()) var @lock = _distributedLockProvider.CreateLock($"UserCode");
using (await @lock.AcquireAsync())
{ {
var isDoctorHaveAccount = await _userRepository.AnyAsync(t => t.DoctorId == doctorId); var isDoctorHaveAccount = await _userRepository.AnyAsync(t => t.DoctorId == doctorId);

View File

@ -8,10 +8,11 @@ using IRaCIS.Core.Application.Contracts;
using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.Helper;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure;
using Medallion.Threading;
namespace IRaCIS.Core.Application.Services namespace IRaCIS.Core.Application.Services
{ {
public class DicomArchiveService :BaseService, IDicomArchiveService public class DicomArchiveService : BaseService, IDicomArchiveService
{ {
private readonly IRepository<DicomStudy> _studyRepository; private readonly IRepository<DicomStudy> _studyRepository;
private readonly IRepository<DicomSeries> _seriesRepository; private readonly IRepository<DicomSeries> _seriesRepository;
@ -21,7 +22,7 @@ namespace IRaCIS.Core.Application.Services
private readonly IWebHostEnvironment _hostEnvironment; private readonly IWebHostEnvironment _hostEnvironment;
private static object lockCodeGenerate = new object(); private readonly IDistributedLockProvider _distributedLockProvider;
private List<Guid> _instanceIdList = new List<Guid>(); private List<Guid> _instanceIdList = new List<Guid>();
@ -31,8 +32,9 @@ namespace IRaCIS.Core.Application.Services
IRepository<DicomInstance> instanceRepository, IRepository<DicomInstance> instanceRepository,
IWebHostEnvironment hostEnvironment, IWebHostEnvironment hostEnvironment,
IRepository<Dictionary> dictionaryRepository, IRepository<Dictionary> dictionaryRepository,
IEasyCachingProvider provider) IEasyCachingProvider provider, IDistributedLockProvider distributedLockProvider)
{ {
_distributedLockProvider = distributedLockProvider;
_hostEnvironment = hostEnvironment; _hostEnvironment = hostEnvironment;
_studyRepository = studyRepository; _studyRepository = studyRepository;
@ -129,7 +131,7 @@ namespace IRaCIS.Core.Application.Services
DicomStudy dicomStudy = CreateDicomStudy(dataset, addtionalInfo, out bool isStudyNeedAdd); DicomStudy dicomStudy = CreateDicomStudy(dataset, addtionalInfo, out bool isStudyNeedAdd);
DicomSeries dicomSeries = CreateDicomSeries(dataset, dicomStudy, out bool isSeriesNeedAdd); DicomSeries dicomSeries = CreateDicomSeries(dataset, dicomStudy, out bool isSeriesNeedAdd);
DicomInstance dicomInstance = CreateDicomInstance(dataset, dicomStudy, dicomSeries,out bool isInstanceNeedAdd); DicomInstance dicomInstance = CreateDicomInstance(dataset, dicomStudy, dicomSeries, out bool isInstanceNeedAdd);
dicomSeries.DicomStudy = dicomStudy; dicomSeries.DicomStudy = dicomStudy;
@ -235,7 +237,7 @@ namespace IRaCIS.Core.Application.Services
{ {
modalityForEdit = "PET"; modalityForEdit = "PET";
} }
if(modality== "PT、CT") if (modality == "PT、CT")
{ {
modalityForEdit = "PET-CT"; modalityForEdit = "PET-CT";
} }
@ -282,9 +284,10 @@ namespace IRaCIS.Core.Application.Services
dicomStudy.PatientBirthDate = $"{dicomStudy.PatientBirthDate[0]}{dicomStudy.PatientBirthDate[1]}{dicomStudy.PatientBirthDate[2]}{dicomStudy.PatientBirthDate[3]}-{dicomStudy.PatientBirthDate[4]}{dicomStudy.PatientBirthDate[5]}-{dicomStudy.PatientBirthDate[6]}{dicomStudy.PatientBirthDate[7]}"; dicomStudy.PatientBirthDate = $"{dicomStudy.PatientBirthDate[0]}{dicomStudy.PatientBirthDate[1]}{dicomStudy.PatientBirthDate[2]}{dicomStudy.PatientBirthDate[3]}-{dicomStudy.PatientBirthDate[4]}{dicomStudy.PatientBirthDate[5]}-{dicomStudy.PatientBirthDate[6]}{dicomStudy.PatientBirthDate[7]}";
} }
lock (lockCodeGenerate) var @lock = _distributedLockProvider.CreateLock($"StudyCode");
{
using (@lock.Acquire())
{
//查询数据库获取最大的Code 没有记录则为0 //查询数据库获取最大的Code 没有记录则为0
var dbStudyCodeIntMax = _studyRepository.Where(s => s.TrialId == addtionalInfo.TrialId).Select(t => t.Code).DefaultIfEmpty().Max(); var dbStudyCodeIntMax = _studyRepository.Where(s => s.TrialId == addtionalInfo.TrialId).Select(t => t.Code).DefaultIfEmpty().Max();
@ -298,9 +301,9 @@ namespace IRaCIS.Core.Application.Services
dicomStudy.StudyCode = AppSettings.GetCodeStr(currentNextCodeInt, nameof(DicomStudy)); dicomStudy.StudyCode = AppSettings.GetCodeStr(currentNextCodeInt, nameof(DicomStudy));
_provider.Set<int>($"{addtionalInfo.TrialId}_{StaticData.CacheKey.StudyMaxCode}", dicomStudy.Code, TimeSpan.FromMinutes(30)); _provider.Set<int>($"{addtionalInfo.TrialId}_{StaticData.CacheKey.StudyMaxCode}", dicomStudy.Code, TimeSpan.FromMinutes(30));
} }
#region Setting Code old #region Setting Code old
//var studyCode = _studyRepository.Where(s => s.TrialId == addtionalInfo.TrialId).Select(t => t.StudyCode).OrderByDescending(c => c).FirstOrDefault(); //var studyCode = _studyRepository.Where(s => s.TrialId == addtionalInfo.TrialId).Select(t => t.StudyCode).OrderByDescending(c => c).FirstOrDefault();

View File

@ -14,16 +14,13 @@ using IRaCIS.Core.Application.MediatR.Handlers;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Threading; using System.Threading;
using Nito.AsyncEx; using Medallion.Threading;
namespace IRaCIS.Core.Application.Service.ImageAndDoc namespace IRaCIS.Core.Application.Service.ImageAndDoc
{ {
[ApiExplorerSettings(GroupName = "Image")] [ApiExplorerSettings(GroupName = "Image")]
public class StudyService : BaseService, IStudyService public class StudyService : BaseService, IStudyService
{ {
private static object lockObj = new object();
private static readonly AsyncLock _mutex = new AsyncLock();
private static readonly AsyncLock _mutex2 = new AsyncLock();
private readonly IEasyCachingProvider _provider; private readonly IEasyCachingProvider _provider;
@ -35,12 +32,12 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
private readonly IRepository<Dictionary> _dictionaryRepository; private readonly IRepository<Dictionary> _dictionaryRepository;
private readonly IRepository<StudyMonitor> _studyMonitorRepository; private readonly IRepository<StudyMonitor> _studyMonitorRepository;
private readonly IDistributedLockProvider _distributedLockProvider;
public StudyService(IEasyCachingProvider provider public StudyService(IEasyCachingProvider provider
, IRepository<SubjectVisit> subjectVisitRepository, , IRepository<SubjectVisit> subjectVisitRepository,
IRepository<DicomInstance> dicomInstanceRepository, IRepository<DicomInstance> dicomInstanceRepository,
IRepository<DicomSeries> dicomSeriesRepository, IRepository<DicomStudy> dicomstudyRepository, IRepository<Dictionary> dictionaryRepository, IRepository<StudyMonitor> studyMonitorRepository) IRepository<DicomSeries> dicomSeriesRepository, IRepository<DicomStudy> dicomstudyRepository, IRepository<Dictionary> dictionaryRepository, IRepository<StudyMonitor> studyMonitorRepository, IDistributedLockProvider distributedLockProvider)
{ {
_provider = provider; _provider = provider;
_subjectVisitRepository = subjectVisitRepository; _subjectVisitRepository = subjectVisitRepository;
@ -49,6 +46,7 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
_dicomstudyRepository = dicomstudyRepository; _dicomstudyRepository = dicomstudyRepository;
_dictionaryRepository = dictionaryRepository; _dictionaryRepository = dictionaryRepository;
_studyMonitorRepository = studyMonitorRepository; _studyMonitorRepository = studyMonitorRepository;
_distributedLockProvider = distributedLockProvider;
} }
@ -160,7 +158,9 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
{ {
var study = _mapper.Map<DicomStudy>(incommand.Study); var study = _mapper.Map<DicomStudy>(incommand.Study);
using (await _mutex.LockAsync()) var @lock = _distributedLockProvider.CreateLock($"StudyCode");
using (await @lock.AcquireAsync())
{ {
//查询数据库获取最大的Code 没有记录则为0 //查询数据库获取最大的Code 没有记录则为0
var dbStudyCodeIntMax = _dicomstudyRepository.Where(s => s.TrialId == trialId).Select(t => t.Code).DefaultIfEmpty().Max(); var dbStudyCodeIntMax = _dicomstudyRepository.Where(s => s.TrialId == trialId).Select(t => t.Code).DefaultIfEmpty().Max();
@ -306,11 +306,11 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
} }
using (await _mutex2.LockAsync()) var @lock2 = _distributedLockProvider.CreateLock($"StudyCommit");
using (await @lock2.AcquireAsync())
{ {
await _dicomInstanceRepository.SaveChangesAsync(); await _dicomInstanceRepository.SaveChangesAsync();
} }
} }
catch (Exception ex) catch (Exception ex)
@ -826,22 +826,22 @@ namespace IRaCIS.Core.Application.Service.ImageAndDoc
} }
result.StudyInstanceUid = studyInstanceUid; result.StudyInstanceUid = studyInstanceUid;
var @lock = _distributedLockProvider.CreateLock($"StudyUpload");
if (result.AllowReUpload || result.AllowUpload) using (@lock.Acquire())
{ {
lock (lockObj) if (result.AllowReUpload || result.AllowUpload)
{ {
_provider.Set($"StudyUid_{trialId}_{studyInstanceUid}", _userInfo.Id, TimeSpan.FromSeconds(30)); _provider.Set($"StudyUid_{trialId}_{studyInstanceUid}", _userInfo.Id, TimeSpan.FromSeconds(30));
} }
}
else else
{
lock (lockObj)
{ {
_provider.Remove($"StudyUid_{trialId}_{studyInstanceUid}"); _provider.Remove($"StudyUid_{trialId}_{studyInstanceUid}");
} }
} }
return result; return result;
} }

View File

@ -3,7 +3,7 @@ using IRaCIS.Application.Contracts;
using IRaCIS.Core.Infra.EFCore; using IRaCIS.Core.Infra.EFCore;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using Nito.AsyncEx; using Medallion.Threading;
namespace IRaCIS.Application.Services namespace IRaCIS.Application.Services
{ {
@ -12,13 +12,13 @@ namespace IRaCIS.Application.Services
{ {
private readonly IRepository<Site> _siteRepository; private readonly IRepository<Site> _siteRepository;
private readonly IRepository<TrialSiteUser> _trialSiteUserRepository; private readonly IRepository<TrialSiteUser> _trialSiteUserRepository;
private readonly IDistributedLockProvider _distributedLockProvider;
private readonly AsyncLock _mutex = new AsyncLock(); public SiteService(IRepository<Site> siteRepository, IRepository<TrialSiteUser> trialSiteUserRepository, IDistributedLockProvider distributedLockProvider)
public SiteService(IRepository<Site> siteRepository, IRepository<TrialSiteUser> trialSiteUserRepository)
{ {
_siteRepository = siteRepository; _siteRepository = siteRepository;
this._trialSiteUserRepository = trialSiteUserRepository; _trialSiteUserRepository = trialSiteUserRepository;
_distributedLockProvider = distributedLockProvider;
} }
/// <summary> 分页获取研究中心列表 </summary> /// <summary> 分页获取研究中心列表 </summary>
@ -58,7 +58,9 @@ namespace IRaCIS.Application.Services
VerifyMsg = _localizer["Site_DupName"] VerifyMsg = _localizer["Site_DupName"]
}; };
using (await _mutex.LockAsync()) var @lock = _distributedLockProvider.CreateLock($"SiteAdd");
using (await @lock.AcquireAsync())
{ {
if (siteCommand.Id == null) if (siteCommand.Id == null)
{ {

View File

@ -12,6 +12,7 @@ using IRaCIS.Core.Infra.Common.Cache;
using Microsoft.Identity.Client; using Microsoft.Identity.Client;
using static IRaCIS.Core.Domain.Share.StaticData; using static IRaCIS.Core.Domain.Share.StaticData;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
using Medallion.Threading;
namespace IRaCIS.Application.Services namespace IRaCIS.Application.Services
{ {
@ -25,7 +26,7 @@ namespace IRaCIS.Application.Services
private readonly IRepository<TrialUser> _userTrialRepository; private readonly IRepository<TrialUser> _userTrialRepository;
private readonly IRepository<UserLog> _userLogRepository; private readonly IRepository<UserLog> _userLogRepository;
private readonly IDistributedLockProvider _distributedLockProvider;
private readonly IMemoryCache _cache; private readonly IMemoryCache _cache;
private readonly IOptionsMonitor<ServiceVerifyConfigOption> _verifyConfig; private readonly IOptionsMonitor<ServiceVerifyConfigOption> _verifyConfig;
@ -40,7 +41,8 @@ namespace IRaCIS.Application.Services
IRepository<TrialUser> userTrialRepository, IRepository<TrialUser> userTrialRepository,
IOptionsMonitor<ServiceVerifyConfigOption> verifyConfig, IOptionsMonitor<ServiceVerifyConfigOption> verifyConfig,
IRepository<UserLog> userLogRepository IRepository<UserLog> userLogRepository
) ,
IDistributedLockProvider distributedLockProvider)
{ {
_userLogRepository = userLogRepository; _userLogRepository = userLogRepository;
@ -52,6 +54,7 @@ namespace IRaCIS.Application.Services
_doctorRepository = doctorRepository; _doctorRepository = doctorRepository;
_userTrialRepository = userTrialRepository; _userTrialRepository = userTrialRepository;
_userLogRepository = userLogRepository; _userLogRepository = userLogRepository;
_distributedLockProvider = distributedLockProvider;
} }
@ -504,6 +507,10 @@ namespace IRaCIS.Application.Services
var saveItem = _mapper.Map<User>(userAddModel); var saveItem = _mapper.Map<User>(userAddModel);
var @lock = _distributedLockProvider.CreateLock($"UserAccount");
using (await @lock.AcquireAsync())
{
saveItem.Code = await _userRepository.Select(t => t.Code).DefaultIfEmpty().MaxAsync() + 1; saveItem.Code = await _userRepository.Select(t => t.Code).DefaultIfEmpty().MaxAsync() + 1;
saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)); saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User));
@ -519,14 +526,13 @@ namespace IRaCIS.Application.Services
await _userRepository.AddAsync(saveItem); await _userRepository.AddAsync(saveItem);
var success = await _userRepository.SaveChangesAsync(); var success = await _userRepository.SaveChangesAsync();
}
await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl); await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl);
return ResponseOutput.Ok( new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode });
return ResponseOutput.Result(success, new UserAddedReturnDTO { Id = saveItem.Id, UserCode = saveItem.UserCode });
} }

View File

@ -5,10 +5,10 @@
//-------------------------------------------------------------------- //--------------------------------------------------------------------
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using Nito.AsyncEx;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using IRaCIS.Core.Application.Service; using IRaCIS.Core.Application.Service;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using Medallion.Threading;
namespace IRaCIS.Core.Application.Contracts namespace IRaCIS.Core.Application.Contracts
{ {
@ -20,19 +20,19 @@ namespace IRaCIS.Core.Application.Contracts
{ {
private readonly IRepository<NoneDicomStudy> _noneDicomStudyRepository; private readonly IRepository<NoneDicomStudy> _noneDicomStudyRepository;
private readonly IRepository<NoneDicomStudyFile> _noneDicomStudyFileRepository; private readonly IRepository<NoneDicomStudyFile> _noneDicomStudyFileRepository;
private readonly AsyncLock _mutex = new AsyncLock(); private readonly IDistributedLockProvider _distributedLockProvider;
private readonly QCCommon _qCCommon; private readonly QCCommon _qCCommon;
public NoneDicomStudyService(IRepository<NoneDicomStudy> noneDicomStudyRepository, public NoneDicomStudyService(IRepository<NoneDicomStudy> noneDicomStudyRepository,
QCCommon qCCommon, QCCommon qCCommon,
IRepository<NoneDicomStudyFile> noneDicomStudyFileRepository) IRepository<NoneDicomStudyFile> noneDicomStudyFileRepository, IDistributedLockProvider distributedLockProvider)
{ {
_qCCommon = qCCommon; _qCCommon = qCCommon;
_noneDicomStudyRepository = noneDicomStudyRepository; _noneDicomStudyRepository = noneDicomStudyRepository;
_noneDicomStudyFileRepository = noneDicomStudyFileRepository; _noneDicomStudyFileRepository = noneDicomStudyFileRepository;
_distributedLockProvider = distributedLockProvider;
} }
@ -62,7 +62,9 @@ namespace IRaCIS.Core.Application.Contracts
} }
NoneDicomStudy? optEntity = null; NoneDicomStudy? optEntity = null;
using (await _mutex.LockAsync()) var @lock = _distributedLockProvider.CreateLock($"NoneDicomCode");
using (await @lock.AcquireAsync())
{ {
if (addOrEditNoneDicomStudy.Id == Guid.Empty || addOrEditNoneDicomStudy.Id == null) if (addOrEditNoneDicomStudy.Id == Guid.Empty || addOrEditNoneDicomStudy.Id == null)
{ {

View File

@ -10,13 +10,13 @@ using WinSCP;
using Newtonsoft.Json; using Newtonsoft.Json;
using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Application.Service.Inspection.DTO; using IRaCIS.Core.Application.Service.Inspection.DTO;
using Nito.AsyncEx;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using IRaCIS.Core.Application.Auth; using IRaCIS.Core.Application.Auth;
using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Models; using IRaCIS.Core.Domain.Models;
using IRaCIS.Core.Application.Service; using IRaCIS.Core.Application.Service;
using Medallion.Threading;
namespace IRaCIS.Core.Application.Image.QA namespace IRaCIS.Core.Application.Image.QA
{ {
@ -35,8 +35,7 @@ namespace IRaCIS.Core.Application.Image.QA
private readonly IRepository<Trial> _trialRepository; private readonly IRepository<Trial> _trialRepository;
private readonly IRepository<VisitTask> _visitTaskRepository; private readonly IRepository<VisitTask> _visitTaskRepository;
private readonly IVisitTaskHelpeService _IVisitTaskHelpeService; private readonly IVisitTaskHelpeService _IVisitTaskHelpeService;
private readonly IDistributedLockProvider _distributedLockProvider;
private readonly AsyncLock _mutex = new AsyncLock();
public QCOperationService(IRepository<SubjectVisit> subjectVisitRepository, public QCOperationService(IRepository<SubjectVisit> subjectVisitRepository,
IRepository<QCChallenge> qcChallengeRepository, IRepository<QCChallenge> qcChallengeRepository,
@ -48,7 +47,8 @@ namespace IRaCIS.Core.Application.Image.QA
IRepository<ReadingClinicalData> readingClinicalDataRepository, IRepository<ReadingClinicalData> readingClinicalDataRepository,
IRepository<QCChallengeDialog> qCChallengeDialogrepository, IRepository<QCChallengeDialog> qCChallengeDialogrepository,
IRepository<CheckChallengeDialog> checkChallengeDialogrepository, IRepository<CheckChallengeDialog> checkChallengeDialogrepository,
IVisitTaskHelpeService visitTaskHelpeService IVisitTaskHelpeService visitTaskHelpeService,
IDistributedLockProvider distributedLockProvider
) )
{ {
_subjectVisitRepository = subjectVisitRepository; _subjectVisitRepository = subjectVisitRepository;
@ -62,6 +62,7 @@ namespace IRaCIS.Core.Application.Image.QA
_trialRepository = trialRepository; _trialRepository = trialRepository;
this._visitTaskRepository = visitTaskRepository; this._visitTaskRepository = visitTaskRepository;
_IVisitTaskHelpeService = visitTaskHelpeService; _IVisitTaskHelpeService = visitTaskHelpeService;
_distributedLockProvider = distributedLockProvider;
} }
#region QC质疑 以及回复 关闭 #region QC质疑 以及回复 关闭
@ -108,9 +109,9 @@ namespace IRaCIS.Core.Application.Image.QA
var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id, t.QCProcessEnum, t.IsImageConsistencyVerification }).FirstOrDefaultAsync()).IfNullThrowException(); var trialConfig = (await _trialRepository.Where(t => t.Id == trialId).Select(t => new { TrialId = t.Id, t.QCProcessEnum, t.IsImageConsistencyVerification }).FirstOrDefaultAsync()).IfNullThrowException();
var @lock = _distributedLockProvider.CreateLock($"QCChallengeCode");
using (await @lock.AcquireAsync())
using (await _mutex.LockAsync())
{ {
//获取编号 //获取编号
var code = _qcChallengeRepository.Where(t => t.TrialId == trialId).Select(t => t.Code).DefaultIfEmpty().Max(); var code = _qcChallengeRepository.Where(t => t.TrialId == trialId).Select(t => t.Code).DefaultIfEmpty().Max();

View File

@ -29,6 +29,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
private readonly IRepository<OrganInfo> _organInfoRepository; private readonly IRepository<OrganInfo> _organInfoRepository;
private readonly IRepository<SubjectVisit> _subjectVisitRepository; private readonly IRepository<SubjectVisit> _subjectVisitRepository;
private readonly IRepository<TumorAssessment_RECIST1Point1> _tumorAssessmentRepository; private readonly IRepository<TumorAssessment_RECIST1Point1> _tumorAssessmentRepository;
private readonly ISubjectVisitService _subjectVisitService;
private readonly IGeneralCalculateService _generalCalculateService; private readonly IGeneralCalculateService _generalCalculateService;
private readonly IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository; private readonly IRepository<ReadingTaskQuestionAnswer> _readingTaskQuestionAnswerRepository;
@ -43,6 +44,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
IRepository<OrganInfo> organInfoRepository, IRepository<OrganInfo> organInfoRepository,
IRepository<SubjectVisit> subjectVisitRepository, IRepository<SubjectVisit> subjectVisitRepository,
IRepository<TumorAssessment_RECIST1Point1> tumorAssessmentRepository, IRepository<TumorAssessment_RECIST1Point1> tumorAssessmentRepository,
ISubjectVisitService subjectVisitService,
IGeneralCalculateService generalCalculateService, IGeneralCalculateService generalCalculateService,
IRepository<ReadingTaskQuestionAnswer> readingTaskQuestionAnswerRepository IRepository<ReadingTaskQuestionAnswer> readingTaskQuestionAnswerRepository
) )
@ -57,6 +59,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
this._organInfoRepository = organInfoRepository; this._organInfoRepository = organInfoRepository;
this._subjectVisitRepository = subjectVisitRepository; this._subjectVisitRepository = subjectVisitRepository;
this._tumorAssessmentRepository = tumorAssessmentRepository; this._tumorAssessmentRepository = tumorAssessmentRepository;
this._subjectVisitService = subjectVisitService;
this._generalCalculateService = generalCalculateService; this._generalCalculateService = generalCalculateService;
this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository; this._readingTaskQuestionAnswerRepository = readingTaskQuestionAnswerRepository;
} }
@ -502,12 +505,13 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
new ReadingCalculateData (){QuestionType=QuestionType.UptakeChange,GetStringFun=GetUptakeChange}, new ReadingCalculateData (){QuestionType=QuestionType.UptakeChange,GetStringFun=GetUptakeChange},
// FDG-PET 评估结果 // FDG-PET 评估结果
new ReadingCalculateData (){QuestionType=QuestionType.UptakeChange,GetStringFun=GetFDGPETOverallAssessment}, new ReadingCalculateData (){QuestionType=QuestionType.FDGPET,GetStringFun=GetFDGPETOverallAssessment},
// 影像学整体肿瘤评估 // 影像学整体肿瘤评估
new ReadingCalculateData (){QuestionType=QuestionType.ImgOncology,GetStringFun=GetImgOncology}, new ReadingCalculateData (){QuestionType=QuestionType.ImgOncology,GetStringFun=GetImgOncology},
// 是否存在Pet
new ReadingCalculateData (){QuestionType=QuestionType.ExistPET,GetStringFun=GetExistPET},
//SUVmax //SUVmax
new ReadingCalculateData (){QuestionType=QuestionType.SUVmax,GetDecimalFun=GetSuvMax}, new ReadingCalculateData (){QuestionType=QuestionType.SUVmax,GetDecimalFun=GetSuvMax},
@ -835,6 +839,11 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
var baseLineVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == taskinfo.SubjectId && x.IsBaseLine).Select(x => x.Id).FirstOrDefaultAsync(); var baseLineVisitId = await _subjectVisitRepository.Where(x => x.SubjectId == taskinfo.SubjectId && x.IsBaseLine).Select(x => x.Id).FirstOrDefaultAsync();
ReadingCalculateDto readingData = await _generalCalculateService.GetReadingCalculateDto(visitTaskId);
await ReadingCalculate(readingData, new List<QuestionType>() { QuestionType.ExistPET });
// 判断当前任务是否是基线 // 判断当前任务是否是基线
if (taskinfo.SourceSubjectVisitId != baseLineVisitId) if (taskinfo.SourceSubjectVisitId != baseLineVisitId)
{ {
@ -959,7 +968,7 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
FirstAddTaskId=x.FirstAddTaskId, FirstAddTaskId=x.FirstAddTaskId,
QuestionId=x.QuestionId, QuestionId=x.QuestionId,
QuestionType=x.QuestionType, QuestionType=x.QuestionType,
OrderMarkName=x.OrderMarkName,
}).ToListAsync(); }).ToListAsync();
questionMarkList.ForEach(x => { questionMarkList.ForEach(x => {
@ -2020,6 +2029,23 @@ namespace IRaCIS.Core.Application.Service.ReadingCalculate
} }
#endregion #endregion
/// <summary>
/// 是否存在PET
/// </summary>
/// <param name="inDto"></param>
/// <returns></returns>
public async Task<string> GetExistPET(ReadingCalculateDto inDto)
{
var studyList = await this._subjectVisitService.GetReadingVisitStudyList(new Contracts.GetReadingVisitStudyListIndto()
{
TrialId = inDto.TrialId,
SujectVisitId = inDto.SubjectVisitId,
VisitTaskId=inDto.VisitTaskId,
});
return studyList.Any(x => x.Modalities.Contains("CT")) ? ReadingYesOrNo.Yes.GetEnumInt() : ReadingYesOrNo.No.GetEnumInt();
}
#region 影像学整体肿瘤评估 #region 影像学整体肿瘤评估
/// <summary> /// <summary>
/// 影像学整体肿瘤评估 /// 影像学整体肿瘤评估

View File

@ -1,51 +0,0 @@
using Microsoft.AspNetCore.JsonPatch.Operations;
using Swashbuckle.AspNetCore.Filters;
namespace IRaCIS.Core.Application.Contracts
{
/// <summary>
/// 实测 标注在服务方法上 没用
/// </summary>
public class JsonPatchUserRequestExample : IExamplesProvider<object>
{
public Operation[] GetExamples()
{
return new[]
{
new Operation
{
op = "replace",
path = "/name",
value = "Gordon"
},
new Operation
{
op = "replace",
path = "/surname",
value = "Freeman"
}
};
}
object IExamplesProvider<object>.GetExamples()
{
return new[]
{
new Operation
{
op = "replace",
path = "/name",
value = "Gordon"
},
new Operation
{
op = "replace",
path = "/surname",
value = "Freeman"
}
};
}
}
}

View File

@ -15,6 +15,7 @@ using MailKit.Security;
using MimeKit; using MimeKit;
using IRaCIS.Core.Application.Helper; using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using Medallion.Threading;
namespace IRaCIS.Core.Application.Contracts namespace IRaCIS.Core.Application.Contracts
{ {
@ -32,24 +33,25 @@ namespace IRaCIS.Core.Application.Contracts
private readonly IRepository<TrialUser> _trialUserRepository; private readonly IRepository<TrialUser> _trialUserRepository;
private readonly ITokenService _tokenService; private readonly ITokenService _tokenService;
private readonly IMailVerificationService _mailVerificationService; private readonly IMailVerificationService _mailVerificationService;
private readonly IDistributedLockProvider _distributedLockProvider;
public TrialSiteSurveyService(IRepository<TrialSiteSurvey> trialSiteSurveyRepository, IRepository<TrialUser> trialUserRepository, IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository, public TrialSiteSurveyService(IRepository<TrialSiteSurvey> trialSiteSurveyRepository, IRepository<TrialUser> trialUserRepository, IRepository<TrialSiteUserSurvey> trialSiteUserSurveyRepository,
IRepository<User> userRepository, IRepository<TrialSite> trialSiteRepository, IRepository<User> userRepository, IRepository<TrialSite> trialSiteRepository,
IRepository<Doctor> doctorRepository, IRepository<Doctor> doctorRepository,
ITokenService tokenService, ITokenService tokenService,
IMailVerificationService mailVerificationService) IMailVerificationService mailVerificationService, IDistributedLockProvider distributedLockProvider)
{ {
_trialSiteSurveyRepository = trialSiteSurveyRepository; _trialSiteSurveyRepository = trialSiteSurveyRepository;
_trialSiteUserSurveyRepository = trialSiteUserSurveyRepository; _trialSiteUserSurveyRepository = trialSiteUserSurveyRepository;
_userRepository = userRepository; _userRepository = userRepository;
_trialUserRepository = trialUserRepository; _trialUserRepository = trialUserRepository;
_trialSiteRepository = trialSiteRepository; _trialSiteRepository = trialSiteRepository;
this._doctorRepository = doctorRepository; _doctorRepository = doctorRepository;
_tokenService = tokenService; _tokenService = tokenService;
_mailVerificationService = mailVerificationService; _mailVerificationService = mailVerificationService;
_distributedLockProvider = distributedLockProvider;
} }
private object lockObj { get; set; } = new object();
/// <summary> /// <summary>
/// 发送验证码 /// 发送验证码
@ -801,7 +803,9 @@ namespace IRaCIS.Core.Application.Contracts
if (sysUserInfo == null) if (sysUserInfo == null)
{ {
lock (lockObj) var @lock = _distributedLockProvider.CreateLock($"UserCode");
using (await @lock.AcquireAsync())
{ {
var saveItem = _mapper.Map<User>(item); var saveItem = _mapper.Map<User>(item);
@ -902,118 +906,7 @@ namespace IRaCIS.Core.Application.Contracts
#region 废弃
//Site 调研邀请
public async Task<IResponseOutput> SendInviteEmail(InviteEmailCommand inviteEmailCommand)
{
var trialInfo = await _repository.FirstOrDefaultAsync<Trial>(t => t.Id == inviteEmailCommand.TrialId);
foreach (var item in inviteEmailCommand.UserList)
{
var messageToSend = new MimeMessage();
//发件地址
messageToSend.From.Add(new MailboxAddress("GRR", "iracis_grr@163.com"));
//收件地址
messageToSend.To.Add(new MailboxAddress(String.Empty, item.Email));
//主题
//$"[来自展影IRC] [{trialInfo.ResearchProgramNo}] 邀请信";
messageToSend.Subject = _localizer["TrialSiteSurvey_IRCInvitation", trialInfo.ResearchProgramNo];
var builder = new BodyBuilder();
//找下系统中是否存在该用户类型的 并且邮箱 或者手机的账户
var sysUserInfo = await _userRepository.Where(t => t.UserTypeId == item.UserTypeId && t.EMail == item.Email).Include(t => t.UserTypeRole).FirstOrDefaultAsync();
//int verificationCode = new Random().Next(100000, 1000000);
//var baseApiUrl = baseUrl.Remove(baseUrl.IndexOf("#")) + "api";
if (sysUserInfo == null)
{
lock (lockObj)
{
var saveItem = _mapper.Map<User>(item);
saveItem.Code = _userRepository.Select(t => t.Code).DefaultIfEmpty().Max() + 1;
saveItem.UserCode = AppSettings.GetCodeStr(saveItem.Code, nameof(User)); ;
saveItem.UserName = saveItem.UserCode;
saveItem.UserTypeEnum = _repository.Where<UserType>(t => t.Id == saveItem.UserTypeId).Select(t => t.UserTypeEnum).First();
//saveItem.Password = MD5Helper.Md5(verificationCode.ToString());
_ = _repository.AddAsync(saveItem).Result;
_ = _repository.SaveChangesAsync().Result;
sysUserInfo = saveItem;
}
}
builder.HtmlBody = @$"<body style='font-family: 微软雅黑;padding: 0;margin: 0;'>
<div style='padding-left: 40px;background: #f6f6f6'>
<div style='padding-top: 20px;'>
<div style='line-height: 40px;font-size: 18px'>
{sysUserInfo.LastName + "/" + sysUserInfo.FirstName}:
</div>
<div style='line-height: 40px;padding-left: 40px;margin-bottom: 10px;'>
{_localizer["TrialSiteSurvey_IRCInvitationContent", trialInfo.ResearchProgramNo]}
</div>
<a href=' {inviteEmailCommand.RouteUrl + "?Id=" + item.Id + "&IsExternalUser=0"}' style='margin-left:60px;font-size:14px;text-decoration: none;display: inline-block;height: 40px;width: 140px;background: #00D1B2;color:#fff;border-radius: 5px;line-height: 40px;text-align: center;margin-bottom: 100px;'>
</a>
</div>
</div>
</body>";
messageToSend.Body = builder.ToMessageBody();
using (var smtp = new MailKit.Net.Smtp.SmtpClient())
{
smtp.ServerCertificateValidationCallback = (s, c, h, e) => true;
smtp.MessageSent += (sender, args) =>
{
_ = _trialSiteUserSurveyRepository.BatchUpdateNoTrackingAsync(t => t.Id == item.Id, u => new TrialSiteUserSurvey() { IsGenerateSuccess = true, InviteState = TrialSiteUserStateEnum.HasSend, ConfirmTime = null, RejectReason = String.Empty, SystemUserId = sysUserInfo.Id, ExpireTime = DateTime.Now.AddDays(7) }).Result;
};
await smtp.ConnectAsync("smtp.163.com", 465, SecureSocketOptions.StartTls);
await smtp.AuthenticateAsync("iracis_grr@163.com", "XLWVQKZAEKLDWOAH");
await smtp.SendAsync(messageToSend);
await smtp.DisconnectAsync(true);
}
}
return ResponseOutput.Ok();
}
#endregion

View File

@ -16,6 +16,7 @@ using Panda.DynamicWebApi.Attributes;
using IRaCIS.Core.Application.Auth; using IRaCIS.Core.Application.Auth;
using IRaCIS.Application.Services; using IRaCIS.Application.Services;
using IRaCIS.Core.Application.Filter; using IRaCIS.Core.Application.Filter;
using Medallion.Threading;
namespace IRaCIS.Core.Application.Service namespace IRaCIS.Core.Application.Service
{ {
@ -31,10 +32,11 @@ namespace IRaCIS.Core.Application.Service
private readonly IRepository<TrialSiteUserSurvey> _trialSiteSurveyUserRepository; private readonly IRepository<TrialSiteUserSurvey> _trialSiteSurveyUserRepository;
private readonly IRepository<TrialSiteUser> _trialSiteUserRepository; private readonly IRepository<TrialSiteUser> _trialSiteUserRepository;
private readonly IMailVerificationService _mailVerificationService; private readonly IMailVerificationService _mailVerificationService;
private readonly IDistributedLockProvider _distributedLockProvider;
public TrialExternalUserService(IRepository<TrialExternalUser> trialExternalUseRepository, IRepository<User> userRepository, IRepository<TrialUser> trialUserRepository, public TrialExternalUserService(IRepository<TrialExternalUser> trialExternalUseRepository, IRepository<User> userRepository, IRepository<TrialUser> trialUserRepository,
IRepository<TrialSiteUserSurvey> trialSiteSurveyUserRepository, IRepository<TrialSiteUser> trialSiteUserRepository, IRepository<TrialSiteUserSurvey> trialSiteSurveyUserRepository, IRepository<TrialSiteUser> trialSiteUserRepository,
IMailVerificationService mailVerificationService) IMailVerificationService mailVerificationService, IDistributedLockProvider distributedLockProvider)
{ {
_trialExternalUseRepository = trialExternalUseRepository; _trialExternalUseRepository = trialExternalUseRepository;
_userRepository = userRepository; _userRepository = userRepository;
@ -43,6 +45,7 @@ namespace IRaCIS.Core.Application.Service
_trialSiteUserRepository = trialSiteUserRepository; _trialSiteUserRepository = trialSiteUserRepository;
_mailVerificationService = mailVerificationService; _mailVerificationService = mailVerificationService;
_distributedLockProvider = distributedLockProvider;
} }
@ -74,6 +77,10 @@ namespace IRaCIS.Core.Application.Service
{ {
if (addOrEditTrialExternalUser.Id == null) if (addOrEditTrialExternalUser.Id == null)
{
var @lock = _distributedLockProvider.CreateLock($"UserCode");
using (await @lock.AcquireAsync())
{ {
var existSysUser = await _userRepository.FirstOrDefaultAsync(t => t.EMail == addOrEditTrialExternalUser.Email && t.UserTypeId == addOrEditTrialExternalUser.UserTypeId); var existSysUser = await _userRepository.FirstOrDefaultAsync(t => t.EMail == addOrEditTrialExternalUser.Email && t.UserTypeId == addOrEditTrialExternalUser.UserTypeId);
@ -168,7 +175,7 @@ namespace IRaCIS.Core.Application.Service
if (trialType == TrialType.NoneOfficial) if (trialType == TrialType.NoneOfficial)
{ {
if (existUser.IsTestUser == false ) if (existUser.IsTestUser == false)
{ {
//---测试项目 不允许加入正式用户 //---测试项目 不允许加入正式用户
throw new BusinessValidationFailedException(_localizer["TrialExternalUser_FormalUserNotAllowed"]); throw new BusinessValidationFailedException(_localizer["TrialExternalUser_FormalUserNotAllowed"]);
@ -204,6 +211,7 @@ namespace IRaCIS.Core.Application.Service
return ResponseOutput.Ok(addEntity.Id.ToString()); return ResponseOutput.Ok(addEntity.Id.ToString());
}
} }
else else

View File

@ -10,5 +10,7 @@ namespace IRaCIS.Core.Application.Interfaces
Task<IResponseOutput> SetSVExecuted(Guid subjectVisitId); Task<IResponseOutput> SetSVExecuted(Guid subjectVisitId);
Task<IResponseOutput> SetSubjectVisitUrgent(Guid subjectVisitId, bool isUrgent); Task<IResponseOutput> SetSubjectVisitUrgent(Guid subjectVisitId, bool isUrgent);
Task<List<VisitStudyDTO>> GetReadingVisitStudyList(GetReadingVisitStudyListIndto indto);
} }
} }

View File

@ -3,13 +3,17 @@ using IRaCIS.Core.Application.Service;
using IRaCIS.Core.Application.ViewModel; using IRaCIS.Core.Application.ViewModel;
using IRaCIS.Core.Domain.Share; using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure; using IRaCIS.Core.Infrastructure;
using MassTransit;
using Medallion.Threading;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using MiniExcelLibs; using MiniExcelLibs;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection.Metadata;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -20,6 +24,8 @@ namespace IRaCIS.Application.Services
[ApiExplorerSettings(GroupName = "Institution")] [ApiExplorerSettings(GroupName = "Institution")]
public class TestService : BaseService public class TestService : BaseService
{ {
public static int IntValue = 100;
private readonly IRepository<Dictionary> _dicRepository; private readonly IRepository<Dictionary> _dicRepository;
private readonly IRepository<Trial> _trialRepository; private readonly IRepository<Trial> _trialRepository;
@ -30,10 +36,13 @@ namespace IRaCIS.Application.Services
private readonly IOptionsMonitor<ServiceVerifyConfigOption> _basicConfig; private readonly IOptionsMonitor<ServiceVerifyConfigOption> _basicConfig;
private readonly IRepository<VisitTask> _visitTaskRepositoryy; private readonly IRepository<VisitTask> _visitTaskRepositoryy;
private readonly IDistributedLockProvider _distributedLockProvider;
public TestService(IRepository<Dictionary> dicRepository, IRepository<Trial> trialRepository/*, IDistributedCache cache*/ private readonly ILogger<TestService> _logger;
, IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig, IOptionsMonitor<ServiceVerifyConfigOption> basicConfig, IRepository<VisitTask> visitTaskRepository) public TestService(IRepository<Dictionary> dicRepository, IRepository<Trial> trialRepository,ILogger<TestService> logger
, IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig, IOptionsMonitor<ServiceVerifyConfigOption> basicConfig, IRepository<VisitTask> visitTaskRepository, IDistributedLockProvider distributedLockProvider)
{ {
_visitTaskRepositoryy = visitTaskRepository; _visitTaskRepositoryy = visitTaskRepository;
@ -42,11 +51,35 @@ namespace IRaCIS.Application.Services
_dicRepository = dicRepository; _dicRepository = dicRepository;
_trialRepository = trialRepository; _trialRepository = trialRepository;
_distributedLockProvider= distributedLockProvider;
_logger= logger;
//_cache = cache; //_cache = cache;
} }
[AllowAnonymous]
public async Task<IResponseOutput> TestDistributedLock( )
{
Console.WriteLine($"我进来了当前值是:" + IntValue);
_logger.LogWarning($"我进来了当前值是:" + IntValue);
var @lock = _distributedLockProvider.CreateLock($"UserAccount");
using (await @lock.AcquireAsync())
{
await Task.Delay(4);
IntValue--;
_logger.LogWarning( IntValue.ToString());
Console.WriteLine(IntValue);
}
return ResponseOutput.Ok(IntValue);
}
[AllowAnonymous] [AllowAnonymous]
public async Task<IResponseOutput> InternationazitionInit() public async Task<IResponseOutput> InternationazitionInit()