既往缓存代码修改,缓存key 整理
This commit is contained in:
@@ -12,6 +12,8 @@ using FellowOakDicom.Imaging.Codec;
|
||||
using System.Data;
|
||||
using IRaCIS.Core.Domain.Models;
|
||||
using FellowOakDicom.Network;
|
||||
using DocumentFormat.OpenXml.Drawing.Charts;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
namespace IRaCIS.Core.Application.Services
|
||||
{
|
||||
@@ -21,7 +23,6 @@ namespace IRaCIS.Core.Application.Services
|
||||
private readonly IRepository<DicomSeries> _seriesRepository;
|
||||
private readonly IRepository<DicomInstance> _instanceRepository;
|
||||
private readonly IRepository<Dictionary> _dictionaryRepository;
|
||||
private readonly IEasyCachingProvider _provider;
|
||||
|
||||
|
||||
private readonly IDistributedLockProvider _distributedLockProvider;
|
||||
@@ -33,7 +34,7 @@ namespace IRaCIS.Core.Application.Services
|
||||
IRepository<DicomSeries> seriesRepository,
|
||||
IRepository<DicomInstance> instanceRepository,
|
||||
IRepository<Dictionary> dictionaryRepository,
|
||||
IEasyCachingProvider provider, IDistributedLockProvider distributedLockProvider)
|
||||
IDistributedLockProvider distributedLockProvider)
|
||||
{
|
||||
_distributedLockProvider = distributedLockProvider;
|
||||
_studyRepository = studyRepository;
|
||||
@@ -42,7 +43,6 @@ namespace IRaCIS.Core.Application.Services
|
||||
|
||||
_instanceRepository = instanceRepository;
|
||||
_dictionaryRepository = dictionaryRepository;
|
||||
_provider = provider;
|
||||
|
||||
}
|
||||
|
||||
@@ -74,20 +74,15 @@ namespace IRaCIS.Core.Application.Services
|
||||
}
|
||||
|
||||
|
||||
var anonymize_AddFixedFiledList = _provider.Get<List<SystemAnonymization>>(StaticData.Anonymize.Anonymize_AddFixedFiled).Value ?? new List<SystemAnonymization>();
|
||||
var anonymize_AddIRCInfoFiledList = _provider.Get<List<SystemAnonymization>>(StaticData.Anonymize.Anonymize_AddIRCInfoFiled).Value ?? new List<SystemAnonymization>();
|
||||
var anonymize_FixedFieldList = _provider.Get<List<SystemAnonymization>>(StaticData.Anonymize.Anonymize_FixedField).Value ?? new List<SystemAnonymization>();
|
||||
var anonymize_IRCInfoFieldList = _provider.Get<List<SystemAnonymization>>(StaticData.Anonymize.Anonymize_IRCInfoField).Value ?? new List<SystemAnonymization>();
|
||||
var anonymizeList = await _fusionCache.GetOrSetAsync(CacheKeys.SystemAnonymization, _ => CacheHelper.GetSystemAnonymizationListAsync(_repository), TimeSpan.FromDays(7));
|
||||
|
||||
var fixedFiledList= anonymizeList.Where(t=>t.IsFixed).ToList();
|
||||
var ircFiledList = anonymizeList.Where(t => t.IsFixed==false).ToList();
|
||||
|
||||
|
||||
if (anonymize_AddFixedFiledList.Union(anonymize_AddIRCInfoFiledList).Union(anonymize_FixedFieldList).Union(anonymize_IRCInfoFieldList).Count() == 0)
|
||||
{
|
||||
//---未取到缓存匿名化配置数据,上传停止,请联系开发人员核实
|
||||
throw new BusinessValidationFailedException(_localizer["DAS_NoAnonCacheData"]);
|
||||
}
|
||||
|
||||
|
||||
foreach (var item in anonymize_AddFixedFiledList.Union(anonymize_FixedFieldList))
|
||||
foreach (var item in fixedFiledList)
|
||||
{
|
||||
|
||||
var dicomTag = new DicomTag(Convert.ToUInt16(item.Group, 16), Convert.ToUInt16(item.Element, 16));
|
||||
@@ -95,7 +90,7 @@ namespace IRaCIS.Core.Application.Services
|
||||
dataset.AddOrUpdate(dicomTag, item.ReplaceValue);
|
||||
}
|
||||
|
||||
foreach (var item in anonymize_AddIRCInfoFiledList.Union(anonymize_IRCInfoFieldList))
|
||||
foreach (var item in ircFiledList)
|
||||
{
|
||||
|
||||
var dicomTag = new DicomTag(Convert.ToUInt16(item.Group, 16), Convert.ToUInt16(item.Element, 16));
|
||||
@@ -196,7 +191,7 @@ namespace IRaCIS.Core.Application.Services
|
||||
}
|
||||
|
||||
|
||||
private DicomStudy CreateDicomStudy(DicomDataset dataset, DicomTrialSiteSubjectInfo addtionalInfo, out bool isStudyNeedAdd)
|
||||
private DicomStudy CreateDicomStudy(DicomDataset dataset, DicomTrialSiteSubjectInfo addtionalInfo, out bool isStudyNeedAdd)
|
||||
{
|
||||
|
||||
string studyInstanceUid = dataset.GetString(DicomTag.StudyInstanceUID);
|
||||
@@ -291,7 +286,7 @@ namespace IRaCIS.Core.Application.Services
|
||||
var dbStudyCodeIntMax = _studyRepository.Where(s => s.TrialId == addtionalInfo.TrialId).Select(t => t.Code).DefaultIfEmpty().Max();
|
||||
|
||||
//获取缓存中的值 并发的时候,需要记录,已被占用的值 这样其他线程在此占用的最大的值上递增
|
||||
var cacheMaxCodeInt = _provider.Get<int>($"{addtionalInfo.TrialId}_{StaticData.CacheKey.StudyMaxCode}").Value;
|
||||
var cacheMaxCodeInt = _fusionCache.GetOrDefault<int>(CacheKeys.TrialStudyMaxCode(addtionalInfo.TrialId));
|
||||
|
||||
int currentNextCodeInt = cacheMaxCodeInt > dbStudyCodeIntMax ? cacheMaxCodeInt + 1 : dbStudyCodeIntMax + 1;
|
||||
|
||||
@@ -299,53 +294,10 @@ namespace IRaCIS.Core.Application.Services
|
||||
|
||||
dicomStudy.StudyCode = AppSettings.GetCodeStr(currentNextCodeInt, nameof(DicomStudy));
|
||||
|
||||
_provider.Set<int>($"{addtionalInfo.TrialId}_{StaticData.CacheKey.StudyMaxCode}", dicomStudy.Code, TimeSpan.FromMinutes(30));
|
||||
_fusionCache.Set(CacheKeys.TrialStudyMaxCode(addtionalInfo.TrialId), dicomStudy.Code, TimeSpan.FromMinutes(30));
|
||||
}
|
||||
|
||||
|
||||
#region Setting Code old
|
||||
|
||||
//var studyCode = _studyRepository.Where(s => s.TrialId == addtionalInfo.TrialId).Select(t => t.StudyCode).OrderByDescending(c => c).FirstOrDefault();
|
||||
|
||||
//var cacheMaxCode = _provider.Get<string>($"{addtionalInfo.TrialId }_{ StaticData.StudyMaxCode}").Value;
|
||||
|
||||
//if (studyCode == null && string.IsNullOrEmpty(cacheMaxCode))
|
||||
//{
|
||||
// dicomStudy.StudyCode = "ST" + 1.ToString().PadLeft(5, '0');
|
||||
|
||||
// _logger.LogWarning($"Thread {id} DB:{studyCode} 生成{ dicomStudy.StudyCode}");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// int dbNum = 0;
|
||||
|
||||
// int cacheNum = 0;
|
||||
|
||||
// if (studyCode != null)
|
||||
// {
|
||||
// int.TryParse(studyCode.Substring(studyCode.Length - 5, 5), out dbNum);
|
||||
// }
|
||||
|
||||
// if (!string.IsNullOrEmpty(cacheMaxCode))
|
||||
// {
|
||||
// int.TryParse(cacheMaxCode.Substring(cacheMaxCode.Length - 5, 5), out cacheNum);
|
||||
// }
|
||||
|
||||
// dbNum = cacheNum > dbNum ? cacheNum : dbNum;
|
||||
|
||||
|
||||
// dicomStudy.StudyCode = "ST" + (++dbNum).ToString().PadLeft(5, '0');
|
||||
|
||||
// _logger.LogWarning($" Thread {id} DB:{studyCode} cache:{cacheNum} 生成{ dicomStudy.StudyCode}");
|
||||
//}
|
||||
|
||||
//_provider.Set<string>($"{addtionalInfo.TrialId }_{ StaticData.StudyMaxCode}", dicomStudy.StudyCode, TimeSpan.FromMinutes(30));
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
return dicomStudy;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user