稽查通用缓存添加
parent
f1fb2068de
commit
7f050a1dd6
|
|
@ -64,7 +64,6 @@
|
|||
<PackageReference Include="RestSharp" Version="112.1.0" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.11" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
|
||||
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
|
|||
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
using static IRaCIS.Core.Domain.Share.StaticData;
|
||||
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Common
|
||||
|
|
@ -39,16 +41,20 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
/// </summary>
|
||||
public IUserInfo _userInfo { get; set; }
|
||||
|
||||
public IFusionCache _fusionCache { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 构造方法
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="userInfo"></param>
|
||||
public AuditingData(IRaCISDBContext dbContext, IUserInfo userInfo)
|
||||
public AuditingData(IRaCISDBContext dbContext, IUserInfo userInfo, IFusionCache fusionCache)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_userInfo = userInfo;
|
||||
_userInfo.BatchId = _userInfo.BatchId == null ? NewId.NextGuid() : _userInfo.BatchId;
|
||||
_fusionCache = fusionCache;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -262,7 +268,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
var entity = item.Entity as ReadingImportFile;
|
||||
|
||||
|
||||
var visitTaskInfo = await _dbContext.VisitTask.Where(x => x.Id == entity.VisitTaskId).Include(x=>x.DoctorUser).FirstOrDefaultAsync();
|
||||
var visitTaskInfo = await _dbContext.VisitTask.Where(x => x.Id == entity.VisitTaskId).Include(x => x.DoctorUser).FirstOrDefaultAsync();
|
||||
|
||||
await InsertInspection<ReadingImportFile>(entity, type, x => new InspectionConvertDTO()
|
||||
{
|
||||
|
|
@ -3696,7 +3702,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
|
||||
string questionName = string.Empty;
|
||||
string questionAnswer = string.Empty;
|
||||
if (thisQuestinonAnswer != null&& question!=null)
|
||||
if (thisQuestinonAnswer != null && question != null)
|
||||
{
|
||||
questionName = _userInfo.IsEn_Us ? question.QuestionEnName : question.QuestionName;
|
||||
questionAnswer = Translationunit(question.Type, question.Unit, question.CustomUnit, unitDataList, thisQuestinonAnswer.Answer);
|
||||
|
|
@ -3857,7 +3863,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
|
||||
entity.OrderMark = await _dbContext.ReadingQuestionTrial.Where(x => x.Id == entity.QuestionId).Select(x => x.OrderMark).FirstOrDefaultAsync();
|
||||
|
||||
entity.RowMark = entity.OrderMark+ entity.RowIndex.GetLesionMark();
|
||||
entity.RowMark = entity.OrderMark + entity.RowIndex.GetLesionMark();
|
||||
|
||||
|
||||
|
||||
|
|
@ -4174,7 +4180,17 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
|
||||
#region 处理标识
|
||||
|
||||
var from = await _dbContext.FrontAuditConfig.FirstOrDefaultAsync(x => x.Identification == inspection.Identification);
|
||||
//批量记录instance 这种稽查的时候,减少数据库查询交互 --稽查缓存
|
||||
var from = await _fusionCache.GetOrSetAsync(InspectionCacheKeys.FrontAuditConfig(inspection.Identification), async _ =>
|
||||
{
|
||||
return await _dbContext.FrontAuditConfig
|
||||
.FirstOrDefaultAsync(x => x.Identification == inspection.Identification);
|
||||
},
|
||||
TimeSpan.FromMinutes(10) // 缓存 10 分钟
|
||||
);
|
||||
|
||||
//var from = await _dbContext.FrontAuditConfig.FirstOrDefaultAsync(x => x.Identification == inspection.Identification);
|
||||
|
||||
inspection.ObjectTypeId = from?.ObjectTypeId;
|
||||
inspection.OptTypeId = from?.OptTypeId;
|
||||
//inspection.ChildrenTypeId = from?.ChildrenTypeId;
|
||||
|
|
@ -4273,14 +4289,20 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
};
|
||||
|
||||
|
||||
|
||||
|
||||
if (inspection.VisitTaskId != null)
|
||||
{
|
||||
|
||||
if (generalData.TrialId == null || generalData.TrialSiteId == null || generalData.SubjectId == null || generalData.TrialReadingCriterionId == null)
|
||||
{
|
||||
var info = await _dbContext.VisitTask.Where(x => x.Id == inspection.VisitTaskId).Select(x => new { SubjectCode = x.Subject.Code, TrialSiteCode = x.Subject.TrialSite.TrialSiteCode, SubjectId = x.SubjectId, x.Subject.TrialSiteId, x.TrialId, x.SourceSubjectVisitId, ReadModuleSubjectVisitId = (Guid?)x.ReadModule.SubjectVisitId, x.TrialReadingCriterionId }).FirstOrDefaultAsync();
|
||||
//var info = await _dbContext.VisitTask.Where(x => x.Id == inspection.VisitTaskId).Select(x => new { SubjectCode = x.Subject.Code, TrialSiteCode = x.Subject.TrialSite.TrialSiteCode, SubjectId = x.SubjectId, x.Subject.TrialSiteId, x.TrialId, x.SourceSubjectVisitId, ReadModuleSubjectVisitId = (Guid?)x.ReadModule.SubjectVisitId, x.TrialReadingCriterionId }).FirstOrDefaultAsync();
|
||||
|
||||
var info = await _fusionCache.GetOrSetAsync(InspectionCacheKeys.VisitTask(inspection.VisitTaskId), async _ =>
|
||||
{
|
||||
return await _dbContext.VisitTask.Where(x => x.Id == inspection.VisitTaskId).Select(x => new { SubjectCode = x.Subject.Code, TrialSiteCode = x.Subject.TrialSite.TrialSiteCode, SubjectId = x.SubjectId, x.Subject.TrialSiteId, x.TrialId, x.SourceSubjectVisitId, ReadModuleSubjectVisitId = (Guid?)x.ReadModule.SubjectVisitId, x.TrialReadingCriterionId }).FirstOrDefaultAsync();
|
||||
|
||||
},
|
||||
TimeSpan.FromDays(1) // 缓存 1天
|
||||
);
|
||||
|
||||
generalData.TrialReadingCriterionId = info?.TrialReadingCriterionId ?? generalData.TrialReadingCriterionId;
|
||||
generalData.TrialId = info?.TrialId ?? generalData.TrialId;
|
||||
|
|
@ -4299,7 +4321,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
{
|
||||
if (generalData.TrialId == null)
|
||||
{
|
||||
var info = await _dbContext.ReadingQuestionCriterionTrial.Where(x => x.Id == inspection.TrialReadingCriterionId).Select(x => new { x.TrialId }).FirstOrDefaultAsync();
|
||||
var info = await _fusionCache.GetOrSetAsync(InspectionCacheKeys.ReadingQuestionCriterionTrial(inspection.TrialReadingCriterionId), async _ =>
|
||||
{
|
||||
return await _dbContext.ReadingQuestionCriterionTrial.Where(x => x.Id == inspection.TrialReadingCriterionId).Select(x => new { x.TrialId }).FirstOrDefaultAsync();
|
||||
},
|
||||
TimeSpan.FromDays(1) // 缓存 1天
|
||||
);
|
||||
|
||||
//var info = await _dbContext.ReadingQuestionCriterionTrial.Where(x => x.Id == inspection.TrialReadingCriterionId).Select(x => new { x.TrialId }).FirstOrDefaultAsync();
|
||||
|
||||
generalData.TrialId = info?.TrialId ?? generalData.TrialId;
|
||||
}
|
||||
|
|
@ -4311,8 +4340,17 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
{
|
||||
if (generalData.TrialId == null || generalData.TrialSiteId == null || generalData.SubjectId == null)
|
||||
{
|
||||
var info = await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x =>
|
||||
|
||||
var info = await _fusionCache.GetOrSetAsync(InspectionCacheKeys.SubjectVisit(inspection.SubjectVisitId), async _ =>
|
||||
{
|
||||
return await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x =>
|
||||
new { x.SubjectId, x.TrialSiteId, x.TrialId, SubjectCode = x.Subject.Code, TrialSiteCode = x.Subject.TrialSite.TrialSiteCode }).FirstOrDefaultAsync();
|
||||
},
|
||||
TimeSpan.FromDays(1) // 缓存 1天
|
||||
);
|
||||
|
||||
// var info = await _dbContext.SubjectVisit.Where(x => x.Id == generalData.SubjectVisitId).Select(x =>
|
||||
//new { x.SubjectId, x.TrialSiteId, x.TrialId, SubjectCode = x.Subject.Code, TrialSiteCode = x.Subject.TrialSite.TrialSiteCode }).FirstOrDefaultAsync();
|
||||
|
||||
|
||||
generalData.TrialId = info?.TrialId ?? generalData.TrialId;
|
||||
|
|
@ -4332,7 +4370,15 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
{
|
||||
if (generalData.TrialId == null || generalData.TrialSiteId == null)
|
||||
{
|
||||
var info = await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { SubjectId = x.Id, x.TrialSiteId, x.TrialId, SubjectCode = x.Code, TrialSiteCode = x.TrialSite.TrialSiteCode }).FirstOrDefaultAsync();
|
||||
//var info = await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { SubjectId = x.Id, x.TrialSiteId, x.TrialId, SubjectCode = x.Code, TrialSiteCode = x.TrialSite.TrialSiteCode }).FirstOrDefaultAsync();
|
||||
|
||||
var info = await _fusionCache.GetOrSetAsync(InspectionCacheKeys.SubjecSiteInfo(inspection.SubjectId), async _ =>
|
||||
{
|
||||
return await _dbContext.Subject.Where(x => x.Id == generalData.SubjectId).Select(x => new { SubjectId = x.Id, x.TrialSiteId, x.TrialId, SubjectCode = x.Code, TrialSiteCode = x.TrialSite.TrialSiteCode }).FirstOrDefaultAsync();
|
||||
},
|
||||
TimeSpan.FromDays(1) // 缓存 1天
|
||||
);
|
||||
|
||||
|
||||
if (info == null)
|
||||
{
|
||||
|
|
@ -4348,11 +4394,6 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
generalData.TrialSiteId = info?.TrialSiteId ?? generalData.TrialSiteId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//以后移除
|
||||
generalData.SiteCode = info?.TrialSiteCode ?? generalData.SiteCode;
|
||||
generalData.SubjectCode = info?.SubjectCode ?? generalData.SubjectCode;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,20 @@ using IRaCIS.Core.Domain.Share;
|
|||
|
||||
namespace IRaCIS.Core.Infra.EFCore.Common
|
||||
{
|
||||
public static class InspectionCacheKeys
|
||||
{
|
||||
public static string FrontAuditConfig(string identification) => $"FrontAuditConfig:{identification}";
|
||||
|
||||
public static string ReadingQuestionCriterionTrial(Guid? trialReadingCriterionId) => $"ReadingQuestionCriterionTrial:{trialReadingCriterionId}";
|
||||
|
||||
public static string SubjectVisit(Guid? subjectVisitId) => $"SubjectVisit:{subjectVisitId}";
|
||||
|
||||
public static string SubjecSiteInfo(Guid? subjectId) => $"Subject:{subjectId}";
|
||||
|
||||
public static string VisitTask(Guid? visitTaskId) => $"VisitTask:{visitTaskId}";
|
||||
}
|
||||
|
||||
|
||||
public class SetInspectionEnumDataDto
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
|
|
@ -63,7 +77,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common
|
|||
|
||||
public string SelectResult { get; set; }
|
||||
|
||||
public bool? IsReadingReset { get;set; }
|
||||
public bool? IsReadingReset { get; set; }
|
||||
}
|
||||
public class InspectionConvertDTO : DataInspection
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging;
|
|||
using Microsoft.VisualBasic;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using ZiggyCreatures.Caching.Fusion;
|
||||
|
||||
|
||||
namespace IRaCIS.Core.Infra.EFCore;
|
||||
|
|
@ -23,7 +24,7 @@ namespace IRaCIS.Core.Infra.EFCore;
|
|||
/// <param name="_mediator"></param>
|
||||
public class AuditEntityInterceptor(IUserInfo _userInfo,
|
||||
ILogger<AuditEntityInterceptor> _logger
|
||||
, IMediator _mediator
|
||||
, IMediator _mediator, IFusionCache _fusionCache
|
||||
) : SaveChangesInterceptor
|
||||
{
|
||||
|
||||
|
|
@ -157,7 +158,7 @@ public class AuditEntityInterceptor(IUserInfo _userInfo,
|
|||
.Where(t => !typeof(DataInspection).IsAssignableFrom(t.Entity.GetType()) && typeof(Entity).IsAssignableFrom(t.Entity.GetType())
|
||||
&& !inspectionGeneralIdList.Contains(((Entity)t.Entity).Id))
|
||||
.ToList();
|
||||
AuditingData auditingData = new AuditingData((IRaCISDBContext)context, _userInfo);
|
||||
AuditingData auditingData = new AuditingData((IRaCISDBContext)context, _userInfo, _fusionCache);
|
||||
|
||||
|
||||
if (entities.Count > 0)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
<PackageReference Include="SharpZipLib" Version="1.4.2" />
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.6.0.2" />
|
||||
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue