diff --git a/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs b/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs index 2df95233d..d5826b0d3 100644 --- a/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs +++ b/IRaCIS.Core.Application/Service/Inspection/InspectionService.cs @@ -140,18 +140,21 @@ namespace IRaCIS.Core.Application.Service.Inspection }; query = query.WhereIf(dto.SiteId != null, x => x.SiteId == dto.SiteId) - .WhereIf(dto.RelationDeadlineTime != null, x => x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1)) + //.WhereIf(dto.RelationDeadlineTime != null, x => x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1)) .WhereIf(dto.TrialId != null, t => (t.TrialId == dto.TrialId) || (t.CreateTime >= trialData.CreateTime && t.CreateTime <= trialData.TrialFinishTime)) .WhereIf(dto.BatchId != null && dto.ObjectRelationParentId == null && dto.GeneralId == null, x => x.BatchId == dto.BatchId) - .WhereIf(dto.BatchId != null && dto.GeneralId != null && dto.ObjectRelationParentId == null, x => x.BatchId == dto.BatchId || x.GeneralId == dto.GeneralId || x.ObjectRelationParentId== dto.GeneralId) - //父稽查 查看关联子记录 x.ObjectRelationParentId== dto.GeneralId + .WhereIf(dto.BatchId != null && dto.GeneralId != null && dto.ObjectRelationParentId == null, x => x.BatchId == dto.BatchId || + ((x.GeneralId == dto.GeneralId || x.ObjectRelationParentId == dto.GeneralId) && x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1))) .WhereIf(dto.ObjectRelationParentId != null && dto.BatchId != null && dto.GeneralId != null, - x => x.GeneralId == dto.ObjectRelationParentId || //子稽查 查询父记录 - x.GeneralId == dto.GeneralId || //同一对象 + x => x.BatchId == dto.BatchId || //同一事务批次 - x.ObjectRelationParentId == dto.GeneralId || //父稽查 查询子记录 - x.ObjectRelationParentId == dto.ObjectRelationParentId //不同对象 但是同一层级 - ) + x.ObjectRelationParentId == dto.ObjectRelationParentId || //不同对象 但是同一层级 适用于子对象 + + + ( ( x.GeneralId == dto.ObjectRelationParentId || //子稽查 查询父记录 + x.GeneralId == dto.GeneralId || //同一对象 + x.ObjectRelationParentId == dto.GeneralId //父稽查 查询子记录 + )&& x.CreateTime <= dto.RelationDeadlineTime.Value.AddSeconds(1))) .WhereIf(!dto.SubjectInfo.IsNullOrEmpty(), x => x.SubjectCode.Contains(dto.SubjectInfo)) //.WhereIf(dto.VisitPlanInfo != null&& dto.VisitPlanInfo!=(decimal) 1.11, x => x.VisitNum == dto.VisitPlanInfo) //.WhereIf(dto.VisitPlanInfo != (decimal)1.11,x=>x.InPlan!=null&& x.InPlan==false) diff --git a/IRaCIS.Core.Application/Service/Visit/SubjectService.cs b/IRaCIS.Core.Application/Service/Visit/SubjectService.cs index 8603dcabc..4ac5448f3 100644 --- a/IRaCIS.Core.Application/Service/Visit/SubjectService.cs +++ b/IRaCIS.Core.Application/Service/Visit/SubjectService.cs @@ -65,7 +65,7 @@ namespace IRaCIS.Application.Services - await _repository.SaveChangesAsync(); + await _subjectRepository.SaveChangesAsync(); return ResponseOutput.Ok(mapedSubject.Id.ToString()); diff --git a/IRaCIS.Core.Application/Triggers/AddSubjectTrigger.cs b/IRaCIS.Core.Application/Triggers/AddSubjectTrigger.cs index 2c94b729b..94a0cd2e6 100644 --- a/IRaCIS.Core.Application/Triggers/AddSubjectTrigger.cs +++ b/IRaCIS.Core.Application/Triggers/AddSubjectTrigger.cs @@ -52,7 +52,7 @@ namespace IRaCIS.Core.Application.Triggers await _subjectVisitRepository.AddRangeAsync(svList); - + await _subjectVisitRepository.SaveChangesAsync(); #region 在f访视计划确认的时候处理 给subject添加访视计划 ////已添加受试者 都不存在该新增的计划名称 那么该项目所有受试者都增加一个访视记录 diff --git a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs index e7c70d83d..6b1b32c8e 100644 --- a/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs +++ b/IRaCIS.Core.Infra.EFCore/Common/AuditingData.cs @@ -411,6 +411,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(entity, type, x => new InspectionConvertDTO() { + GeneralId=x.Id, SubjectId = x.Id, SubjectCode = x.Code, }, new @@ -543,13 +544,14 @@ namespace IRaCIS.Core.Infra.EFCore.Common var subjectCode = entity.Subject?.Code; await InsertInspection(item.Entity as SubjectVisit, type, x => new InspectionConvertDTO() { + GeneralId=x.Id, SubjectCode = subjectCode, SubjectId = x.SubjectId, SubjectVisitId = x.Id, SubjectVisitName = x.VisitName, BlindName = x.BlindName, Reason = reason, - }, null, item.OriginalValues); + }); } // 既往手术史 @@ -907,6 +909,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common await InsertInspection(item.Entity as ReadModule, type, x => new InspectionConvertDTO() { GeneralId = x.Id, + ObjectRelationParentId = entity.ReadingPeriodSetId, SubjectVisitId = x.SubjectVisitId, IsDistinctionInterface = false, }, new @@ -969,7 +972,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common /// 表达式 /// 其他对象 /// - public async Task InsertInspection(T entityObj, string type, Expression> expression = null, object otherItem = null, object originaldata = null) where T : class + public async Task InsertInspection(T entityObj, string type, Expression> expression = null, object otherItem = null, object originaldata = null) where T : Entity { InspectionConvertDTO inspection = new InspectionConvertDTO(); @@ -981,6 +984,8 @@ namespace IRaCIS.Core.Infra.EFCore.Common inspection = f(entityObj); } + //避免重复赋值 + inspection.GeneralId = entityObj.Id; inspection.Identification = await GetInspectionRecordIdentificationAsync(entityObj, type, inspection.IsDistinctionInterface); @@ -1028,7 +1033,7 @@ namespace IRaCIS.Core.Infra.EFCore.Common inspection.BatchId = _userInfo.BatchId.Value; - await _dbContext.DataInspection.AddAsync(inspection); + await _dbContext.DataInspection.AddAsync(inspection ); //await AddInspectionRecordAsync( entityObj, inspection, otherItem); diff --git a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs index 322cb6fe9..873687b71 100644 --- a/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs +++ b/IRaCIS.Core.Infra.EFCore/Context/IRaCISDBContext.cs @@ -463,8 +463,14 @@ namespace IRaCIS.Core.Infra.EFCore { try { - var entities = ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added)).Where(x => x.Entity.GetType() != typeof(DataInspection)).ToList(); + //触发器里面提交事务 业务方法里面提交事务 会记录两次 + var inspectionGeneralIdList = ChangeTracker.Entries().Where(t => typeof(DataInspection).IsAssignableFrom(t.Entity.GetType())).Select(t => ((DataInspection)t.Entity).GeneralId).ToList(); + + var entities = ChangeTracker.Entries().Where(u => (u.State == EntityState.Modified || u.State == EntityState.Deleted || u.State == EntityState.Added)) + .Where(t => ! typeof(DataInspection).IsAssignableFrom(t.Entity.GetType()) && !inspectionGeneralIdList.Contains(((Entity) t.Entity).Id )) + .ToList(); AuditingData auditingData = new AuditingData(this, _userInfo); + await auditingData.IncomingEntitys(entities); } catch (Exception) diff --git a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs index 0644f35f9..e7412d808 100644 --- a/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs +++ b/IRaCIS.Core.Infra.EFCore/Repository/Repository.cs @@ -394,6 +394,7 @@ namespace IRaCIS.Core.Infra.EFCore public async Task SaveChangesAsync(CancellationToken cancellationToken = default) { + return await _dbContext.SaveChangesAsync(cancellationToken) > 0; }